[llvm] [offload] add KNOWN_FAILURE_ON unittest macro (PR #196275)
Piotr Balcer via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 08:24:56 PDT 2026
https://github.com/pbalcer updated https://github.com/llvm/llvm-project/pull/196275
>From 0282b4f6cb8c6836be6c3aeadbe3e022260ac9e6 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 | 49 +++++++++++++++++++
.../event/olGetEventElapsedTime.cpp | 1 +
.../kernel/olCalculateOptimalOccupancy.cpp | 7 ++-
.../OffloadAPI/kernel/olLaunchKernel.cpp | 10 ++++
.../unittests/OffloadAPI/memory/olMemFill.cpp | 5 ++
.../OffloadAPI/queue/olDestroyQueue.cpp | 2 +
.../OffloadAPI/queue/olLaunchHostFunction.cpp | 14 +++++-
.../OffloadAPI/symbol/olGetSymbolInfo.cpp | 2 +
8 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index 6f9961e2c6d58..2b6df40ab710a 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -9,6 +9,8 @@
#include <OffloadAPI.h>
#include <OffloadPrint.hpp>
#include <gtest/gtest.h>
+#include <optional>
+#include <string>
#include <thread>
#include "Environment.hpp"
@@ -61,6 +63,53 @@
} while (0)
#endif
+struct BackendMatcher {
+ ol_platform_backend_t Backend;
+ std::string Message;
+
+ BackendMatcher(ol_platform_backend_t B, std::string M = {})
+ : Backend(B), Message(std::move(M)) {}
+};
+
+struct LevelZero : BackendMatcher {
+ LevelZero(std::string M = {})
+ : BackendMatcher(OL_PLATFORM_BACKEND_LEVEL_ZERO, std::move(M)) {}
+};
+
+struct CUDA : BackendMatcher {
+ CUDA(std::string M = {})
+ : BackendMatcher(OL_PLATFORM_BACKEND_CUDA, std::move(M)) {}
+};
+
+struct AMDGPU : BackendMatcher {
+ AMDGPU(std::string M = {})
+ : BackendMatcher(OL_PLATFORM_BACKEND_AMDGPU, std::move(M)) {}
+};
+
+inline std::string knownFailureMessage(const BackendMatcher &M) {
+ std::string Msg;
+ llvm::raw_string_ostream OS(Msg);
+ OS << "Known failure on " << M.Backend;
+ if (!M.Message.empty())
+ OS << ": " << M.Message;
+ return Msg;
+}
+
+inline std::optional<std::string>
+findKnownFailure(ol_platform_backend_t CurBackend,
+ std::initializer_list<BackendMatcher> Matchers) {
+ for (const auto &M : Matchers) {
+ if (M.Backend == CurBackend)
+ return knownFailureMessage(M);
+ }
+ return std::nullopt;
+}
+
+#define KNOWN_FAILURE_ON(...) \
+ if (auto KFMsg = \
+ ::findKnownFailure(this->getPlatformBackend(), {__VA_ARGS__})) \
+ GTEST_SKIP() << *KFMsg
+
#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..c9d56a661712b 100644
--- a/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp
+++ b/offload/unittests/OffloadAPI/event/olGetEventElapsedTime.cpp
@@ -16,6 +16,7 @@ namespace {
struct olGetEventElapsedTimeTest : OffloadQueueTest {
void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
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..264ea207166bc 100644
--- a/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olCalculateOptimalOccupancy.cpp
@@ -10,7 +10,12 @@
#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(LevelZero{"unsupported feature"});
+ }
+};
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..ee6b557c7c1fa 100644
--- a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
@@ -107,6 +107,8 @@ TEST_P(olLaunchKernelFooTest, Success) {
}
TEST_P(olLaunchKernelFooTest, SuccessThreaded) {
+ KNOWN_FAILURE_ON(LevelZero{"thread-safety issues"});
+
threadify([&](size_t) {
void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED,
@@ -170,6 +172,8 @@ TEST_P(olLaunchKernelFooTest, SuccessSynchronous) {
}
TEST_P(olLaunchKernelLocalMemTest, Success) {
+ KNOWN_FAILURE_ON(LevelZero{"unsupported DynSharedMemory"});
+
LaunchArgs.NumGroups.x = 4;
LaunchArgs.DynSharedMemory = 64 * sizeof(uint32_t);
@@ -195,6 +199,8 @@ TEST_P(olLaunchKernelLocalMemTest, Success) {
}
TEST_P(olLaunchKernelLocalMemReductionTest, Success) {
+ KNOWN_FAILURE_ON(LevelZero{"unsupported DynSharedMemory"});
+
LaunchArgs.NumGroups.x = 4;
LaunchArgs.DynSharedMemory = 64 * sizeof(uint32_t);
@@ -218,6 +224,8 @@ TEST_P(olLaunchKernelLocalMemReductionTest, Success) {
}
TEST_P(olLaunchKernelLocalMemStaticTest, Success) {
+ KNOWN_FAILURE_ON(LevelZero{"unsupported DynSharedMemory"});
+
LaunchArgs.NumGroups.x = 4;
LaunchArgs.DynSharedMemory = 0;
@@ -272,6 +280,8 @@ TEST_P(olLaunchKernelGlobalTest, InvalidNotAKernel) {
}
TEST_P(olLaunchKernelGlobalCtorTest, Success) {
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
+
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..b19665bda43ae 100644
--- a/offload/unittests/OffloadAPI/memory/olMemFill.cpp
+++ b/offload/unittests/OffloadAPI/memory/olMemFill.cpp
@@ -11,6 +11,11 @@
#include <gtest/gtest.h>
struct olMemFillTest : OffloadQueueTest {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
+ }
+
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..78116ed49287b 100644
--- a/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
+++ b/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
@@ -19,6 +19,8 @@ TEST_P(olDestroyQueueTest, Success) {
}
TEST_P(olDestroyQueueTest, SuccessDelayedResolution) {
+ KNOWN_FAILURE_ON(LevelZero{"implicit synchronization issues"});
+
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..982c02a57001e 100644
--- a/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp
+++ b/offload/unittests/OffloadAPI/queue/olLaunchHostFunction.cpp
@@ -11,10 +11,20 @@
#include <gtest/gtest.h>
#include <thread>
-struct olLaunchHostFunctionTest : OffloadQueueTest {};
+struct olLaunchHostFunctionTest : OffloadQueueTest {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
+ }
+};
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchHostFunctionTest);
-struct olLaunchHostFunctionKernelTest : OffloadKernelTest {};
+struct olLaunchHostFunctionKernelTest : OffloadKernelTest {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(OffloadKernelTest::SetUp());
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
+ }
+};
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..20df0cd6764c5 100644
--- a/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp
+++ b/offload/unittests/OffloadAPI/symbol/olGetSymbolInfo.cpp
@@ -52,6 +52,8 @@ TEST_P(olGetSymbolInfoKernelTest, InvalidSize) {
}
TEST_P(olGetSymbolInfoGlobalTest, SuccessSize) {
+ KNOWN_FAILURE_ON(LevelZero{"unsupported feature"});
+
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