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