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