• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015-2016 The Khronos Group 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 "Miscellaneous" section of the
16 // 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 SpirvVector = spvtest::TextToBinaryTest::SpirvVector;
27 using spvtest::MakeInstruction;
28 using ::testing::Eq;
29 using TextToBinaryMisc = spvtest::TextToBinaryTest;
30 
TEST_F(TextToBinaryMisc,OpNop)31 TEST_F(TextToBinaryMisc, OpNop) {
32   EXPECT_THAT(CompiledInstructions("OpNop"),
33               Eq(MakeInstruction(spv::Op::OpNop, {})));
34 }
35 
TEST_F(TextToBinaryMisc,OpUndef)36 TEST_F(TextToBinaryMisc, OpUndef) {
37   const SpirvVector code = CompiledInstructions(R"(%f32 = OpTypeFloat 32
38                                                    %u = OpUndef %f32)");
39   const uint32_t typeID = 1;
40   EXPECT_THAT(code[1], Eq(typeID));
41   EXPECT_THAT(Subvector(code, 3),
42               Eq(MakeInstruction(spv::Op::OpUndef, {typeID, 2})));
43 }
44 
TEST_F(TextToBinaryMisc,OpWrong)45 TEST_F(TextToBinaryMisc, OpWrong) {
46   EXPECT_THAT(CompileFailure(" OpWrong %1 %2"),
47               Eq("Invalid Opcode name 'OpWrong'"));
48 }
49 
TEST_F(TextToBinaryMisc,OpWrongAfterRight)50 TEST_F(TextToBinaryMisc, OpWrongAfterRight) {
51   const auto assembly = R"(
52 OpCapability Shader
53 OpMemoryModel Logical GLSL450
54 OpXYZ
55 )";
56   EXPECT_THAT(CompileFailure(assembly), Eq("Invalid Opcode name 'OpXYZ'"));
57 }
58 
59 }  // namespace
60 }  // namespace spvtools
61