| 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 |
|
| 31 |
TEST_F(TextToBinaryMisc, OpNop) { |
| 32 |
EXPECT_THAT(CompiledInstructions("OpNop"), Eq(MakeInstruction(SpvOpNop, {}))); |
| 33 |
} |
| 34 |
|
| 35 |
TEST_F(TextToBinaryMisc, OpUndef) { |
| 36 |
const SpirvVector code = CompiledInstructions(R"(%f32 = OpTypeFloat 32 |
| 37 |
%u = OpUndef %f32)"); |
| 38 |
const uint32_t typeID = 1; |
| 39 |
EXPECT_THAT(code[1], Eq(typeID)); |
| 40 |
EXPECT_THAT(Subvector(code, 3), Eq(MakeInstruction(SpvOpUndef, {typeID, 2}))); |
| 41 |
} |
| 42 |
|
| 43 |
TEST_F(TextToBinaryMisc, OpWrong) { |
| 44 |
EXPECT_THAT(CompileFailure(" OpWrong %1 %2"), |
| 45 |
Eq("Invalid Opcode name 'OpWrong'")); |
| 46 |
} |
| 47 |
|
| 48 |
TEST_F(TextToBinaryMisc, OpWrongAfterRight) { |
| 49 |
const auto assembly = R"( |
| 50 |
OpCapability Shader |
| 51 |
OpMemoryModel Logical GLSL450 |
| 52 |
OpXYZ |
| 53 |
)"; |
| 54 |
EXPECT_THAT(CompileFailure(assembly), Eq("Invalid Opcode name 'OpXYZ'")); |
| 55 |
} |
| 56 |
|
| 57 |
} // namespace |
| 58 |
} // namespace spvtools |