[llvm] [offload] add KNOWN_FAILURE_ON unittest macro (PR #196275)

Piotr Balcer via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 04:19:39 PDT 2026


https://github.com/pbalcer updated https://github.com/llvm/llvm-project/pull/196275

>From e1ab3d400f05cf8cfcadac383d28ebedf5e7aa81 Mon Sep 17 00:00:00 2001
From: Piotr Balcer <piotr.balcer at intel.com>
Date: Thu, 7 May 2026 10:23:05 +0000
Subject: [PATCH] [offload] add KNOWN_FAILURE_ON unittest macro

... and disable failing level-zero tests, to be reenabled once
the plugin is fully functional.
---
 .../unittests/OffloadAPI/common/Fixtures.hpp    | 17 +++++++++++++++++
 .../OffloadAPI/event/olGetEventElapsedTime.cpp  |  2 ++
 .../kernel/olCalculateOptimalOccupancy.cpp      |  8 +++++++-
 .../OffloadAPI/kernel/olLaunchKernel.cpp        | 15 +++++++++++++++
 .../unittests/OffloadAPI/memory/olMemFill.cpp   |  6 ++++++
 .../OffloadAPI/queue/olDestroyQueue.cpp         |  4 ++++
 .../OffloadAPI/queue/olLaunchHostFunction.cpp   | 16 ++++++++++++++--
 .../OffloadAPI/symbol/olGetSymbolInfo.cpp       |  3 +++
 8 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index 6f9961e2c6d58..21dce036400b2 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -61,6 +61,23 @@
   } while (0)
 #endif
 
