[llvm] [libsycl] Add UT build and min test set (PR #199915)

Kseniya Tikhomirova via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 05:04:41 PDT 2026


================
@@ -0,0 +1,150 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains declarations and utilities for liboffload mocking in
+/// libsycl unit tests.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_UNITTESTS_MOCK_HELPERS_HPP
+#define _LIBSYCL_UNITTESTS_MOCK_HELPERS_HPP
+
+#include <OffloadAPI.h>
+
+#include <gmock/gmock.h>
+
+#include <atomic>
+#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <unordered_map>
+#include <vector>
+
+namespace mock {
+
+struct ol_dummy_handle_t {
+  ol_dummy_handle_t(size_t DataSize = 0)
+      : MStorage(DataSize), MSize(DataSize) {}
+  ol_dummy_handle_t(unsigned char *Data, size_t Size)
+      : MStorage(Size), MSize(Size) {
+    std::memcpy(MStorage.data(), Data, Size);
+  }
+  std::atomic<size_t> MRefCounter = 1;
+  std::vector<unsigned char> MStorage;
+  size_t MSize;
+
+  template <typename T> T getDataAs() {
+    assert(MStorage.size() >= sizeof(T));
+    return *reinterpret_cast<T *>(MStorage.data());
+  }
+
+  template <typename T> T setDataAs(T Val) {
+    assert(MStorage.size() >= sizeof(T));
+    return *reinterpret_cast<T *>(MStorage.data()) = Val;
+  }
+};
+
+using dummy_handle_t = ol_dummy_handle_t *;
+
+template <class T> inline T createDummyHandle(size_t Size = 0) {
+  dummy_handle_t DummyHandlePtr = new ol_dummy_handle_t(Size);
+  return reinterpret_cast<T>(DummyHandlePtr);
+}
+
+template <class T>
+inline T createDummyHandleWithData(unsigned char *Data, size_t Size) {
+  auto DummyHandlePtr = new ol_dummy_handle_t(Data, Size);
+  return reinterpret_cast<T>(DummyHandlePtr);
+}
+
+template <class T> inline void releaseDummyHandle(T Handle) {
+  auto DummyHandlePtr = reinterpret_cast<dummy_handle_t>(Handle);
+  delete DummyHandlePtr;
+}
----------------
KseniyaTikhomirova wrote:

you are right, removed

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


More information about the llvm-commits mailing list