[llvm] [Offload] Skip most liboffload testts if no devices (PR #157417)

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 03:19:19 PDT 2025


https://github.com/RossBrunton created https://github.com/llvm/llvm-project/pull/157417

If there are no devices available for testing on liboffload, the test
will no longer throw an error when it fails to instantiate.

The tests will be silently skipped, but with a warning printed to
stderr.


>From 5fb6e13dbd3771e4026f3fb0ea9d92a9a856c77c Mon Sep 17 00:00:00 2001
From: Ross Brunton <ross at codeplay.com>
Date: Mon, 8 Sep 2025 11:17:38 +0100
Subject: [PATCH] [Offload] Skip most liboffload testts if no devices

If there are no devices available for testing on liboffload, the test
will no longer throw an error when it fails to instantiate.

The tests will be silently skipped, but with a warning printed to
stderr.
---
 offload/unittests/OffloadAPI/common/Environment.cpp | 3 +++
 offload/unittests/OffloadAPI/common/Fixtures.hpp    | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/offload/unittests/OffloadAPI/common/Environment.cpp b/offload/unittests/OffloadAPI/common/Environment.cpp
index 80077138b8cc8..024094aec2e49 100644
--- a/offload/unittests/OffloadAPI/common/Environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -129,6 +129,9 @@ const std::vector<TestEnvironment::Device> &TestEnvironment::getDevices() {
     }
   }
 
+  if (Devices.size() <= 1)
+    errs() << "Warning: No devices found for OffloadAPI tests.\n";
+
   return Devices;
 }
 
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index 0538e60f276e3..c5a35faba7a27 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -250,9 +250,13 @@ struct OffloadEventTest : OffloadQueueTest {
   ol_event_handle_t Event = nullptr;
 };
 
+// Devices might not be available for offload testing, so allow uninstantiated
+// tests (as the device list will be empty). This means that all tests requiring
+// a device will be silently skipped.
 #define OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(FIXTURE)                      \
   INSTANTIATE_TEST_SUITE_P(                                                    \
       , FIXTURE, ::testing::ValuesIn(TestEnvironment::getDevices()),           \
       [](const ::testing::TestParamInfo<TestEnvironment::Device> &info) {      \
         return SanitizeString(info.param.Name);                                \
-      })
+      });                                                                      \
+  GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FIXTURE)



More information about the llvm-commits mailing list