+inline bool
+isKnownFailureOnBackend(ol_platform_backend_t CurBackend,
+                        std::initializer_list<ol_platform_backend_t> Backends) {
+  for (ol_platform_backend_t B : Backends) {
+    if (CurBackend == B)
+      return true;
+  }
+  return false;
+}
+
+#define KNOWN_FAILURE_ON(...)                                                  \
+  GTEST_AMBIGUOUS_ELSE_BLOCKER_                                                \
+  if (!isKnownFailureOnBackend(this->getPlatformBackend(), {__VA_ARGS__}))     \
+    ;                                                                          \
+  else                                                                         \
+    GTEST_SKIP() << "Skipping known failure. "
+
 #define RETURN_ON_FATAL_FAILURE(...)                                           \
   __VA_ARGS__;                                                                 \
   if (this->HasFatalFailure() || this->IsSkipped()) {                          \
diff --git a/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp b/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp
index aca2dccff72fe..aa6aa14b40cd9 100644
--- a/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp
+++ b/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp
@@ -16,6 +16,8 @@ namespace {
 struct olGetEventElapsedTimeTest : OffloadQueueTest {
   void SetUp() override {
     RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+    KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+        << "Unsupported feature in Level Zero plugin";
 
     ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin));
     ASSERT_SUCCESS(olCreateProgram(Device, DeviceBin->getBufferStart(),
diff --git a/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp b/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp
index 17fa383cac3f4..4d91f3c4c72ed 100644
--- a/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp
@@ -10,7 +10,13 @@
 #include <OffloadAPI.h>
 #include <gtest/gtest.h>
 
-using olCalculateOptimalOccupancyTest = OffloadKernelTest;
+struct olCalculateOptimalOccupancyTest : OffloadKernelTest {
+  void SetUp() override {
+    RETURN_ON_FATAL_FAILURE(OffloadKernelTest::SetUp());
+    KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+        << "Unsupported feature in Level Zero plugin";
+  }
+};
 OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCalculateOptimalOccupancyTest);
 
 TEST_P(olCalculateOptimalOccupancyTest, Success) {
diff --git a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
index 166b8dabff0d8..80bedff016970 100644
--- a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
@@ -107,6 +107,9 @@ TEST_P(olLaunchKernelFooTest, Success) {
 }
 
 TEST_P(olLaunchKernelFooTest, SuccessThreaded) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Thread-safety issues in Level Zero plugin.";
+
   threadify([&](size_t) {
     void *Mem;
     ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
@@ -170,6 +173,9 @@ TEST_P(olLaunchKernelFooTest, SuccessSynchronous) {
 }
 
 TEST_P(olLaunchKernelLocalMemTest, Success) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Event synchronization issues in Level Zero plugin.";
+
   LaunchArgs.NumGroups.x = 4;
   LaunchArgs.DynSharedMemory = 64 * sizeof(uint32_t);
 
@@ -195,6 +201,9 @@ TEST_P(olLaunchKernelLocalMemTest, Success) {
 }
 
 TEST_P(olLaunchKernelLocalMemReductionTest, Success) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Event synchronization issues in Level Zero plugin.";
+
   LaunchArgs.NumGroups.x = 4;
   LaunchArgs.DynSharedMemory = 64 * sizeof(uint32_t);
 
@@ -218,6 +227,9 @@ TEST_P(olLaunchKernelLocalMemReductionTest, Success) {
 }
 
 TEST_P(olLaunchKernelLocalMemStaticTest, Success) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Event synchronization issues in Level Zero plugin.";
+
   LaunchArgs.NumGroups.x = 4;
   LaunchArgs.DynSharedMemory = 0;
 
@@ -272,6 +284,9 @@ TEST_P(olLaunchKernelGlobalTest, InvalidNotAKernel) {
 }
 
 TEST_P(olLaunchKernelGlobalCtorTest, Success) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Event synchronization issues in Level Zero plugin.";
+
   void *Mem;
   ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
                             LaunchArgs.GroupSize.x * sizeof(uint32_t), &Mem));
diff --git a/offload/unittests/OffloadAPI/memory/olMemFill.cpp b/offload/unittests/OffloadAPI/memory/olMemFill.cpp
index a84ed3d78eccf..a87a7d7a801ff 100644
--- a/offload/unittests/OffloadAPI/memory/olMemFill.cpp
+++ b/offload/unittests/OffloadAPI/memory/olMemFill.cpp
@@ -11,6 +11,12 @@
 #include <gtest/gtest.h>
 
 struct olMemFillTest : OffloadQueueTest {
+  void SetUp() override {
+    RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+    KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+        << "Unsupported feature in Level Zero plugin";
+  }
+
   template <typename PatternTy, PatternTy PatternVal, size_t Size,
             bool Block = false>
   void test_body() {
diff --git a/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp b/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
index aa9e372ede2c8..ffc47260a8ebb 100644
--- a/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
+++ b/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
@@ -19,6 +19,10 @@ TEST_P(olDestroyQueueTest, Success) {
 }
 
 TEST_P(olDestroyQueueTest, SuccessDelayedResolution) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Implicit synchronization issues in Level Zero plugin.";
+  EXPECT_TRUE(true);
+
   ManuallyTriggeredTask Manual;
   ASSERT_SUCCESS(Manual.enqueue(Queue));
   ASSERT_SUCCESS(olDestroyQueue(Queue));
diff --git a/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp b/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp
index aa86750f6adf9..2d47c1949fdac 100644
--- a/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp
+++ b/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp
@@ -11,10 +11,22 @@
 #include <gtest/gtest.h>
 #include <thread>
 
-struct olLaunchHostFunctionTest : OffloadQueueTest {};
+struct olLaunchHostFunctionTest : OffloadQueueTest {
+  void SetUp() override {
+    RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+    KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+        << "Unsupported feature in Level Zero plugin";
+  }
+};
 OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchHostFunctionTest);
 
-struct olLaunchHostFunctionKernelTest : OffloadKernelTest {};
+struct olLaunchHostFunctionKernelTest : OffloadKernelTest {
+  void SetUp() override {
+    RETURN_ON_FATAL_FAILURE(OffloadKernelTest::SetUp());
+    KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+        << "Unsupported feature in Level Zero plugin";
+  }
+};
 OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchHostFunctionKernelTest);
 
 TEST_P(olLaunchHostFunctionTest, Success) {
diff --git a/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp b/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp
index ed8f4716974cd..72492c79bb8e9 100644
--- a/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp
+++ b/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp
@@ -52,6 +52,9 @@ TEST_P(olGetSymbolInfoKernelTest, InvalidSize) {
 }
 
 TEST_P(olGetSymbolInfoGlobalTest, SuccessSize) {
+  KNOWN_FAILURE_ON(OL_PLATFORM_BACKEND_LEVEL_ZERO)
+      << "Unsupported feature in Level Zero plugin";
+
   size_t RetrievedSize = 0;
   ASSERT_SUCCESS(olGetSymbolInfo(Global, OL_SYMBOL_INFO_GLOBAL_VARIABLE_SIZE,
                                  sizeof(RetrievedSize), &RetrievedSize));



More information about the llvm-commits mailing list