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