Skip to content

Commit 214380f

Browse files
committed
Fix unit tests for static builds
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent d76cae1 commit 214380f

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

test/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,60 @@ add_executable(
88
driver_ordering_unit_tests.cpp
99
driver_ordering_helper_tests.cpp
1010
)
11+
12+
# For static builds, we need to include the loader source files directly
13+
# since they are not built into the library when BUILD_STATIC=1
14+
if(BUILD_STATIC)
15+
target_sources(tests PRIVATE
16+
${CMAKE_SOURCE_DIR}/source/loader/ze_loader.cpp
17+
${CMAKE_SOURCE_DIR}/source/loader/ze_loader_api.cpp
18+
${CMAKE_SOURCE_DIR}/source/loader/ze_ldrddi.cpp
19+
${CMAKE_SOURCE_DIR}/source/loader/ze_ldrddi_driver_ddi.cpp
20+
${CMAKE_SOURCE_DIR}/source/loader/zet_ldrddi.cpp
21+
${CMAKE_SOURCE_DIR}/source/loader/zet_ldrddi_driver_ddi.cpp
22+
${CMAKE_SOURCE_DIR}/source/loader/zes_ldrddi.cpp
23+
${CMAKE_SOURCE_DIR}/source/loader/zes_ldrddi_driver_ddi.cpp
24+
${CMAKE_SOURCE_DIR}/source/loader/zel_tracing_ldrddi.cpp
25+
)
26+
27+
# Platform-specific source files
28+
if(WIN32)
29+
target_sources(tests PRIVATE
30+
${CMAKE_SOURCE_DIR}/source/loader/windows/driver_discovery_win.cpp
31+
${CMAKE_SOURCE_DIR}/source/loader/windows/loader_init.cpp
32+
)
33+
else()
34+
target_sources(tests PRIVATE
35+
${CMAKE_SOURCE_DIR}/source/loader/linux/driver_discovery_lin.cpp
36+
${CMAKE_SOURCE_DIR}/source/loader/linux/loader_init.cpp
37+
)
38+
endif()
39+
40+
# Add the same definitions as the source CMakeLists.txt
41+
target_compile_definitions(tests PRIVATE
42+
L0_LOADER_VERSION="${PROJECT_VERSION_MAJOR}"
43+
L0_VALIDATION_LAYER_SUPPORTED_VERSION="${PROJECT_VERSION_MAJOR}"
44+
L0_STATIC_LOADER_BUILD="1"
45+
)
46+
endif()
47+
1148
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/source/inc)
1249
target_link_libraries(
1350
tests
51+
PRIVATE
1452
GTest::gtest_main
1553
${TARGET_LOADER_NAME}
1654
level_zero_utils
1755
)
1856

57+
# For static builds, we need additional system libraries
58+
if(BUILD_STATIC)
59+
target_link_libraries(tests PRIVATE ${CMAKE_DL_LIBS})
60+
if(UNIX AND NOT APPLE)
61+
target_link_libraries(tests PRIVATE pthread)
62+
endif()
63+
endif()
64+
1965
add_test(NAME tests_api COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeGetLoaderVersionsAPIThenValidVersionIsReturned*)
2066
set_property(TEST tests_api PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1")
2167
add_test(NAME tests_init_gpu_all COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithGPUTypeThenExpectPassWithGPUorAllOnly*)

0 commit comments

Comments
 (0)