instruction_descriptor_test.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "gtest/gtest.h"
  16. #include "source/fuzz/fuzzer_util.h"
  17. #include "test/fuzz/fuzz_test_util.h"
  18. namespace spvtools {
  19. namespace fuzz {
  20. namespace {
  21. TEST(InstructionDescriptorTest, BasicTest) {
  22. std::string shader = R"(
  23. OpCapability Shader
  24. %1 = OpExtInstImport "GLSL.std.450"
  25. OpMemoryModel Logical GLSL450
  26. OpEntryPoint Fragment %4 "main"
  27. OpExecutionMode %4 OriginUpperLeft
  28. OpSource ESSL 310
  29. %2 = OpTypeVoid
  30. %3 = OpTypeFunction %2
  31. %6 = OpTypeInt 32 0
  32. %7 = OpTypePointer Function %6
  33. %9 = OpConstant %6 0
  34. %10 = OpTypeInt 32 1
  35. %11 = OpTypePointer Function %10
  36. %13 = OpConstant %10 2
  37. %32 = OpConstant %10 0
  38. %4 = OpFunction %2 None %3
  39. %5 = OpLabel
  40. %164 = OpVariable %11 Function
  41. %165 = OpVariable %11 Function
  42. OpBranch %16
  43. %16 = OpLabel
  44. OpStore %164 %32
  45. OpStore %165 %13
  46. OpReturn
  47. OpFunctionEnd
  48. )";
  49. const auto env = SPV_ENV_UNIVERSAL_1_4;
  50. const auto consumer = nullptr;
  51. const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
  52. spvtools::ValidatorOptions validator_options;
  53. ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
  54. kConsoleMessageConsumer));
  55. for (auto& function : *context->module()) {
  56. for (auto& block : function) {
  57. for (auto inst_it = block.cbegin(); inst_it != block.cend(); ++inst_it) {
  58. ASSERT_EQ(&*inst_it,
  59. FindInstruction(MakeInstructionDescriptor(block, inst_it),
  60. context.get()));
  61. }
  62. }
  63. }
  64. }
  65. } // namespace
  66. } // namespace fuzz
  67. } // namespace spvtools