1fd4e5da5Sopenharmony_ci// Copyright (c) 2016 Google Inc.
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci#include "gmock/gmock.h"
16fd4e5da5Sopenharmony_ci#include "test/test_fixture.h"
17fd4e5da5Sopenharmony_ci
18fd4e5da5Sopenharmony_cinamespace spvtools {
19fd4e5da5Sopenharmony_cinamespace {
20fd4e5da5Sopenharmony_ci
21fd4e5da5Sopenharmony_ciusing ::spvtest::MakeInstruction;
22fd4e5da5Sopenharmony_ciusing ::testing::Eq;
23fd4e5da5Sopenharmony_ci
24fd4e5da5Sopenharmony_ciusing OpTypePipeStorageTest = spvtest::TextToBinaryTest;
25fd4e5da5Sopenharmony_ci
26fd4e5da5Sopenharmony_ci// It can assemble, but should not validate.  Validation checks for version
27fd4e5da5Sopenharmony_ci// and capability are in another test file.
28fd4e5da5Sopenharmony_ciTEST_F(OpTypePipeStorageTest, OpcodeAssemblesInV10) {
29fd4e5da5Sopenharmony_ci  EXPECT_THAT(
30fd4e5da5Sopenharmony_ci      CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_0),
31fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpTypePipeStorage, {1})));
32fd4e5da5Sopenharmony_ci}
33fd4e5da5Sopenharmony_ci
34fd4e5da5Sopenharmony_ciTEST_F(OpTypePipeStorageTest, ArgumentCount) {
35fd4e5da5Sopenharmony_ci  EXPECT_THAT(
36fd4e5da5Sopenharmony_ci      CompileFailure("OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
37fd4e5da5Sopenharmony_ci      Eq("Expected <result-id> at the beginning of an instruction, found "
38fd4e5da5Sopenharmony_ci         "'OpTypePipeStorage'."));
39fd4e5da5Sopenharmony_ci  EXPECT_THAT(
40fd4e5da5Sopenharmony_ci      CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
41fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpTypePipeStorage, {1})));
42fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5",
43fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
44fd4e5da5Sopenharmony_ci              Eq("'=' expected after result id but found '%2'."));
45fd4e5da5Sopenharmony_ci}
46fd4e5da5Sopenharmony_ci
47fd4e5da5Sopenharmony_ciusing OpConstantPipeStorageTest = spvtest::TextToBinaryTest;
48fd4e5da5Sopenharmony_ci
49fd4e5da5Sopenharmony_ciTEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) {
50fd4e5da5Sopenharmony_ci  EXPECT_THAT(
51fd4e5da5Sopenharmony_ci      CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
52fd4e5da5Sopenharmony_ci                           SPV_ENV_UNIVERSAL_1_0),
53fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
54fd4e5da5Sopenharmony_ci}
55fd4e5da5Sopenharmony_ci
56fd4e5da5Sopenharmony_ciTEST_F(OpConstantPipeStorageTest, ArgumentCount) {
57fd4e5da5Sopenharmony_ci  EXPECT_THAT(
58fd4e5da5Sopenharmony_ci      CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
59fd4e5da5Sopenharmony_ci      Eq("Expected <result-id> at the beginning of an instruction, found "
60fd4e5da5Sopenharmony_ci         "'OpConstantPipeStorage'."));
61fd4e5da5Sopenharmony_ci  EXPECT_THAT(
62fd4e5da5Sopenharmony_ci      CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
63fd4e5da5Sopenharmony_ci      Eq("Expected operand for OpConstantPipeStorage instruction, but found "
64fd4e5da5Sopenharmony_ci         "the end of the stream."));
65fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4",
66fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
67fd4e5da5Sopenharmony_ci              Eq("Expected operand for OpConstantPipeStorage instruction, but "
68fd4e5da5Sopenharmony_ci                 "found the end of the stream."));
69fd4e5da5Sopenharmony_ci  EXPECT_THAT(
70fd4e5da5Sopenharmony_ci      CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
71fd4e5da5Sopenharmony_ci                           SPV_ENV_UNIVERSAL_1_1),
72fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
73fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7",
74fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
75fd4e5da5Sopenharmony_ci              Eq("'=' expected after result id but found '%7'."));
76fd4e5da5Sopenharmony_ci}
77fd4e5da5Sopenharmony_ci
78fd4e5da5Sopenharmony_ciTEST_F(OpConstantPipeStorageTest, ArgumentTypes) {
79fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5",
80fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
81fd4e5da5Sopenharmony_ci              Eq("Invalid unsigned integer literal: %3"));
82fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5",
83fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
84fd4e5da5Sopenharmony_ci              Eq("Invalid unsigned integer literal: %4"));
85fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5",
86fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
87fd4e5da5Sopenharmony_ci              Eq("Expected id to start with %."));
88fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"",
89fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
90fd4e5da5Sopenharmony_ci              Eq("Invalid unsigned integer literal: \"ab\""));
91fd4e5da5Sopenharmony_ci}
92fd4e5da5Sopenharmony_ci
93fd4e5da5Sopenharmony_ciusing OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest;
94fd4e5da5Sopenharmony_ci
95fd4e5da5Sopenharmony_ciTEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) {
96fd4e5da5Sopenharmony_ci  EXPECT_THAT(
97fd4e5da5Sopenharmony_ci      CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
98fd4e5da5Sopenharmony_ci                           SPV_ENV_UNIVERSAL_1_0),
99fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
100fd4e5da5Sopenharmony_ci}
101fd4e5da5Sopenharmony_ci
102fd4e5da5Sopenharmony_ciTEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) {
103fd4e5da5Sopenharmony_ci  EXPECT_THAT(
104fd4e5da5Sopenharmony_ci      CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
105fd4e5da5Sopenharmony_ci      Eq("Expected <result-id> at the beginning of an instruction, found "
106fd4e5da5Sopenharmony_ci         "'OpCreatePipeFromPipeStorage'."));
107fd4e5da5Sopenharmony_ci  EXPECT_THAT(
108fd4e5da5Sopenharmony_ci      CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
109fd4e5da5Sopenharmony_ci      Eq("Expected operand for OpCreatePipeFromPipeStorage instruction, but "
110fd4e5da5Sopenharmony_ci         "found the end of the stream."));
111fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop",
112fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
113fd4e5da5Sopenharmony_ci              Eq("Expected operand for OpCreatePipeFromPipeStorage "
114fd4e5da5Sopenharmony_ci                 "instruction, but found the next instruction instead."));
115fd4e5da5Sopenharmony_ci  EXPECT_THAT(
116fd4e5da5Sopenharmony_ci      CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
117fd4e5da5Sopenharmony_ci                           SPV_ENV_UNIVERSAL_1_1),
118fd4e5da5Sopenharmony_ci      Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
119fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5",
120fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
121fd4e5da5Sopenharmony_ci              Eq("'=' expected after result id but found '%5'."));
122fd4e5da5Sopenharmony_ci}
123fd4e5da5Sopenharmony_ci
124fd4e5da5Sopenharmony_ciTEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) {
125fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3",
126fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
127fd4e5da5Sopenharmony_ci              Eq("Expected id to start with %."));
128fd4e5da5Sopenharmony_ci  EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3",
129fd4e5da5Sopenharmony_ci                             SPV_ENV_UNIVERSAL_1_1),
130fd4e5da5Sopenharmony_ci              Eq("Expected id to start with %."));
131fd4e5da5Sopenharmony_ci}
132fd4e5da5Sopenharmony_ci
133fd4e5da5Sopenharmony_ci}  // namespace
134fd4e5da5Sopenharmony_ci}  // namespace spvtools
135