Skip to content

Commit 15458e7

Browse files
committed
[Offload] Add check-offload-unit for liboffload unittests
1 parent eea1efe commit 15458e7

File tree

10 files changed

+82
-187
lines changed

10 files changed

+82
-187
lines changed

offload/test/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,37 @@ add_offload_testsuite(check-offload
6363
EXCLUDE_FROM_CHECK_ALL
6464
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
6565
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
66+
67+
# Add liboffload unit tests based on available devices rather than configured targets
68+
macro(add_offload_unittest_suite target_name)
69+
set(OFFLOAD_PLATFORM ${target_name})
70+
string(TOLOWER "${OFFLOAD_PLATFORM}" SUITE_NAME)
71+
72+
configure_lit_site_cfg(
73+
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
74+
${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}/lit.site.cfg
75+
MAIN_CONFIG
76+
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
77+
78+
add_lit_testsuite(check-offload-unit-${SUITE_NAME} "Running offload unittest suite for ${SUITE_NAME}"
79+
${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}
80+
EXCLUDE_FROM_CHECK_ALL
81+
DEPENDS OffloadUnitTests)
82+
83+
list(APPEND OFFLOAD_UNIT_TEST_SUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME})
84+
endmacro()
85+
86+
set (OFFLOAD_UNIT_TEST_SUITES "")
87+
88+
if (LIBOMPTARGET_FOUND_NVIDIA_GPU)
89+
add_offload_unittest_suite("CUDA")
90+
endif()
91+
92+
if (LIBOMPTARGET_FOUND_AMDGPU_GPU)
93+
add_offload_unittest_suite("AMDGPU")
94+
endif()
95+
96+
add_lit_testsuite(check-offload-unit "Running offload unittest suites"
97+
${OFFLOAD_UNIT_TEST_SUITES}
98+
EXCLUDE_FROM_CHECK_ALL
99+
DEPENDS LLVMOffload OffloadUnitTests)

offload/test/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ config.name = 'libomptarget :: ' + config.libomptarget_current_target
6969
config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
7070

7171
# excludes: A list of directories to exclude from the testuites.
72-
config.excludes = ['Inputs']
72+
config.excludes = ['Inputs', 'unit']
7373

7474
# test_source_root: The root path where tests are located.
7575
config.test_source_root = os.path.dirname(__file__)

offload/test/unit/lit.cfg.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- Python -*-
2+
3+
# Configuration file for the 'lit' test runner.
4+
5+
import os
6+
import subprocess
7+
8+
import lit.formats
9+
10+
# name: The name of this test suite.
11+
config.name = "Offload-Unit-{}".format(config.offload_platform)
12+
13+
# suffixes: A list of file extensions to treat as test files.
14+
config.suffixes = []
15+
16+
config.environment = { "OFFLOAD_UNITTEST_PLATFORM" : config.offload_platform}
17+
18+
# test_source_root: The root path where tests are located.
19+
# test_exec_root: The root path where tests should be run.
20+
config.test_exec_root = os.path.join(config.library_dir, "unittests")
21+
config.test_source_root = config.test_exec_root
22+
23+
# testFormat: The test format to use to interpret tests.
24+
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, ".unittests")

offload/test/unit/lit.site.cfg.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@AUTO_GEN_COMMENT@
2+
3+
config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
4+
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
5+
config.offload_platform = "@OFFLOAD_PLATFORM@"
6+
7+
# Let the main config do the real work.
8+
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/unit/lit.cfg.py")
9+

offload/unittests/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
add_custom_target(LibomptUnitTests)
2-
set_target_properties(LibomptUnitTests PROPERTIES FOLDER "Tests/UnitTests")
1+
add_custom_target(OffloadUnitTests)
2+
set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")
33

4-
function(add_libompt_unittest test_dirname)
5-
add_unittest(LibomptUnitTests ${test_dirname} ${ARGN})
4+
function(add_offload_unittest test_dirname)
5+
add_unittest(OffloadUnitTests ${test_dirname} ${ARGN})
66
endfunction()
77

8-
# add_subdirectory(Plugins)
98
add_subdirectory(OffloadAPI)

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
44
add_subdirectory(device_code)
55
message(${OFFLOAD_TEST_DEVICE_CODE_PATH})
66

7-
add_libompt_unittest("offload.unittests"
7+
add_offload_unittest("offload.unittests"
88
${CMAKE_CURRENT_SOURCE_DIR}/common/Environment.cpp
99
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfoSize.cpp
@@ -22,7 +22,7 @@ add_libompt_unittest("offload.unittests"
2222
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
2323
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
2424
)
25-
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} LibomptUnitTestsDeviceBins)
25+
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} OffloadUnitTestsDeviceBins)
2626
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
2727
target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
2828
target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})

offload/unittests/OffloadAPI/common/Environment.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ ol_device_handle_t TestEnvironment::getDevice() {
6565
static ol_device_handle_t Device = nullptr;
6666

6767
if (!Device) {
68+
if (const char *EnvStr = getenv("OFFLOAD_UNITTEST_PLATFORM")) {
69+
if (SelectedPlatform != "")
70+
errs() << "Warning: --platform argument ignored as "
71+
"OFFLOAD_UNITTEST_PLATFORM env var overrides it.\n";
72+
SelectedPlatform = EnvStr;
73+
}
74+
6875
if (SelectedPlatform != "") {
6976
olIterateDevices(
7077
[](ol_device_handle_t D, void *Data) {

offload/unittests/OffloadAPI/device_code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ endif()
6262
add_offload_test_device_code(foo.c foo)
6363
add_offload_test_device_code(bar.c bar)
6464

65-
add_custom_target(LibomptUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
65+
add_custom_target(OffloadUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
6666

6767
set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

offload/unittests/Plugins/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

offload/unittests/Plugins/NextgenPluginsTest.cpp

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)