1fd4e5da5Sopenharmony_ci// Copyright (c) 2015-2016 The Khronos Group Inc. 2fd4e5da5Sopenharmony_ci// 3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 6fd4e5da5Sopenharmony_ci// 7fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 13fd4e5da5Sopenharmony_ci// limitations under the License. 14fd4e5da5Sopenharmony_ci 15fd4e5da5Sopenharmony_ci#include <vector> 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h" 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_cinamespace spvtools { 20fd4e5da5Sopenharmony_cinamespace { 21fd4e5da5Sopenharmony_ci 22fd4e5da5Sopenharmony_ciusing GetTargetTest = ::testing::TestWithParam<spv_target_env>; 23fd4e5da5Sopenharmony_ciusing ::testing::ValuesIn; 24fd4e5da5Sopenharmony_ci 25fd4e5da5Sopenharmony_ciTEST_P(GetTargetTest, Default) { 26fd4e5da5Sopenharmony_ci spv_operand_table table; 27fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_SUCCESS, spvOperandTableGet(&table, GetParam())); 28fd4e5da5Sopenharmony_ci ASSERT_NE(0u, table->count); 29fd4e5da5Sopenharmony_ci ASSERT_NE(nullptr, table->types); 30fd4e5da5Sopenharmony_ci} 31fd4e5da5Sopenharmony_ci 32fd4e5da5Sopenharmony_ciTEST_P(GetTargetTest, InvalidPointerTable) { 33fd4e5da5Sopenharmony_ci ASSERT_EQ(SPV_ERROR_INVALID_POINTER, spvOperandTableGet(nullptr, GetParam())); 34fd4e5da5Sopenharmony_ci} 35fd4e5da5Sopenharmony_ci 36fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(OperandTableGet, GetTargetTest, 37fd4e5da5Sopenharmony_ci ValuesIn(std::vector<spv_target_env>{ 38fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1, 39fd4e5da5Sopenharmony_ci SPV_ENV_VULKAN_1_0})); 40fd4e5da5Sopenharmony_ci 41fd4e5da5Sopenharmony_ciTEST(OperandString, AllAreDefinedExceptVariable) { 42fd4e5da5Sopenharmony_ci // None has no string, so don't test it. 43fd4e5da5Sopenharmony_ci EXPECT_EQ(0u, SPV_OPERAND_TYPE_NONE); 44fd4e5da5Sopenharmony_ci // Start testing at enum with value 1, skipping None. 45fd4e5da5Sopenharmony_ci for (int i = 1; i < int(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES); i++) { 46fd4e5da5Sopenharmony_ci const auto type = static_cast<spv_operand_type_t>(i); 47fd4e5da5Sopenharmony_ci if (spvOperandIsVariable(type)) { 48fd4e5da5Sopenharmony_ci EXPECT_STREQ("unknown", spvOperandTypeStr(type)) 49fd4e5da5Sopenharmony_ci << " variable type " << i << " has a name '" 50fd4e5da5Sopenharmony_ci << spvOperandTypeStr(type) << "'when it should not"; 51fd4e5da5Sopenharmony_ci } else { 52fd4e5da5Sopenharmony_ci EXPECT_STRNE("unknown", spvOperandTypeStr(type)) 53fd4e5da5Sopenharmony_ci << " operand type " << i << " has no name when it should"; 54fd4e5da5Sopenharmony_ci } 55fd4e5da5Sopenharmony_ci } 56fd4e5da5Sopenharmony_ci} 57fd4e5da5Sopenharmony_ci 58fd4e5da5Sopenharmony_ciTEST(OperandIsConcreteMask, Sample) { 59fd4e5da5Sopenharmony_ci // Check a few operand types preceding the concrete mask types. 60fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_NONE)); 61fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_ID)); 62fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_LITERAL_INTEGER)); 63fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_CAPABILITY)); 64fd4e5da5Sopenharmony_ci 65fd4e5da5Sopenharmony_ci // Check all the concrete mask operand types. 66fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_IMAGE)); 67fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_FP_FAST_MATH_MODE)); 68fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_SELECTION_CONTROL)); 69fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_LOOP_CONTROL)); 70fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_FUNCTION_CONTROL)); 71fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_MEMORY_ACCESS)); 72fd4e5da5Sopenharmony_ci 73fd4e5da5Sopenharmony_ci // Check a few operand types after the concrete mask types, including the 74fd4e5da5Sopenharmony_ci // optional forms for Image and MemoryAccess. 75fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_ID)); 76fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_IMAGE)); 77fd4e5da5Sopenharmony_ci EXPECT_FALSE( 78fd4e5da5Sopenharmony_ci spvOperandIsConcreteMask(SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS)); 79fd4e5da5Sopenharmony_ci} 80fd4e5da5Sopenharmony_ci 81fd4e5da5Sopenharmony_ciTEST(OperandType, NoneTypeClassification) { 82fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcrete(SPV_OPERAND_TYPE_NONE)); 83fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsOptional(SPV_OPERAND_TYPE_NONE)); 84fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsVariable(SPV_OPERAND_TYPE_NONE)); 85fd4e5da5Sopenharmony_ci} 86fd4e5da5Sopenharmony_ci 87fd4e5da5Sopenharmony_ciTEST(OperandType, EndSentinelTypeClassification) { 88fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcrete(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES)); 89fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsOptional(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES)); 90fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsVariable(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES)); 91fd4e5da5Sopenharmony_ci} 92fd4e5da5Sopenharmony_ci 93fd4e5da5Sopenharmony_ciTEST(OperandType, WidthForcingTypeClassification) { 94fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsConcrete(SPV_FORCE_32BIT_spv_operand_type_t)); 95fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsOptional(SPV_FORCE_32BIT_spv_operand_type_t)); 96fd4e5da5Sopenharmony_ci EXPECT_FALSE(spvOperandIsVariable(SPV_FORCE_32BIT_spv_operand_type_t)); 97fd4e5da5Sopenharmony_ci} 98fd4e5da5Sopenharmony_ci 99fd4e5da5Sopenharmony_ciTEST(OperandType, EachTypeIsEitherConcreteOrOptionalNotBoth) { 100fd4e5da5Sopenharmony_ci EXPECT_EQ(0u, SPV_OPERAND_TYPE_NONE); 101fd4e5da5Sopenharmony_ci // Start testing at enum with value 1, skipping None. 102fd4e5da5Sopenharmony_ci for (int i = 1; i < int(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES); i++) { 103fd4e5da5Sopenharmony_ci const auto type = static_cast<spv_operand_type_t>(i); 104fd4e5da5Sopenharmony_ci EXPECT_NE(spvOperandIsConcrete(type), spvOperandIsOptional(type)) 105fd4e5da5Sopenharmony_ci << " operand type " << int(type) << " concrete? " 106fd4e5da5Sopenharmony_ci << int(spvOperandIsConcrete(type)) << " optional? " 107fd4e5da5Sopenharmony_ci << int(spvOperandIsOptional(type)); 108fd4e5da5Sopenharmony_ci } 109fd4e5da5Sopenharmony_ci} 110fd4e5da5Sopenharmony_ci 111fd4e5da5Sopenharmony_ciTEST(OperandType, EachVariableTypeIsOptional) { 112fd4e5da5Sopenharmony_ci EXPECT_EQ(0u, SPV_OPERAND_TYPE_NONE); 113fd4e5da5Sopenharmony_ci // Start testing at enum with value 1, skipping None. 114fd4e5da5Sopenharmony_ci for (int i = 1; i < int(SPV_OPERAND_TYPE_NUM_OPERAND_TYPES); i++) { 115fd4e5da5Sopenharmony_ci const auto type = static_cast<spv_operand_type_t>(i); 116fd4e5da5Sopenharmony_ci if (spvOperandIsVariable(type)) { 117fd4e5da5Sopenharmony_ci EXPECT_TRUE(spvOperandIsOptional(type)) << " variable type " << int(type); 118fd4e5da5Sopenharmony_ci } 119fd4e5da5Sopenharmony_ci } 120fd4e5da5Sopenharmony_ci} 121fd4e5da5Sopenharmony_ci 122fd4e5da5Sopenharmony_ci} // namespace 123fd4e5da5Sopenharmony_ci} // namespace spvtools 124