blob: 891828bdf23653573608fdde10a8205037da50e1 [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()
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()
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)
34 set(multi_value_args SRCS LIBS)
35 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)
Lei Zhang71fac5a2016-08-05 13:46:45 -040042 endif()
Lei Zhang190b0d32016-08-07 22:49:00 -040043 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
Lei Zhang71fac5a2016-08-05 13:46:45 -040044 # 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.
Lei Zhangef600df2016-09-07 17:26:18 -040048 target_compile_options(${target} PRIVATE /wd4503)
Lei Zhang71fac5a2016-08-05 13:46:45 -040049 endif()
Lei Zhangef600df2016-09-07 17:26:18 -040050 target_include_directories(${target} PRIVATE
51 ${SPIRV_HEADER_INCLUDE_DIR}
Lei Zhang71fac5a2016-08-05 13:46:45 -040052 ${spirv-tools_SOURCE_DIR}
53 ${spirv-tools_SOURCE_DIR}/include
Lei Zhangef600df2016-09-07 17:26:18 -040054 ${spirv-tools_SOURCE_DIR}/test
Lei Zhang71fac5a2016-08-05 13:46:45 -040055 ${gtest_SOURCE_DIR}/include
56 ${gmock_SOURCE_DIR}/include
57 )
Lei Zhangef600df2016-09-07 17:26:18 -040058 target_link_libraries(${target} PRIVATE ${ARG_LIBS})
59 target_link_libraries(${target} PRIVATE gmock_main)
60 add_test(NAME spirv-tools-${target} COMMAND ${target})
Lei Zhang71fac5a2016-08-05 13:46:45 -040061 endif()
62endfunction()
63
64set(TEST_SOURCES
Lei Zhang4f57e142016-09-22 11:05:30 -040065 test_fixture.h
66 unit_spirv.h
Lei Zhang71fac5a2016-08-05 13:46:45 -040067
Lei Zhang4f57e142016-09-22 11:05:30 -040068 assembly_context_test.cpp
69 assembly_format_test.cpp
70 binary_destroy_test.cpp
71 binary_endianness_test.cpp
72 binary_header_get_test.cpp
73 binary_parse_test.cpp
74 binary_to_text_test.cpp
75 binary_to_text.literal_test.cpp
76 capability_set_test.cpp
77 comment_test.cpp
78 ext_inst.glsl_test.cpp
79 ext_inst.opencl_test.cpp
80 fix_word_test.cpp
81 generator_magic_number_test.cpp
82 hex_float_test.cpp
83 immediate_int_test.cpp
84 libspirv_macros_test.cpp
85 named_id_test.cpp
86 name_mapper_test.cpp
87 opcode_make_test.cpp
88 opcode_require_capabilities_test.cpp
89 opcode_split_test.cpp
90 opcode_table_get_test.cpp
91 operand_capabilities_test.cpp
92 operand_test.cpp
93 operand_pattern_test.cpp
94 software_version_test.cpp
95 target_env_test.cpp
96 text_advance_test.cpp
97 text_destroy_test.cpp
98 text_literal_test.cpp
99 text_start_new_inst_test.cpp
100 text_to_binary.annotation_test.cpp
101 text_to_binary.barrier_test.cpp
102 text_to_binary.constant_test.cpp
103 text_to_binary.control_flow_test.cpp
104 text_to_binary_test.cpp
105 text_to_binary.debug_test.cpp
106 text_to_binary.device_side_enqueue_test.cpp
107 text_to_binary.extension_test.cpp
108 text_to_binary.function_test.cpp
109 text_to_binary.group_test.cpp
110 text_to_binary.image_test.cpp
111 text_to_binary.literal_test.cpp
112 text_to_binary.memory_test.cpp
113 text_to_binary.misc_test.cpp
114 text_to_binary.mode_setting_test.cpp
115 text_to_binary.pipe_storage_test.cpp
116 text_to_binary.type_declaration_test.cpp
117 text_to_binary.subgroup_dispatch_test.cpp
118 text_word_get_test.cpp
119
120 unit_spirv.cpp
Lei Zhang71fac5a2016-08-05 13:46:45 -0400121)
Lei Zhanga35919c2016-09-08 17:26:53 -0400122
Lei Zhang71fac5a2016-08-05 13:46:45 -0400123add_spvtools_unittest(
Lei Zhangef600df2016-09-07 17:26:18 -0400124 TARGET spirv_unit_tests
Lei Zhang71fac5a2016-08-05 13:46:45 -0400125 SRCS ${TEST_SOURCES}
126 LIBS ${SPIRV_TOOLS})
127
128add_spvtools_unittest(
Lei Zhanga35919c2016-09-08 17:26:53 -0400129 TARGET diagnostic
Lei Zhang4f57e142016-09-22 11:05:30 -0400130 SRCS diagnostic_test.cpp
Lei Zhanga35919c2016-09-08 17:26:53 -0400131 LIBS ${SPIRV_TOOLS})
132
133add_spvtools_unittest(
Lei Zhang755f97f2016-09-02 18:06:18 -0400134 TARGET c_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400135 SRCS c_interface_test.cpp
Lei Zhang755f97f2016-09-02 18:06:18 -0400136 LIBS ${SPIRV_TOOLS})
137
138add_spvtools_unittest(
Lei Zhang71fac5a2016-08-05 13:46:45 -0400139 TARGET cpp_interface
Lei Zhang4f57e142016-09-22 11:05:30 -0400140 SRCS cpp_interface_test.cpp
141 LIBS SPIRV-Tools-opt)
Lei Zhang71fac5a2016-08-05 13:46:45 -0400142
qining1773b952016-09-01 14:27:04 -0400143add_spvtools_unittest(
144 TARGET parse_number
Lei Zhang4f57e142016-09-22 11:05:30 -0400145 SRCS parse_number_test.cpp
qining1773b952016-09-01 14:27:04 -0400146 LIBS ${SPIRV_TOOLS})
147
Lei Zhangbfd7cd62016-09-08 11:43:48 -0400148add_spvtools_unittest(
149 TARGET log
Lei Zhang4f57e142016-09-22 11:05:30 -0400150 SRCS log_test.cpp
Lei Zhangbfd7cd62016-09-08 11:43:48 -0400151 LIBS ${SPIRV_TOOLS})
152
Lei Zhang71fac5a2016-08-05 13:46:45 -0400153add_subdirectory(opt)
Lei Zhang219f0cc2016-09-07 17:43:15 -0400154add_subdirectory(val)