[llvm] [Offload] Split offload unittests into multiple files (PR #142418)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 08:50:39 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-offload

Author: Ross Brunton (RossBrunton)

<details>
<summary>Changes</summary>

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
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)

``````````

</details>


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


More information about the llvm-commits mailing list