2015-05-22 17:26:19 +00:00
|
|
|
// Copyright (c) 2015 The Khronos Group Inc.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and/or associated documentation files (the
|
|
|
|
// "Materials"), to deal in the Materials without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Materials, and to
|
|
|
|
// permit persons to whom the Materials are furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Materials.
|
|
|
|
//
|
|
|
|
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
|
|
|
|
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
|
|
|
|
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
|
|
|
|
// https://www.khronos.org/registry/
|
|
|
|
//
|
|
|
|
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
|
|
|
2015-12-22 20:15:46 +00:00
|
|
|
#include "source/spirv_constant.h"
|
2015-11-17 21:46:55 +00:00
|
|
|
#include "UnitSPIRV.h"
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-08-31 19:24:32 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
class BinaryHeaderGet : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
BinaryHeaderGet() { memset(code, 0, sizeof(code)); }
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
2015-11-11 15:17:16 +00:00
|
|
|
code[0] = SpvMagicNumber;
|
|
|
|
code[1] = SpvVersion;
|
2015-05-22 17:26:19 +00:00
|
|
|
code[2] = SPV_GENERATOR_CODEPLAY;
|
|
|
|
code[3] = 1; // NOTE: Bound
|
|
|
|
code[4] = 0; // NOTE: Schema; reserved
|
|
|
|
code[5] = 0; // NOTE: Instructions
|
|
|
|
|
|
|
|
binary.code = code;
|
|
|
|
binary.wordCount = 6;
|
|
|
|
}
|
2015-11-11 16:05:07 +00:00
|
|
|
spv_const_binary_t get_const_binary() {
|
|
|
|
return spv_const_binary_t{binary.code, binary.wordCount};
|
|
|
|
}
|
2015-05-22 17:26:19 +00:00
|
|
|
virtual void TearDown() {}
|
|
|
|
|
|
|
|
uint32_t code[6];
|
|
|
|
spv_binary_t binary;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(BinaryHeaderGet, Default) {
|
|
|
|
spv_endianness_t endian;
|
2015-11-11 16:05:07 +00:00
|
|
|
spv_const_binary_t const_bin = get_const_binary();
|
|
|
|
ASSERT_EQ(SPV_SUCCESS, spvBinaryEndianness(&const_bin, &endian));
|
2015-05-22 17:26:19 +00:00
|
|
|
|
|
|
|
spv_header_t header;
|
2015-11-11 16:05:07 +00:00
|
|
|
ASSERT_EQ(SPV_SUCCESS, spvBinaryHeaderGet(&const_bin, endian, &header));
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-11 15:17:16 +00:00
|
|
|
ASSERT_EQ(static_cast<uint32_t>(SpvMagicNumber), header.magic);
|
2015-11-18 14:22:10 +00:00
|
|
|
ASSERT_EQ(0x10000u, header.version);
|
2015-11-11 15:17:16 +00:00
|
|
|
ASSERT_EQ(static_cast<uint32_t>(SPV_GENERATOR_CODEPLAY), header.generator);
|
2015-05-22 17:26:19 +00:00
|
|
|
ASSERT_EQ(1u, header.bound);
|
|
|
|
ASSERT_EQ(0u, header.schema);
|
|
|
|
ASSERT_EQ(&code[5], header.instructions);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BinaryHeaderGet, InvalidCode) {
|
2015-11-11 16:05:07 +00:00
|
|
|
spv_const_binary_t binary = {nullptr, 0};
|
2015-05-22 17:26:19 +00:00
|
|
|
spv_header_t header;
|
|
|
|
ASSERT_EQ(SPV_ERROR_INVALID_BINARY,
|
|
|
|
spvBinaryHeaderGet(&binary, SPV_ENDIANNESS_LITTLE, &header));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(BinaryHeaderGet, InvalidPointerHeader) {
|
2015-11-11 16:05:07 +00:00
|
|
|
spv_const_binary_t const_bin = get_const_binary();
|
2015-05-22 17:26:19 +00:00
|
|
|
ASSERT_EQ(SPV_ERROR_INVALID_POINTER,
|
2015-11-11 16:05:07 +00:00
|
|
|
spvBinaryHeaderGet(&const_bin, SPV_ENDIANNESS_LITTLE, nullptr));
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
2015-08-31 19:24:32 +00:00
|
|
|
|
2015-10-30 20:06:15 +00:00
|
|
|
TEST_F(BinaryHeaderGet, TruncatedHeader) {
|
2015-11-18 14:22:10 +00:00
|
|
|
for (uint8_t i = 1; i < SPV_INDEX_INSTRUCTION; i++) {
|
2015-10-30 20:06:15 +00:00
|
|
|
binary.wordCount = i;
|
2015-11-11 16:05:07 +00:00
|
|
|
spv_const_binary_t const_bin = get_const_binary();
|
2015-10-30 20:06:15 +00:00
|
|
|
ASSERT_EQ(SPV_ERROR_INVALID_BINARY,
|
2015-11-11 16:05:07 +00:00
|
|
|
spvBinaryHeaderGet(&const_bin, SPV_ENDIANNESS_LITTLE, nullptr));
|
2015-10-30 20:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 19:24:32 +00:00
|
|
|
} // anonymous namespace
|