blob: bf0792cfc797f9b0324f8ec6e61ce15d8afb9591 [file] [log] [blame]
Lei Zhangeb6fc512016-03-16 22:43:31 -04001# Copyright (c) 2015-2016 The Khronos Group Inc.
2#
David Neto9fc86582016-09-01 15:33:59 -04003# 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 Zhangeb6fc512016-03-16 22:43:31 -04006#
David Neto9fc86582016-09-01 15:33:59 -04007# http://www.apache.org/licenses/LICENSE-2.0
Lei Zhangeb6fc512016-03-16 22:43:31 -04008#
David Neto9fc86582016-09-01 15:33:59 -04009# 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 Zhangeb6fc512016-03-16 22:43:31 -040014
Lei Zhang1a050b12016-06-21 18:29:36 -040015# 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 Zhang2ea74492016-05-22 13:48:08 -040021
Lei Zhang71fac5a2016-08-05 13:46:45 -040022if (NOT "${SPIRV_SKIP_TESTS}")
23 if (TARGET gmock_main)
Lei Zhangeb6fc512016-03-16 22:43:31 -040024 message(STATUS "Found Google Mock, building tests.")
Lei Zhangeb6fc512016-03-16 22:43:31 -040025 else()
Lei Zhangb93c0662017-12-05 10:55:00 -050026 message(STATUS "Did not find googletest, tests will not be built. "
Lei Zhangeb6fc512016-03-16 22:43:31 -040027 "To enable tests place googletest in '<spirv-dir>/external/googletest'.")
28 endif()
29endif()
Lei Zhang71fac5a2016-08-05 13:46:45 -040030
31function(add_spvtools_unittest)
32 if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main)
Jeff Bolz60fac962018-11-06 08:26:23 -060033 set(one_value_args TARGET PCH_FILE)
Józef Kucia30138972018-02-02 23:37:14 +010034 set(multi_value_args SRCS LIBS ENVIRONMENT)
Lei Zhang71fac5a2016-08-05 13:46:45 -040035 cmake_parse_arguments(
36 ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
Lei Zhangef600df2016-09-07 17:26:18 -040037 set(target test_${ARG_TARGET})
Jeff Bolz60fac962018-11-06 08:26:23 -060038 set(SRC_COPY ${ARG_SRCS})
39 if (DEFINED ARG_PCH_FILE)
Jeff Bolzc06a35b2018-11-07 08:15:04 -060040 spvtools_pch(SRC_COPY ${ARG_PCH_FILE})
Jeff Bolz60fac962018-11-06 08:26:23 -060041 endif()
42 add_executable(${target} ${SRC_COPY})
Lei Zhangef600df2016-09-07 17:26:18 -040043 spvtools_default_compile_options(${target})
Lei Zhang71fac5a2016-08-05 13:46:45 -040044 if(${COMPILER_IS_LIKE_GNU})
Lei Zhangef600df2016-09-07 17:26:18 -040045 target_compile_options(${target} PRIVATE -Wno-undef)
David Neto76555bd2017-11-08 00:23:42 -050046 # Effcee and RE2 headers exhibit shadowing.
47 target_compile_options(${target} PRIVATE -Wno-shadow)
Lei Zhang71fac5a2016-08-05 13:46:45 -040048 endif()
Lei Zhang190b0d32016-08-07 22:49:00 -040049 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
Lei Zhang71fac5a2016-08-05 13:46:45 -040050 # 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 Zhangef600df2016-09-07 17:26:18 -040054 target_compile_options(${target} PRIVATE /wd4503)
David Neto7ba59ac2017-12-11 12:05:04 -050055 # 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 Zhang71fac5a2016-08-05 13:46:45 -040059 endif()
Lei Zhangef600df2016-09-07 17:26:18 -040060 target_include_directories(${target} PRIVATE
61 ${SPIRV_HEADER_INCLUDE_DIR}
Lei Zhang71fac5a2016-08-05 13:46:45 -040062 ${spirv-tools_SOURCE_DIR}
63 ${spirv-tools_SOURCE_DIR}/include
Lei Zhangef600df2016-09-07 17:26:18 -040064 ${spirv-tools_SOURCE_DIR}/test
Andrey Tuganovc804c122017-03-15 17:28:24 -040065 ${spirv-tools_BINARY_DIR}
Lei Zhang71fac5a2016-08-05 13:46:45 -040066 ${gtest_SOURCE_DIR}/include
67 ${gmock_SOURCE_DIR}/include
68 )
David Neto76555bd2017-11-08 00:23:42 -050069 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 Zhangef600df2016-09-07 17:26:18 -040073 target_link_libraries(${target} PRIVATE ${ARG_LIBS})
David Neto76555bd2017-11-08 00:23:42 -050074 if (TARGET effcee)
75 target_link_libraries(${target} PRIVATE effcee)
76 endif()
Lei Zhangef600df2016-09-07 17:26:18 -040077 target_link_libraries(${target} PRIVATE gmock_main)
78 add_test(NAME spirv-tools-${target} COMMAND ${target})
Józef Kucia30138972018-02-02 23:37:14 +010079 if (DEFINED ARG_ENVIRONMENT)
80 set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT})
81 endif()
Lei Zhang5c3c0542017-04-05 17:32:39 -040082 set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
Lei Zhang71fac5a2016-08-05 13:46:45 -040083 endif()
84endfunction()
85
86set(TEST_SOURCES
Lei Zhang4f57e142016-09-22 11:05:30 -040087 test_fixture.h
88 unit_spirv.h
Lei Zhang71fac5a2016-08-05 13:46:45 -040089
Lei Zhang4f57e142016-09-22 11:05:30 -040090 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 Neto37422e92016-12-19 13:26:42 -050096 binary_strnlen_s_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -040097 binary_to_text_test.cpp
98 binary_to_text.literal_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -040099 comment_test.cpp
dan sinclair9e6f5132018-11-01 10:19:37 -0400100 diagnostic_test.cpp
Andrey Tuganovc804c122017-03-15 17:28:24 -0400101 enum_string_mapping_test.cpp
Andrey Tuganov1fb8c372017-03-09 18:24:35 -0500102 enum_set_test.cpp
David Neto59de6102017-12-03 12:30:08 -0500103 ext_inst.debuginfo_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400104 ext_inst.glsl_test.cpp
105 ext_inst.opencl_test.cpp
106 fix_word_test.cpp
107 generator_magic_number_test.cpp
108 hex_float_test.cpp
109 immediate_int_test.cpp
110 libspirv_macros_test.cpp
dan sinclair9e6f5132018-11-01 10:19:37 -0400111 log_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400112 named_id_test.cpp
113 name_mapper_test.cpp
114 opcode_make_test.cpp
115 opcode_require_capabilities_test.cpp
116 opcode_split_test.cpp
117 opcode_table_get_test.cpp
118 operand_capabilities_test.cpp
119 operand_test.cpp
120 operand_pattern_test.cpp
dan sinclair9e6f5132018-11-01 10:19:37 -0400121 parse_number_test.cpp
122 preserve_numeric_ids_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400123 software_version_test.cpp
dan sinclair9e6f5132018-11-01 10:19:37 -0400124 string_utils_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400125 target_env_test.cpp
126 text_advance_test.cpp
127 text_destroy_test.cpp
128 text_literal_test.cpp
129 text_start_new_inst_test.cpp
130 text_to_binary.annotation_test.cpp
131 text_to_binary.barrier_test.cpp
David Neto63f57d92019-05-07 12:27:18 -0400132 text_to_binary.composite_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400133 text_to_binary.constant_test.cpp
134 text_to_binary.control_flow_test.cpp
135 text_to_binary_test.cpp
136 text_to_binary.debug_test.cpp
137 text_to_binary.device_side_enqueue_test.cpp
138 text_to_binary.extension_test.cpp
139 text_to_binary.function_test.cpp
140 text_to_binary.group_test.cpp
141 text_to_binary.image_test.cpp
142 text_to_binary.literal_test.cpp
143 text_to_binary.memory_test.cpp
144 text_to_binary.misc_test.cpp
145 text_to_binary.mode_setting_test.cpp
146 text_to_binary.pipe_storage_test.cpp
147 text_to_binary.type_declaration_test.cpp
148 text_to_binary.subgroup_dispatch_test.cpp
Lei Zhang1ef6b192018-03-14 13:06:18 -0400149 text_to_binary.reserved_sampling_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400150 text_word_get_test.cpp
151
152 unit_spirv.cpp
Lei Zhang71fac5a2016-08-05 13:46:45 -0400153)
Lei Zhanga35919c2016-09-08 17:26:53 -0400154
Jeff Bolzc06a35b2018-11-07 08:15:04 -0600155spvtools_pch(TEST_SOURCES pch_test)
Jeff Bolz60fac962018-11-06 08:26:23 -0600156
Lei Zhang71fac5a2016-08-05 13:46:45 -0400157add_spvtools_unittest(
Lei Zhangef600df2016-09-07 17:26:18 -0400158 TARGET spirv_unit_tests
Lei Zhang71fac5a2016-08-05 13:46:45 -0400159 SRCS ${TEST_SOURCES}
160 LIBS ${SPIRV_TOOLS})
161
162add_spvtools_unittest(
Lei Zhang755f97f2016-09-02 18:06:18 -0400163 TARGET c_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400164 SRCS c_interface_test.cpp
Lei Zhang755f97f2016-09-02 18:06:18 -0400165 LIBS ${SPIRV_TOOLS})
166
167add_spvtools_unittest(
Józef Kucia30138972018-02-02 23:37:14 +0100168 TARGET c_interface_shared
169 SRCS c_interface_test.cpp
170 LIBS ${SPIRV_TOOLS}-shared
171 ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>)
172
173add_spvtools_unittest(
Lei Zhang71fac5a2016-08-05 13:46:45 -0400174 TARGET cpp_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400175 SRCS cpp_interface_test.cpp
176 LIBS SPIRV-Tools-opt)
Lei Zhang71fac5a2016-08-05 13:46:45 -0400177
Jaebaek Seo3b594e12018-03-07 09:25:51 -0500178if (${SPIRV_TIMER_ENABLED})
179add_spvtools_unittest(
180 TARGET timer
181 SRCS timer_test.cpp
182 LIBS ${SPIRV_TOOLS})
183endif()
184
Andrey Tuganovb173d1c2017-04-11 19:46:15 -0400185
Andrey Tuganov3eb716c2017-04-24 15:17:33 -0400186add_spvtools_unittest(
187 TARGET bit_stream
188 SRCS bit_stream.cpp
dan sinclair5fc011b2018-08-14 09:52:05 -0400189 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
190 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
Andrey Tuganov3eb716c2017-04-24 15:17:33 -0400191 LIBS ${SPIRV_TOOLS})
192
Andrey Tuganov40a28292017-05-25 11:21:12 -0400193add_spvtools_unittest(
194 TARGET huffman_codec
195 SRCS huffman_codec.cpp
dan sinclair5fc011b2018-08-14 09:52:05 -0400196 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
197 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
198 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/huffman_codec.h
Andrey Tuganov40a28292017-05-25 11:21:12 -0400199 LIBS ${SPIRV_TOOLS})
200
Andrey Tuganov8d3882a2017-06-12 12:01:39 -0400201add_spvtools_unittest(
202 TARGET move_to_front
203 SRCS move_to_front_test.cpp
dan sinclair5fc011b2018-08-14 09:52:05 -0400204 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.h
205 ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.cpp
Andrey Tuganov8d3882a2017-06-12 12:01:39 -0400206 LIBS ${SPIRV_TOOLS})
207
Andrey Tuganov73e8dac2017-05-31 13:07:51 -0400208add_subdirectory(comp)
Pierre Moreau86627f72017-07-13 02:16:51 +0200209add_subdirectory(link)
Lei Zhang71fac5a2016-08-05 13:46:45 -0400210add_subdirectory(opt)
Alastair Donaldsonf3acb952018-11-21 19:03:09 +0000211add_subdirectory(reduce)
Andrey Tuganov4f216402017-04-06 16:55:26 -0400212add_subdirectory(stats)
Diego Novillo03000a32018-08-03 18:08:46 -0400213add_subdirectory(tools)
Steven Perron720beb12017-10-10 09:47:01 -0400214add_subdirectory(util)
Andrey Tuganov73e8dac2017-05-31 13:07:51 -0400215add_subdirectory(val)