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) |
| 33 | set(one_value_args TARGET) |
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}) |
| 38 | add_executable(${target} ${ARG_SRCS}) |
| 39 | spvtools_default_compile_options(${target}) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 40 | if(${COMPILER_IS_LIKE_GNU}) |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 41 | target_compile_options(${target} PRIVATE -Wno-undef) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 42 | # Effcee and RE2 headers exhibit shadowing. |
| 43 | target_compile_options(${target} PRIVATE -Wno-shadow) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 44 | endif() |
Lei Zhang | 190b0d3 | 2016-08-07 22:49:00 -0400 | [diff] [blame] | 45 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 46 | # Disable C4503 "decorated name length exceeded" warning, |
| 47 | # triggered by some heavily templated types. |
| 48 | # We don't care much about that in test code. |
| 49 | # Important to do since we have warnings-as-errors. |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 50 | target_compile_options(${target} PRIVATE /wd4503) |
David Neto | 7ba59ac | 2017-12-11 12:05:04 -0500 | [diff] [blame] | 51 | # Googletest accidentally turns off support for ::testing::Combine |
| 52 | # in VS 2017. See https://github.com/google/googletest/issues/1352 |
| 53 | # Forcibly turn it on again. |
| 54 | target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 55 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 56 | target_include_directories(${target} PRIVATE |
| 57 | ${SPIRV_HEADER_INCLUDE_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 58 | ${spirv-tools_SOURCE_DIR} |
| 59 | ${spirv-tools_SOURCE_DIR}/include |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 60 | ${spirv-tools_SOURCE_DIR}/test |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 61 | ${spirv-tools_BINARY_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 62 | ${gtest_SOURCE_DIR}/include |
| 63 | ${gmock_SOURCE_DIR}/include |
| 64 | ) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 65 | if (TARGET effcee) |
| 66 | # If using Effcee for testing, then add its include directory. |
| 67 | target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR}) |
| 68 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 69 | target_link_libraries(${target} PRIVATE ${ARG_LIBS}) |
David Neto | 76555bd | 2017-11-08 00:23:42 -0500 | [diff] [blame] | 70 | if (TARGET effcee) |
| 71 | target_link_libraries(${target} PRIVATE effcee) |
| 72 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 73 | target_link_libraries(${target} PRIVATE gmock_main) |
| 74 | add_test(NAME spirv-tools-${target} COMMAND ${target}) |
Józef Kucia | 3013897 | 2018-02-02 23:37:14 +0100 | [diff] [blame] | 75 | if (DEFINED ARG_ENVIRONMENT) |
| 76 | set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT}) |
| 77 | endif() |
Lei Zhang | 5c3c054 | 2017-04-05 17:32:39 -0400 | [diff] [blame] | 78 | set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 79 | endif() |
| 80 | endfunction() |
| 81 | |
| 82 | set(TEST_SOURCES |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 83 | test_fixture.h |
| 84 | unit_spirv.h |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 85 | |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 86 | assembly_context_test.cpp |
| 87 | assembly_format_test.cpp |
| 88 | binary_destroy_test.cpp |
| 89 | binary_endianness_test.cpp |
| 90 | binary_header_get_test.cpp |
| 91 | binary_parse_test.cpp |
David Neto | 37422e9 | 2016-12-19 13:26:42 -0500 | [diff] [blame] | 92 | binary_strnlen_s_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 93 | binary_to_text_test.cpp |
| 94 | binary_to_text.literal_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 95 | comment_test.cpp |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 96 | enum_string_mapping_test.cpp |
Andrey Tuganov | 1fb8c37 | 2017-03-09 18:24:35 -0500 | [diff] [blame] | 97 | enum_set_test.cpp |
David Neto | 59de610 | 2017-12-03 12:30:08 -0500 | [diff] [blame] | 98 | ext_inst.debuginfo_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 99 | ext_inst.glsl_test.cpp |
| 100 | ext_inst.opencl_test.cpp |
| 101 | fix_word_test.cpp |
| 102 | generator_magic_number_test.cpp |
| 103 | hex_float_test.cpp |
| 104 | immediate_int_test.cpp |
| 105 | libspirv_macros_test.cpp |
| 106 | named_id_test.cpp |
| 107 | name_mapper_test.cpp |
| 108 | opcode_make_test.cpp |
| 109 | opcode_require_capabilities_test.cpp |
| 110 | opcode_split_test.cpp |
| 111 | opcode_table_get_test.cpp |
| 112 | operand_capabilities_test.cpp |
| 113 | operand_test.cpp |
| 114 | operand_pattern_test.cpp |
| 115 | software_version_test.cpp |
| 116 | target_env_test.cpp |
| 117 | text_advance_test.cpp |
| 118 | text_destroy_test.cpp |
| 119 | text_literal_test.cpp |
| 120 | text_start_new_inst_test.cpp |
| 121 | text_to_binary.annotation_test.cpp |
| 122 | text_to_binary.barrier_test.cpp |
| 123 | text_to_binary.constant_test.cpp |
| 124 | text_to_binary.control_flow_test.cpp |
| 125 | text_to_binary_test.cpp |
| 126 | text_to_binary.debug_test.cpp |
| 127 | text_to_binary.device_side_enqueue_test.cpp |
| 128 | text_to_binary.extension_test.cpp |
| 129 | text_to_binary.function_test.cpp |
| 130 | text_to_binary.group_test.cpp |
| 131 | text_to_binary.image_test.cpp |
| 132 | text_to_binary.literal_test.cpp |
| 133 | text_to_binary.memory_test.cpp |
| 134 | text_to_binary.misc_test.cpp |
| 135 | text_to_binary.mode_setting_test.cpp |
| 136 | text_to_binary.pipe_storage_test.cpp |
| 137 | text_to_binary.type_declaration_test.cpp |
| 138 | text_to_binary.subgroup_dispatch_test.cpp |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 139 | text_to_binary.reserved_sampling_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 140 | text_word_get_test.cpp |
| 141 | |
| 142 | unit_spirv.cpp |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 143 | ) |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 144 | |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 145 | add_spvtools_unittest( |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 146 | TARGET spirv_unit_tests |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 147 | SRCS ${TEST_SOURCES} |
| 148 | LIBS ${SPIRV_TOOLS}) |
| 149 | |
| 150 | add_spvtools_unittest( |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 151 | TARGET diagnostic |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 152 | SRCS diagnostic_test.cpp |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 153 | LIBS ${SPIRV_TOOLS}) |
| 154 | |
| 155 | add_spvtools_unittest( |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 156 | TARGET c_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 157 | SRCS c_interface_test.cpp |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 158 | LIBS ${SPIRV_TOOLS}) |
| 159 | |
| 160 | add_spvtools_unittest( |
Józef Kucia | 3013897 | 2018-02-02 23:37:14 +0100 | [diff] [blame] | 161 | TARGET c_interface_shared |
| 162 | SRCS c_interface_test.cpp |
| 163 | LIBS ${SPIRV_TOOLS}-shared |
| 164 | ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>) |
| 165 | |
| 166 | add_spvtools_unittest( |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 167 | TARGET cpp_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 168 | SRCS cpp_interface_test.cpp |
| 169 | LIBS SPIRV-Tools-opt) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 170 | |
qining | 1773b95 | 2016-09-01 14:27:04 -0400 | [diff] [blame] | 171 | add_spvtools_unittest( |
| 172 | TARGET parse_number |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 173 | SRCS parse_number_test.cpp |
qining | 1773b95 | 2016-09-01 14:27:04 -0400 | [diff] [blame] | 174 | LIBS ${SPIRV_TOOLS}) |
| 175 | |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 176 | add_spvtools_unittest( |
Andrey Tuganov | b011633 | 2017-03-10 15:58:15 -0500 | [diff] [blame] | 177 | TARGET string_utils |
| 178 | SRCS string_utils_test.cpp |
| 179 | LIBS ${SPIRV_TOOLS}) |
| 180 | |
Jaebaek Seo | 3b594e1 | 2018-03-07 09:25:51 -0500 | [diff] [blame^] | 181 | if (${SPIRV_TIMER_ENABLED}) |
| 182 | add_spvtools_unittest( |
| 183 | TARGET timer |
| 184 | SRCS timer_test.cpp |
| 185 | LIBS ${SPIRV_TOOLS}) |
| 186 | endif() |
| 187 | |
Andrey Tuganov | b011633 | 2017-03-10 15:58:15 -0500 | [diff] [blame] | 188 | add_spvtools_unittest( |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 189 | TARGET log |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 190 | SRCS log_test.cpp |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 191 | LIBS ${SPIRV_TOOLS}) |
| 192 | |
Andrey Tuganov | b173d1c | 2017-04-11 19:46:15 -0400 | [diff] [blame] | 193 | add_spvtools_unittest( |
| 194 | TARGET preserve_numeric_ids |
| 195 | SRCS preserve_numeric_ids_test.cpp |
| 196 | LIBS ${SPIRV_TOOLS}) |
| 197 | |
Andrey Tuganov | 3eb716c | 2017-04-24 15:17:33 -0400 | [diff] [blame] | 198 | add_spvtools_unittest( |
| 199 | TARGET bit_stream |
| 200 | SRCS bit_stream.cpp |
| 201 | LIBS ${SPIRV_TOOLS}) |
| 202 | |
Andrey Tuganov | 40a2829 | 2017-05-25 11:21:12 -0400 | [diff] [blame] | 203 | add_spvtools_unittest( |
| 204 | TARGET huffman_codec |
| 205 | SRCS huffman_codec.cpp |
| 206 | LIBS ${SPIRV_TOOLS}) |
| 207 | |
Andrey Tuganov | 8d3882a | 2017-06-12 12:01:39 -0400 | [diff] [blame] | 208 | add_spvtools_unittest( |
| 209 | TARGET move_to_front |
| 210 | SRCS move_to_front_test.cpp |
| 211 | LIBS ${SPIRV_TOOLS}) |
| 212 | |
Andrey Tuganov | 73e8dac | 2017-05-31 13:07:51 -0400 | [diff] [blame] | 213 | add_subdirectory(comp) |
Pierre Moreau | 86627f7 | 2017-07-13 02:16:51 +0200 | [diff] [blame] | 214 | add_subdirectory(link) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 215 | add_subdirectory(opt) |
Andrey Tuganov | 4f21640 | 2017-04-06 16:55:26 -0400 | [diff] [blame] | 216 | add_subdirectory(stats) |
Steven Perron | 720beb1 | 2017-10-10 09:47:01 -0400 | [diff] [blame] | 217 | add_subdirectory(util) |
Andrey Tuganov | 73e8dac | 2017-05-31 13:07:51 -0400 | [diff] [blame] | 218 | add_subdirectory(val) |