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 23namespace spvtools { 24namespace { 25 26using SpirvVector = spvtest::TextToBinaryTest::SpirvVector; 27using spvtest::MakeInstruction; 28using ::testing::Eq; 29using TextToBinaryMisc = spvtest::TextToBinaryTest; 30 31TEST_F(TextToBinaryMisc, OpNop) { 32 EXPECT_THAT(CompiledInstructions("OpNop"), 33 Eq(MakeInstruction(spv::Op::OpNop, {}))); 34} 35 36TEST_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 45TEST_F(TextToBinaryMisc, OpWrong) { 46 EXPECT_THAT(CompileFailure(" OpWrong %1 %2"), 47 Eq("Invalid Opcode name 'OpWrong'")); 48} 49 50TEST_F(TextToBinaryMisc, OpWrongAfterRight) { 51 const auto assembly = R"( 52OpCapability Shader 53OpMemoryModel Logical GLSL450 54OpXYZ 55)"; 56 EXPECT_THAT(CompileFailure(assembly), Eq("Invalid Opcode name 'OpXYZ'")); 57} 58 59} // namespace 60} // namespace spvtools 61