forked from oneapi-src/level-zero-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
378 lines (330 loc) · 12.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# Copyright (C) 2019-2023 Intel Corporation
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
project(level-zero-tests)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(clang_tools)
include(custom_functions)
include(vs2019_missing_redist_workaround)
find_package(PNG REQUIRED)
find_package(Git)
if(NOT TARGET GTest::GTest AND NOT TARGET GMock::GMock AND NOT BUILD_ZE_PERF_TESTS_ONLY)
if(NOT DEFINED GTEST_ROOT)
set(GTEST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/googletest")
if(NOT EXISTS "${GTEST_ROOT}/CMakeLists.txt")
if(Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
set(SUBMODULE_INIT_CMD submodule update --init --recursive)
set(SUBMODULE_INIT_CMD_STRING "submodule update --init --recursive")
message(WARNING "Unable to locate third_party/googletest submodule in checkout - Trying to fetch with ${GIT_EXECUTABLE} ${SUBMODULE_INIT_CMD_STRING}")
execute_process(
COMMAND ${GIT_EXECUTABLE} ${SUBMODULE_INIT_CMD}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE SUBMODULE_INIT_RESULT)
if(NOT SUBMODULE_INIT_RESULT EQUAL "0")
message(FATAL_ERROR "Google test submodule checkout failed with ${SUBMODULE_INIT_RESULT}")
endif()
endif()
endif()
endif()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory("${GTEST_ROOT}" "${GTEST_ROOT}/build" EXCLUDE_FROM_ALL)
add_library(GTest::GTest ALIAS gtest)
add_library(GMock::GMock ALIAS gmock)
endif()
enable_testing()
add_compile_definitions(GTEST_HAS_EXCEPTIONS=0)
set(CMAKE_CXX_STANDARD 14)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/20638
set(_Boost_LOG_SETUP_DEPENDENCIES log)
set(_Boost_LOG_DEPENDENCIES "")
if(BUILD_ZE_PERF_TESTS_ONLY)
# do not require boost when building perf tests only, will skip tests that use boost
find_package(Boost 1.65 COMPONENTS log program_options timer chrono system serialization)
else()
find_package(Boost 1.65 REQUIRED COMPONENTS log program_options timer chrono system serialization)
endif()
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
find_package(LevelZero REQUIRED COMPONENTS ${LevelZero_COMPONENTS})
option(REQUIRE_OPENCL_BENCHMARKS
"Ensures that the OpenCL benchmarks are also built (requires OpenCL)"
NO
)
if(REQUIRE_OPENCL_BENCHMARKS)
find_package(OpenCL 2.1 REQUIRED)
if(NOT OpenCL_FOUND)
message(ERROR "OpenCL Benchmarks were requested but OpenCL was not found.")
endif()
message(STATUS "OpenCL_FOUND: ${OpenCL_FOUND}")
endif()
set(MEDIA_ROOT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/mediadata")
set(MEDIA_DIRECTORY "${MEDIA_ROOT_DIRECTORY}/merged")
set(MEDIADATA_ROOT "${MEDIA_ROOT_DIRECTORY}/external")
file(COPY "${MEDIA_ROOT_DIRECTORY}/internal/bmp" DESTINATION "${MEDIA_DIRECTORY}")
file(COPY "${MEDIA_ROOT_DIRECTORY}/internal/png" DESTINATION "${MEDIA_DIRECTORY}")
if(NOT DEFINED GROUP)
set(GROUP "/")
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/out" CACHE PATH "..." FORCE)
endif()
function(assert_valid_test_group_name group_name)
set(regex "^([/]([A-Za-z0-9_]*))*$")
string(REGEX MATCH "${regex}" valid_name "${group_name}")
if(NOT "${group_name}" STREQUAL "${valid_name}")
message(FATAL_ERROR "${group_name} is not a valid test group name, valid regex: ${regex}")
endif()
endfunction()
# Cmake 3.8 doesn't support the list(SUBLIST ...) command
function(list_sublist list_var start_index length result_var)
if(length EQUAL 0)
set("${result_var}" "" PARENT_SCOPE)
return()
endif()
math(EXPR end_index "${start_index}+${length}-1")
set("${result_var}" "")
foreach(index RANGE ${start_index} ${end_index})
list(GET "${list_var}" "${index}" item)
list(APPEND "${result_var}" "${item}")
endforeach()
set("${result_var}" "${${result_var}}" PARENT_SCOPE)
endfunction()
function(is_test_group_member group1 group2 result_var)
assert_valid_test_group_name("${group1}")
assert_valid_test_group_name("${group2}")
string(REGEX MATCHALL "([A-Za-z0-9_])+" group1_list "${group1}")
string(REGEX MATCHALL "([A-Za-z0-9_])+" group2_list "${group2}")
list(LENGTH group1_list group1_list_length)
list(LENGTH group2_list group2_list_length)
if(group1_list_length GREATER group2_list_length)
set(list_length ${group2_list_length})
else()
set(list_length ${group1_list_length})
endif()
# list(SUBLIST group2_list 0 "${group1_list_length}" group2_common)
list_sublist(group2_list 0 "${list_length}" group2_common)
if(group2_common STREQUAL group1_list)
set("${result_var}" "TRUE" PARENT_SCOPE)
else()
set("${result_var}" "FALSE" PARENT_SCOPE)
endif()
endfunction()
set(sys_destination "${CMAKE_INSTALL_PREFIX}")
function(add_lzt_test_executable)
set(options "")
set(oneValueArgs NAME PREFIX GROUP EXTENDED)
set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES KERNELS KERNELSCUSTOM MEDIA DEFINES)
cmake_parse_arguments(ADD_LZT_TEST_EXECUTABLE
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
assert_valid_test_group_name("${ADD_LZT_TEST_EXECUTABLE_GROUP}")
if(DEFINED EXTENDED_BUILD)
if(NOT DEFINED EXTENDED_BUILD_ALL)
if(NOT DEFINED ADD_LZT_TEST_EXECUTABLE_EXTENDED)
message(STATUS "Ignoring ${ADD_LZT_TEST_EXECUTABLE_NAME} because it is not an extended test")
return()
endif()
endif()
endif()
is_test_group_member("${GROUP}" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" in_scope)
if(NOT in_scope)
return()
endif()
is_test_group_member("/conformance_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_conformance_test)
is_test_group_member("/perf_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_perf_test)
is_test_group_member("/negative_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_negative_test)
is_test_group_member("/layer_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_layer_test)
is_test_group_member("/stress_tests" "${ADD_LZT_TEST_EXECUTABLE_GROUP}" is_stress_test)
if(is_conformance_test)
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
level_zero_tests::test_harness
GMock::GMock
GTest::GTest
)
set(component "conformance-tests")
elseif(is_negative_test)
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
level_zero_tests::test_harness
GMock::GMock
GTest::GTest
)
set(component "negative-tests")
elseif(is_perf_test)
list(APPEND ADD_LZT_TEST_EXECUTABLE_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_LIST_DIR}/../common/include
)
set(component "perf-tests")
elseif(is_layer_test)
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
level_zero_tests::test_harness
GMock::GMock
GTest::GTest
)
set(component "layer-tests")
elseif(is_stress_test)
list(APPEND ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES
level_zero_tests::test_harness
GMock::GMock
GTest::GTest
)
list(APPEND ADD_LZT_TEST_EXECUTABLE_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_LIST_DIR}/../common/include
)
set(component "stress-tests")
endif()
add_executable(${ADD_LZT_TEST_EXECUTABLE_NAME} ${ADD_LZT_TEST_EXECUTABLE_SOURCES})
target_compile_definitions(${ADD_LZT_TEST_EXECUTABLE_NAME}
PRIVATE
${ADD_LZT_TEST_EXECUTABLE_DEFINES}
)
target_link_libraries(${ADD_LZT_TEST_EXECUTABLE_NAME}
PRIVATE
LevelZero::LevelZero
${ADD_LZT_TEST_EXECUTABLE_LINK_LIBRARIES}
)
target_include_directories(${ADD_LZT_TEST_EXECUTABLE_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${ADD_LZT_TEST_EXECUTABLE_INCLUDE_DIRECTORIES}
)
set(destination "${CMAKE_INSTALL_PREFIX}/${ADD_LZT_TEST_EXECUTABLE_PREFIX}")
set(sys_destination "${CMAKE_INSTALL_PREFIX}/${ADD_LZT_TEST_EXECUTABLE_PREFIX}")
foreach(kernel ${ADD_LZT_TEST_EXECUTABLE_KERNELS})
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/kernels/${kernel}.spv"
DESTINATION ${destination}
)
endforeach()
foreach(kernel ${ADD_LZT_TEST_EXECUTABLE_KERNELSCUSTOM})
install(
FILES "${kernel}"
DESTINATION ${destination}
)
endforeach()
foreach(media ${ADD_LZT_TEST_EXECUTABLE_MEDIA})
install(
FILES "${MEDIA_DIRECTORY}/${media}"
DESTINATION ${destination}
)
endforeach()
install(
TARGETS ${ADD_LZT_TEST_EXECUTABLE_NAME}
DESTINATION ${destination}
COMPONENT ${component}
)
if(MSVC)
set_target_properties(${ADD_LZT_TEST_EXECUTABLE_NAME}
PROPERTIES
VS_DEBUGGER_COMMAND_ARGUMENTS ""
VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)"
)
endif()
endfunction()
if(MSVC)
if(DEFINED PNG_LIBRARY_RELEASE)
get_filename_component(PNG_RUNTIME_LIBRARY_PATH "${PNG_LIBRARY_RELEASE}" DIRECTORY)
elseif (DEFINED PNG_LIBRARY_DEBUG)
get_filename_component(PNG_RUNTIME_LIBRARY_PATH "${PNG_LIBRARY_DEBUG}" DIRECTORY)
endif()
if (PNG_RUNTIME_LIBRARY_PATH STREQUAL "")
get_filename_component(PNG_RUNTIME_LIBRARY_PATH "${PNG_LIBRARY}" DIRECTORY)
endif()
set(PNG_RUNTIME_LIBRARY_PATH "${PNG_RUNTIME_LIBRARY_PATH}/../bin")
message(STATUS "PNG_RUNTIME_LIBRARY_PATH=${PNG_RUNTIME_LIBRARY_PATH}")
file(GLOB PNG_DLLS
"${PNG_RUNTIME_LIBRARY_PATH}/*.dll"
)
INSTALL(FILES ${PNG_DLLS} DESTINATION ${sys_destination})
if(DEFINED ZLIB_LIBRARY_RELEASE)
get_filename_component(ZLIB_RUNTIME_LIBRARY_PATH "${ZLIB_LIBRARY_RELEASE}" DIRECTORY)
elseif (DEFINED ZLIB_LIBRARY_DEBUG)
get_filename_component(ZLIB_RUNTIME_LIBRARY_PATH "${ZLIB_LIBRARY_DEBUG}" DIRECTORY)
endif()
if (ZLIB_RUNTIME_LIBRARY_PATH STREQUAL "")
get_filename_component(ZLIB_RUNTIME_LIBRARY_PATH "${ZLIB_LIBRARY}" DIRECTORY)
endif()
set(ZLIB_RUNTIME_LIBRARY_PATH "${ZLIB_RUNTIME_LIBRARY_PATH}/../bin")
message(STATUS "ZLIB_RUNTIME_LIBRARY_PATH=${ZLIB_RUNTIME_LIBRARY_PATH}")
file(GLOB ZLIB_DLLS
"${ZLIB_RUNTIME_LIBRARY_PATH}/*.dll"
)
INSTALL(FILES ${ZLIB_DLLS} DESTINATION ${sys_destination})
endif()
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ${sys_destination})
include(InstallRequiredSystemLibraries)
if(NOT DEFINED MANIFEST_BUILD_PATH)
set(MANIFEST_BUILD_PATH "${PROJECT_BINARY_DIR}/manifest.txt")
endif()
install(FILES "${MANIFEST_BUILD_PATH}" DESTINATION "${CMAKE_INSTALL_PREFIX}")
function(add_lzt_test)
set(oneValueArgs NAME GROUP EXTENDED)
set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES KERNELS MEDIA)
cmake_parse_arguments(ADD_LZT_TEST
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
assert_valid_test_group_name("${ADD_LZT_TEST_GROUP}")
if(DEFINED EXTENDED_BUILD)
if(NOT DEFINED EXTENDED_BUILD_ALL)
if(NOT DEFINED ADD_LZT_TEST_EXTENDED)
message(STATUS "Ignoring ${ADD_LZT_TEST_NAME} because it is not an extended test")
return()
endif()
endif()
endif()
is_test_group_member("${GROUP}" "${ADD_LZT_TEST_GROUP}" in_scope)
if(NOT in_scope)
message(STATUS "Ignoring ${ADD_LZT_TEST_NAME} because it is not in ${GROUP}")
return()
else()
message(STATUS "Adding ${ADD_LZT_TEST_NAME}")
endif()
add_lzt_test_executable(
NAME ${ADD_LZT_TEST_NAME}
GROUP ${ADD_LZT_TEST_GROUP}
SOURCES ${ADD_LZT_TEST_SOURCES}
INCLUDE_DIRECTORIES ${ADD_LZT_TEST_INCLUDE_DIRECTORIES}
LINK_LIBRARIES ${ADD_LZT_TEST_LINK_LIBRARIES}
KERNELS ${ADD_LZT_TEST_KERNELS}
KERNELSCUSTOM ${ADD_LZT_TEST_KERNELSCUSTOM}
MEDIA ${ADD_LZT_TEST_MEDIA}
EXTENDED ${ADD_LZT_TEST_EXTENDED}
)
file(APPEND
"${MANIFEST_BUILD_PATH}"
"${ADD_LZT_TEST_NAME}${CMAKE_NEWLINE}"
)
endfunction()
if(WIN32)
set(CMAKE_NEWLINE "\r\n")
else()
set(CMAKE_NEWLINE "\n")
endif()
option(ENABLE_ZESYSMAN
"Enables build of zesysman"
NO
)
if(ENABLE_ZESYSMAN)
add_subdirectory(zesysman)
endif()
if(BUILD_ZE_PERF_TESTS_ONLY)
if(Boost_FOUND)
add_subdirectory(utils/logging)
add_subdirectory(utils/image)
add_subdirectory(utils/utils)
endif()
add_subdirectory(perf_tests)
else()
add_subdirectory(utils)
add_subdirectory(perf_tests)
add_subdirectory(conformance_tests)
add_subdirectory(negative_tests)
add_subdirectory(layer_tests)
add_subdirectory(stress_tests)
endif()