2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-14 18:50:37 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-09-14 18:50:37 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-14 18:50:37 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-09-14 18:50:37 +00:00
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Function" section of the
|
|
|
|
// SPIR-V spec.
|
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-09-14 18:50:37 +00:00
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "test/test_fixture.h"
|
|
|
|
#include "test/unit_spirv.h"
|
2015-09-14 18:50:37 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-14 18:50:37 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-10-01 20:58:17 +00:00
|
|
|
using spvtest::EnumCase;
|
2015-09-14 18:50:37 +00:00
|
|
|
using spvtest::MakeInstruction;
|
2015-10-01 20:58:17 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2015-09-14 18:50:37 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
|
|
|
|
// Test OpFunction
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using OpFunctionControlTest = spvtest::TextToBinaryTestBase<
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::TestWithParam<EnumCase<SpvFunctionControlMask>>>;
|
2015-09-14 18:50:37 +00:00
|
|
|
|
|
|
|
TEST_P(OpFunctionControlTest, AnySingleFunctionControlMask) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "%result_id = OpFunction %result_type " +
|
|
|
|
GetParam().name() + " %function_type ";
|
2015-09-14 18:50:37 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpFunction, {1, 2, GetParam().value(), 3})));
|
2015-09-14 18:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clang-format off
|
2015-10-28 17:40:52 +00:00
|
|
|
#define CASE(VALUE,NAME) { SpvFunctionControl##VALUE, NAME }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryFunctionTest, OpFunctionControlTest,
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::ValuesIn(std::vector<EnumCase<SpvFunctionControlMask>>{
|
2015-09-14 18:50:37 +00:00
|
|
|
CASE(MaskNone, "None"),
|
|
|
|
CASE(InlineMask, "Inline"),
|
|
|
|
CASE(DontInlineMask, "DontInline"),
|
|
|
|
CASE(PureMask, "Pure"),
|
|
|
|
CASE(ConstMask, "Const"),
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-14 18:50:37 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-10-13 20:00:01 +00:00
|
|
|
TEST_F(OpFunctionControlTest, CombinedFunctionControlMask) {
|
2015-09-16 22:32:54 +00:00
|
|
|
// Sample a single combination. This ensures we've integrated
|
|
|
|
// the instruction parsing logic with spvTextParseMask.
|
|
|
|
const std::string input =
|
|
|
|
"%result_id = OpFunction %result_type Inline|Pure|Const %function_type";
|
2015-10-28 17:40:52 +00:00
|
|
|
const uint32_t expected_mask = SpvFunctionControlInlineMask |
|
|
|
|
SpvFunctionControlPureMask |
|
|
|
|
SpvFunctionControlConstMask;
|
2015-09-16 22:32:54 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpFunction, {1, 2, expected_mask, 3})));
|
2015-09-16 22:32:54 +00:00
|
|
|
}
|
2015-09-14 18:50:37 +00:00
|
|
|
|
2015-10-13 20:00:01 +00:00
|
|
|
TEST_F(OpFunctionControlTest, WrongFunctionControl) {
|
|
|
|
EXPECT_THAT(CompileFailure("%r = OpFunction %t Inline|Unroll %ft"),
|
2015-11-24 23:37:24 +00:00
|
|
|
Eq("Invalid function control operand 'Inline|Unroll'."));
|
2015-10-13 20:00:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 18:50:37 +00:00
|
|
|
// TODO(dneto): OpFunctionParameter
|
|
|
|
// TODO(dneto): OpFunctionEnd
|
|
|
|
// TODO(dneto): OpFunctionCall
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|