spvTextWithFormatToBinary(
text.str, text.length, SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL,
opcodeTable, operandTable, extInstTable, &binary, &diagnostic));
- ASSERT_TRUE(diagnostic);
+ ASSERT_NE(nullptr, diagnostic);
EXPECT_STREQ(
"Expected <opcode> at the beginning of an instruction, found '%2'.",
diagnostic->error);
spvTextWithFormatToBinary(
text.str, text.length, SPV_ASSEMBLY_SYNTAX_FORMAT_ASSIGNMENT,
opcodeTable, operandTable, extInstTable, &binary, &diagnostic));
- ASSERT_TRUE(diagnostic);
+ ASSERT_NE(nullptr, diagnostic);
EXPECT_STREQ(
"Expected <result-id> at the beginning of an instruction, found "
"'OpConstant'.",
spvTextWithFormatToBinary(
text.str, text.length, SPV_ASSEMBLY_SYNTAX_FORMAT_ASSIGNMENT,
opcodeTable, operandTable, extInstTable, &binary, &diagnostic));
- ASSERT_TRUE(diagnostic);
+ ASSERT_NE(nullptr, diagnostic);
EXPECT_STREQ(
"Expected <result-id> at the beginning of an instruction, found "
"'OpConstant'.",
spvTextWithFormatToBinary(
text.str, text.length, SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL,
opcodeTable, operandTable, extInstTable, &binary, &diagnostic));
- ASSERT_TRUE(diagnostic);
+ ASSERT_NE(nullptr, diagnostic);
EXPECT_STREQ(
"Expected <opcode> at the beginning of an instruction, found '%3'.",
diagnostic->error);
// A test case for typed mask expansion
struct MaskExpansionCase {
- const spv_operand_type_t type;
- const uint32_t mask;
- const spv_operand_pattern_t initial;
- const spv_operand_pattern_t expected;
+ spv_operand_type_t type;
+ uint32_t mask;
+ spv_operand_pattern_t initial;
+ spv_operand_pattern_t expected;
};
using MaskExpansionTest = ::testing::TestWithParam<MaskExpansionCase>;
ASSERT_EQ(SPV_SUCCESS, spvTextToLiteral("-2147483648", &l));
EXPECT_EQ(SPV_LITERAL_TYPE_INT_32, l.type);
- EXPECT_EQ(-2147483648, l.value.i32);
+ EXPECT_EQ((-2147483647L - 1), l.value.i32);
}
TEST(TextLiteral, GoodU32) {
ASSERT_EQ(SPV_SUCCESS, spvTextToLiteral("-2147483649", &l));
EXPECT_EQ(SPV_LITERAL_TYPE_INT_64, l.type);
- EXPECT_EQ(-2147483649, l.value.i64);
+ EXPECT_EQ(-2147483649LL, l.value.i64);
}
TEST(TextLiteral, GoodU64) {
TEST(TextStartsWithOp, YesForValueGenerationForm) {
spv_position_t startPosition = {};
EXPECT_TRUE(
- spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
+ spvTextIsStartOfNewInst(AutoText("%foo = OpAdd"), &startPosition));
EXPECT_TRUE(
- spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
+ spvTextIsStartOfNewInst(AutoText("%foo = OpAdd"), &startPosition));
}
TEST(TextStartsWithOp, NoForNearlyValueGeneration) {
spv_position_t startPosition = {};
- EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("\%foo = "), &startPosition));
- EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("\%foo "), &startPosition));
- EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("\%foo"), &startPosition));
+ EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("%foo = "), &startPosition));
+ EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("%foo "), &startPosition));
+ EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("%foo"), &startPosition));
}
struct DecorateSimpleCase {
// Place the enum value first, so it's easier to read the binary dumps when
// the test fails.
- const spv::Decoration decoration;
- const std::string name;
- const std::vector<uint32_t> operands;
+ spv::Decoration decoration;
+ std::string name;
+ std::vector<uint32_t> operands;
};
using OpDecorateSimpleTest =
struct DecorateEnumCase {
// Place the enum value first, so it's easier to read the binary dumps when
// the test fails.
- const uint32_t value; // The value within the enum, e.g. Position
- const std::string name;
- const uint32_t enum_value; // Which enum, e.g. BuiltIn
- const std::string enum_name;
+ uint32_t value; // The value within the enum, e.g. Position
+ std::string name;
+ uint32_t enum_value; // Which enum, e.g. BuiltIn
+ std::string enum_name;
};
using OpDecorateEnumTest = test_fixture::TextToBinaryTestBase<
// A single test case for a linkage
struct DecorateLinkageCase {
- const uint32_t linkage_type_value;
- const std::string linkage_type_name;
- const std::string external_name;
+ uint32_t linkage_type_value;
+ std::string linkage_type_name;
+ std::string external_name;
};
using OpDecorateLinkageTest = test_fixture::TextToBinaryTestBase<
using spvtest::MakeInstruction;
using ::testing::Eq;
-// An example case for an enumerated value.
-template <typename E>
-struct EnumCase {
- E value;
- std::string name;
-};
-
// Test Sampler Addressing Mode enum values
using SamplerAddressingModeTest = test_fixture::TextToBinaryTestBase<
"%result = OpConstantSampler %type " + GetParam().name + " 0 Nearest";
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpConstantSampler,
- {1, 2, GetParam().value, 0, 0})));
+ {1, 2, GetParam().get_value(), 0, 0})));
}
// clang-format off
"%result = OpConstantSampler %type Clamp 0 " + GetParam().name;
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpConstantSampler,
- {1, 2, 2, 0, GetParam().value})));
+ {1, 2, 2, 0, GetParam().get_value()})));
}
// clang-format off
using ::testing::Eq;
using test_fixture::TextToBinaryTest;
-// An example case for an enumerated value.
-template <typename E>
-struct EnumCase {
- E value;
- std::string name;
-};
-
// Test OpSelectionMerge
using OpSelectionMergeTest = test_fixture::TextToBinaryTestBase<
std::string input = "OpSelectionMerge %1 " + GetParam().name;
EXPECT_THAT(
CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpSelectionMerge, {1, GetParam().value})));
+ Eq(MakeInstruction(spv::OpSelectionMerge, {1, GetParam().get_value()})));
}
// clang-format off
TEST_P(OpLoopMergeTest, AnySingleLoopControlMask) {
std::string input = "OpLoopMerge %1 " + GetParam().name;
- EXPECT_THAT(CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpLoopMerge, {1, GetParam().value})));
+ EXPECT_THAT(
+ CompiledInstructions(input),
+ Eq(MakeInstruction(spv::OpLoopMerge, {1, GetParam().get_value()})));
}
// clang-format off
// A single test case for OpSource
struct LanguageCase {
- const char* language_name;
- const spv::SourceLanguage language_value;
- const uint32_t version;
+ uint32_t get_language_value() const {
+ return static_cast<uint32_t>(language_value);
+ }
+ char* language_name;
+ spv::SourceLanguage language_value;
+ uint32_t version;
};
// clang-format off
std::string input = std::string("OpSource ") + GetParam().language_name +
" " + std::to_string(GetParam().version);
EXPECT_THAT(CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpSource, {GetParam().language_value,
+ Eq(MakeInstruction(spv::OpSource, {GetParam().get_language_value(),
GetParam().version})));
}
using ::testing::Eq;
using test_fixture::TextToBinaryTest;;
-// An example case for an enumerated value.
-template <typename E>
-struct EnumCase {
- E value;
- std::string name;
-};
-
// Test OpFunction
using OpFunctionControlTest = test_fixture::TextToBinaryTestBase<
GetParam().name + " %function_type ";
EXPECT_THAT(
CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpFunction, {1, 2, GetParam().value, 3})));
+ Eq(MakeInstruction(spv::OpFunction, {1, 2, GetParam().get_value(), 3})));
}
// clang-format off
using spvtest::MakeInstruction;
using ::testing::Eq;
-// An example case for an enumerated value.
-template <typename E>
-struct EnumCase {
- E value;
- std::string name;
-};
-
// Test GroupOperation enum
-using GroupOperationTest =
- test_fixture::TextToBinaryTestBase <
+using GroupOperationTest = test_fixture::TextToBinaryTestBase<
::testing::TestWithParam<EnumCase<spv::GroupOperation>>>;
TEST_P(GroupOperationTest, AnyGroupOperation) {
std::string input =
"%result = OpGroupIAdd %type %scope " + GetParam().name + " %x";
- EXPECT_THAT(
- CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpGroupIAdd, {1, 2, 3, GetParam().value, 4})));
+ EXPECT_THAT(CompiledInstructions(input),
+ Eq(MakeInstruction(spv::OpGroupIAdd,
+ {1, 2, 3, GetParam().get_value(), 4})));
}
// clang-format off
// An example case for an enumerated value.
template <typename E>
struct EnumCaseWithOperands {
+ uint32_t get_value() const { return static_cast<uint32_t>(value); }
E value;
std::string name;
std::vector<uint32_t> operands;
std::stringstream input;
input << "OpStore %ptr %value " << GetParam().name;
for (auto operand : GetParam().operands) input << " " << operand;
- std::vector<uint32_t> expected_operands{1, 2, GetParam().value};
+ std::vector<uint32_t> expected_operands{1, 2, GetParam().get_value()};
expected_operands.insert(expected_operands.end(), GetParam().operands.begin(),
GetParam().operands.end());
EXPECT_THAT(CompiledInstructions(input.str()),
TEST_P(StorageClassTest, AnyStorageClass) {
std::string input = "%1 = OpVariable %2 " + GetParam().name;
EXPECT_THAT(CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpVariable, {2, 1, GetParam().value})));
+ Eq(MakeInstruction(spv::OpVariable, {2, 1, GetParam().get_value()})));
}
// clang-format off
// An example case for OpMemoryModel
struct MemoryModelCase {
+ uint32_t get_addressing_value() const {
+ return static_cast<uint32_t>(addressing_value);
+ }
+ uint32_t get_memory_value() const {
+ return static_cast<uint32_t>(memory_value);
+ }
spv::AddressingModel addressing_value;
std::string addressing_name;
spv::MemoryModel memory_value;
GetParam().memory_name;
EXPECT_THAT(
CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpMemoryModel, {GetParam().addressing_value,
- GetParam().memory_value})));
+ Eq(MakeInstruction(spv::OpMemoryModel, {GetParam().get_addressing_value(),
+ GetParam().get_memory_value()})));
}
#define CASE(ADDRESSING, MEMORY) \
// An example case for OpEntryPoint
struct EntryPointCase {
+ uint32_t get_execution_value() const {
+ return static_cast<uint32_t>(execution_value);
+ }
spv::ExecutionModel execution_value;
std::string execution_name;
std::string entry_point_name;
TEST_P(OpEntryPointTest, AnyEntryPointCase) {
// TODO(dneto): utf-8, escaping, quoting cases for entry point name.
- std::string input = "OpEntryPoint " + GetParam().execution_name +
- " %1 \"" + GetParam().entry_point_name + "\"";
- std::vector<uint32_t> expected_operands{GetParam().execution_value, 1};
+ std::string input = "OpEntryPoint " + GetParam().execution_name + " %1 \"" +
+ GetParam().entry_point_name + "\"";
+ std::vector<uint32_t> expected_operands{GetParam().get_execution_value(), 1};
std::vector<uint32_t> encoded_entry_point_name =
MakeVector(GetParam().entry_point_name);
expected_operands.insert(expected_operands.end(),
// A single test case for a simple OpExecutionMode.
// An execution mode has no operands, or just literal numbers as operands.
struct ExecutionModeCase {
- const spv::ExecutionMode mode_value;
- const std::string mode_name;
- const std::vector<uint32_t> operands;
+ uint32_t get_mode_value() const { return static_cast<uint32_t>(mode_value); }
+ spv::ExecutionMode mode_value;
+ std::string mode_name;
+ std::vector<uint32_t> operands;
};
using OpExecutionModeTest = test_fixture::TextToBinaryTestBase<
std::stringstream input;
input << "OpExecutionMode %1 " << GetParam().mode_name;
for (auto operand : GetParam().operands) input << " " << operand;
- std::vector<uint32_t> expected_operands{1, GetParam().mode_value};
+ std::vector<uint32_t> expected_operands{1, GetParam().get_mode_value()};
expected_operands.insert(expected_operands.end(), GetParam().operands.begin(),
GetParam().operands.end());
EXPECT_THAT(CompiledInstructions(input.str()),
// Test OpCapability
-struct CapabilityCase {
- spv::Capability value;
- std::string name;
-};
-
using OpCapabilityTest = test_fixture::TextToBinaryTestBase<
- ::testing::TestWithParam<CapabilityCase>>;
+ ::testing::TestWithParam<EnumCase<spv::Capability>>>;
TEST_P(OpCapabilityTest, AnyCapability) {
std::string input = "OpCapability " + GetParam().name;
EXPECT_THAT(CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpCapability, {GetParam().value})));
+ Eq(MakeInstruction(spv::OpCapability, {GetParam().get_value()})));
}
// clang-format off
#define CASE(NAME) { spv::Capability##NAME, #NAME }
INSTANTIATE_TEST_CASE_P(TextToBinaryCapability, OpCapabilityTest,
- ::testing::ValuesIn(std::vector<CapabilityCase>{
+ ::testing::ValuesIn(std::vector<EnumCase<spv::Capability>>{
CASE(Matrix),
CASE(Shader),
CASE(Geometry),
using spvtest::MakeInstruction;
using ::testing::Eq;
-// An example case for an enumerated value.
-template <typename E>
-struct EnumCase {
- const E value;
- const std::string name;
-};
-
// Test Dim enums via OpTypeImage
using DimTest = test_fixture::TextToBinaryTestBase<
GetParam().name + " 2 3 0 4 Rgba8";
EXPECT_THAT(
CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpTypeImage, {1, 2, GetParam().value, 2, 3, 0, 4,
+ Eq(MakeInstruction(spv::OpTypeImage, {1, 2, GetParam().get_value(), 2, 3, 0, 4,
spv::ImageFormatRgba8})));
}
"%imageType = OpTypeImage %sampledType 1D 2 3 0 4 " + GetParam().name;
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpTypeImage, {1, 2, spv::Dim1D, 2, 3, 0,
- 4, GetParam().value})));
+ 4, GetParam().get_value()})));
}
// clang-format off
// TODO(dneto): In Rev31 and later, pipes are opaque, and so the %2, which
// is the type-of-element operand, should be dropped.
std::string input = "%1 = OpTypePipe %2 " + GetParam().name;
- EXPECT_THAT(CompiledInstructions(input),
- Eq(MakeInstruction(spv::OpTypePipe, {1, 2, GetParam().value})));
+ EXPECT_THAT(
+ CompiledInstructions(input),
+ Eq(MakeInstruction(spv::OpTypePipe, {1, 2, GetParam().get_value()})));
}
// clang-format off
INSTANTIATE_TEST_CASE_P(
TextToBinaryTypePipe, OpTypePipeTest,
::testing::ValuesIn(std::vector<EnumCase<spv::AccessQualifier>>{
- CASE(ReadOnly),
- CASE(WriteOnly),
- CASE(ReadWrite),
- }));
+ CASE(ReadOnly),
+ CASE(WriteOnly),
+ CASE(ReadWrite),
+ }));
#undef CASE
// clang-format on
// An mask parsing test case.
struct MaskCase {
- const spv_operand_type_t which_enum;
- const uint32_t expected_value;
- const char* expression;
+ spv_operand_type_t which_enum;
+ uint32_t expected_value;
+ char* expression;
};
using GoodMaskParseTest = ::testing::TestWithParam<MaskCase>;
)");
// Minimal check: The OpSwitch opcode word is correct.
- EXPECT_EQ(int(spv::OpSwitch) || (7 << 16), code[14]);
+ EXPECT_EQ((int(spv::OpSwitch) | (7 << 16)), code[14 + SPV_INDEX_INSTRUCTION]);
}
TEST_F(TextToBinaryTest, GoodSwitchZeroCasesOneDefault) {
)");
// Minimal check: The OpSwitch opcode word is correct.
- EXPECT_EQ(int(spv::OpSwitch) || (3 << 16), code[10]);
+ EXPECT_EQ((int(spv::OpSwitch) | (3 << 16)), code[10 + SPV_INDEX_INSTRUCTION]);
}
TEST_F(TextToBinaryTest, BadSwitchTruncatedCase) {
spv_text_t text;
};
+// An example case for an enumerated value.
+template <typename E>
+struct EnumCase {
+ uint32_t get_value() const { return static_cast<uint32_t>(value); }
+ E value;
+ std::string name;
+};
+
#define I32_ENDIAN_HOST (o32_host_order.value)
#endif