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() |
| 26 | message(STATUS "Did not find googletest, tests will not be built." |
| 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) |
| 34 | set(multi_value_args SRCS LIBS) |
| 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) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 42 | endif() |
Lei Zhang | 190b0d3 | 2016-08-07 22:49:00 -0400 | [diff] [blame] | 43 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 44 | # Disable C4503 "decorated name length exceeded" warning, |
| 45 | # triggered by some heavily templated types. |
| 46 | # We don't care much about that in test code. |
| 47 | # Important to do since we have warnings-as-errors. |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 48 | target_compile_options(${target} PRIVATE /wd4503) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 49 | endif() |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 50 | target_include_directories(${target} PRIVATE |
| 51 | ${SPIRV_HEADER_INCLUDE_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 52 | ${spirv-tools_SOURCE_DIR} |
| 53 | ${spirv-tools_SOURCE_DIR}/include |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 54 | ${spirv-tools_SOURCE_DIR}/test |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 55 | ${spirv-tools_BINARY_DIR} |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 56 | ${gtest_SOURCE_DIR}/include |
| 57 | ${gmock_SOURCE_DIR}/include |
| 58 | ) |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 59 | target_link_libraries(${target} PRIVATE ${ARG_LIBS}) |
| 60 | target_link_libraries(${target} PRIVATE gmock_main) |
| 61 | add_test(NAME spirv-tools-${target} COMMAND ${target}) |
Lei Zhang | 5c3c054 | 2017-04-05 17:32:39 -0400 | [diff] [blame] | 62 | set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests") |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 63 | endif() |
| 64 | endfunction() |
| 65 | |
| 66 | set(TEST_SOURCES |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 67 | test_fixture.h |
| 68 | unit_spirv.h |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 69 | |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 70 | assembly_context_test.cpp |
| 71 | assembly_format_test.cpp |
| 72 | binary_destroy_test.cpp |
| 73 | binary_endianness_test.cpp |
| 74 | binary_header_get_test.cpp |
| 75 | binary_parse_test.cpp |
David Neto | 37422e9 | 2016-12-19 13:26:42 -0500 | [diff] [blame] | 76 | binary_strnlen_s_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 77 | binary_to_text_test.cpp |
| 78 | binary_to_text.literal_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 79 | comment_test.cpp |
Andrey Tuganov | c804c12 | 2017-03-15 17:28:24 -0400 | [diff] [blame] | 80 | enum_string_mapping_test.cpp |
Andrey Tuganov | 1fb8c37 | 2017-03-09 18:24:35 -0500 | [diff] [blame] | 81 | enum_set_test.cpp |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 82 | ext_inst.glsl_test.cpp |
| 83 | ext_inst.opencl_test.cpp |
| 84 | fix_word_test.cpp |
| 85 | generator_magic_number_test.cpp |
| 86 | hex_float_test.cpp |
| 87 | immediate_int_test.cpp |
| 88 | libspirv_macros_test.cpp |
| 89 | named_id_test.cpp |
| 90 | name_mapper_test.cpp |
| 91 | opcode_make_test.cpp |
| 92 | opcode_require_capabilities_test.cpp |
| 93 | opcode_split_test.cpp |
| 94 | opcode_table_get_test.cpp |
| 95 | operand_capabilities_test.cpp |
| 96 | operand_test.cpp |
| 97 | operand_pattern_test.cpp |
| 98 | software_version_test.cpp |
| 99 | target_env_test.cpp |
| 100 | text_advance_test.cpp |
| 101 | text_destroy_test.cpp |
| 102 | text_literal_test.cpp |
| 103 | text_start_new_inst_test.cpp |
| 104 | text_to_binary.annotation_test.cpp |
| 105 | text_to_binary.barrier_test.cpp |
| 106 | text_to_binary.constant_test.cpp |
| 107 | text_to_binary.control_flow_test.cpp |
| 108 | text_to_binary_test.cpp |
| 109 | text_to_binary.debug_test.cpp |
| 110 | text_to_binary.device_side_enqueue_test.cpp |
| 111 | text_to_binary.extension_test.cpp |
| 112 | text_to_binary.function_test.cpp |
| 113 | text_to_binary.group_test.cpp |
| 114 | text_to_binary.image_test.cpp |
| 115 | text_to_binary.literal_test.cpp |
| 116 | text_to_binary.memory_test.cpp |
| 117 | text_to_binary.misc_test.cpp |
| 118 | text_to_binary.mode_setting_test.cpp |
| 119 | text_to_binary.pipe_storage_test.cpp |
| 120 | text_to_binary.type_declaration_test.cpp |
| 121 | text_to_binary.subgroup_dispatch_test.cpp |
| 122 | text_word_get_test.cpp |
| 123 | |
| 124 | unit_spirv.cpp |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 125 | ) |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 126 | |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 127 | add_spvtools_unittest( |
Lei Zhang | ef600df | 2016-09-07 17:26:18 -0400 | [diff] [blame] | 128 | TARGET spirv_unit_tests |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 129 | SRCS ${TEST_SOURCES} |
| 130 | LIBS ${SPIRV_TOOLS}) |
| 131 | |
| 132 | add_spvtools_unittest( |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 133 | TARGET diagnostic |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 134 | SRCS diagnostic_test.cpp |
Lei Zhang | a35919c | 2016-09-08 17:26:53 -0400 | [diff] [blame] | 135 | LIBS ${SPIRV_TOOLS}) |
| 136 | |
| 137 | add_spvtools_unittest( |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 138 | TARGET c_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 139 | SRCS c_interface_test.cpp |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 140 | LIBS ${SPIRV_TOOLS}) |
| 141 | |
| 142 | add_spvtools_unittest( |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 143 | TARGET cpp_interface |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 144 | SRCS cpp_interface_test.cpp |
| 145 | LIBS SPIRV-Tools-opt) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 146 | |
qining | 1773b95 | 2016-09-01 14:27:04 -0400 | [diff] [blame] | 147 | add_spvtools_unittest( |
| 148 | TARGET parse_number |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 149 | SRCS parse_number_test.cpp |
qining | 1773b95 | 2016-09-01 14:27:04 -0400 | [diff] [blame] | 150 | LIBS ${SPIRV_TOOLS}) |
| 151 | |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 152 | add_spvtools_unittest( |
Andrey Tuganov | b011633 | 2017-03-10 15:58:15 -0500 | [diff] [blame] | 153 | TARGET string_utils |
| 154 | SRCS string_utils_test.cpp |
| 155 | LIBS ${SPIRV_TOOLS}) |
| 156 | |
| 157 | add_spvtools_unittest( |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 158 | TARGET log |
Lei Zhang | 4f57e14 | 2016-09-22 11:05:30 -0400 | [diff] [blame] | 159 | SRCS log_test.cpp |
Lei Zhang | bfd7cd6 | 2016-09-08 11:43:48 -0400 | [diff] [blame] | 160 | LIBS ${SPIRV_TOOLS}) |
| 161 | |
Andrey Tuganov | b173d1c | 2017-04-11 19:46:15 -0400 | [diff] [blame] | 162 | add_spvtools_unittest( |
| 163 | TARGET preserve_numeric_ids |
| 164 | SRCS preserve_numeric_ids_test.cpp |
| 165 | LIBS ${SPIRV_TOOLS}) |
| 166 | |
Andrey Tuganov | 3eb716c | 2017-04-24 15:17:33 -0400 | [diff] [blame] | 167 | add_spvtools_unittest( |
| 168 | TARGET bit_stream |
| 169 | SRCS bit_stream.cpp |
| 170 | LIBS ${SPIRV_TOOLS}) |
| 171 | |
Andrey Tuganov | 40a2829 | 2017-05-25 11:21:12 -0400 | [diff] [blame] | 172 | add_spvtools_unittest( |
| 173 | TARGET huffman_codec |
| 174 | SRCS huffman_codec.cpp |
| 175 | LIBS ${SPIRV_TOOLS}) |
| 176 | |
Andrey Tuganov | 8d3882a | 2017-06-12 12:01:39 -0400 | [diff] [blame] | 177 | add_spvtools_unittest( |
| 178 | TARGET move_to_front |
| 179 | SRCS move_to_front_test.cpp |
| 180 | LIBS ${SPIRV_TOOLS}) |
| 181 | |
Andrey Tuganov | 73e8dac | 2017-05-31 13:07:51 -0400 | [diff] [blame] | 182 | add_subdirectory(comp) |
Pierre Moreau | 86627f7 | 2017-07-13 02:16:51 +0200 | [diff] [blame^] | 183 | add_subdirectory(link) |
Lei Zhang | 71fac5a | 2016-08-05 13:46:45 -0400 | [diff] [blame] | 184 | add_subdirectory(opt) |
Andrey Tuganov | 4f21640 | 2017-04-06 16:55:26 -0400 | [diff] [blame] | 185 | add_subdirectory(stats) |
Andrey Tuganov | 73e8dac | 2017-05-31 13:07:51 -0400 | [diff] [blame] | 186 | add_subdirectory(val) |