instruction_descriptor_test.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "source/fuzz/instruction_descriptor.h"
  15. #include "test/fuzz/fuzz_test_util.h"
  16. namespace spvtools {
  17. namespace fuzz {
  18. namespace {
  19. TEST(InstructionDescriptorTest, BasicTest) {
  20. std::string shader = R"(
  21. OpCapability Shader
  22. %1 = OpExtInstImport "GLSL.std.450"
  23. OpMemoryModel Logical GLSL450
  24. OpEntryPoint Fragment %4 "main"
  25. OpExecutionMode %4 OriginUpperLeft
  26. OpSource ESSL 310
  27. %2 = OpTypeVoid
  28. %3 = OpTypeFunction %2
  29. %6 = OpTypeInt 32 0
  30. %7 = OpTypePointer Function %6
  31. %9 = OpConstant %6 0
  32. %10 = OpTypeInt 32 1
  33. %11 = OpTypePointer Function %10
  34. %13 = OpConstant %10 2
  35. %32 = OpConstant %10 0
  36. %4 = OpFunction %2 None %3
  37. %5 = OpLabel
  38. %164 = OpVariable %11 Function
  39. %165 = OpVariable %11 Function
  40. OpBranch %16
  41. %16 = OpLabel
  42. OpStore %164 %32
  43. OpStore %165 %13
  44. OpReturn
  45. OpFunctionEnd
  46. )";
  47. const auto env = SPV_ENV_UNIVERSAL_1_4;
  48. const auto consumer = nullptr;
  49. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  50. ASSERT_TRUE(IsValid(env, context.get()));
  51. for (auto& function : *context->module()) {
  52. for (auto& block : function) {
  53. for (auto inst_it = block.cbegin(); inst_it != block.cend(); ++inst_it) {
  54. ASSERT_EQ(&*inst_it,
  55. FindInstruction(MakeInstructionDescriptor(block, inst_it),
  56. context.get()));
  57. }
  58. }
  59. }
  60. }
  61. } // namespace
  62. } // namespace fuzz
  63. } // namespace spvtools