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 25namespace spvtools { 26namespace { 27 28using spvtest::EnumCase; 29using spvtest::MakeInstruction; 30using ::testing::Eq; 31 32// Test GroupOperation enum 33 34using GroupOperationTest = spvtest::TextToBinaryTestBase< 35 ::testing::TestWithParam<EnumCase<spv::GroupOperation>>>; 36 37TEST_P(GroupOperationTest, AnyGroupOperation) { 38 const std::string input = 39 "%result = OpGroupIAdd %type %scope " + GetParam().name() + " %x"; 40 EXPECT_THAT(CompiledInstructions(input), 41 Eq(MakeInstruction(spv::Op::OpGroupIAdd, 42 {1, 2, 3, (uint32_t)GetParam().value(), 4}))); 43} 44 45// clang-format off 46#define CASE(NAME) { spv::GroupOperation::NAME, #NAME} 47INSTANTIATE_TEST_SUITE_P(TextToBinaryGroupOperation, GroupOperationTest, 48 ::testing::ValuesIn(std::vector<EnumCase<spv::GroupOperation>>{ 49 CASE(Reduce), 50 CASE(InclusiveScan), 51 CASE(ExclusiveScan), 52 })); 53#undef CASE 54// clang-format on 55 56TEST_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