aboutsummaryrefslogtreecommitdiff
path: root/test/fuzz/transformation_access_chain_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/fuzz/transformation_access_chain_test.cpp')
-rw-r--r--test/fuzz/transformation_access_chain_test.cpp169
1 files changed, 76 insertions, 93 deletions
diff --git a/test/fuzz/transformation_access_chain_test.cpp b/test/fuzz/transformation_access_chain_test.cpp
index fa19aa50..bddcf5fe 100644
--- a/test/fuzz/transformation_access_chain_test.cpp
+++ b/test/fuzz/transformation_access_chain_test.cpp
@@ -129,7 +129,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
// Check the case where the index type is not a 32-bit integer.
TransformationAccessChain invalid_index_example1(
- 101, 28, {29}, MakeInstructionDescriptor(42, spv::Op::OpReturn, 0));
+ 101, 28, {29}, MakeInstructionDescriptor(42, SpvOpReturn, 0));
// Since the index is not a 32-bit integer type but a 32-bit float type,
// ValidIndexComposite should return false and thus the transformation is not
@@ -138,95 +138,86 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation_context));
// Bad: id is not fresh
- ASSERT_FALSE(
- TransformationAccessChain(
- 43, 43, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 43, 43, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: pointer id does not exist
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 1000, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 1000, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: pointer id is not a type
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 5, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 5, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: pointer id is not a pointer
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 23, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 23, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: index id does not exist
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 43, {1000}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 43, {1000}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: index id is not a constant and the pointer refers to a struct
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 43, {24}, MakeInstructionDescriptor(25, spv::Op::OpIAdd, 0))
- .IsApplicable(context.get(), transformation_context));
-
- // Bad: too many indices
ASSERT_FALSE(TransformationAccessChain(
- 100, 43, {80, 80, 80},
- MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
+ 100, 43, {24}, MakeInstructionDescriptor(25, SpvOpIAdd, 0))
.IsApplicable(context.get(), transformation_context));
- // Bad: index id is out of bounds when accessing a struct
+ // Bad: too many indices
ASSERT_FALSE(
- TransformationAccessChain(
- 100, 43, {83, 80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
+ TransformationAccessChain(100, 43, {80, 80, 80},
+ MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context));
- // Bad: attempt to insert before variable
+ // Bad: index id is out of bounds when accessing a struct
ASSERT_FALSE(
- TransformationAccessChain(
- 100, 34, {}, MakeInstructionDescriptor(36, spv::Op::OpVariable, 0))
+ TransformationAccessChain(100, 43, {83, 80},
+ MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context));
+ // Bad: attempt to insert before variable
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 34, {}, MakeInstructionDescriptor(36, SpvOpVariable, 0))
+ .IsApplicable(context.get(), transformation_context));
+
// Bad: OpTypeBool must be present in the module to clamp an index
ASSERT_FALSE(
- TransformationAccessChain(
- 100, 36, {80, 81}, MakeInstructionDescriptor(37, spv::Op::OpStore, 0))
+ TransformationAccessChain(100, 36, {80, 81},
+ MakeInstructionDescriptor(37, SpvOpStore, 0))
.IsApplicable(context.get(), transformation_context));
// Bad: pointer not available
- ASSERT_FALSE(TransformationAccessChain(
- 100, 43, {80},
- MakeInstructionDescriptor(21, spv::Op::OpAccessChain, 0))
- .IsApplicable(context.get(), transformation_context));
-
- // Bad: instruction descriptor does not identify anything
ASSERT_FALSE(
TransformationAccessChain(
- 100, 43, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 100))
+ 100, 43, {80}, MakeInstructionDescriptor(21, SpvOpAccessChain, 0))
.IsApplicable(context.get(), transformation_context));
+ // Bad: instruction descriptor does not identify anything
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 43, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 100))
+ .IsApplicable(context.get(), transformation_context));
+
#ifndef NDEBUG
// Bad: pointer is null
ASSERT_DEATH(
- TransformationAccessChain(
- 100, 46, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
+ TransformationAccessChain(100, 46, {80},
+ MakeInstructionDescriptor(24, SpvOpLoad, 0))
.IsApplicable(context.get(), transformation_context),
"Access chains should not be created from null/undefined pointers");
#endif
// Bad: pointer to result type does not exist
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 52, {0}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 52, {0}, MakeInstructionDescriptor(24, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
{
TransformationAccessChain transformation(
- 100, 43, {80}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0));
+ 100, 43, {80}, MakeInstructionDescriptor(24, SpvOpLoad, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -239,7 +230,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 101, 28, {81}, MakeInstructionDescriptor(42, spv::Op::OpReturn, 0));
+ 101, 28, {81}, MakeInstructionDescriptor(42, SpvOpReturn, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -252,7 +243,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 102, 44, {}, MakeInstructionDescriptor(44, spv::Op::OpStore, 0));
+ 102, 44, {}, MakeInstructionDescriptor(44, SpvOpStore, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -265,8 +256,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 103, 13, {80},
- MakeInstructionDescriptor(21, spv::Op::OpAccessChain, 0));
+ 103, 13, {80}, MakeInstructionDescriptor(21, SpvOpAccessChain, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -279,7 +269,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 104, 34, {}, MakeInstructionDescriptor(44, spv::Op::OpStore, 1));
+ 104, 34, {}, MakeInstructionDescriptor(44, SpvOpStore, 1));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -292,7 +282,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 105, 38, {}, MakeInstructionDescriptor(40, spv::Op::OpFunctionCall, 0));
+ 105, 38, {}, MakeInstructionDescriptor(40, SpvOpFunctionCall, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -305,7 +295,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
{
TransformationAccessChain transformation(
- 106, 14, {}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0));
+ 106, 14, {}, MakeInstructionDescriptor(24, SpvOpLoad, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -319,7 +309,7 @@ TEST(TransformationAccessChainTest, BasicTest) {
// Check the case where the access chain's base pointer has the irrelevant
// pointee fact; the resulting access chain should inherit this fact.
TransformationAccessChain transformation(
- 107, 54, {}, MakeInstructionDescriptor(24, spv::Op::OpLoad, 0));
+ 107, 54, {}, MakeInstructionDescriptor(24, SpvOpLoad, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -450,10 +440,9 @@ TEST(TransformationAccessChainTest, StructIndexMustBeConstant) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: %9 is a pointer to a struct, but %20 is not a constant.
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 9, {20}, MakeInstructionDescriptor(9, spv::Op::OpReturn, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 9, {20}, MakeInstructionDescriptor(9, SpvOpReturn, 0))
+ .IsApplicable(context.get(), transformation_context));
}
TEST(TransformationAccessChainTest, IsomorphicStructs) {
@@ -489,7 +478,7 @@ TEST(TransformationAccessChainTest, IsomorphicStructs) {
MakeUnique<FactManager>(context.get()), validator_options);
{
TransformationAccessChain transformation(
- 100, 11, {}, MakeInstructionDescriptor(5, spv::Op::OpReturn, 0));
+ 100, 11, {}, MakeInstructionDescriptor(5, SpvOpReturn, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -499,7 +488,7 @@ TEST(TransformationAccessChainTest, IsomorphicStructs) {
}
{
TransformationAccessChain transformation(
- 101, 12, {}, MakeInstructionDescriptor(5, spv::Op::OpReturn, 0));
+ 101, 12, {}, MakeInstructionDescriptor(5, SpvOpReturn, 0));
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
@@ -598,56 +587,51 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: no ids given for clamping
- ASSERT_FALSE(
- TransformationAccessChain(
- 100, 29, {17}, MakeInstructionDescriptor(36, spv::Op::OpLoad, 0))
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(TransformationAccessChain(
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0))
+ .IsApplicable(context.get(), transformation_context));
// Bad: an id given for clamping is not fresh
ASSERT_FALSE(TransformationAccessChain(
- 100, 29, {17},
- MakeInstructionDescriptor(36, spv::Op::OpLoad, 0),
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0),
{{46, 201}})
.IsApplicable(context.get(), transformation_context));
// Bad: an id given for clamping is not fresh
ASSERT_FALSE(TransformationAccessChain(
- 100, 29, {17},
- MakeInstructionDescriptor(36, spv::Op::OpLoad, 0),
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0),
{{200, 46}})
.IsApplicable(context.get(), transformation_context));
// Bad: an id given for clamping is the same as the id for the access chain
ASSERT_FALSE(TransformationAccessChain(
- 100, 29, {17},
- MakeInstructionDescriptor(36, spv::Op::OpLoad, 0),
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0),
{{100, 201}})
.IsApplicable(context.get(), transformation_context));
// Bad: the fresh ids given are not distinct
ASSERT_FALSE(TransformationAccessChain(
- 100, 29, {17},
- MakeInstructionDescriptor(36, spv::Op::OpLoad, 0),
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0),
{{200, 200}})
.IsApplicable(context.get(), transformation_context));
// Bad: not enough ids given for clamping (2 pairs needed)
- ASSERT_FALSE(TransformationAccessChain(
- 104, 34, {45, 10, 46},
- MakeInstructionDescriptor(46, spv::Op::OpReturn, 0),
- {{208, 209}, {209, 211}})
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(
+ TransformationAccessChain(104, 34, {45, 10, 46},
+ MakeInstructionDescriptor(46, SpvOpReturn, 0),
+ {{208, 209}, {209, 211}})
+ .IsApplicable(context.get(), transformation_context));
// Bad: the fresh ids given are not distinct
- ASSERT_FALSE(TransformationAccessChain(
- 104, 34, {45, 10, 46},
- MakeInstructionDescriptor(46, spv::Op::OpReturn, 0),
- {{208, 209}, {209, 211}})
- .IsApplicable(context.get(), transformation_context));
+ ASSERT_FALSE(
+ TransformationAccessChain(104, 34, {45, 10, 46},
+ MakeInstructionDescriptor(46, SpvOpReturn, 0),
+ {{208, 209}, {209, 211}})
+ .IsApplicable(context.get(), transformation_context));
{
TransformationAccessChain transformation(
- 100, 29, {17}, MakeInstructionDescriptor(36, spv::Op::OpLoad, 0),
+ 100, 29, {17}, MakeInstructionDescriptor(36, SpvOpLoad, 0),
{{200, 201}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
@@ -659,7 +643,7 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
{
TransformationAccessChain transformation(
- 101, 29, {36}, MakeInstructionDescriptor(38, spv::Op::OpLoad, 0),
+ 101, 29, {36}, MakeInstructionDescriptor(38, SpvOpLoad, 0),
{{202, 203}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
@@ -671,7 +655,7 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
{
TransformationAccessChain transformation(
- 102, 32, {10, 40}, MakeInstructionDescriptor(42, spv::Op::OpLoad, 0),
+ 102, 32, {10, 40}, MakeInstructionDescriptor(42, SpvOpLoad, 0),
{{204, 205}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
@@ -683,7 +667,7 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
{
TransformationAccessChain transformation(
- 103, 34, {11}, MakeInstructionDescriptor(45, spv::Op::OpLoad, 0),
+ 103, 34, {11}, MakeInstructionDescriptor(45, SpvOpLoad, 0),
{{206, 207}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
@@ -695,8 +679,7 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
{
TransformationAccessChain transformation(
- 104, 34, {45, 10, 46},
- MakeInstructionDescriptor(46, spv::Op::OpReturn, 0),
+ 104, 34, {45, 10, 46}, MakeInstructionDescriptor(46, SpvOpReturn, 0),
{{208, 209}, {210, 211}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));