blob: 5317e1f1f2415bec18fff8bdf550e35ac0efaa59 [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)
33 set(one_value_args TARGET)
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})
38 add_executable(${target} ${ARG_SRCS})
39 spvtools_default_compile_options(${target})
Lei Zhang71fac5a2016-08-05 13:46:45 -040040 if(${COMPILER_IS_LIKE_GNU})
Lei Zhangef600df2016-09-07 17:26:18 -040041 target_compile_options(${target} PRIVATE -Wno-undef)
David Neto76555bd2017-11-08 00:23:42 -050042 # Effcee and RE2 headers exhibit shadowing.
43 target_compile_options(${target} PRIVATE -Wno-shadow)
Lei Zhang71fac5a2016-08-05 13:46:45 -040044 endif()
Lei Zhang190b0d32016-08-07 22:49:00 -040045 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
Lei Zhang71fac5a2016-08-05 13:46:45 -040046 # 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 Zhangef600df2016-09-07 17:26:18 -040050 target_compile_options(${target} PRIVATE /wd4503)
David Neto7ba59ac2017-12-11 12:05:04 -050051 # 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 Zhang71fac5a2016-08-05 13:46:45 -040055 endif()
Lei Zhangef600df2016-09-07 17:26:18 -040056 target_include_directories(${target} PRIVATE
57 ${SPIRV_HEADER_INCLUDE_DIR}
Lei Zhang71fac5a2016-08-05 13:46:45 -040058 ${spirv-tools_SOURCE_DIR}
59 ${spirv-tools_SOURCE_DIR}/include
Lei Zhangef600df2016-09-07 17:26:18 -040060 ${spirv-tools_SOURCE_DIR}/test
Andrey Tuganovc804c122017-03-15 17:28:24 -040061 ${spirv-tools_BINARY_DIR}
Lei Zhang71fac5a2016-08-05 13:46:45 -040062 ${gtest_SOURCE_DIR}/include
63 ${gmock_SOURCE_DIR}/include
64 )
David Neto76555bd2017-11-08 00:23:42 -050065 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 Zhangef600df2016-09-07 17:26:18 -040069 target_link_libraries(${target} PRIVATE ${ARG_LIBS})
David Neto76555bd2017-11-08 00:23:42 -050070 if (TARGET effcee)
71 target_link_libraries(${target} PRIVATE effcee)
72 endif()
Lei Zhangef600df2016-09-07 17:26:18 -040073 target_link_libraries(${target} PRIVATE gmock_main)
74 add_test(NAME spirv-tools-${target} COMMAND ${target})
Józef Kucia30138972018-02-02 23:37:14 +010075 if (DEFINED ARG_ENVIRONMENT)
76 set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT})
77 endif()
Lei Zhang5c3c0542017-04-05 17:32:39 -040078 set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
Lei Zhang71fac5a2016-08-05 13:46:45 -040079 endif()
80endfunction()
81
82set(TEST_SOURCES
Lei Zhang4f57e142016-09-22 11:05:30 -040083 test_fixture.h
84 unit_spirv.h
Lei Zhang71fac5a2016-08-05 13:46:45 -040085
Lei Zhang4f57e142016-09-22 11:05:30 -040086 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 Neto37422e92016-12-19 13:26:42 -050092 binary_strnlen_s_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -040093 binary_to_text_test.cpp
94 binary_to_text.literal_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -040095 comment_test.cpp
Andrey Tuganovc804c122017-03-15 17:28:24 -040096 enum_string_mapping_test.cpp
Andrey Tuganov1fb8c372017-03-09 18:24:35 -050097 enum_set_test.cpp
David Neto59de6102017-12-03 12:30:08 -050098 ext_inst.debuginfo_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -040099 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 Zhang1ef6b192018-03-14 13:06:18 -0400139 text_to_binary.reserved_sampling_test.cpp
Lei Zhang4f57e142016-09-22 11:05:30 -0400140 text_word_get_test.cpp
141
142 unit_spirv.cpp
Lei Zhang71fac5a2016-08-05 13:46:45 -0400143)
Lei Zhanga35919c2016-09-08 17:26:53 -0400144
Lei Zhang71fac5a2016-08-05 13:46:45 -0400145add_spvtools_unittest(
Lei Zhangef600df2016-09-07 17:26:18 -0400146 TARGET spirv_unit_tests
Lei Zhang71fac5a2016-08-05 13:46:45 -0400147 SRCS ${TEST_SOURCES}
148 LIBS ${SPIRV_TOOLS})
149
150add_spvtools_unittest(
Lei Zhanga35919c2016-09-08 17:26:53 -0400151 TARGET diagnostic
Lei Zhang4f57e142016-09-22 11:05:30 -0400152 SRCS diagnostic_test.cpp
Lei Zhanga35919c2016-09-08 17:26:53 -0400153 LIBS ${SPIRV_TOOLS})
154
155add_spvtools_unittest(
Lei Zhang755f97f2016-09-02 18:06:18 -0400156 TARGET c_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400157 SRCS c_interface_test.cpp
Lei Zhang755f97f2016-09-02 18:06:18 -0400158 LIBS ${SPIRV_TOOLS})
159
160add_spvtools_unittest(
Józef Kucia30138972018-02-02 23:37:14 +0100161 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
166add_spvtools_unittest(
Lei Zhang71fac5a2016-08-05 13:46:45 -0400167 TARGET cpp_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400168 SRCS cpp_interface_test.cpp
169 LIBS SPIRV-Tools-opt)
Lei Zhang71fac5a2016-08-05 13:46:45 -0400170
qining1773b952016-09-01 14:27:04 -0400171add_spvtools_unittest(
172 TARGET parse_number
Lei Zhang4f57e142016-09-22 11:05:30 -0400173 SRCS parse_number_test.cpp
qining1773b952016-09-01 14:27:04 -0400174 LIBS ${SPIRV_TOOLS})
175
Lei Zhangbfd7cd62016-09-08 11:43:48 -0400176add_spvtools_unittest(
Andrey Tuganovb0116332017-03-10 15:58:15 -0500177 TARGET string_utils
178 SRCS string_utils_test.cpp
179 LIBS ${SPIRV_TOOLS})
180
Jaebaek Seo3b594e12018-03-07 09:25:51 -0500181if (${SPIRV_TIMER_ENABLED})
182add_spvtools_unittest(
183 TARGET timer
184 SRCS timer_test.cpp
185 LIBS ${SPIRV_TOOLS})
186endif()
187
Andrey Tuganovb0116332017-03-10 15:58:15 -0500188add_spvtools_unittest(
Lei Zhangbfd7cd62016-09-08 11:43:48 -0400189 TARGET log
Lei Zhang4f57e142016-09-22 11:05:30 -0400190 SRCS log_test.cpp
Lei Zhangbfd7cd62016-09-08 11:43:48 -0400191 LIBS ${SPIRV_TOOLS})
192
Andrey Tuganovb173d1c2017-04-11 19:46:15 -0400193add_spvtools_unittest(
194 TARGET preserve_numeric_ids
195 SRCS preserve_numeric_ids_test.cpp
196 LIBS ${SPIRV_TOOLS})
197
Andrey Tuganov3eb716c2017-04-24 15:17:33 -0400198add_spvtools_unittest(
199 TARGET bit_stream
200 SRCS bit_stream.cpp
201 LIBS ${SPIRV_TOOLS})
202
Andrey Tuganov40a28292017-05-25 11:21:12 -0400203add_spvtools_unittest(
204 TARGET huffman_codec
205 SRCS huffman_codec.cpp
206 LIBS ${SPIRV_TOOLS})
207
Andrey Tuganov8d3882a2017-06-12 12:01:39 -0400208add_spvtools_unittest(
209 TARGET move_to_front
210 SRCS move_to_front_test.cpp
211 LIBS ${SPIRV_TOOLS})
212
Andrey Tuganov73e8dac2017-05-31 13:07:51 -0400213add_subdirectory(comp)
Pierre Moreau86627f72017-07-13 02:16:51 +0200214add_subdirectory(link)
Lei Zhang71fac5a2016-08-05 13:46:45 -0400215add_subdirectory(opt)
Andrey Tuganov4f216402017-04-06 16:55:26 -0400216add_subdirectory(stats)
Steven Perron720beb12017-10-10 09:47:01 -0400217add_subdirectory(util)
Andrey Tuganov73e8dac2017-05-31 13:07:51 -0400218add_subdirectory(val)