text_to_binary.group_test.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "Group Instrucions" section of the
  15. // SPIR-V spec.
  16. #include <string>
  17. #include <vector>
  18. #include "gmock/gmock.h"
  19. #include "test/test_fixture.h"
  20. #include "test/unit_spirv.h"
  21. namespace spvtools {
  22. namespace {
  23. using spvtest::EnumCase;
  24. using spvtest::MakeInstruction;
  25. using ::testing::Eq;
  26. // Test GroupOperation enum
  27. using GroupOperationTest = spvtest::TextToBinaryTestBase<
  28. ::testing::TestWithParam<EnumCase<SpvGroupOperation>>>;
  29. TEST_P(GroupOperationTest, AnyGroupOperation) {
  30. const std::string input =
  31. "%result = OpGroupIAdd %type %scope " + GetParam().name() + " %x";
  32. EXPECT_THAT(
  33. CompiledInstructions(input),
  34. Eq(MakeInstruction(SpvOpGroupIAdd, {1, 2, 3, GetParam().value(), 4})));
  35. }
  36. // clang-format off
  37. #define CASE(NAME) { SpvGroupOperation##NAME, #NAME}
  38. INSTANTIATE_TEST_SUITE_P(TextToBinaryGroupOperation, GroupOperationTest,
  39. ::testing::ValuesIn(std::vector<EnumCase<SpvGroupOperation>>{
  40. CASE(Reduce),
  41. CASE(InclusiveScan),
  42. CASE(ExclusiveScan),
  43. }));
  44. #undef CASE
  45. // clang-format on
  46. TEST_F(GroupOperationTest, WrongGroupOperation) {
  47. EXPECT_THAT(CompileFailure("%r = OpGroupUMin %t %e xxyyzz %x"),
  48. Eq("Invalid group operation 'xxyyzz'."));
  49. }
  50. // TODO(dneto): OpGroupAsyncCopy
  51. // TODO(dneto): OpGroupWaitEvents
  52. // TODO(dneto): OpGroupAll
  53. // TODO(dneto): OpGroupAny
  54. // TODO(dneto): OpGroupBroadcast
  55. // TODO(dneto): OpGroupIAdd
  56. // TODO(dneto): OpGroupFAdd
  57. // TODO(dneto): OpGroupFMin
  58. // TODO(dneto): OpGroupUMin
  59. // TODO(dneto): OpGroupSMin
  60. // TODO(dneto): OpGroupFMax
  61. // TODO(dneto): OpGroupUMax
  62. // TODO(dneto): OpGroupSMax
  63. } // namespace
  64. } // namespace spvtools