forked from KhronosGroup/SPIRV-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_to_binary.barrier_test.cpp
161 lines (137 loc) · 5.99 KB
/
text_to_binary.barrier_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) 2015-2016 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Assembler tests for instructions in the "Barrier Instructions" section
// of the SPIR-V spec.
#include "unit_spirv.h"
#include "test_fixture.h"
#include "gmock/gmock.h"
namespace {
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::_;
using spvtest::MakeInstruction;
using spvtest::TextToBinaryTest;
// Test OpMemoryBarrier
using OpMemoryBarrier = spvtest::TextToBinaryTest;
TEST_F(OpMemoryBarrier, Good) {
const std::string input = "OpMemoryBarrier %1 %2\n";
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(SpvOpMemoryBarrier, {1, 2})));
EXPECT_THAT(EncodeAndDecodeSuccessfully(input), Eq(input));
}
TEST_F(OpMemoryBarrier, BadMissingScopeId) {
const std::string input = "OpMemoryBarrier\n";
EXPECT_THAT(CompileFailure(input),
Eq("Expected operand, found end of stream."));
}
TEST_F(OpMemoryBarrier, BadInvalidScopeId) {
const std::string input = "OpMemoryBarrier 99\n";
EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
}
TEST_F(OpMemoryBarrier, BadMissingMemorySemanticsId) {
const std::string input = "OpMemoryBarrier %scope\n";
EXPECT_THAT(CompileFailure(input),
Eq("Expected operand, found end of stream."));
}
TEST_F(OpMemoryBarrier, BadInvalidMemorySemanticsId) {
const std::string input = "OpMemoryBarrier %scope 14\n";
EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
}
// TODO(dneto): OpControlBarrier
// TODO(dneto): OpGroupAsyncCopy
// TODO(dneto): OpGroupWaitEvents
// TODO(dneto): OpGroupAll
// TODO(dneto): OpGroupAny
// TODO(dneto): OpGroupBroadcast
// TODO(dneto): OpGroupIAdd
// TODO(dneto): OpGroupFAdd
// TODO(dneto): OpGroupFMin
// TODO(dneto): OpGroupUMin
// TODO(dneto): OpGroupSMin
// TODO(dneto): OpGroupFMax
// TODO(dneto): OpGroupUMax
// TODO(dneto): OpGroupSMax
using NamedMemoryBarrierTest = spvtest::TextToBinaryTest;
TEST_F(NamedMemoryBarrierTest, OpcodeUnrecognizedInV10) {
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier %bar %scope %semantics",
SPV_ENV_UNIVERSAL_1_0),
Eq("Invalid Opcode name 'OpMemoryNamedBarrier'"));
}
TEST_F(NamedMemoryBarrierTest, ArgumentCount) {
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected operand, found end of stream."));
EXPECT_THAT(
CompileFailure("OpMemoryNamedBarrier %bar", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected operand, found end of stream."));
EXPECT_THAT(
CompileFailure("OpMemoryNamedBarrier %bar %scope", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected operand, found end of stream."));
EXPECT_THAT(
CompiledInstructions("OpMemoryNamedBarrier %bar %scope %semantics",
SPV_ENV_UNIVERSAL_1_1),
ElementsAre(spvOpcodeMake(4, SpvOpMemoryNamedBarrier), _, _, _));
EXPECT_THAT(
CompileFailure("OpMemoryNamedBarrier %bar %scope %semantics %extra",
SPV_ENV_UNIVERSAL_1_1),
Eq("Expected '=', found end of stream."));
}
TEST_F(NamedMemoryBarrierTest, ArgumentTypes) {
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier 123 %scope %semantics",
SPV_ENV_UNIVERSAL_1_1),
Eq("Expected id to start with %."));
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier %bar %scope \"semantics\"",
SPV_ENV_UNIVERSAL_1_1),
Eq("Expected id to start with %."));
}
using TypeNamedBarrierTest = spvtest::TextToBinaryTest;
TEST_F(TypeNamedBarrierTest, OpcodeUnrecognizedInV10) {
EXPECT_THAT(CompileFailure("%t = OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_0),
Eq("Invalid Opcode name 'OpTypeNamedBarrier'"));
}
TEST_F(TypeNamedBarrierTest, ArgumentCount) {
EXPECT_THAT(CompileFailure("OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected <result-id> at the beginning of an instruction, "
"found 'OpTypeNamedBarrier'."));
EXPECT_THAT(
CompiledInstructions("%t = OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
ElementsAre(spvOpcodeMake(2, SpvOpTypeNamedBarrier), _));
EXPECT_THAT(
CompileFailure("%t = OpTypeNamedBarrier 1 2 3", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected <opcode> or <result-id> at the beginning of an instruction, "
"found '1'."));
}
using NamedBarrierInitializeTest = spvtest::TextToBinaryTest;
TEST_F(NamedBarrierInitializeTest, OpcodeUnrecognizedInV10) {
EXPECT_THAT(CompileFailure("%bar = OpNamedBarrierInitialize %type %count",
SPV_ENV_UNIVERSAL_1_0),
Eq("Invalid Opcode name 'OpNamedBarrierInitialize'"));
}
TEST_F(NamedBarrierInitializeTest, ArgumentCount) {
EXPECT_THAT(
CompileFailure("%bar = OpNamedBarrierInitialize", SPV_ENV_UNIVERSAL_1_1),
Eq("Expected operand, found end of stream."));
EXPECT_THAT(CompileFailure("%bar = OpNamedBarrierInitialize %ype",
SPV_ENV_UNIVERSAL_1_1),
Eq("Expected operand, found end of stream."));
EXPECT_THAT(
CompiledInstructions("%bar = OpNamedBarrierInitialize %type %count",
SPV_ENV_UNIVERSAL_1_1),
ElementsAre(spvOpcodeMake(4, SpvOpNamedBarrierInitialize), _, _, _));
EXPECT_THAT(
CompileFailure("%bar = OpNamedBarrierInitialize %type %count \"extra\"",
SPV_ENV_UNIVERSAL_1_1),
Eq("Expected <opcode> or <result-id> at the beginning of an instruction, "
"found '\"extra\"'."));
}
} // anonymous namespace