1 // Copyright (c) 2016 Google 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 #include "gmock/gmock.h"
16 #include "test/test_fixture.h"
17
18 namespace spvtools {
19 namespace {
20
21 using ::spvtest::MakeInstruction;
22 using ::testing::Eq;
23
24 using OpTypePipeStorageTest = spvtest::TextToBinaryTest;
25
26 // It can assemble, but should not validate. Validation checks for version
27 // and capability are in another test file.
TEST_F(OpTypePipeStorageTest,OpcodeAssemblesInV10)28 TEST_F(OpTypePipeStorageTest, OpcodeAssemblesInV10) {
29 EXPECT_THAT(
30 CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_0),
31 Eq(MakeInstruction(SpvOpTypePipeStorage, {1})));
32 }
33
TEST_F(OpTypePipeStorageTest,ArgumentCount)34 TEST_F(OpTypePipeStorageTest, ArgumentCount) {
35 EXPECT_THAT(
36 CompileFailure("OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
37 Eq("Expected <result-id> at the beginning of an instruction, found "
38 "'OpTypePipeStorage'."));
39 EXPECT_THAT(
40 CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
41 Eq(MakeInstruction(SpvOpTypePipeStorage, {1})));
42 EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5",
43 SPV_ENV_UNIVERSAL_1_1),
44 Eq("'=' expected after result id."));
45 }
46
47 using OpConstantPipeStorageTest = spvtest::TextToBinaryTest;
48
TEST_F(OpConstantPipeStorageTest,OpcodeAssemblesInV10)49 TEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) {
50 EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
51 SPV_ENV_UNIVERSAL_1_0),
52 Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5})));
53 }
54
TEST_F(OpConstantPipeStorageTest,ArgumentCount)55 TEST_F(OpConstantPipeStorageTest, ArgumentCount) {
56 EXPECT_THAT(
57 CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
58 Eq("Expected <result-id> at the beginning of an instruction, found "
59 "'OpConstantPipeStorage'."));
60 EXPECT_THAT(
61 CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
62 Eq("Expected operand for OpConstantPipeStorage instruction, but found "
63 "the end of the stream."));
64 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4",
65 SPV_ENV_UNIVERSAL_1_1),
66 Eq("Expected operand for OpConstantPipeStorage instruction, but "
67 "found the end of the stream."));
68 EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
69 SPV_ENV_UNIVERSAL_1_1),
70 Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5})));
71 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7",
72 SPV_ENV_UNIVERSAL_1_1),
73 Eq("'=' expected after result id."));
74 }
75
TEST_F(OpConstantPipeStorageTest,ArgumentTypes)76 TEST_F(OpConstantPipeStorageTest, ArgumentTypes) {
77 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5",
78 SPV_ENV_UNIVERSAL_1_1),
79 Eq("Invalid unsigned integer literal: %3"));
80 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5",
81 SPV_ENV_UNIVERSAL_1_1),
82 Eq("Invalid unsigned integer literal: %4"));
83 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5",
84 SPV_ENV_UNIVERSAL_1_1),
85 Eq("Expected id to start with %."));
86 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"",
87 SPV_ENV_UNIVERSAL_1_1),
88 Eq("Invalid unsigned integer literal: \"ab\""));
89 }
90
91 using OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest;
92
TEST_F(OpCreatePipeFromPipeStorageTest,OpcodeAssemblesInV10)93 TEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) {
94 EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
95 SPV_ENV_UNIVERSAL_1_0),
96 Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3})));
97 }
98
TEST_F(OpCreatePipeFromPipeStorageTest,ArgumentCount)99 TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) {
100 EXPECT_THAT(
101 CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
102 Eq("Expected <result-id> at the beginning of an instruction, found "
103 "'OpCreatePipeFromPipeStorage'."));
104 EXPECT_THAT(
105 CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
106 Eq("Expected operand for OpCreatePipeFromPipeStorage instruction, but "
107 "found the end of the stream."));
108 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop",
109 SPV_ENV_UNIVERSAL_1_1),
110 Eq("Expected operand for OpCreatePipeFromPipeStorage "
111 "instruction, but found the next instruction instead."));
112 EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
113 SPV_ENV_UNIVERSAL_1_1),
114 Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3})));
115 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5",
116 SPV_ENV_UNIVERSAL_1_1),
117 Eq("'=' expected after result id."));
118 }
119
TEST_F(OpCreatePipeFromPipeStorageTest,ArgumentTypes)120 TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) {
121 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3",
122 SPV_ENV_UNIVERSAL_1_1),
123 Eq("Expected id to start with %."));
124 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3",
125 SPV_ENV_UNIVERSAL_1_1),
126 Eq("Expected id to start with %."));
127 }
128
129 } // namespace
130 } // namespace spvtools
131