operand_test.cpp 2.9 KB

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