• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# 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#   )
21
22if (NOT "${SPIRV_SKIP_TESTS}")
23  if (TARGET gmock_main)
24    message(STATUS "Found Google Mock, building tests.")
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()
29endif()
30
31function(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})
37    set(target test_${ARG_TARGET})
38    add_executable(${target} ${ARG_SRCS})
39    spvtools_default_compile_options(${target})
40    if(${COMPILER_IS_LIKE_GNU})
41      target_compile_options(${target} PRIVATE -Wno-undef)
42    endif()
43    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
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.
48      target_compile_options(${target} PRIVATE /wd4503)
49    endif()
50    target_include_directories(${target} PRIVATE
51      ${SPIRV_HEADER_INCLUDE_DIR}
52      ${spirv-tools_SOURCE_DIR}
53      ${spirv-tools_SOURCE_DIR}/include
54      ${spirv-tools_SOURCE_DIR}/test
55      ${spirv-tools_BINARY_DIR}
56      ${gtest_SOURCE_DIR}/include
57      ${gmock_SOURCE_DIR}/include
58    )
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})
62    set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
63  endif()
64endfunction()
65
66set(TEST_SOURCES
67  test_fixture.h
68  unit_spirv.h
69
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
76  binary_strnlen_s_test.cpp
77  binary_to_text_test.cpp
78  binary_to_text.literal_test.cpp
79  comment_test.cpp
80  enum_string_mapping_test.cpp
81  enum_set_test.cpp
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
125)
126
127add_spvtools_unittest(
128  TARGET spirv_unit_tests
129  SRCS ${TEST_SOURCES}
130  LIBS ${SPIRV_TOOLS})
131
132add_spvtools_unittest(
133  TARGET diagnostic
134  SRCS diagnostic_test.cpp
135  LIBS ${SPIRV_TOOLS})
136
137add_spvtools_unittest(
138  TARGET c_interface
139  SRCS c_interface_test.cpp
140  LIBS ${SPIRV_TOOLS})
141
142add_spvtools_unittest(
143  TARGET cpp_interface
144  SRCS cpp_interface_test.cpp
145  LIBS SPIRV-Tools-opt)
146
147add_spvtools_unittest(
148  TARGET parse_number
149  SRCS parse_number_test.cpp
150  LIBS ${SPIRV_TOOLS})
151
152add_spvtools_unittest(
153  TARGET string_utils
154  SRCS string_utils_test.cpp
155  LIBS ${SPIRV_TOOLS})
156
157add_spvtools_unittest(
158  TARGET log
159  SRCS log_test.cpp
160  LIBS ${SPIRV_TOOLS})
161
162add_spvtools_unittest(
163  TARGET preserve_numeric_ids
164  SRCS preserve_numeric_ids_test.cpp
165  LIBS ${SPIRV_TOOLS})
166
167add_spvtools_unittest(
168  TARGET bit_stream
169  SRCS bit_stream.cpp
170  LIBS ${SPIRV_TOOLS})
171
172add_spvtools_unittest(
173  TARGET huffman_codec
174  SRCS huffman_codec.cpp
175  LIBS ${SPIRV_TOOLS})
176
177add_spvtools_unittest(
178  TARGET move_to_front
179  SRCS move_to_front_test.cpp
180  LIBS ${SPIRV_TOOLS})
181
182add_subdirectory(comp)
183add_subdirectory(opt)
184add_subdirectory(stats)
185add_subdirectory(val)
186