Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 1 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | # |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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 |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 6 | # |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 8 | # |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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. |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 14 | |
Lei Zhang | 1a050b1 | 2016-06-21 18:29:36 -0400 | [diff] [blame] | 15 | # Add a SPIR-V Tools unit test. Signature: |
| 16 | # add_spvtools_unittest( |
| 17 | # TARGET target_name |
| 18 | # SRCS src_file.h src_file.cpp |
| 19 | # LIBS lib1 lib2 |
| 20 | # ) |
Lei Zhang | 2ea7449 | 2016-05-22 13:48:08 -0400 | [diff] [blame] | 21 | |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 22 | if (NOT "${SPIRV_SKIP_TESTS}") |
| 23 | if (TARGET gmock_main) |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 24 | message(STATUS "Found Google Mock, building tests.") |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 25 | else() |
Lei Zhang | b93c066 | 2017-12-05 10:55:00 -0500 | [diff] [blame] | 26 | message(STATUS "Did not find googletest, tests will not be built. " |
Lei Zhang | eb6fc51 | 2016-03-16 22:43:31 -0400 | [diff] [blame] | 27 | "To enable tests place googletest in '<spirv-dir>/external/googletest'.") |
| 28 | endif() |
| 29 | endif() |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 30 | |
| 31 | function(add_spvtools_unittest) |
| 32 | if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main) |
Jeff Bolz | 60fac96 | 2018-11-06 08:26:23 -0600 | [diff] [blame] | 33 | set(one_value_args TARGET PCH_FILE) |
Józef Kucia | 3013897 | 2018-02-02 23:37:14 +0100 | [diff] [blame] | 34 | set(multi_value_args SRCS LIBS ENVIRONMENT) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 35 | cmake_parse_arguments( |
| 36 | ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN}) |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 37 | set(target test_${ARG_TARGET}) |
Jeff Bolz | 60fac96 | 2018-11-06 08:26:23 -0600 | [diff] [blame] | 38 | set(SRC_COPY ${ARG_SRCS}) |
| 39 | if (DEFINED ARG_PCH_FILE) |
Jeff Bolz | c06a35b | 2018-11-07 08:15:04 -0600 | [diff] [blame] | 40 | spvtools_pch(SRC_COPY ${ARG_PCH_FILE}) |
Jeff Bolz | 60fac96 | 2018-11-06 08:26:23 -0600 | [diff] [blame] | 41 | endif() |
| 42 | add_executable(${target} ${SRC_COPY}) |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 43 | spvtools_default_compile_options(${target}) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 44 | if(${COMPILER_IS_LIKE_GNU}) |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 45 | target_compile_options(${target} PRIVATE -Wno-undef) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 46 | # Effcee and RE2 headers exhibit shadowing. |
| 47 | target_compile_options(${target} PRIVATE -Wno-shadow) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 48 | endif() |
Lei Zhang | 190b0d3 | 2016-08-07 22:49:00 -0400 | [diff] [blame] | 49 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 50 | # Disable C4503 "decorated name length exceeded" warning, |
| 51 | # triggered by some heavily templated types. |
| 52 | # We don't care much about that in test code. |
| 53 | # Important to do since we have warnings-as-errors. |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 54 | target_compile_options(${target} PRIVATE /wd4503) |
David Neto | 7ba59ac | 2017-12-11 12:05:04 -0500 | [diff] [blame] | 55 | # Googletest accidentally turns off support for ::testing::Combine |
| 56 | # in VS 2017. See https://github.com/google/googletest/issues/1352 |
| 57 | # Forcibly turn it on again. |
| 58 | target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 59 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 60 | target_include_directories(${target} PRIVATE |
| 61 | ${SPIRV_HEADER_INCLUDE_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 62 | ${spirv-tools_SOURCE_DIR} |
| 63 | ${spirv-tools_SOURCE_DIR}/include |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 64 | ${spirv-tools_SOURCE_DIR}/test |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 65 | ${spirv-tools_BINARY_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 66 | ${gtest_SOURCE_DIR}/include |
| 67 | ${gmock_SOURCE_DIR}/include |
| 68 | ) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 69 | if (TARGET effcee) |
| 70 | # If using Effcee for testing, then add its include directory. |
| 71 | target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR}) |
| 72 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 73 | target_link_libraries(${target} PRIVATE ${ARG_LIBS}) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 74 | if (TARGET effcee) |
| 75 | target_link_libraries(${target} PRIVATE effcee) |
| 76 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 77 | target_link_libraries(${target} PRIVATE gmock_main) |
| 78 | add_test(NAME spirv-tools-${target} COMMAND ${target}) |
Józef Kucia | 3013897 | 2018-02-02 23:37:14 +0100 | [diff] [blame] | 79 | if (DEFINED ARG_ENVIRONMENT) |
| 80 | set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT}) |
| 81 | endif() |
Lei Zhang | 5c3c054 | 2017-04-05 17:32:39 -0400 | [diff] [blame] | 82 | set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 83 | endif() |
| 84 | endfunction() |
| 85 | |
| 86 | set(TEST_SOURCES |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 87 | test_fixture.h |
| 88 | unit_spirv.h |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 89 | |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 90 | assembly_context_test.cpp |
| 91 | assembly_format_test.cpp |
| 92 | binary_destroy_test.cpp |
| 93 | binary_endianness_test.cpp |
| 94 | binary_header_get_test.cpp |
| 95 | binary_parse_test.cpp |
David Neto | 37422e9 | 2016-12-19 13:26:42 -0500 | [diff] [blame] | 96 | binary_strnlen_s_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 97 | binary_to_text_test.cpp |
| 98 | binary_to_text.literal_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 99 | comment_test.cpp |
dan sinclair | 9e6f513 | 2018-11-01 10:19:37 -0400 | [diff] [blame] | 100 | diagnostic_test.cpp |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 101 | enum_string_mapping_test.cpp |
Andrey Tuganov | 1fb8c37 | 2017-03-09 18:24:35 -0500 | [diff] [blame] | 102 | enum_set_test.cpp |
David Neto | 64f36ea | 2019-12-19 17:16:26 -0500 | [diff] [blame^] | 103 | ext_inst.cldebug100_test.cpp |
David Neto | 59de610 | 2017-12-03 12:30:08 -0500 | [diff] [blame] | 104 | ext_inst.debuginfo_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 105 | ext_inst.glsl_test.cpp |
David Neto | e70b009 | 2019-12-18 18:10:29 -0500 | [diff] [blame] | 106 | ext_inst.non_semantic_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 107 | ext_inst.opencl_test.cpp |
| 108 | fix_word_test.cpp |
| 109 | generator_magic_number_test.cpp |
| 110 | hex_float_test.cpp |
| 111 | immediate_int_test.cpp |
| 112 | libspirv_macros_test.cpp |
dan sinclair | 9e6f513 | 2018-11-01 10:19:37 -0400 | [diff] [blame] | 113 | log_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 114 | named_id_test.cpp |
| 115 | name_mapper_test.cpp |
| 116 | opcode_make_test.cpp |
| 117 | opcode_require_capabilities_test.cpp |
| 118 | opcode_split_test.cpp |
| 119 | opcode_table_get_test.cpp |
| 120 | operand_capabilities_test.cpp |
| 121 | operand_test.cpp |
| 122 | operand_pattern_test.cpp |
dan sinclair | 9e6f513 | 2018-11-01 10:19:37 -0400 | [diff] [blame] | 123 | parse_number_test.cpp |
| 124 | preserve_numeric_ids_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 125 | software_version_test.cpp |
dan sinclair | 9e6f513 | 2018-11-01 10:19:37 -0400 | [diff] [blame] | 126 | string_utils_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 127 | target_env_test.cpp |
| 128 | text_advance_test.cpp |
| 129 | text_destroy_test.cpp |
| 130 | text_literal_test.cpp |
| 131 | text_start_new_inst_test.cpp |
| 132 | text_to_binary.annotation_test.cpp |
| 133 | text_to_binary.barrier_test.cpp |
David Neto | 63f57d9 | 2019-05-07 12:27:18 -0400 | [diff] [blame] | 134 | text_to_binary.composite_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 135 | text_to_binary.constant_test.cpp |
| 136 | text_to_binary.control_flow_test.cpp |
| 137 | text_to_binary_test.cpp |
| 138 | text_to_binary.debug_test.cpp |
| 139 | text_to_binary.device_side_enqueue_test.cpp |
| 140 | text_to_binary.extension_test.cpp |
| 141 | text_to_binary.function_test.cpp |
| 142 | text_to_binary.group_test.cpp |
| 143 | text_to_binary.image_test.cpp |
| 144 | text_to_binary.literal_test.cpp |
| 145 | text_to_binary.memory_test.cpp |
| 146 | text_to_binary.misc_test.cpp |
| 147 | text_to_binary.mode_setting_test.cpp |
| 148 | text_to_binary.pipe_storage_test.cpp |
| 149 | text_to_binary.type_declaration_test.cpp |
| 150 | text_to_binary.subgroup_dispatch_test.cpp |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 151 | text_to_binary.reserved_sampling_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 152 | text_word_get_test.cpp |
| 153 | |
| 154 | unit_spirv.cpp |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 155 | ) |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 156 | |
Jeff Bolz | c06a35b | 2018-11-07 08:15:04 -0600 | [diff] [blame] | 157 | spvtools_pch(TEST_SOURCES pch_test) |
Jeff Bolz | 60fac96 | 2018-11-06 08:26:23 -0600 | [diff] [blame] | 158 | |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 159 | add_spvtools_unittest( |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 160 | TARGET spirv_unit_tests |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 161 | SRCS ${TEST_SOURCES} |
| 162 | LIBS ${SPIRV_TOOLS}) |
| 163 | |
| 164 | add_spvtools_unittest( |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 165 | TARGET c_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 166 | SRCS c_interface_test.cpp |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 167 | LIBS ${SPIRV_TOOLS}) |
| 168 | |
| 169 | add_spvtools_unittest( |
Józef Kucia | 3013897 | 2018-02-02 23:37:14 +0100 | [diff] [blame] | 170 | TARGET c_interface_shared |
| 171 | SRCS c_interface_test.cpp |
| 172 | LIBS ${SPIRV_TOOLS}-shared |
| 173 | ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>) |
| 174 | |
| 175 | add_spvtools_unittest( |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 176 | TARGET cpp_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 177 | SRCS cpp_interface_test.cpp |
| 178 | LIBS SPIRV-Tools-opt) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 179 | |
Jaebaek Seo | 3b594e1 | 2018-03-07 09:25:51 -0500 | [diff] [blame] | 180 | if (${SPIRV_TIMER_ENABLED}) |
| 181 | add_spvtools_unittest( |
| 182 | TARGET timer |
| 183 | SRCS timer_test.cpp |
| 184 | LIBS ${SPIRV_TOOLS}) |
| 185 | endif() |
| 186 | |
Andrey Tuganov | b173d1c | 2017-04-11 19:46:15 -0400 | [diff] [blame] | 187 | |
Pierre Moreau | 86627f7 | 2017-07-13 02:16:51 +0200 | [diff] [blame] | 188 | add_subdirectory(link) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 189 | add_subdirectory(opt) |
Alastair Donaldson | f3acb95 | 2018-11-21 19:03:09 +0000 | [diff] [blame] | 190 | add_subdirectory(reduce) |
Alastair Donaldson | 1b71e45 | 2019-05-29 16:42:46 +0100 | [diff] [blame] | 191 | add_subdirectory(fuzz) |
Diego Novillo | 03000a3 | 2018-08-03 18:08:46 -0400 | [diff] [blame] | 192 | add_subdirectory(tools) |
Steven Perron | 720beb1 | 2017-10-10 09:47:01 -0400 | [diff] [blame] | 193 | add_subdirectory(util) |
Andrey Tuganov | 73e8dac | 2017-05-31 13:07:51 -0400 | [diff] [blame] | 194 | add_subdirectory(val) |