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 15if (${SPIRV_SKIP_TESTS}) 16 return() 17endif() 18 19if (TARGET gmock_main) 20 message(STATUS "Found Google Mock, building tests.") 21else() 22 message(STATUS "Did not find googletest, tests will not be built. " 23 "To enable tests place googletest in '<spirv-dir>/external/googletest'.") 24endif() 25 26# Add a SPIR-V Tools unit test. Signature: 27# add_spvtools_unittest( 28# TARGET target_name 29# SRCS src_file.h src_file.cpp 30# LIBS lib1 lib2 31# ) 32function(add_spvtools_unittest) 33 if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main) 34 set(one_value_args TARGET PCH_FILE) 35 set(multi_value_args SRCS LIBS ENVIRONMENT DEFINES) 36 cmake_parse_arguments( 37 ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN}) 38 set(target test_${ARG_TARGET}) 39 set(SRC_COPY ${ARG_SRCS}) 40 if (DEFINED ARG_PCH_FILE) 41 spvtools_pch(SRC_COPY ${ARG_PCH_FILE}) 42 endif() 43 add_executable(${target} ${SRC_COPY}) 44 target_compile_definitions(${target} PUBLIC ${ARG_DEFINES}) 45 spvtools_default_compile_options(${target}) 46 if(${COMPILER_IS_LIKE_GNU}) 47 target_compile_options(${target} PRIVATE -Wno-undef) 48 # Effcee and RE2 headers exhibit shadowing. 49 target_compile_options(${target} PRIVATE -Wno-shadow) 50 endif() 51 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 52 # Disable C4503 "decorated name length exceeded" warning, 53 # triggered by some heavily templated types. 54 # We don't care much about that in test code. 55 # Important to do since we have warnings-as-errors. 56 target_compile_options(${target} PRIVATE /wd4503) 57 # Googletest accidentally turns off support for ::testing::Combine 58 # in VS 2017. See https://github.com/google/googletest/issues/1352 59 # Forcibly turn it on again. 60 target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1) 61 endif() 62 target_include_directories(${target} PRIVATE 63 ${SPIRV_HEADER_INCLUDE_DIR} 64 ${spirv-tools_SOURCE_DIR} 65 ${spirv-tools_SOURCE_DIR}/include 66 ${spirv-tools_SOURCE_DIR}/test 67 ${spirv-tools_BINARY_DIR} 68 ${gtest_SOURCE_DIR}/include 69 ${gmock_SOURCE_DIR}/include 70 ) 71 if (TARGET effcee) 72 # If using Effcee for testing, then add its include directory. 73 target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR}) 74 endif() 75 target_link_libraries(${target} PRIVATE ${ARG_LIBS}) 76 if (TARGET effcee) 77 target_link_libraries(${target} PRIVATE effcee) 78 endif() 79 target_link_libraries(${target} PRIVATE gmock_main) 80 add_test(NAME spirv-tools-${target} COMMAND ${target}) 81 if (DEFINED ARG_ENVIRONMENT) 82 set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT}) 83 endif() 84 set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests") 85 endif() 86endfunction() 87 88set(TEST_SOURCES 89 test_fixture.h 90 unit_spirv.h 91 92 assembly_context_test.cpp 93 assembly_format_test.cpp 94 binary_destroy_test.cpp 95 binary_endianness_test.cpp 96 binary_header_get_test.cpp 97 binary_parse_test.cpp 98 binary_strnlen_s_test.cpp 99 binary_to_text_test.cpp 100 binary_to_text.literal_test.cpp 101 comment_test.cpp 102 diagnostic_test.cpp 103 enum_string_mapping_test.cpp 104 enum_set_test.cpp 105 ext_inst.cldebug100_test.cpp 106 ext_inst.debuginfo_test.cpp 107 ext_inst.glsl_test.cpp 108 ext_inst.non_semantic_test.cpp 109 ext_inst.opencl_test.cpp 110 fix_word_test.cpp 111 generator_magic_number_test.cpp 112 hex_float_test.cpp 113 immediate_int_test.cpp 114 libspirv_macros_test.cpp 115 named_id_test.cpp 116 name_mapper_test.cpp 117 opcode_make_test.cpp 118 opcode_require_capabilities_test.cpp 119 opcode_split_test.cpp 120 opcode_table_get_test.cpp 121 operand_capabilities_test.cpp 122 operand_test.cpp 123 operand_pattern_test.cpp 124 parse_number_test.cpp 125 preserve_numeric_ids_test.cpp 126 software_version_test.cpp 127 string_utils_test.cpp 128 target_env_test.cpp 129 text_advance_test.cpp 130 text_destroy_test.cpp 131 text_literal_test.cpp 132 text_start_new_inst_test.cpp 133 text_to_binary.annotation_test.cpp 134 text_to_binary.barrier_test.cpp 135 text_to_binary.composite_test.cpp 136 text_to_binary.constant_test.cpp 137 text_to_binary.control_flow_test.cpp 138 text_to_binary_test.cpp 139 text_to_binary.debug_test.cpp 140 text_to_binary.device_side_enqueue_test.cpp 141 text_to_binary.extension_test.cpp 142 text_to_binary.function_test.cpp 143 text_to_binary.group_test.cpp 144 text_to_binary.image_test.cpp 145 text_to_binary.literal_test.cpp 146 text_to_binary.memory_test.cpp 147 text_to_binary.misc_test.cpp 148 text_to_binary.mode_setting_test.cpp 149 text_to_binary.pipe_storage_test.cpp 150 text_to_binary.type_declaration_test.cpp 151 text_to_binary.subgroup_dispatch_test.cpp 152 text_to_binary.reserved_sampling_test.cpp 153 text_word_get_test.cpp 154 155 unit_spirv.cpp 156) 157 158spvtools_pch(TEST_SOURCES pch_test) 159 160add_spvtools_unittest( 161 TARGET spirv_unit_tests 162 SRCS ${TEST_SOURCES} 163 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) 164 165add_spvtools_unittest( 166 TARGET c_interface 167 SRCS c_interface_test.cpp 168 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) 169 170add_spvtools_unittest( 171 TARGET c_interface_shared 172 SRCS c_interface_test.cpp 173 LIBS ${SPIRV_TOOLS}-shared 174 ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>) 175 176add_spvtools_unittest( 177 TARGET cpp_interface 178 SRCS cpp_interface_test.cpp 179 LIBS SPIRV-Tools-opt) 180 181if (${SPIRV_TIMER_ENABLED}) 182add_spvtools_unittest( 183 TARGET timer 184 SRCS timer_test.cpp 185 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY}) 186endif() 187 188 189add_subdirectory(diff) 190add_subdirectory(link) 191add_subdirectory(lint) 192add_subdirectory(opt) 193add_subdirectory(reduce) 194add_subdirectory(fuzz) 195add_subdirectory(tools) 196add_subdirectory(util) 197add_subdirectory(val) 198add_subdirectory(fuzzers) 199