text_to_binary.misc_test.cpp 1.8 KB

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