1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc. 2fd4e5da5Sopenharmony_ci// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights 3fd4e5da5Sopenharmony_ci// reserved. 4fd4e5da5Sopenharmony_ci// 5fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 6fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License. 7fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at 8fd4e5da5Sopenharmony_ci// 9fd4e5da5Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 10fd4e5da5Sopenharmony_ci// 11fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 12fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 13fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and 15fd4e5da5Sopenharmony_ci// limitations under the License. 16fd4e5da5Sopenharmony_ci 17fd4e5da5Sopenharmony_ci// Tests for OpExtension validator rules. 18fd4e5da5Sopenharmony_ci 19fd4e5da5Sopenharmony_ci#include <string> 20fd4e5da5Sopenharmony_ci#include <utility> 21fd4e5da5Sopenharmony_ci#include <vector> 22fd4e5da5Sopenharmony_ci 23fd4e5da5Sopenharmony_ci#include "gtest/gtest.h" 24fd4e5da5Sopenharmony_ci#include "source/enum_string_mapping.h" 25fd4e5da5Sopenharmony_ci#include "source/extensions.h" 26fd4e5da5Sopenharmony_ci 27fd4e5da5Sopenharmony_cinamespace spvtools { 28fd4e5da5Sopenharmony_cinamespace { 29fd4e5da5Sopenharmony_ci 30fd4e5da5Sopenharmony_ciusing ::testing::Values; 31fd4e5da5Sopenharmony_ciusing ::testing::ValuesIn; 32fd4e5da5Sopenharmony_ci 33fd4e5da5Sopenharmony_ciusing ExtensionTest = 34fd4e5da5Sopenharmony_ci ::testing::TestWithParam<std::pair<Extension, std::string>>; 35fd4e5da5Sopenharmony_ciusing UnknownExtensionTest = ::testing::TestWithParam<std::string>; 36fd4e5da5Sopenharmony_ciusing CapabilityTest = 37fd4e5da5Sopenharmony_ci ::testing::TestWithParam<std::pair<spv::Capability, std::string>>; 38fd4e5da5Sopenharmony_ci 39fd4e5da5Sopenharmony_ciTEST_P(ExtensionTest, TestExtensionFromString) { 40fd4e5da5Sopenharmony_ci const std::pair<Extension, std::string>& param = GetParam(); 41fd4e5da5Sopenharmony_ci const Extension extension = param.first; 42fd4e5da5Sopenharmony_ci const std::string extension_str = param.second; 43fd4e5da5Sopenharmony_ci Extension result_extension; 44fd4e5da5Sopenharmony_ci ASSERT_TRUE(GetExtensionFromString(extension_str.c_str(), &result_extension)); 45fd4e5da5Sopenharmony_ci EXPECT_EQ(extension, result_extension); 46fd4e5da5Sopenharmony_ci} 47fd4e5da5Sopenharmony_ci 48fd4e5da5Sopenharmony_ciTEST_P(ExtensionTest, TestExtensionToString) { 49fd4e5da5Sopenharmony_ci const std::pair<Extension, std::string>& param = GetParam(); 50fd4e5da5Sopenharmony_ci const Extension extension = param.first; 51fd4e5da5Sopenharmony_ci const std::string extension_str = param.second; 52fd4e5da5Sopenharmony_ci const std::string result_str = ExtensionToString(extension); 53fd4e5da5Sopenharmony_ci EXPECT_EQ(extension_str, result_str); 54fd4e5da5Sopenharmony_ci} 55fd4e5da5Sopenharmony_ci 56fd4e5da5Sopenharmony_ciTEST_P(UnknownExtensionTest, TestExtensionFromStringFails) { 57fd4e5da5Sopenharmony_ci Extension result_extension; 58fd4e5da5Sopenharmony_ci ASSERT_FALSE(GetExtensionFromString(GetParam().c_str(), &result_extension)); 59fd4e5da5Sopenharmony_ci} 60fd4e5da5Sopenharmony_ci 61fd4e5da5Sopenharmony_ciTEST_P(CapabilityTest, TestCapabilityToString) { 62fd4e5da5Sopenharmony_ci const std::pair<spv::Capability, std::string>& param = GetParam(); 63fd4e5da5Sopenharmony_ci const spv::Capability capability = param.first; 64fd4e5da5Sopenharmony_ci const std::string capability_str = param.second; 65fd4e5da5Sopenharmony_ci const std::string result_str = CapabilityToString(capability); 66fd4e5da5Sopenharmony_ci EXPECT_EQ(capability_str, result_str); 67fd4e5da5Sopenharmony_ci} 68fd4e5da5Sopenharmony_ci 69fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P( 70fd4e5da5Sopenharmony_ci AllExtensions, ExtensionTest, 71fd4e5da5Sopenharmony_ci ValuesIn(std::vector<std::pair<Extension, std::string>>({ 72fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_16bit_storage, "SPV_KHR_16bit_storage"}, 73fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_device_group, "SPV_KHR_device_group"}, 74fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_multiview, "SPV_KHR_multiview"}, 75fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_shader_ballot, "SPV_KHR_shader_ballot"}, 76fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_shader_draw_parameters, 77fd4e5da5Sopenharmony_ci "SPV_KHR_shader_draw_parameters"}, 78fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_subgroup_vote, "SPV_KHR_subgroup_vote"}, 79fd4e5da5Sopenharmony_ci {Extension::kSPV_NVX_multiview_per_view_attributes, 80fd4e5da5Sopenharmony_ci "SPV_NVX_multiview_per_view_attributes"}, 81fd4e5da5Sopenharmony_ci {Extension::kSPV_NV_geometry_shader_passthrough, 82fd4e5da5Sopenharmony_ci "SPV_NV_geometry_shader_passthrough"}, 83fd4e5da5Sopenharmony_ci {Extension::kSPV_NV_sample_mask_override_coverage, 84fd4e5da5Sopenharmony_ci "SPV_NV_sample_mask_override_coverage"}, 85fd4e5da5Sopenharmony_ci {Extension::kSPV_NV_stereo_view_rendering, 86fd4e5da5Sopenharmony_ci "SPV_NV_stereo_view_rendering"}, 87fd4e5da5Sopenharmony_ci {Extension::kSPV_NV_viewport_array2, "SPV_NV_viewport_array2"}, 88fd4e5da5Sopenharmony_ci {Extension::kSPV_GOOGLE_decorate_string, "SPV_GOOGLE_decorate_string"}, 89fd4e5da5Sopenharmony_ci {Extension::kSPV_GOOGLE_hlsl_functionality1, 90fd4e5da5Sopenharmony_ci "SPV_GOOGLE_hlsl_functionality1"}, 91fd4e5da5Sopenharmony_ci {Extension::kSPV_KHR_8bit_storage, "SPV_KHR_8bit_storage"}, 92fd4e5da5Sopenharmony_ci }))); 93fd4e5da5Sopenharmony_ci 94fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(UnknownExtensions, UnknownExtensionTest, 95fd4e5da5Sopenharmony_ci Values("", "SPV_KHR_", "SPV_KHR_device_group_ERROR", 96fd4e5da5Sopenharmony_ci /*alphabetically before all extensions*/ "A", 97fd4e5da5Sopenharmony_ci /*alphabetically after all extensions*/ "Z", 98fd4e5da5Sopenharmony_ci "SPV_ERROR_random_string_hfsdklhlktherh")); 99fd4e5da5Sopenharmony_ci 100fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P( 101fd4e5da5Sopenharmony_ci AllCapabilities, CapabilityTest, 102fd4e5da5Sopenharmony_ci ValuesIn(std::vector<std::pair<spv::Capability, std::string>>( 103fd4e5da5Sopenharmony_ci {{spv::Capability::Matrix, "Matrix"}, 104fd4e5da5Sopenharmony_ci {spv::Capability::Shader, "Shader"}, 105fd4e5da5Sopenharmony_ci {spv::Capability::Geometry, "Geometry"}, 106fd4e5da5Sopenharmony_ci {spv::Capability::Tessellation, "Tessellation"}, 107fd4e5da5Sopenharmony_ci {spv::Capability::Addresses, "Addresses"}, 108fd4e5da5Sopenharmony_ci {spv::Capability::Linkage, "Linkage"}, 109fd4e5da5Sopenharmony_ci {spv::Capability::Kernel, "Kernel"}, 110fd4e5da5Sopenharmony_ci {spv::Capability::Vector16, "Vector16"}, 111fd4e5da5Sopenharmony_ci {spv::Capability::Float16Buffer, "Float16Buffer"}, 112fd4e5da5Sopenharmony_ci {spv::Capability::Float16, "Float16"}, 113fd4e5da5Sopenharmony_ci {spv::Capability::Float64, "Float64"}, 114fd4e5da5Sopenharmony_ci {spv::Capability::Int64, "Int64"}, 115fd4e5da5Sopenharmony_ci {spv::Capability::Int64Atomics, "Int64Atomics"}, 116fd4e5da5Sopenharmony_ci {spv::Capability::ImageBasic, "ImageBasic"}, 117fd4e5da5Sopenharmony_ci {spv::Capability::ImageReadWrite, "ImageReadWrite"}, 118fd4e5da5Sopenharmony_ci {spv::Capability::ImageMipmap, "ImageMipmap"}, 119fd4e5da5Sopenharmony_ci {spv::Capability::Pipes, "Pipes"}, 120fd4e5da5Sopenharmony_ci {spv::Capability::Groups, "Groups"}, 121fd4e5da5Sopenharmony_ci {spv::Capability::DeviceEnqueue, "DeviceEnqueue"}, 122fd4e5da5Sopenharmony_ci {spv::Capability::LiteralSampler, "LiteralSampler"}, 123fd4e5da5Sopenharmony_ci {spv::Capability::AtomicStorage, "AtomicStorage"}, 124fd4e5da5Sopenharmony_ci {spv::Capability::Int16, "Int16"}, 125fd4e5da5Sopenharmony_ci {spv::Capability::TessellationPointSize, "TessellationPointSize"}, 126fd4e5da5Sopenharmony_ci {spv::Capability::GeometryPointSize, "GeometryPointSize"}, 127fd4e5da5Sopenharmony_ci {spv::Capability::ImageGatherExtended, "ImageGatherExtended"}, 128fd4e5da5Sopenharmony_ci {spv::Capability::StorageImageMultisample, "StorageImageMultisample"}, 129fd4e5da5Sopenharmony_ci {spv::Capability::UniformBufferArrayDynamicIndexing, 130fd4e5da5Sopenharmony_ci "UniformBufferArrayDynamicIndexing"}, 131fd4e5da5Sopenharmony_ci {spv::Capability::SampledImageArrayDynamicIndexing, 132fd4e5da5Sopenharmony_ci "SampledImageArrayDynamicIndexing"}, 133fd4e5da5Sopenharmony_ci {spv::Capability::StorageBufferArrayDynamicIndexing, 134fd4e5da5Sopenharmony_ci "StorageBufferArrayDynamicIndexing"}, 135fd4e5da5Sopenharmony_ci {spv::Capability::StorageImageArrayDynamicIndexing, 136fd4e5da5Sopenharmony_ci "StorageImageArrayDynamicIndexing"}, 137fd4e5da5Sopenharmony_ci {spv::Capability::ClipDistance, "ClipDistance"}, 138fd4e5da5Sopenharmony_ci {spv::Capability::CullDistance, "CullDistance"}, 139fd4e5da5Sopenharmony_ci {spv::Capability::ImageCubeArray, "ImageCubeArray"}, 140fd4e5da5Sopenharmony_ci {spv::Capability::SampleRateShading, "SampleRateShading"}, 141fd4e5da5Sopenharmony_ci {spv::Capability::ImageRect, "ImageRect"}, 142fd4e5da5Sopenharmony_ci {spv::Capability::SampledRect, "SampledRect"}, 143fd4e5da5Sopenharmony_ci {spv::Capability::GenericPointer, "GenericPointer"}, 144fd4e5da5Sopenharmony_ci {spv::Capability::Int8, "Int8"}, 145fd4e5da5Sopenharmony_ci {spv::Capability::InputAttachment, "InputAttachment"}, 146fd4e5da5Sopenharmony_ci {spv::Capability::SparseResidency, "SparseResidency"}, 147fd4e5da5Sopenharmony_ci {spv::Capability::MinLod, "MinLod"}, 148fd4e5da5Sopenharmony_ci {spv::Capability::Sampled1D, "Sampled1D"}, 149fd4e5da5Sopenharmony_ci {spv::Capability::Image1D, "Image1D"}, 150fd4e5da5Sopenharmony_ci {spv::Capability::SampledCubeArray, "SampledCubeArray"}, 151fd4e5da5Sopenharmony_ci {spv::Capability::SampledBuffer, "SampledBuffer"}, 152fd4e5da5Sopenharmony_ci {spv::Capability::ImageBuffer, "ImageBuffer"}, 153fd4e5da5Sopenharmony_ci {spv::Capability::ImageMSArray, "ImageMSArray"}, 154fd4e5da5Sopenharmony_ci {spv::Capability::StorageImageExtendedFormats, 155fd4e5da5Sopenharmony_ci "StorageImageExtendedFormats"}, 156fd4e5da5Sopenharmony_ci {spv::Capability::ImageQuery, "ImageQuery"}, 157fd4e5da5Sopenharmony_ci {spv::Capability::DerivativeControl, "DerivativeControl"}, 158fd4e5da5Sopenharmony_ci {spv::Capability::InterpolationFunction, "InterpolationFunction"}, 159fd4e5da5Sopenharmony_ci {spv::Capability::TransformFeedback, "TransformFeedback"}, 160fd4e5da5Sopenharmony_ci {spv::Capability::GeometryStreams, "GeometryStreams"}, 161fd4e5da5Sopenharmony_ci {spv::Capability::StorageImageReadWithoutFormat, 162fd4e5da5Sopenharmony_ci "StorageImageReadWithoutFormat"}, 163fd4e5da5Sopenharmony_ci {spv::Capability::StorageImageWriteWithoutFormat, 164fd4e5da5Sopenharmony_ci "StorageImageWriteWithoutFormat"}, 165fd4e5da5Sopenharmony_ci {spv::Capability::MultiViewport, "MultiViewport"}, 166fd4e5da5Sopenharmony_ci {spv::Capability::SubgroupDispatch, "SubgroupDispatch"}, 167fd4e5da5Sopenharmony_ci {spv::Capability::NamedBarrier, "NamedBarrier"}, 168fd4e5da5Sopenharmony_ci {spv::Capability::PipeStorage, "PipeStorage"}, 169fd4e5da5Sopenharmony_ci {spv::Capability::SubgroupBallotKHR, "SubgroupBallotKHR"}, 170fd4e5da5Sopenharmony_ci {spv::Capability::DrawParameters, "DrawParameters"}, 171fd4e5da5Sopenharmony_ci {spv::Capability::SubgroupVoteKHR, "SubgroupVoteKHR"}, 172fd4e5da5Sopenharmony_ci {spv::Capability::StorageBuffer16BitAccess, 173fd4e5da5Sopenharmony_ci "StorageBuffer16BitAccess"}, 174fd4e5da5Sopenharmony_ci {spv::Capability::StorageUniformBufferBlock16, 175fd4e5da5Sopenharmony_ci "StorageBuffer16BitAccess"}, // Preferred name 176fd4e5da5Sopenharmony_ci {spv::Capability::UniformAndStorageBuffer16BitAccess, 177fd4e5da5Sopenharmony_ci "UniformAndStorageBuffer16BitAccess"}, 178fd4e5da5Sopenharmony_ci {spv::Capability::StorageUniform16, 179fd4e5da5Sopenharmony_ci "UniformAndStorageBuffer16BitAccess"}, // Preferred name 180fd4e5da5Sopenharmony_ci {spv::Capability::StoragePushConstant16, "StoragePushConstant16"}, 181fd4e5da5Sopenharmony_ci {spv::Capability::StorageInputOutput16, "StorageInputOutput16"}, 182fd4e5da5Sopenharmony_ci {spv::Capability::DeviceGroup, "DeviceGroup"}, 183fd4e5da5Sopenharmony_ci {spv::Capability::AtomicFloat32AddEXT, "AtomicFloat32AddEXT"}, 184fd4e5da5Sopenharmony_ci {spv::Capability::AtomicFloat64AddEXT, "AtomicFloat64AddEXT"}, 185fd4e5da5Sopenharmony_ci {spv::Capability::AtomicFloat32MinMaxEXT, "AtomicFloat32MinMaxEXT"}, 186fd4e5da5Sopenharmony_ci {spv::Capability::AtomicFloat64MinMaxEXT, "AtomicFloat64MinMaxEXT"}, 187fd4e5da5Sopenharmony_ci {spv::Capability::MultiView, "MultiView"}, 188fd4e5da5Sopenharmony_ci {spv::Capability::Int64ImageEXT, "Int64ImageEXT"}, 189fd4e5da5Sopenharmony_ci {spv::Capability::SampleMaskOverrideCoverageNV, 190fd4e5da5Sopenharmony_ci "SampleMaskOverrideCoverageNV"}, 191fd4e5da5Sopenharmony_ci {spv::Capability::GeometryShaderPassthroughNV, 192fd4e5da5Sopenharmony_ci "GeometryShaderPassthroughNV"}, 193fd4e5da5Sopenharmony_ci // The next two are different names for the same token. 194fd4e5da5Sopenharmony_ci {spv::Capability::ShaderViewportIndexLayerNV, 195fd4e5da5Sopenharmony_ci "ShaderViewportIndexLayerEXT"}, 196fd4e5da5Sopenharmony_ci {spv::Capability::ShaderViewportIndexLayerEXT, 197fd4e5da5Sopenharmony_ci "ShaderViewportIndexLayerEXT"}, 198fd4e5da5Sopenharmony_ci {spv::Capability::ShaderViewportMaskNV, "ShaderViewportMaskNV"}, 199fd4e5da5Sopenharmony_ci {spv::Capability::ShaderStereoViewNV, "ShaderStereoViewNV"}, 200fd4e5da5Sopenharmony_ci {spv::Capability::PerViewAttributesNV, "PerViewAttributesNV"}}))); 201fd4e5da5Sopenharmony_ci 202fd4e5da5Sopenharmony_ci} // namespace 203fd4e5da5Sopenharmony_ci} // namespace spvtools 204