Debian Codegraph @

test/CMakeLists.txt

raw
1 # Copyright (c) 2015-2016 The Khronos Group Inc.
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 if (${SPIRV_SKIP_TESTS})
16 return()
17 endif()
18
19 if (TARGET gmock_main)
20 message(STATUS "Found Google Mock, building tests.")
21 else()
22 message(STATUS "Did not find googletest, tests will not be built. "
23 "To enable tests place googletest in '<spirv-dir>/external/googletest'.")
24 endif()
25
26 # Add a SPIR-V Tools unit test. Signature:
27 # add_spvtools_unittest(
28 # TARGET target_name
29 # SRCS src_file.h src_file.cpp
30 # LIBS lib1 lib2
31 # )
32 function(add_spvtools_unittest)
33 if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main)
34 set(one_value_args TARGET PCH_FILE)
35 set(multi_value_args SRCS LIBS ENVIRONMENT DEFINES)
36 cmake_parse_arguments(
37 ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
38 set(target test_${ARG_TARGET})
39 set(SRC_COPY ${ARG_SRCS})
40 if (DEFINED ARG_PCH_FILE)
41 spvtools_pch(SRC_COPY ${ARG_PCH_FILE})
42 endif()
43 add_executable(${target} ${SRC_COPY})
44 target_compile_definitions(${target} PUBLIC ${ARG_DEFINES})
45 spvtools_default_compile_options(${target})
46 if(${COMPILER_IS_LIKE_GNU})
47 target_compile_options(${target} PRIVATE -Wno-undef)
48 # Effcee and RE2 headers exhibit shadowing.
49 target_compile_options(${target} PRIVATE -Wno-shadow)
50 endif()
51 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
52 # Disable C4503 "decorated name length exceeded" warning,
53 # triggered by some heavily templated types.
54 # We don't care much about that in test code.
55 # Important to do since we have warnings-as-errors.
56 target_compile_options(${target} PRIVATE /wd4503)
57 # Googletest accidentally turns off support for ::testing::Combine
58 # in VS 2017. See https://github.com/google/googletest/issues/1352
59 # Forcibly turn it on again.
60 target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1)
61 endif()
62 target_include_directories(${target} PRIVATE
63 ${SPIRV_HEADER_INCLUDE_DIR}
64 ${spirv-tools_SOURCE_DIR}
65 ${spirv-tools_SOURCE_DIR}/include
66 ${spirv-tools_SOURCE_DIR}/test
67 ${spirv-tools_BINARY_DIR}
68 ${gtest_SOURCE_DIR}/include
69 ${gmock_SOURCE_DIR}/include
70 )
71 if (TARGET effcee)
72 # If using Effcee for testing, then add its include directory.
73 target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR})
74 endif()
75 target_link_libraries(${target} PRIVATE ${ARG_LIBS})
76 if (TARGET effcee)
77 target_link_libraries(${target} PRIVATE effcee)
78 endif()
79 target_link_libraries(${target} PRIVATE gmock_main)
80 add_test(NAME spirv-tools-${target} COMMAND ${target})
81 if (DEFINED ARG_ENVIRONMENT)
82 set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT})
83 endif()
84 set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
85 endif()
86 endfunction()
87
88 set(TEST_SOURCES
89 test_fixture.h
90 unit_spirv.h
91 ${spirv-tools_SOURCE_DIR}/tools/io.h
92
93 assembly_context_test.cpp
94 assembly_format_test.cpp
95 binary_destroy_test.cpp
96 binary_endianness_test.cpp
97 binary_header_get_test.cpp
98 binary_parse_test.cpp
99 binary_strnlen_s_test.cpp
100 binary_to_text_test.cpp
101 binary_to_text.literal_test.cpp
102 comment_test.cpp
103 diagnostic_test.cpp
104 enum_string_mapping_test.cpp
105 enum_set_test.cpp
106 ext_inst.arm_motion_engine_test.cpp
107 ext_inst.cldebug100_test.cpp
108 ext_inst.debuginfo_test.cpp
109 ext_inst.glsl_test.cpp
110 ext_inst.non_semantic_test.cpp
111 ext_inst.opencl_test.cpp
112 ext_inst.tosa_test.cpp
113 ext_inst_lookup_test.cpp
114 fix_word_test.cpp
115 generator_magic_number_test.cpp
116 hex_float_test.cpp
117 hex_to_text_test.cpp
118 immediate_int_test.cpp
119 libspirv_macros_test.cpp
120 named_id_test.cpp
121 name_mapper_test.cpp
122 op_unknown_test.cpp
123 opcode_lookup_test.cpp
124 opcode_make_test.cpp
125 opcode_require_capabilities_test.cpp
126 opcode_split_test.cpp
127 operand_capabilities_test.cpp
128 operand_lookup_test.cpp
129 operand_test.cpp
130 operand_pattern_test.cpp
131 parse_number_test.cpp
132 preserve_numeric_ids_test.cpp
133 software_version_test.cpp
134 string_utils_test.cpp
135 target_env_test.cpp
136 text_advance_test.cpp
137 text_destroy_test.cpp
138 text_literal_test.cpp
139 text_start_new_inst_test.cpp
140 text_to_binary.annotation_test.cpp
141 text_to_binary.barrier_test.cpp
142 text_to_binary.composite_test.cpp
143 text_to_binary.constant_test.cpp
144 text_to_binary.control_flow_test.cpp
145 text_to_binary_test.cpp
146 text_to_binary.debug_test.cpp
147 text_to_binary.device_side_enqueue_test.cpp
148 text_to_binary.extension_test.cpp
149 text_to_binary.function_test.cpp
150 text_to_binary.group_test.cpp
151 text_to_binary.image_test.cpp
152 text_to_binary.literal_test.cpp
153 text_to_binary.memory_test.cpp
154 text_to_binary.misc_test.cpp
155 text_to_binary.mode_setting_test.cpp
156 text_to_binary.pipe_storage_test.cpp
157 text_to_binary.type_declaration_test.cpp
158 text_to_binary.subgroup_dispatch_test.cpp
159 text_to_binary.reserved_sampling_test.cpp
160 text_word_get_test.cpp
161 to_string_test.cpp
162
163 unit_spirv.cpp
164 ${spirv-tools_SOURCE_DIR}/tools/io.cpp
165 )
166
167 spvtools_pch(TEST_SOURCES pch_test)
168
169 add_spvtools_unittest(
170 TARGET spirv_unit_tests
171 SRCS ${TEST_SOURCES}
172 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
173
174 add_spvtools_unittest(
175 TARGET c_interface
176 SRCS c_interface_test.cpp
177 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
178
179 add_spvtools_unittest(
180 TARGET c_interface_shared
181 SRCS c_interface_test.cpp
182 LIBS ${SPIRV_TOOLS}-shared
183 ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>)
184
185 add_spvtools_unittest(
186 TARGET cpp_interface
187 SRCS cpp_interface_test.cpp
188 LIBS SPIRV-Tools-opt)
189
190 if (${SPIRV_TIMER_ENABLED})
191 add_spvtools_unittest(
192 TARGET timer
193 SRCS timer_test.cpp
194 LIBS ${SPIRV_TOOLS_FULL_VISIBILITY})
195 endif()
196
197
198 add_subdirectory(diff)
199 add_subdirectory(link)
200 add_subdirectory(lint)
201 add_subdirectory(opt)
202 add_subdirectory(reduce)
203 add_subdirectory(fuzz)
204 add_subdirectory(tools)
205 add_subdirectory(util)
206 add_subdirectory(val)
207 add_subdirectory(fuzzers)