Setup dependent external sources
[platform/upstream/VK-GL-CTS.git] / external / spirv-tools / src / test / operand_test.cpp
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 #include "unit_spirv.h"
16
17 namespace {
18
19 using GetTargetTest = ::testing::TestWithParam<spv_target_env>;
20 using ::testing::ValuesIn;
21 using std::vector;
22
23 TEST_P(GetTargetTest, Default) {
24   spv_operand_table table;
25   ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&table, GetParam()));
26   ASSERT_NE(0u, table->count);
27   ASSERT_NE(nullptr, table->types);
28 }
29
30 TEST_P(GetTargetTest, InvalidPointerTable) {
31   ASSERT_EQ(SPV_ERROR_INVALID_POINTER, spvOperandTableGet(nullptr, GetParam()));
32 }
33
34 INSTANTIATE_TEST_CASE_P(OperandTableGet, GetTargetTest,
35                         ValuesIn(vector<spv_target_env>{SPV_ENV_UNIVERSAL_1_0,
36                                                         SPV_ENV_UNIVERSAL_1_1,
37                                                         SPV_ENV_VULKAN_1_0}), );
38
39 TEST(OperandString, AllAreDefinedExceptVariable) {
40   // None has no string, so don't test it.
41   EXPECT_EQ(0u, SPV_OPERAND_TYPE_NONE);
42   // Start testing at enum with value 1, skipping None.
43   for (int i = 1; i < int(SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE); i++) {
44     EXPECT_NE(nullptr, spvOperandTypeStr(static_cast<spv_operand_type_t>(i)))
45         << " Operand type " << i;
46   }
47 }
48
49 TEST(OperandIsConcreteMask, Sample) {
50   // Check a few operand types preceding the concrete mask types.
51   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_NONE));
52   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_ID));
53   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_LITERAL_INTEGER));
54   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_CAPABILITY));
55
56   // Check all the concrete mask operand types.
57   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_IMAGE));
58   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_FP_FAST_MATH_MODE));
59   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_SELECTION_CONTROL));
60   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_LOOP_CONTROL));
61   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_FUNCTION_CONTROL));
62   EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_MEMORY_ACCESS));
63
64   // Check a few operand types after the concrete mask types, including the
65   // optional forms for Image and MemoryAccess.
66   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_ID));
67   EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_IMAGE));
68   EXPECT_FALSE(
69       spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS));
70 }
71
72 }  // anonymous namespace