ext_inst.non_semantic_test.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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(
  38. spirv, SPV_BINARY_TO_TEXT_OPTION_NONE, SPV_ENV_UNIVERSAL_1_0);
  39. EXPECT_THAT(disassembly, Eq(spirv));
  40. }
  41. TEST_F(NonSemanticTextToBinaryTest, InvalidExtInstSetName) {
  42. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  43. %1 = OpExtInstImport "NonSemantic_Testing_ExtInst"
  44. )";
  45. EXPECT_THAT(
  46. CompileFailure(spirv),
  47. Eq("Invalid extended instruction import 'NonSemantic_Testing_ExtInst'"));
  48. }
  49. TEST_F(NonSemanticTextToBinaryTest, NonSemanticIntParameter) {
  50. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  51. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  52. %2 = OpTypeVoid
  53. %3 = OpExtInst %2 %1 1 99999
  54. )";
  55. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  56. }
  57. TEST_F(NonSemanticTextToBinaryTest, NonSemanticFloatParameter) {
  58. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  59. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  60. %2 = OpTypeVoid
  61. %3 = OpExtInst %2 %1 1 3.141592
  62. )";
  63. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  64. }
  65. TEST_F(NonSemanticTextToBinaryTest, NonSemanticStringParameter) {
  66. std::string spirv = R"(OpExtension "SPV_KHR_non_semantic_info"
  67. %1 = OpExtInstImport "NonSemantic.Testing.ExtInst"
  68. %2 = OpTypeVoid
  69. %3 = OpExtInst %2 %1 1 "foobar"
  70. )";
  71. EXPECT_THAT(CompileFailure(spirv), Eq("Expected id to start with %."));
  72. }
  73. } // namespace
  74. } // namespace spvtools