text_to_binary.pipe_storage_test.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (c) 2016 Google 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. #include "gmock/gmock.h"
  15. #include "test/test_fixture.h"
  16. namespace spvtools {
  17. namespace {
  18. using ::spvtest::MakeInstruction;
  19. using ::testing::Eq;
  20. using OpTypePipeStorageTest = spvtest::TextToBinaryTest;
  21. // It can assemble, but should not validate. Validation checks for version
  22. // and capability are in another test file.
  23. TEST_F(OpTypePipeStorageTest, OpcodeAssemblesInV10) {
  24. EXPECT_THAT(
  25. CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_0),
  26. Eq(MakeInstruction(spv::Op::OpTypePipeStorage, {1})));
  27. }
  28. TEST_F(OpTypePipeStorageTest, ArgumentCount) {
  29. EXPECT_THAT(
  30. CompileFailure("OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
  31. Eq("Expected <result-id> at the beginning of an instruction, found "
  32. "'OpTypePipeStorage'."));
  33. EXPECT_THAT(
  34. CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1),
  35. Eq(MakeInstruction(spv::Op::OpTypePipeStorage, {1})));
  36. EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5",
  37. SPV_ENV_UNIVERSAL_1_1),
  38. Eq("'=' expected after result id but found '%2'."));
  39. }
  40. using OpConstantPipeStorageTest = spvtest::TextToBinaryTest;
  41. TEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) {
  42. EXPECT_THAT(
  43. CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
  44. SPV_ENV_UNIVERSAL_1_0),
  45. Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
  46. }
  47. TEST_F(OpConstantPipeStorageTest, ArgumentCount) {
  48. EXPECT_THAT(
  49. CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  50. Eq("Expected <result-id> at the beginning of an instruction, found "
  51. "'OpConstantPipeStorage'."));
  52. EXPECT_THAT(
  53. CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  54. Eq("Expected operand for OpConstantPipeStorage instruction, but found "
  55. "the end of the stream."));
  56. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4",
  57. SPV_ENV_UNIVERSAL_1_1),
  58. Eq("Expected operand for OpConstantPipeStorage instruction, but "
  59. "found the end of the stream."));
  60. EXPECT_THAT(
  61. CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
  62. SPV_ENV_UNIVERSAL_1_1),
  63. Eq(MakeInstruction(spv::Op::OpConstantPipeStorage, {1, 2, 3, 4, 5})));
  64. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7",
  65. SPV_ENV_UNIVERSAL_1_1),
  66. Eq("'=' expected after result id but found '%7'."));
  67. }
  68. TEST_F(OpConstantPipeStorageTest, ArgumentTypes) {
  69. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5",
  70. SPV_ENV_UNIVERSAL_1_1),
  71. Eq("Invalid unsigned integer literal: %3"));
  72. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5",
  73. SPV_ENV_UNIVERSAL_1_1),
  74. Eq("Invalid unsigned integer literal: %4"));
  75. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5",
  76. SPV_ENV_UNIVERSAL_1_1),
  77. Eq("Expected id to start with %."));
  78. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"",
  79. SPV_ENV_UNIVERSAL_1_1),
  80. Eq("Invalid unsigned integer literal: \"ab\""));
  81. }
  82. using OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest;
  83. TEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) {
  84. EXPECT_THAT(
  85. CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
  86. SPV_ENV_UNIVERSAL_1_0),
  87. Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
  88. }
  89. TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) {
  90. EXPECT_THAT(
  91. CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  92. Eq("Expected <result-id> at the beginning of an instruction, found "
  93. "'OpCreatePipeFromPipeStorage'."));
  94. EXPECT_THAT(
  95. CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  96. Eq("Expected operand for OpCreatePipeFromPipeStorage instruction, but "
  97. "found the end of the stream."));
  98. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop",
  99. SPV_ENV_UNIVERSAL_1_1),
  100. Eq("Expected operand for OpCreatePipeFromPipeStorage "
  101. "instruction, but found the next instruction instead."));
  102. EXPECT_THAT(
  103. CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
  104. SPV_ENV_UNIVERSAL_1_1),
  105. Eq(MakeInstruction(spv::Op::OpCreatePipeFromPipeStorage, {1, 2, 3})));
  106. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5",
  107. SPV_ENV_UNIVERSAL_1_1),
  108. Eq("'=' expected after result id but found '%5'."));
  109. }
  110. TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) {
  111. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3",
  112. SPV_ENV_UNIVERSAL_1_1),
  113. Eq("Expected id to start with %."));
  114. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3",
  115. SPV_ENV_UNIVERSAL_1_1),
  116. Eq("Expected id to start with %."));
  117. }
  118. } // namespace
  119. } // namespace spvtools