summaryrefslogtreecommitdiff
path: root/modules/sycl/tests/skip.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-11-09 22:32:31 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-11-09 22:32:31 +0100
commit2e63c4a31f946a8bafa92c49c1a0a116c0eb6dae (patch)
tree9d9b1022350a21d106a954513cc9567fd974e781 /modules/sycl/tests/skip.hpp
parent5c708bb3a0c9faec82a0deb32478370f9d780ea8 (diff)
downloadlibs-lbm-2e63c4a31f946a8bafa92c49c1a0a116c0eb6dae.tar.gz
Fixing rocm up
Diffstat (limited to 'modules/sycl/tests/skip.hpp')
-rw-r--r--modules/sycl/tests/skip.hpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/modules/sycl/tests/skip.hpp b/modules/sycl/tests/skip.hpp
new file mode 100644
index 0000000..c653591
--- /dev/null
+++ b/modules/sycl/tests/skip.hpp
@@ -0,0 +1,89 @@
+#pragma once
+
+#include <exception>
+#include <iostream>
+#include <string>
+
+/**
+ * Skip support for device tests.
+ *
+ * forstio's suite only has pass and fail: SAW_EXPECT throws and the case is
+ * reported as a failure. That is the wrong verdict for a device test on a
+ * machine with no such device -- "this backend is absent" is not the same
+ * finding as "this backend is broken", and conflating them means a red suite
+ * that everyone learns to ignore.
+ *
+ * These let a case attempt the work and bow out cleanly instead. A skip is
+ * printed so it stays visible rather than looking like a silent pass.
+ */
+
+#define KEL_SKIP(reason) \
+ do { \
+ std::cout << "[ SKIP ] " << __FILE__ << ":" << __LINE__ << ": " \
+ << (reason) << std::endl; \
+ return; \
+ } while(false)
+
+#define KEL_SKIP_IF(cond, reason) \
+ do { \
+ if((cond)){ \
+ KEL_SKIP(reason); \
+ } \
+ } while(false)
+
+/**
+ * Runs `expr`, skipping the case if it throws.
+ *
+ * Device construction is the usual culprit: a missing runtime or an
+ * unavailable backend surfaces as an exception out of the queue constructor,
+ * long before any of the behaviour under test could be wrong.
+ */
+#define KEL_SKIP_ON_THROW(expr, reason) \
+ do { \
+ try { \
+ (void)(expr); \
+ } catch(const std::exception& e){ \
+ std::cout << "[ SKIP ] " << __FILE__ << ":" << __LINE__ << ": " \
+ << (reason) << " (" << e.what() << ")" << std::endl; \
+ return; \
+ } catch(...){ \
+ std::cout << "[ SKIP ] " << __FILE__ << ":" << __LINE__ << ": " \
+ << (reason) << std::endl; \
+ return; \
+ } \
+ } while(false)
+
+namespace kel {
+namespace lbm {
+namespace test {
+
+/**
+ * True when a default queue can be constructed, i.e. there is some backend to
+ * run on at all. Cached, because probing is not free and the answer cannot
+ * change within a run.
+ */
+inline bool sycl_available(){
+ static const bool ok = [](){
+ try {
+ acpp::sycl::queue q;
+ // Touching the device is what actually proves a backend resolved;
+ // constructing the queue alone can succeed lazily.
+ (void) q.get_device();
+ return true;
+ } catch(...){
+ return false;
+ }
+ }();
+ return ok;
+}
+
+}
+}
+}
+
+/**
+ * Guard for a whole device test case.
+ */
+#define KEL_REQUIRE_SYCL() \
+ KEL_SKIP_IF(!::kel::lbm::test::sycl_available(), \
+ "no usable SYCL device on this machine")