ext_inst.non_semantic_test.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  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. // Assembler tests for non-semantic extended instructions
  15. #include <string>
  16. #include <vector>
  17. #include "gmock/gmock.h"
  18. #include "test/test_fixture.h"
  19. #include "test/unit_spirv.h"
  20. using ::testing::Eq;
  21. namespace spvtools {
  22. namespace {
  23. using NonSemanticRoundTripTest = RoundTripTest;
  24. using NonSemanticTextToBinaryTest = spvtest::TextToBinaryTest;
  25. TEST_F(NonSemanticRoundTripTest, NonSemanticInsts) {
  26. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  27. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  28. %2 = OpTypeVoid
  29. %3 = OpExtInst %2 %1 132384681 %2
  30. %4 = OpTypeInt 32 0
  31. %5 = OpConstant %4 123
  32. %6 = OpString "Test string"
  33. %7 = OpExtInst %4 %1 82198732 %5 %6
  34. %8 = OpExtInstImport "NonSemantic.Testing.AnotherUnknownExtInstSet"
  35. %9 = OpExtInst %4 %8 613874321 %7 %5 %6
  36. )";
  37. std::string disassembly = EncodeAndDecodeSuccessfully(spirv);
  38. EXPECT_THAT(disassembly, Eq(spirv));
  39. }
  40. TEST_F(NonSemanticTextToBinaryTest, InvalidExtInstSetName) {
  41. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  42. %1 = OpExtInstImport "NonSemantic_Testing_ExtInst"
  43. )";
  44. EXPECT_THAT(
  45. CompileFailure(spirv),
  46. Eq("Invalid extended instruction import 'NonSemantic_Testing_ExtInst'"));
  47. }
  48. TEST_F(NonSemanticTextToBinaryTest, NonSemanticIntParameter) {
  49. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  50. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  51. %2 = OpTypeVoid
  52. %3 = OpExtInst %2 %1 1 99999
  53. )";
  54. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  55. }
  56. TEST_F(NonSemanticTextToBinaryTest, NonSemanticFloatParameter) {
  57. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  58. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  59. %2 = OpTypeVoid
  60. %3 = OpExtInst %2 %1 1 3.141592
  61. )";
  62. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  63. }
  64. TEST_F(NonSemanticTextToBinaryTest, NonSemanticStringParameter) {
  65. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  66. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  67. %2 = OpTypeVoid
  68. %3 = OpExtInst %2 %1 1 "foobar"
  69. )";
  70. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  71. }
  72. } // namespace
  73. } // namespace spvtools