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(spv::Op::OpTypePipeStorage, {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(spv::Op::OpTypePipeStorage, {1})));
42 EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5",
43 SPV_ENV_UNIVERSAL_1_1),
44 Eq("'=' expected after result id but found '%2'."));
45 }
46
47 using OpConstantPipeStorageTest = spvtest::TextToBinaryTest;
48
TEST_F(OpConstantPipeStorageTest,OpcodeAssemblesInV10)49 TEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) {
50 EXPECT_THAT(
51 CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
52 SPV_ENV_UNIVERSAL_1_0),
53 Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
54 }
55
TEST_F(OpConstantPipeStorageTest,ArgumentCount)56 TEST_F(OpConstantPipeStorageTest, ArgumentCount) {
57 EXPECT_THAT(
58 CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
59 Eq("Expected <result-id> at the beginning of an instruction, found "
60 "'OpConstantPipeStorage'."));
61 EXPECT_THAT(
62 CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
63 Eq("Expected operand for OpConstantPipeStorage instruction, but found "
64 "the end of the stream."));
65 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4",
66 SPV_ENV_UNIVERSAL_1_1),
67 Eq("Expected operand for OpConstantPipeStorage instruction, but "
68 "found the end of the stream."));
69 EXPECT_THAT(
70 CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
71 SPV_ENV_UNIVERSAL_1_1),
72 Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
73 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7",
74 SPV_ENV_UNIVERSAL_1_1),
75 Eq("'=' expected after result id but found '%7'."));
76 }
77
TEST_F(OpConstantPipeStorageTest,ArgumentTypes)78 TEST_F(OpConstantPipeStorageTest, ArgumentTypes) {
79 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5",
80 SPV_ENV_UNIVERSAL_1_1),
81 Eq("Invalid unsigned integer literal: %3"));
82 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5",
83 SPV_ENV_UNIVERSAL_1_1),
84 Eq("Invalid unsigned integer literal: %4"));
85 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5",
86 SPV_ENV_UNIVERSAL_1_1),
87 Eq("Expected id to start with %."));
88 EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"",
89 SPV_ENV_UNIVERSAL_1_1),
90 Eq("Invalid unsigned integer literal: \"ab\""));
91 }
92
93 using OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest;
94
TEST_F(OpCreatePipeFromPipeStorageTest,OpcodeAssemblesInV10)95 TEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) {
96 EXPECT_THAT(
97 CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
98 SPV_ENV_UNIVERSAL_1_0),
99 Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
100 }
101
TEST_F(OpCreatePipeFromPipeStorageTest,ArgumentCount)102 TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) {
103 EXPECT_THAT(
104 CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
105 Eq("Expected <result-id> at the beginning of an instruction, found "
106 "'OpCreatePipeFromPipeStorage'."));
107 EXPECT_THAT(
108 CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
109 Eq("Expected operand for OpCreatePipeFromPipeStorage instruction, but "
110 "found the end of the stream."));
111 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop",
112 SPV_ENV_UNIVERSAL_1_1),
113 Eq("Expected operand for OpCreatePipeFromPipeStorage "
114 "instruction, but found the next instruction instead."));
115 EXPECT_THAT(
116 CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
117 SPV_ENV_UNIVERSAL_1_1),
118 Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
119 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5",
120 SPV_ENV_UNIVERSAL_1_1),
121 Eq("'=' expected after result id but found '%5'."));
122 }
123
TEST_F(OpCreatePipeFromPipeStorageTest,ArgumentTypes)124 TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) {
125 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3",
126 SPV_ENV_UNIVERSAL_1_1),
127 Eq("Expected id to start with %."));
128 EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3",
129 SPV_ENV_UNIVERSAL_1_1),
130 Eq("Expected id to start with %."));
131 }
132
133 } // namespace
134 } // namespace spvtools
135