| 21 | namespace { |
| 22 | |
| 23 | TEST(FuzzerUtilMaybeFindBlockTest, BasicTest) { |
| 24 | std::string shader = R"( |
| 25 | OpCapability Shader |
| 26 | %1 = OpExtInstImport "GLSL.std.450" |
| 27 | OpMemoryModel Logical GLSL450 |
| 28 | OpEntryPoint Fragment %4 "main" |
| 29 | OpExecutionMode %4 OriginUpperLeft |
| 30 | OpSource ESSL 310 |
| 31 | OpDecorate %8 RelaxedPrecision |
| 32 | %2 = OpTypeVoid |
| 33 | %3 = OpTypeFunction %2 |
| 34 | %6 = OpTypeInt 32 1 |
| 35 | %7 = OpTypePointer Function %6 |
| 36 | %9 = OpConstant %6 1 |
| 37 | %10 = OpConstant %6 2 |
| 38 | %4 = OpFunction %2 None %3 |
| 39 | %5 = OpLabel |
| 40 | %8 = OpVariable %7 Function |
| 41 | OpBranch %11 |
| 42 | %11 = OpLabel |
| 43 | OpStore %8 %9 |
| 44 | OpBranch %12 |
| 45 | %12 = OpLabel |
| 46 | OpStore %8 %10 |
| 47 | OpReturn |
| 48 | OpFunctionEnd |
| 49 | )"; |
| 50 | |
| 51 | const auto env = SPV_ENV_UNIVERSAL_1_4; |
| 52 | const auto consumer = nullptr; |
| 53 | const std::unique_ptr<opt::IRContext> context = |
| 54 | BuildModule(env, consumer, shader, kFuzzAssembleOption); |
| 55 | spvtools::ValidatorOptions validator_options; |
| 56 | ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options, |
| 57 | kConsoleMessageConsumer)); |
| 58 | |
| 59 | // Only blocks with id 11 and 12 can be found. |
| 60 | // Should return nullptr when id is not a label or id was not found. |
| 61 | uint32_t block_id1 = 11; |
| 62 | uint32_t block_id2 = 12; |
| 63 | uint32_t block_id3 = 13; |
| 64 | uint32_t block_id4 = 8; |
| 65 | |
| 66 | opt::IRContext* ir_context = context.get(); |
| 67 | // Block with id 11 should be found. |
| 68 | ASSERT_TRUE(fuzzerutil::MaybeFindBlock(ir_context, block_id1) != nullptr); |
| 69 | // Block with id 12 should be found. |
| 70 | ASSERT_TRUE(fuzzerutil::MaybeFindBlock(ir_context, block_id2) != nullptr); |
| 71 | // Block with id 13 cannot be found. |
| 72 | ASSERT_FALSE(fuzzerutil::MaybeFindBlock(ir_context, block_id3) != nullptr); |
| 73 | // Block with id 8 exists but don't not of type OpLabel. |
| 74 | ASSERT_FALSE(fuzzerutil::MaybeFindBlock(ir_context, block_id4) != nullptr); |
| 75 | } |
| 76 | |
| 77 | TEST(FuzzerutilTest, FuzzerUtilMaybeGetBoolConstantTest) { |
| 78 | std::string shader = R"( |
nothing calls this directly
no test coverage detected