text_to_binary.misc_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // Assembler tests for instructions in the "Miscellaneous" section of the
  15. // SPIR-V spec.
  16. #include "test/unit_spirv.h"
  17. #include "gmock/gmock.h"
  18. #include "test/test_fixture.h"
  19. namespace spvtools {
  20. namespace {
  21. using SpirvVector = spvtest::TextToBinaryTest::SpirvVector;
  22. using spvtest::MakeInstruction;
  23. using ::testing::Eq;
  24. using TextToBinaryMisc = spvtest::TextToBinaryTest;
  25. TEST_F(TextToBinaryMisc, OpNop) {
  26. EXPECT_THAT(CompiledInstructions("OpNop"),
  27. Eq(MakeInstruction(spv::Op::OpNop, {})));
  28. }
  29. TEST_F(TextToBinaryMisc, OpUndef) {
  30. const SpirvVector code = CompiledInstructions(R"(%f32 = OpTypeFloat 32
  31. %u = OpUndef %f32)");
  32. const uint32_t typeID = 1;
  33. EXPECT_THAT(code[1], Eq(typeID));
  34. EXPECT_THAT(Subvector(code, 3),
  35. Eq(MakeInstruction(spv::Op::OpUndef, {typeID, 2})));
  36. }
  37. TEST_F(TextToBinaryMisc, OpWrong) {
  38. EXPECT_THAT(CompileFailure(" OpWrong %1 %2"),
  39. Eq("Invalid Opcode name 'OpWrong'"));
  40. }
  41. TEST_F(TextToBinaryMisc, OpWrongAfterRight) {
  42. const auto assembly = R"(
  43. OpCapability Shader
  44. OpMemoryModel Logical GLSL450
  45. OpXYZ
  46. )";
  47. EXPECT_THAT(CompileFailure(assembly), Eq("Invalid Opcode name 'OpXYZ'"));
  48. }
  49. } // namespace
  50. } // namespace spvtools