text_to_binary.subgroup_dispatch_test.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Assembler tests for instructions in the "Barrier Instructions" section
  15. // of the 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 ::spvtest::MakeInstruction;
  22. using ::testing::Eq;
  23. using OpGetKernelLocalSizeForSubgroupCountTest = spvtest::TextToBinaryTest;
  24. // We should be able to assemble it. Validation checks are in another test
  25. // file.
  26. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, OpcodeAssemblesInV10) {
  27. EXPECT_THAT(
  28. CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  29. "%sgcount %invoke %param %param_size %param_align",
  30. SPV_ENV_UNIVERSAL_1_0),
  31. Eq(MakeInstruction(SpvOpGetKernelLocalSizeForSubgroupCount,
  32. {1, 2, 3, 4, 5, 6, 7})));
  33. }
  34. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentCount) {
  35. EXPECT_THAT(CompileFailure("OpGetKernelLocalSizeForSubgroupCount",
  36. SPV_ENV_UNIVERSAL_1_1),
  37. Eq("Expected <result-id> at the beginning of an instruction, "
  38. "found 'OpGetKernelLocalSizeForSubgroupCount'."));
  39. EXPECT_THAT(CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount",
  40. SPV_ENV_UNIVERSAL_1_1),
  41. Eq("Expected operand, found end of stream."));
  42. EXPECT_THAT(
  43. CompileFailure("%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6",
  44. SPV_ENV_UNIVERSAL_1_1),
  45. Eq("Expected operand, found end of stream."));
  46. EXPECT_THAT(
  47. CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  48. "%sgcount %invoke %param %param_size %param_align",
  49. SPV_ENV_UNIVERSAL_1_1),
  50. Eq(MakeInstruction(SpvOpGetKernelLocalSizeForSubgroupCount,
  51. {1, 2, 3, 4, 5, 6, 7})));
  52. EXPECT_THAT(
  53. CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  54. "%sgcount %invoke %param %param_size %param_align %extra",
  55. SPV_ENV_UNIVERSAL_1_1),
  56. Eq("Expected '=', found end of stream."));
  57. }
  58. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentTypes) {
  59. EXPECT_THAT(CompileFailure(
  60. "%1 = OpGetKernelLocalSizeForSubgroupCount 2 %3 %4 %5 %6 %7",
  61. SPV_ENV_UNIVERSAL_1_1),
  62. Eq("Expected id to start with %."));
  63. EXPECT_THAT(
  64. CompileFailure(
  65. "%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6 \"abc\"",
  66. SPV_ENV_UNIVERSAL_1_1),
  67. Eq("Expected id to start with %."));
  68. }
  69. using OpGetKernelMaxNumSubgroupsTest = spvtest::TextToBinaryTest;
  70. TEST_F(OpGetKernelMaxNumSubgroupsTest, OpcodeAssemblesInV10) {
  71. EXPECT_THAT(
  72. CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
  73. "%invoke %param %param_size %param_align",
  74. SPV_ENV_UNIVERSAL_1_0),
  75. Eq(MakeInstruction(SpvOpGetKernelMaxNumSubgroups, {1, 2, 3, 4, 5, 6})));
  76. }
  77. TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentCount) {
  78. EXPECT_THAT(
  79. CompileFailure("OpGetKernelMaxNumSubgroups", SPV_ENV_UNIVERSAL_1_1),
  80. Eq("Expected <result-id> at the beginning of an instruction, found "
  81. "'OpGetKernelMaxNumSubgroups'."));
  82. EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups",
  83. SPV_ENV_UNIVERSAL_1_1),
  84. Eq("Expected operand, found end of stream."));
  85. EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5",
  86. SPV_ENV_UNIVERSAL_1_1),
  87. Eq("Expected operand, found end of stream."));
  88. EXPECT_THAT(
  89. CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
  90. "%invoke %param %param_size %param_align",
  91. SPV_ENV_UNIVERSAL_1_1),
  92. Eq(MakeInstruction(SpvOpGetKernelMaxNumSubgroups, {1, 2, 3, 4, 5, 6})));
  93. EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups %type %invoke "
  94. "%param %param_size %param_align %extra",
  95. SPV_ENV_UNIVERSAL_1_1),
  96. Eq("Expected '=', found end of stream."));
  97. }
  98. TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentTypes) {
  99. EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups 2 %3 %4 %5 %6",
  100. SPV_ENV_UNIVERSAL_1_1),
  101. Eq("Expected id to start with %."));
  102. EXPECT_THAT(
  103. CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5 \"abc\"",
  104. SPV_ENV_UNIVERSAL_1_1),
  105. Eq("Expected id to start with %."));
  106. }
  107. } // namespace
  108. } // namespace spvtools