text_to_binary.pipe_storage_test.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(SpvOpTypePipeStorage, {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(SpvOpTypePipeStorage, {1})));
  36. EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5",
  37. SPV_ENV_UNIVERSAL_1_1),
  38. Eq("'=' expected after result id."));
  39. }
  40. using OpConstantPipeStorageTest = spvtest::TextToBinaryTest;
  41. TEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) {
  42. EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
  43. SPV_ENV_UNIVERSAL_1_0),
  44. Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5})));
  45. }
  46. TEST_F(OpConstantPipeStorageTest, ArgumentCount) {
  47. EXPECT_THAT(
  48. CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  49. Eq("Expected <result-id> at the beginning of an instruction, found "
  50. "'OpConstantPipeStorage'."));
  51. EXPECT_THAT(
  52. CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  53. Eq("Expected operand, found end of stream."));
  54. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4",
  55. SPV_ENV_UNIVERSAL_1_1),
  56. Eq("Expected operand, found end of stream."));
  57. EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5",
  58. SPV_ENV_UNIVERSAL_1_1),
  59. Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5})));
  60. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7",
  61. SPV_ENV_UNIVERSAL_1_1),
  62. Eq("'=' expected after result id."));
  63. }
  64. TEST_F(OpConstantPipeStorageTest, ArgumentTypes) {
  65. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5",
  66. SPV_ENV_UNIVERSAL_1_1),
  67. Eq("Invalid unsigned integer literal: %3"));
  68. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5",
  69. SPV_ENV_UNIVERSAL_1_1),
  70. Eq("Invalid unsigned integer literal: %4"));
  71. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5",
  72. SPV_ENV_UNIVERSAL_1_1),
  73. Eq("Expected id to start with %."));
  74. EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"",
  75. SPV_ENV_UNIVERSAL_1_1),
  76. Eq("Invalid unsigned integer literal: \"ab\""));
  77. }
  78. using OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest;
  79. TEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) {
  80. EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
  81. SPV_ENV_UNIVERSAL_1_0),
  82. Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3})));
  83. }
  84. TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) {
  85. EXPECT_THAT(
  86. CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  87. Eq("Expected <result-id> at the beginning of an instruction, found "
  88. "'OpCreatePipeFromPipeStorage'."));
  89. EXPECT_THAT(
  90. CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1),
  91. Eq("Expected operand, found end of stream."));
  92. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop",
  93. SPV_ENV_UNIVERSAL_1_1),
  94. Eq("Expected operand, found next instruction instead."));
  95. EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3",
  96. SPV_ENV_UNIVERSAL_1_1),
  97. Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3})));
  98. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5",
  99. SPV_ENV_UNIVERSAL_1_1),
  100. Eq("'=' expected after result id."));
  101. }
  102. TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) {
  103. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3",
  104. SPV_ENV_UNIVERSAL_1_1),
  105. Eq("Expected id to start with %."));
  106. EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3",
  107. SPV_ENV_UNIVERSAL_1_1),
  108. Eq("Expected id to start with %."));
  109. }
  110. } // namespace
  111. } // namespace spvtools