• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Assembler tests for instructions in the "Barrier Instructions" section
16 // of the SPIR-V spec.
17 
18 #include "test/unit_spirv.h"
19 
20 #include "gmock/gmock.h"
21 #include "test/test_fixture.h"
22 
23 namespace spvtools {
24 namespace {
25 
26 using ::spvtest::MakeInstruction;
27 using ::testing::Eq;
28 
29 using OpGetKernelLocalSizeForSubgroupCountTest = spvtest::TextToBinaryTest;
30 
31 // We should be able to assemble it.  Validation checks are in another test
32 // file.
TEST_F(OpGetKernelLocalSizeForSubgroupCountTest,OpcodeAssemblesInV10)33 TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, OpcodeAssemblesInV10) {
34   EXPECT_THAT(
35       CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
36                            "%sgcount %invoke %param %param_size %param_align",
37                            SPV_ENV_UNIVERSAL_1_0),
38       Eq(MakeInstruction(SpvOpGetKernelLocalSizeForSubgroupCount,
39                          {1, 2, 3, 4, 5, 6, 7})));
40 }
41 
TEST_F(OpGetKernelLocalSizeForSubgroupCountTest,ArgumentCount)42 TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentCount) {
43   EXPECT_THAT(CompileFailure("OpGetKernelLocalSizeForSubgroupCount",
44                              SPV_ENV_UNIVERSAL_1_1),
45               Eq("Expected <result-id> at the beginning of an instruction, "
46                  "found 'OpGetKernelLocalSizeForSubgroupCount'."));
47   EXPECT_THAT(CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount",
48                              SPV_ENV_UNIVERSAL_1_1),
49               Eq("Expected operand, found end of stream."));
50   EXPECT_THAT(
51       CompileFailure("%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6",
52                      SPV_ENV_UNIVERSAL_1_1),
53       Eq("Expected operand, found end of stream."));
54   EXPECT_THAT(
55       CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
56                            "%sgcount %invoke %param %param_size %param_align",
57                            SPV_ENV_UNIVERSAL_1_1),
58       Eq(MakeInstruction(SpvOpGetKernelLocalSizeForSubgroupCount,
59                          {1, 2, 3, 4, 5, 6, 7})));
60   EXPECT_THAT(
61       CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount %type "
62                      "%sgcount %invoke %param %param_size %param_align %extra",
63                      SPV_ENV_UNIVERSAL_1_1),
64       Eq("Expected '=', found end of stream."));
65 }
66 
TEST_F(OpGetKernelLocalSizeForSubgroupCountTest,ArgumentTypes)67 TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentTypes) {
68   EXPECT_THAT(CompileFailure(
69                   "%1 = OpGetKernelLocalSizeForSubgroupCount 2 %3 %4 %5 %6 %7",
70                   SPV_ENV_UNIVERSAL_1_1),
71               Eq("Expected id to start with %."));
72   EXPECT_THAT(
73       CompileFailure(
74           "%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6 \"abc\"",
75           SPV_ENV_UNIVERSAL_1_1),
76       Eq("Expected id to start with %."));
77 }
78 
79 using OpGetKernelMaxNumSubgroupsTest = spvtest::TextToBinaryTest;
80 
TEST_F(OpGetKernelMaxNumSubgroupsTest,OpcodeAssemblesInV10)81 TEST_F(OpGetKernelMaxNumSubgroupsTest, OpcodeAssemblesInV10) {
82   EXPECT_THAT(
83       CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
84                            "%invoke %param %param_size %param_align",
85                            SPV_ENV_UNIVERSAL_1_0),
86       Eq(MakeInstruction(SpvOpGetKernelMaxNumSubgroups, {1, 2, 3, 4, 5, 6})));
87 }
88 
TEST_F(OpGetKernelMaxNumSubgroupsTest,ArgumentCount)89 TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentCount) {
90   EXPECT_THAT(
91       CompileFailure("OpGetKernelMaxNumSubgroups", SPV_ENV_UNIVERSAL_1_1),
92       Eq("Expected <result-id> at the beginning of an instruction, found "
93          "'OpGetKernelMaxNumSubgroups'."));
94   EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups",
95                              SPV_ENV_UNIVERSAL_1_1),
96               Eq("Expected operand, found end of stream."));
97   EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5",
98                              SPV_ENV_UNIVERSAL_1_1),
99               Eq("Expected operand, found end of stream."));
100   EXPECT_THAT(
101       CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
102                            "%invoke %param %param_size %param_align",
103                            SPV_ENV_UNIVERSAL_1_1),
104       Eq(MakeInstruction(SpvOpGetKernelMaxNumSubgroups, {1, 2, 3, 4, 5, 6})));
105   EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups %type %invoke "
106                              "%param %param_size %param_align %extra",
107                              SPV_ENV_UNIVERSAL_1_1),
108               Eq("Expected '=', found end of stream."));
109 }
110 
TEST_F(OpGetKernelMaxNumSubgroupsTest,ArgumentTypes)111 TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentTypes) {
112   EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups 2 %3 %4 %5 %6",
113                              SPV_ENV_UNIVERSAL_1_1),
114               Eq("Expected id to start with %."));
115   EXPECT_THAT(
116       CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5 \"abc\"",
117                      SPV_ENV_UNIVERSAL_1_1),
118       Eq("Expected id to start with %."));
119 }
120 
121 }  // namespace
122 }  // namespace spvtools
123