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