Skip to content

[Offload] Split offload unittests into multiple files #142418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

RossBrunton
Copy link
Contributor

Rather than a single offload.unittests file, this will produce
device.unittests, event.unittests, etc.. This should reduce time
spent building tests, and make it easier to manually run a subset of
the tests.

Note that check-offload-unit will still run all the tests.

Rather than a single `offload.unittests` file, this will produce
`device.unittests`, `event.unittests`, etc.. This should reduce time
spent building tests, and make it easier to manually run a subset of
the tests.

Note that `check-offload-unit` will still run all the tests.
@llvmbot llvmbot added the offload label Jun 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2025

@llvm/pr-subscribers-offload

Author: Ross Brunton (RossBrunton)

Changes

Rather than a single offload.unittests file, this will produce
device.unittests, event.unittests, etc.. This should reduce time
spent building tests, and make it easier to manually run a subset of
the tests.

Note that check-offload-unit will still run all the tests.


Full diff: https://github.com/llvm/llvm-project/pull/142418.diff

2 Files Affected:

  • (modified) offload/unittests/CMakeLists.txt (+11-1)
  • (modified) offload/unittests/OffloadAPI/CMakeLists.txt (+30-24)
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index f9cb56ae0c024..efd821584f6bc 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -2,7 +2,17 @@ add_custom_target(OffloadUnitTests)
 set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")
 
 function(add_offload_unittest test_dirname)
-  add_unittest(OffloadUnitTests ${test_dirname} ${ARGN})
+  set(TARGET_NAME "${test_dirname}.unittests")
+
+  list(TRANSFORM ARGN PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" OUTPUT_VARIABLE FILES)
+
+  add_unittest(OffloadUnitTests "${TARGET_NAME}"
+    ${CMAKE_CURRENT_SOURCE_DIR}/common/Environment.cpp
+    ${FILES})
+  add_dependencies(${TARGET_NAME} ${PLUGINS_TEST_COMMON} OffloadUnitTestsDeviceBins)
+  target_compile_definitions(${TARGET_NAME} PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
+  target_link_libraries(${TARGET_NAME} PRIVATE ${PLUGINS_TEST_COMMON})
+  target_include_directories(${TARGET_NAME} PRIVATE ${PLUGINS_TEST_INCLUDE})
 endfunction()
 
 add_subdirectory(OffloadAPI)
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index 54b5c4e245e62..2844b675e5de1 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -3,27 +3,33 @@ set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
 
 add_subdirectory(device_code)
 
-add_offload_unittest("offload.unittests"
-    ${CMAKE_CURRENT_SOURCE_DIR}/common/Environment.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfoSize.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/device/olIterateDevices.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDeviceInfo.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/device/olGetDeviceInfoSize.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/queue/olCreateQueue.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/queue/olWaitQueue.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/queue/olDestroyQueue.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/memory/olMemAlloc.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/memory/olMemFree.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/memory/olMemcpy.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/program/olCreateProgram.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/program/olDestroyProgram.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/event/olDestroyEvent.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/event/olWaitEvent.cpp
-    )
-add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} OffloadUnitTestsDeviceBins)
-target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
-target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
-target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})
+add_offload_unittest("device"
+    device/olIterateDevices.cpp
+    device/olGetDeviceInfo.cpp
+    device/olGetDeviceInfoSize.cpp)
+
+add_offload_unittest("event"
+    event/olDestroyEvent.cpp
+    event/olWaitEvent.cpp)
+
+add_offload_unittest("kernel"
+    kernel/olGetKernel.cpp
+    kernel/olLaunchKernel.cpp)
+
+add_offload_unittest("memory"
+    memory/olMemAlloc.cpp
+    memory/olMemFree.cpp
+    memory/olMemcpy.cpp)
+
+add_offload_unittest("platform"
+    platform/olGetPlatformInfo.cpp
+    platform/olGetPlatformInfoSize.cpp)
+
+add_offload_unittest("program"
+    program/olCreateProgram.cpp
+    program/olDestroyProgram.cpp)
+
+add_offload_unittest("queue"
+    queue/olCreateQueue.cpp
+    queue/olWaitQueue.cpp
+    queue/olDestroyQueue.cpp)

@@ -2,7 +2,17 @@ add_custom_target(OffloadUnitTests)
set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")

function(add_offload_unittest test_dirname)
add_unittest(OffloadUnitTests ${test_dirname} ${ARGN})
set(TARGET_NAME "${test_dirname}.unittests")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: Don't use all caps names for anything but things intended as global vars in CMake.

@jhuber6 jhuber6 merged commit e83c803 into llvm:main Jun 2, 2025
9 checks passed
sallto pushed a commit to sallto/llvm-project that referenced this pull request Jun 3, 2025
Rather than a single `offload.unittests` file, this will produce
`device.unittests`, `event.unittests`, etc.. This should reduce time
spent building tests, and make it easier to manually run a subset of
the tests.

Note that `check-offload-unit` will still run all the tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants