[Offload] Add check-offload-unit for liboffload unittests (#137312)
Adds a `check-offload-unit` target for running the liboffload unit test
suite. This unit test binary runs the tests for every available device.
This can optionally filtered to devices from a single platform, but the
check target runs on everything.
The target is not part of `check-offload` and does not get propagated to
the top level build. I'm not sure if either of these things are
desirable, but I'm happy to look into it if we want.
Also remove the `offload/unittests/Plugins` test as it's dead code and
doesn't build.
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index d956d27..705ae8a 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -142,6 +142,9 @@
// Preemptively initialize all devices in the plugin
for (auto &Platform : Platforms()) {
+ // Do not use the host plugin - it isn't supported.
+ if (Platform.BackendType == OL_PLATFORM_BACKEND_UNKNOWN)
+ continue;
auto Err = Platform.Plugin->init();
[[maybe_unused]] std::string InfoMsg = toString(std::move(Err));
for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();
diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index 4768d9c..711621d 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -63,3 +63,15 @@
EXCLUDE_FROM_CHECK_ALL
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
+
+# Add liboffload unit tests - the test binary will run on all available devices
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
+
+add_lit_testsuite(check-offload-unit "Running offload unittest suites"
+ ${CMAKE_CURRENT_BINARY_DIR}/unit
+ EXCLUDE_FROM_CHECK_ALL
+ DEPENDS LLVMOffload OffloadUnitTests)
diff --git a/offload/test/lit.cfg b/offload/test/lit.cfg
index f7ed287..0725b56 100644
--- a/offload/test/lit.cfg
+++ b/offload/test/lit.cfg
@@ -69,7 +69,7 @@
config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
# excludes: A list of directories to exclude from the testuites.
-config.excludes = ['Inputs']
+config.excludes = ['Inputs', 'unit']
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
diff --git a/offload/test/unit/lit.cfg.py b/offload/test/unit/lit.cfg.py
new file mode 100644
index 0000000..5c68f6b
--- /dev/null
+++ b/offload/test/unit/lit.cfg.py
@@ -0,0 +1,22 @@
+# -*- Python -*-
+
+# Configuration file for the 'lit' test runner.
+
+import os
+import subprocess
+
+import lit.formats
+
+# name: The name of this test suite.
+config.name = "Offload-Unit"
+
+# suffixes: A list of file extensions to treat as test files.
+config.suffixes = []
+
+# test_source_root: The root path where tests are located.
+# test_exec_root: The root path where tests should be run.
+config.test_exec_root = os.path.join(config.library_dir, "unittests")
+config.test_source_root = config.test_exec_root
+
+# testFormat: The test format to use to interpret tests.
+config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, ".unittests")
diff --git a/offload/test/unit/lit.site.cfg.in b/offload/test/unit/lit.site.cfg.in
new file mode 100644
index 0000000..8019878
--- /dev/null
+++ b/offload/test/unit/lit.site.cfg.in
@@ -0,0 +1,8 @@
+@AUTO_GEN_COMMENT@
+
+config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
+config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/unit/lit.cfg.py")
+
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index 25ac4b2..f9cb56a 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -1,9 +1,8 @@
-add_custom_target(LibomptUnitTests)
-set_target_properties(LibomptUnitTests PROPERTIES FOLDER "Tests/UnitTests")
+add_custom_target(OffloadUnitTests)
+set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")
-function(add_libompt_unittest test_dirname)
- add_unittest(LibomptUnitTests ${test_dirname} ${ARGN})
+function(add_offload_unittest test_dirname)
+ add_unittest(OffloadUnitTests ${test_dirname} ${ARGN})
endfunction()
-# add_subdirectory(Plugins)
add_subdirectory(OffloadAPI)
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index c4d628a..fb480e0 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -4,7 +4,7 @@
add_subdirectory(device_code)
message(${OFFLOAD_TEST_DEVICE_CODE_PATH})
-add_libompt_unittest("offload.unittests"
+add_offload_unittest("offload.unittests"
${CMAKE_CURRENT_SOURCE_DIR}/common/Environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfoSize.cpp
@@ -22,7 +22,7 @@
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
)
-add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} LibomptUnitTestsDeviceBins)
+add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} OffloadUnitTestsDeviceBins)
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})
diff --git a/offload/unittests/OffloadAPI/common/Environment.cpp b/offload/unittests/OffloadAPI/common/Environment.cpp
index 88cf33e..9433472 100644
--- a/offload/unittests/OffloadAPI/common/Environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -37,6 +37,15 @@
return Out;
}
+raw_ostream &operator<<(raw_ostream &Out, const ol_device_handle_t &Device) {
+ size_t Size;
+ olGetDeviceInfoSize(Device, OL_DEVICE_INFO_NAME, &Size);
+ std::vector<char> Name(Size);
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_NAME, Size, Name.data());
+ Out << Name.data();
+ return Out;
+}
+
void printPlatforms() {
SmallDenseSet<ol_platform_handle_t> Platforms;
using DeviceVecT = SmallVector<ol_device_handle_t, 8>;
@@ -61,48 +70,64 @@
}
}
-ol_device_handle_t TestEnvironment::getDevice() {
- static ol_device_handle_t Device = nullptr;
+const std::vector<TestEnvironment::Device> &TestEnvironment::getDevices() {
+ static std::vector<TestEnvironment::Device> Devices{};
+ if (Devices.empty()) {
+ // If a specific platform is requested, filter to devices belonging to it.
+ if (const char *EnvStr = getenv("OFFLOAD_UNITTEST_PLATFORM")) {
+ if (SelectedPlatform != "")
+ errs() << "Warning: --platform argument ignored as "
+ "OFFLOAD_UNITTEST_PLATFORM env var overrides it.\n";
+ SelectedPlatform = EnvStr;
+ }
- if (!Device) {
if (SelectedPlatform != "") {
olIterateDevices(
[](ol_device_handle_t D, void *Data) {
ol_platform_handle_t Platform;
olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform),
&Platform);
-
+ ol_platform_backend_t Backend;
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), &Backend);
std::string PlatformName;
raw_string_ostream S(PlatformName);
S << Platform;
-
- if (PlatformName == SelectedPlatform) {
- *(static_cast<ol_device_handle_t *>(Data)) = D;
- return false;
+ if (PlatformName == SelectedPlatform &&
+ Backend != OL_PLATFORM_BACKEND_HOST) {
+ std::string Name;
+ raw_string_ostream NameStr(Name);
+ NameStr << PlatformName << "_" << D;
+ static_cast<std::vector<TestEnvironment::Device> *>(Data)
+ ->push_back({D, Name});
}
-
return true;
},
- &Device);
-
- if (Device == nullptr) {
- errs() << "No device found with the platform \"" << SelectedPlatform
- << "\". Choose from:"
- << "\n";
- printPlatforms();
- std::exit(1);
- }
+ &Devices);
} else {
+ // No platform specified, discover every device that isn't the host.
olIterateDevices(
[](ol_device_handle_t D, void *Data) {
- *(static_cast<ol_device_handle_t *>(Data)) = D;
- return false;
+ ol_platform_handle_t Platform;
+ olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform),
+ &Platform);
+ ol_platform_backend_t Backend;
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(Backend), &Backend);
+ if (Backend != OL_PLATFORM_BACKEND_HOST) {
+ std::string Name;
+ raw_string_ostream NameStr(Name);
+ NameStr << Platform << "_" << D;
+ static_cast<std::vector<TestEnvironment::Device> *>(Data)
+ ->push_back({D, Name});
+ }
+ return true;
},
- &Device);
+ &Devices);
}
}
- return Device;
+ return Devices;
}
ol_device_handle_t TestEnvironment::getHostDevice() {
diff --git a/offload/unittests/OffloadAPI/common/Environment.hpp b/offload/unittests/OffloadAPI/common/Environment.hpp
index a0bf688..7946a82 100644
--- a/offload/unittests/OffloadAPI/common/Environment.hpp
+++ b/offload/unittests/OffloadAPI/common/Environment.hpp
@@ -13,7 +13,13 @@
#include <gtest/gtest.h>
namespace TestEnvironment {
-ol_device_handle_t getDevice();
+
+struct Device {
+ ol_device_handle_t Handle;
+ std::string Name;
+};
+
+const std::vector<Device> &getDevices();
ol_device_handle_t getHostDevice();
bool loadDeviceBinary(const std::string &BinaryName, ol_device_handle_t Device,
std::unique_ptr<llvm::MemoryBuffer> &BinaryOut);
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index 028ebf4..2303601 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -42,15 +42,26 @@
} \
(void)0
+inline std::string SanitizeString(const std::string &Str) {
+ auto NewStr = Str;
+ std::replace_if(
+ NewStr.begin(), NewStr.end(), [](char C) { return !std::isalnum(C); },
+ '_');
+ return NewStr;
+}
+
struct OffloadTest : ::testing::Test {
ol_device_handle_t Host = TestEnvironment::getHostDevice();
};
-struct OffloadDeviceTest : OffloadTest {
+struct OffloadDeviceTest
+ : OffloadTest,
+ ::testing::WithParamInterface<TestEnvironment::Device> {
void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadTest::SetUp());
- Device = TestEnvironment::getDevice();
+ auto DeviceParam = GetParam();
+ Device = DeviceParam.Handle;
if (Device == nullptr)
GTEST_SKIP() << "No available devices.";
}
@@ -120,3 +131,10 @@
ol_queue_handle_t Queue = nullptr;
};
+
+#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); \
+ })
diff --git a/offload/unittests/OffloadAPI/device/olDeviceInfo.hpp b/offload/unittests/OffloadAPI/device/olDeviceInfo.hpp
deleted file mode 100644
index 0691525..0000000
--- a/offload/unittests/OffloadAPI/device/olDeviceInfo.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-//===------- Offload API tests - Helpers for device info query testing ----===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-#pragma once
-
-#include <unordered_map>
-#include <vector>
-
-// TODO: We could autogenerate these
-inline std::vector<ol_device_info_t> DeviceQueries = {
- OL_DEVICE_INFO_TYPE, OL_DEVICE_INFO_PLATFORM, OL_DEVICE_INFO_NAME,
- OL_DEVICE_INFO_VENDOR, OL_DEVICE_INFO_DRIVER_VERSION};
-
-inline std::unordered_map<ol_device_info_t, size_t> DeviceInfoSizeMap = {
- {OL_DEVICE_INFO_TYPE, sizeof(ol_device_type_t)},
- {OL_DEVICE_INFO_PLATFORM, sizeof(ol_platform_handle_t)},
-};
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index f71f60a..46ed622 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -1,4 +1,4 @@
-//===------- Offload API tests - olGetDeviceInfo ---------------------===//
+//===------- Offload API tests - olGetDeviceInfo --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,68 +7,87 @@
//===----------------------------------------------------------------------===//
#include "../common/Fixtures.hpp"
-#include "olDeviceInfo.hpp"
#include <OffloadAPI.h>
#include <gtest/gtest.h>
-struct olGetDeviceInfoTest : OffloadDeviceTest,
- ::testing::WithParamInterface<ol_device_info_t> {
+using olGetDeviceInfoTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetDeviceInfoTest);
- void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); }
-};
-
-INSTANTIATE_TEST_SUITE_P(
- , olGetDeviceInfoTest, ::testing::ValuesIn(DeviceQueries),
- [](const ::testing::TestParamInfo<ol_device_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(olGetDeviceInfoTest, Success) {
- ol_device_info_t InfoType = GetParam();
- size_t Size = 0;
-
- ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
-
- std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(olGetDeviceInfo(Device, InfoType, Size, InfoData.data()));
-
- if (InfoType == OL_DEVICE_INFO_PLATFORM) {
- auto *ReturnedPlatform =
- reinterpret_cast<ol_platform_handle_t *>(InfoData.data());
- ASSERT_NE(nullptr, *ReturnedPlatform);
- }
+TEST_P(olGetDeviceInfoTest, SuccessType) {
+ ol_device_type_t DeviceType;
+ ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE,
+ sizeof(ol_device_type_t), &DeviceType));
}
-TEST_F(olGetDeviceInfoTest, InvalidNullHandleDevice) {
+TEST_P(olGetDeviceInfoTest, SuccessPlatform) {
+ ol_platform_handle_t Platform = nullptr;
+ ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_PLATFORM,
+ sizeof(ol_platform_handle_t), &Platform));
+ ASSERT_NE(Platform, nullptr);
+}
+
+TEST_P(olGetDeviceInfoTest, SuccessName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_NAME, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> Name;
+ Name.resize(Size);
+ ASSERT_SUCCESS(
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_NAME, Size, Name.data()));
+ ASSERT_EQ(std::strlen(Name.data()), Size - 1);
+}
+
+TEST_P(olGetDeviceInfoTest, SuccessVendor) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_VENDOR, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> Vendor;
+ Vendor.resize(Size);
+ ASSERT_SUCCESS(
+ olGetDeviceInfo(Device, OL_DEVICE_INFO_VENDOR, Size, Vendor.data()));
+ ASSERT_EQ(std::strlen(Vendor.data()), Size - 1);
+}
+
+TEST_P(olGetDeviceInfoTest, SuccessDriverVersion) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetDeviceInfoSize(Device, OL_DEVICE_INFO_DRIVER_VERSION, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> DriverVersion;
+ DriverVersion.resize(Size);
+ ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_DRIVER_VERSION, Size,
+ DriverVersion.data()));
+ ASSERT_EQ(std::strlen(DriverVersion.data()), Size - 1);
+}
+
+TEST_P(olGetDeviceInfoTest, InvalidNullHandleDevice) {
ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetDeviceInfo(nullptr, OL_DEVICE_INFO_TYPE,
sizeof(ol_device_type_t), &DeviceType));
}
-TEST_F(olGetDeviceInfoTest, InvalidEnumerationInfoType) {
+TEST_P(olGetDeviceInfoTest, InvalidEnumerationInfoType) {
ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetDeviceInfo(Device, OL_DEVICE_INFO_FORCE_UINT32,
sizeof(ol_device_type_t), &DeviceType));
}
-TEST_F(olGetDeviceInfoTest, InvalidSizePropSize) {
+TEST_P(olGetDeviceInfoTest, InvalidSizePropSize) {
ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 0, &DeviceType));
}
-TEST_F(olGetDeviceInfoTest, InvalidSizePropSizeSmall) {
+TEST_P(olGetDeviceInfoTest, InvalidSizePropSizeSmall) {
ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE,
sizeof(DeviceType) - 1, &DeviceType));
}
-TEST_F(olGetDeviceInfoTest, InvalidNullPointerPropValue) {
+TEST_P(olGetDeviceInfoTest, InvalidNullPointerPropValue) {
ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, sizeof(DeviceType),
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
index b4b5042..edd2704 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp
@@ -9,50 +9,54 @@
#include <OffloadAPI.h>
#include "../common/Fixtures.hpp"
-#include "olDeviceInfo.hpp"
-struct olGetDeviceInfoSizeTest
- : OffloadDeviceTest,
- ::testing::WithParamInterface<ol_device_info_t> {
+using olGetDeviceInfoSizeTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetDeviceInfoSizeTest);
- void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); }
-};
-
-// TODO: We could autogenerate the list of enum values
-INSTANTIATE_TEST_SUITE_P(
- , olGetDeviceInfoSizeTest, ::testing::ValuesIn(DeviceQueries),
- [](const ::testing::TestParamInfo<ol_device_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(olGetDeviceInfoSizeTest, Success) {
- ol_device_info_t InfoType = GetParam();
+TEST_P(olGetDeviceInfoSizeTest, SuccessType) {
size_t Size = 0;
-
- ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
- auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
- if (ExpectedSize != DeviceInfoSizeMap.end()) {
- ASSERT_EQ(Size, ExpectedSize->second);
- } else {
- ASSERT_NE(Size, 0lu);
- }
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, &Size));
+ ASSERT_EQ(Size, sizeof(ol_device_type_t));
}
-TEST_F(olGetDeviceInfoSizeTest, InvalidNullHandle) {
+TEST_P(olGetDeviceInfoSizeTest, SuccessPlatform) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_PLATFORM, &Size));
+ ASSERT_EQ(Size, sizeof(ol_platform_handle_t));
+}
+
+TEST_P(olGetDeviceInfoSizeTest, SuccessName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_NAME, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+TEST_P(olGetDeviceInfoSizeTest, SuccessVendor) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_VENDOR, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+TEST_P(olGetDeviceInfoSizeTest, SuccessDriverVersion) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetDeviceInfoSize(Device, OL_DEVICE_INFO_DRIVER_VERSION, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+TEST_P(olGetDeviceInfoSizeTest, InvalidNullHandle) {
size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetDeviceInfoSize(nullptr, OL_DEVICE_INFO_TYPE, &Size));
}
-TEST_F(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) {
+TEST_P(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) {
size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetDeviceInfoSize(Device, OL_DEVICE_INFO_FORCE_UINT32, &Size));
}
-TEST_F(olGetDeviceInfoSizeTest, InvalidNullPointer) {
+TEST_P(olGetDeviceInfoSizeTest, InvalidNullPointer) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, nullptr));
}
diff --git a/offload/unittests/OffloadAPI/device_code/CMakeLists.txt b/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
index ded555b..5814943 100644
--- a/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
@@ -62,6 +62,6 @@
add_offload_test_device_code(foo.c foo)
add_offload_test_device_code(bar.c bar)
-add_custom_target(LibomptUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
+add_custom_target(OffloadUnitTestsDeviceBins DEPENDS ${BIN_PATHS})
set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
diff --git a/offload/unittests/OffloadAPI/kernel/olGetKernel.cpp b/offload/unittests/OffloadAPI/kernel/olGetKernel.cpp
index f320d19..097439e 100644
--- a/offload/unittests/OffloadAPI/kernel/olGetKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olGetKernel.cpp
@@ -11,20 +11,21 @@
#include <gtest/gtest.h>
using olGetKernelTest = OffloadProgramTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetKernelTest);
-TEST_F(olGetKernelTest, Success) {
+TEST_P(olGetKernelTest, Success) {
ol_kernel_handle_t Kernel = nullptr;
ASSERT_SUCCESS(olGetKernel(Program, "foo", &Kernel));
ASSERT_NE(Kernel, nullptr);
}
-TEST_F(olGetKernelTest, InvalidNullProgram) {
+TEST_P(olGetKernelTest, InvalidNullProgram) {
ol_kernel_handle_t Kernel = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetKernel(nullptr, "foo", &Kernel));
}
-TEST_F(olGetKernelTest, InvalidNullKernelPointer) {
+TEST_P(olGetKernelTest, InvalidNullKernelPointer) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetKernel(Program, "foo", nullptr));
}
diff --git a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
index 2e51a48..20462e2 100644
--- a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
@@ -43,7 +43,9 @@
ol_kernel_launch_size_args_t LaunchArgs{};
};
-TEST_F(olLaunchKernelTest, Success) {
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelTest);
+
+TEST_P(olLaunchKernelTest, Success) {
void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem));
struct {
@@ -63,7 +65,7 @@
ASSERT_SUCCESS(olMemFree(Mem));
}
-TEST_F(olLaunchKernelTest, SuccessSynchronous) {
+TEST_P(olLaunchKernelTest, SuccessSynchronous) {
void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem));
diff --git a/offload/unittests/OffloadAPI/memory/olMemAlloc.cpp b/offload/unittests/OffloadAPI/memory/olMemAlloc.cpp
index 580ba02..00e428e 100644
--- a/offload/unittests/OffloadAPI/memory/olMemAlloc.cpp
+++ b/offload/unittests/OffloadAPI/memory/olMemAlloc.cpp
@@ -11,35 +11,36 @@
#include <gtest/gtest.h>
using olMemAllocTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemAllocTest);
-TEST_F(olMemAllocTest, SuccessAllocManaged) {
+TEST_P(olMemAllocTest, SuccessAllocManaged) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc);
}
-TEST_F(olMemAllocTest, SuccessAllocHost) {
+TEST_P(olMemAllocTest, SuccessAllocHost) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc);
}
-TEST_F(olMemAllocTest, SuccessAllocDevice) {
+TEST_P(olMemAllocTest, SuccessAllocDevice) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc);
}
-TEST_F(olMemAllocTest, InvalidNullDevice) {
+TEST_P(olMemAllocTest, InvalidNullDevice) {
void *Alloc = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olMemAlloc(nullptr, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
}
-TEST_F(olMemAllocTest, InvalidNullOutPtr) {
+TEST_P(olMemAllocTest, InvalidNullOutPtr) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, nullptr));
}
diff --git a/offload/unittests/OffloadAPI/memory/olMemFree.cpp b/offload/unittests/OffloadAPI/memory/olMemFree.cpp
index 99ad389..dfaf9bd 100644
--- a/offload/unittests/OffloadAPI/memory/olMemFree.cpp
+++ b/offload/unittests/OffloadAPI/memory/olMemFree.cpp
@@ -11,26 +11,27 @@
#include <gtest/gtest.h>
using olMemFreeTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemFreeTest);
-TEST_F(olMemFreeTest, SuccessFreeManaged) {
+TEST_P(olMemFreeTest, SuccessFreeManaged) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc));
}
-TEST_F(olMemFreeTest, SuccessFreeHost) {
+TEST_P(olMemFreeTest, SuccessFreeHost) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc));
}
-TEST_F(olMemFreeTest, SuccessFreeDevice) {
+TEST_P(olMemFreeTest, SuccessFreeDevice) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc));
}
-TEST_F(olMemFreeTest, InvalidNullPtr) {
+TEST_P(olMemFreeTest, InvalidNullPtr) {
void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olMemFree(nullptr));
diff --git a/offload/unittests/OffloadAPI/memory/olMemcpy.cpp b/offload/unittests/OffloadAPI/memory/olMemcpy.cpp
index b00ded9..c1762b4 100644
--- a/offload/unittests/OffloadAPI/memory/olMemcpy.cpp
+++ b/offload/unittests/OffloadAPI/memory/olMemcpy.cpp
@@ -11,8 +11,9 @@
#include <gtest/gtest.h>
using olMemcpyTest = OffloadQueueTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemcpyTest);
-TEST_F(olMemcpyTest, SuccessHtoD) {
+TEST_P(olMemcpyTest, SuccessHtoD) {
constexpr size_t Size = 1024;
void *Alloc;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, Size, &Alloc));
@@ -23,7 +24,7 @@
olMemFree(Alloc);
}
-TEST_F(olMemcpyTest, SuccessDtoH) {
+TEST_P(olMemcpyTest, SuccessDtoH) {
constexpr size_t Size = 1024;
void *Alloc;
std::vector<uint8_t> Input(Size, 42);
@@ -41,7 +42,7 @@
ASSERT_SUCCESS(olMemFree(Alloc));
}
-TEST_F(olMemcpyTest, SuccessDtoD) {
+TEST_P(olMemcpyTest, SuccessDtoD) {
constexpr size_t Size = 1024;
void *AllocA;
void *AllocB;
@@ -64,7 +65,7 @@
ASSERT_SUCCESS(olMemFree(AllocB));
}
-TEST_F(olMemcpyTest, SuccessHtoHSync) {
+TEST_P(olMemcpyTest, SuccessHtoHSync) {
constexpr size_t Size = 1024;
std::vector<uint8_t> Input(Size, 42);
std::vector<uint8_t> Output(Size, 0);
@@ -77,7 +78,7 @@
}
}
-TEST_F(olMemcpyTest, SuccessDtoHSync) {
+TEST_P(olMemcpyTest, SuccessDtoHSync) {
constexpr size_t Size = 1024;
void *Alloc;
std::vector<uint8_t> Input(Size, 42);
@@ -94,7 +95,7 @@
ASSERT_SUCCESS(olMemFree(Alloc));
}
-TEST_F(olMemcpyTest, SuccessSizeZero) {
+TEST_P(olMemcpyTest, SuccessSizeZero) {
constexpr size_t Size = 1024;
std::vector<uint8_t> Input(Size, 42);
std::vector<uint8_t> Output(Size, 0);
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
index bd6ad3f..862b008 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp
@@ -9,66 +9,80 @@
#include <OffloadAPI.h>
#include "../common/Fixtures.hpp"
-#include "olPlatformInfo.hpp"
-struct olGetPlatformInfoTest
- : OffloadPlatformTest,
- ::testing::WithParamInterface<ol_platform_info_t> {};
+using olGetPlatformInfoTest = OffloadPlatformTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetPlatformInfoTest);
-INSTANTIATE_TEST_SUITE_P(
- olGetPlatformInfo, olGetPlatformInfoTest,
- ::testing::ValuesIn(PlatformQueries),
- [](const ::testing::TestParamInfo<ol_platform_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(olGetPlatformInfoTest, Success) {
+TEST_P(olGetPlatformInfoTest, SuccessName) {
size_t Size = 0;
- ol_platform_info_t InfoType = GetParam();
-
- ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size));
- std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(olGetPlatformInfo(Platform, InfoType, Size, InfoData.data()));
-
- // Info types with a dynamic size are all char[] so we can verify the returned
- // string is the expected size.
- auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
- if (ExpectedSize == PlatformInfoSizeMap.end()) {
- ASSERT_EQ(Size, strlen(InfoData.data()) + 1);
- }
+ ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> Name;
+ Name.resize(Size);
+ ASSERT_SUCCESS(
+ olGetPlatformInfo(Platform, OL_PLATFORM_INFO_NAME, Size, Name.data()));
+ ASSERT_EQ(std::strlen(Name.data()), Size - 1);
}
-TEST_F(olGetPlatformInfoTest, InvalidNullHandle) {
+TEST_P(olGetPlatformInfoTest, SuccessVendorName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_VENDOR_NAME, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> VendorName;
+ VendorName.resize(Size);
+ ASSERT_SUCCESS(olGetPlatformInfo(Platform, OL_PLATFORM_INFO_VENDOR_NAME, Size,
+ VendorName.data()));
+ ASSERT_EQ(std::strlen(VendorName.data()), Size - 1);
+}
+
+TEST_P(olGetPlatformInfoTest, SuccessVersion) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_VERSION, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> Version;
+ Version.resize(Size);
+ ASSERT_SUCCESS(olGetPlatformInfo(Platform, OL_PLATFORM_INFO_VERSION, Size,
+ Version.data()));
+ ASSERT_EQ(std::strlen(Version.data()), Size - 1);
+}
+
+TEST_P(olGetPlatformInfoTest, SuccessBackend) {
+ ol_platform_backend_t Backend;
+ ASSERT_SUCCESS(olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(ol_platform_backend_t), &Backend));
+}
+
+TEST_P(olGetPlatformInfoTest, InvalidNullHandle) {
ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetPlatformInfo(nullptr, OL_PLATFORM_INFO_BACKEND,
sizeof(Backend), &Backend));
}
-TEST_F(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) {
+TEST_P(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) {
ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_FORCE_UINT32,
sizeof(Backend), &Backend));
}
-TEST_F(olGetPlatformInfoTest, InvalidSizeZero) {
+TEST_P(olGetPlatformInfoTest, InvalidSizeZero) {
ol_platform_backend_t Backend;
ASSERT_ERROR(
OL_ERRC_INVALID_SIZE,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 0, &Backend));
}
-TEST_F(olGetPlatformInfoTest, InvalidSizeSmall) {
+TEST_P(olGetPlatformInfoTest, InvalidSizeSmall) {
ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
sizeof(Backend) - 1, &Backend));
}
-TEST_F(olGetPlatformInfoTest, InvalidNullPointerPropValue) {
+TEST_P(olGetPlatformInfoTest, InvalidNullPointerPropValue) {
ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
diff --git a/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
index 5f6067e..9ed9835 100644
--- a/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
+++ b/offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp
@@ -9,48 +9,51 @@
#include <OffloadAPI.h>
#include "../common/Fixtures.hpp"
-#include "olPlatformInfo.hpp"
-struct olGetPlatformInfoSizeTest
- : OffloadPlatformTest,
- ::testing::WithParamInterface<ol_platform_info_t> {};
+using olGetPlatformInfoSizeTest = OffloadPlatformTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetPlatformInfoSizeTest);
-INSTANTIATE_TEST_SUITE_P(
- olGetPlatformInfoSize, olGetPlatformInfoSizeTest,
- ::testing::ValuesIn(PlatformQueries),
- [](const ::testing::TestParamInfo<ol_platform_info_t> &info) {
- std::stringstream ss;
- ss << info.param;
- return ss.str();
- });
-
-TEST_P(olGetPlatformInfoSizeTest, Success) {
+TEST_P(olGetPlatformInfoSizeTest, SuccessName) {
size_t Size = 0;
- ol_platform_info_t InfoType = GetParam();
-
- ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size));
- auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
- if (ExpectedSize != PlatformInfoSizeMap.end()) {
- ASSERT_EQ(Size, ExpectedSize->second);
- } else {
- ASSERT_NE(Size, 0lu);
- }
+ ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size));
+ ASSERT_NE(Size, 0ul);
}
-TEST_F(olGetPlatformInfoSizeTest, InvalidNullHandle) {
+TEST_P(olGetPlatformInfoSizeTest, SuccessVendorName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_VENDOR_NAME, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+TEST_P(olGetPlatformInfoSizeTest, SuccessVersion) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_VERSION, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+TEST_P(olGetPlatformInfoSizeTest, SuccessBackend) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(
+ olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_BACKEND, &Size));
+ ASSERT_EQ(Size, sizeof(ol_platform_backend_t));
+}
+
+TEST_P(olGetPlatformInfoSizeTest, InvalidNullHandle) {
size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetPlatformInfoSize(nullptr, OL_PLATFORM_INFO_BACKEND, &Size));
}
-TEST_F(olGetPlatformInfoSizeTest, InvalidPlatformInfoEnumeration) {
+TEST_P(olGetPlatformInfoSizeTest, InvalidPlatformInfoEnumeration) {
size_t Size = 0;
ASSERT_ERROR(
OL_ERRC_INVALID_ENUMERATION,
olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_FORCE_UINT32, &Size));
}
-TEST_F(olGetPlatformInfoSizeTest, InvalidNullPointer) {
+TEST_P(olGetPlatformInfoSizeTest, InvalidNullPointer) {
ASSERT_ERROR(
OL_ERRC_INVALID_NULL_POINTER,
olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_BACKEND, nullptr));
diff --git a/offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp b/offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
deleted file mode 100644
index f61bca0..0000000
--- a/offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-//===------- Offload API tests - Helpers for platform info query testing --===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-#pragma once
-
-#include <unordered_map>
-#include <vector>
-
-// TODO: We could autogenerate these
-
-inline std::vector<ol_platform_info_t> PlatformQueries = {
- OL_PLATFORM_INFO_NAME, OL_PLATFORM_INFO_VENDOR_NAME,
- OL_PLATFORM_INFO_VERSION, OL_PLATFORM_INFO_BACKEND};
-
-inline std::unordered_map<ol_platform_info_t, size_t> PlatformInfoSizeMap = {
- {OL_PLATFORM_INFO_BACKEND, sizeof(ol_platform_backend_t)},
-};
diff --git a/offload/unittests/OffloadAPI/program/olCreateProgram.cpp b/offload/unittests/OffloadAPI/program/olCreateProgram.cpp
index c586c04..5363957 100644
--- a/offload/unittests/OffloadAPI/program/olCreateProgram.cpp
+++ b/offload/unittests/OffloadAPI/program/olCreateProgram.cpp
@@ -11,8 +11,9 @@
#include <gtest/gtest.h>
using olCreateProgramTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCreateProgramTest);
-TEST_F(olCreateProgramTest, Success) {
+TEST_P(olCreateProgramTest, Success) {
std::unique_ptr<llvm::MemoryBuffer> DeviceBin;
ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin));
diff --git a/offload/unittests/OffloadAPI/program/olDestroyProgram.cpp b/offload/unittests/OffloadAPI/program/olDestroyProgram.cpp
index ea21dad..d7fc73b 100644
--- a/offload/unittests/OffloadAPI/program/olDestroyProgram.cpp
+++ b/offload/unittests/OffloadAPI/program/olDestroyProgram.cpp
@@ -11,12 +11,13 @@
#include <gtest/gtest.h>
using olDestroyProgramTest = OffloadProgramTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyProgramTest);
-TEST_F(olDestroyProgramTest, Success) {
+TEST_P(olDestroyProgramTest, Success) {
ASSERT_SUCCESS(olDestroyProgram(Program));
Program = nullptr;
}
-TEST_F(olDestroyProgramTest, InvalidNullHandle) {
+TEST_P(olDestroyProgramTest, InvalidNullHandle) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyProgram(nullptr));
}
diff --git a/offload/unittests/OffloadAPI/queue/olCreateQueue.cpp b/offload/unittests/OffloadAPI/queue/olCreateQueue.cpp
index 0534deb..8a2b964 100644
--- a/offload/unittests/OffloadAPI/queue/olCreateQueue.cpp
+++ b/offload/unittests/OffloadAPI/queue/olCreateQueue.cpp
@@ -11,18 +11,19 @@
#include <gtest/gtest.h>
using olCreateQueueTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCreateQueueTest);
-TEST_F(olCreateQueueTest, Success) {
+TEST_P(olCreateQueueTest, Success) {
ol_queue_handle_t Queue = nullptr;
ASSERT_SUCCESS(olCreateQueue(Device, &Queue));
ASSERT_NE(Queue, nullptr);
}
-TEST_F(olCreateQueueTest, InvalidNullHandleDevice) {
+TEST_P(olCreateQueueTest, InvalidNullHandleDevice) {
ol_queue_handle_t Queue = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olCreateQueue(nullptr, &Queue));
}
-TEST_F(olCreateQueueTest, InvalidNullPointerQueue) {
+TEST_P(olCreateQueueTest, InvalidNullPointerQueue) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olCreateQueue(Device, nullptr));
}
diff --git a/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp b/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
index b54694e..0dc8527 100644
--- a/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
+++ b/offload/unittests/OffloadAPI/queue/olDestroyQueue.cpp
@@ -11,12 +11,13 @@
#include <gtest/gtest.h>
using olDestroyQueueTest = OffloadQueueTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyQueueTest);
-TEST_F(olDestroyQueueTest, Success) {
+TEST_P(olDestroyQueueTest, Success) {
ASSERT_SUCCESS(olDestroyQueue(Queue));
Queue = nullptr;
}
-TEST_F(olDestroyQueueTest, InvalidNullHandle) {
+TEST_P(olDestroyQueueTest, InvalidNullHandle) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyQueue(nullptr));
}
diff --git a/offload/unittests/OffloadAPI/queue/olWaitQueue.cpp b/offload/unittests/OffloadAPI/queue/olWaitQueue.cpp
index 07ef774..5079444 100644
--- a/offload/unittests/OffloadAPI/queue/olWaitQueue.cpp
+++ b/offload/unittests/OffloadAPI/queue/olWaitQueue.cpp
@@ -11,7 +11,8 @@
#include <gtest/gtest.h>
using olWaitQueueTest = OffloadQueueTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olWaitQueueTest);
-TEST_F(olWaitQueueTest, SuccessEmptyQueue) {
+TEST_P(olWaitQueueTest, SuccessEmptyQueue) {
ASSERT_SUCCESS(olWaitQueue(Queue));
}
diff --git a/offload/unittests/Plugins/CMakeLists.txt b/offload/unittests/Plugins/CMakeLists.txt
deleted file mode 100644
index 06e5288..0000000
--- a/offload/unittests/Plugins/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-set(PLUGINS_TEST_COMMON omptarget)
-set(PLUGINS_TEST_SOURCES NextgenPluginsTest.cpp)
-set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR})
-
-foreach(PLUGIN IN LISTS LIBOMPTARGET_TESTED_PLUGINS)
- message(STATUS "Building plugin unit tests for ${PLUGIN}")
- add_libompt_unittest("${PLUGIN}.unittests" ${PLUGINS_TEST_SOURCES})
- add_dependencies("${PLUGIN}.unittests" ${PLUGINS_TEST_COMMON} ${PLUGIN})
- target_link_libraries("${PLUGIN}.unittests" PRIVATE ${PLUGINS_TEST_COMMON} ${PLUGIN})
- target_include_directories("${PLUGIN}.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})
-endforeach()
diff --git a/offload/unittests/Plugins/NextgenPluginsTest.cpp b/offload/unittests/Plugins/NextgenPluginsTest.cpp
deleted file mode 100644
index 479b3f6..0000000
--- a/offload/unittests/Plugins/NextgenPluginsTest.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-//===------- unittests/Plugins/NextgenPluginsTest.cpp - Plugin tests ------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#include "omptarget.h"
-#include "gtest/gtest.h"
-
-#include <unordered_set>
-
-const int DEVICE_ID = 0;
-std::unordered_set<int> setup_map;
-
-int init_test_device(int ID) {
- if (setup_map.find(ID) != setup_map.end()) {
- return OFFLOAD_SUCCESS;
- }
- if (__tgt_rtl_init_plugin() == OFFLOAD_FAIL ||
- __tgt_rtl_init_device(ID) == OFFLOAD_FAIL) {
- return OFFLOAD_FAIL;
- }
- setup_map.insert(ID);
- return OFFLOAD_SUCCESS;
-}
-
-// Test plugin initialization
-TEST(NextgenPluginsTest, PluginInit) {
- EXPECT_EQ(OFFLOAD_SUCCESS, init_test_device(DEVICE_ID));
-}
-
-// Test GPU allocation and R/W
-TEST(NextgenPluginsTest, PluginAlloc) {
- int32_t test_value = 23;
- int32_t host_value = -1;
- int64_t var_size = sizeof(int32_t);
-
- // Init plugin and device
- EXPECT_EQ(OFFLOAD_SUCCESS, init_test_device(DEVICE_ID));
-
- // Allocate memory
- void *device_ptr =
- __tgt_rtl_data_alloc(DEVICE_ID, var_size, nullptr, TARGET_ALLOC_DEFAULT);
-
- // Check that the result is not null
- EXPECT_NE(device_ptr, nullptr);
-
- // Submit data to device
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_submit(DEVICE_ID, device_ptr,
- &test_value, var_size));
-
- // Read data from device
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_retrieve(DEVICE_ID, &host_value,
- device_ptr, var_size));
-
- // Compare values
- EXPECT_EQ(host_value, test_value);
-
- // Cleanup data
- EXPECT_EQ(OFFLOAD_SUCCESS,
- __tgt_rtl_data_delete(DEVICE_ID, device_ptr, TARGET_ALLOC_DEFAULT));
-}
-
-// Test async GPU allocation and R/W
-TEST(NextgenPluginsTest, PluginAsyncAlloc) {
- int32_t test_value = 47;
- int32_t host_value = -1;
- int64_t var_size = sizeof(int32_t);
- __tgt_async_info *info;
-
- // Init plugin and device
- EXPECT_EQ(OFFLOAD_SUCCESS, init_test_device(DEVICE_ID));
-
- // Check if device supports async
- // Platforms like x86_64 don't support it
- if (__tgt_rtl_init_async_info(DEVICE_ID, &info) == OFFLOAD_SUCCESS) {
- // Allocate memory
- void *device_ptr = __tgt_rtl_data_alloc(DEVICE_ID, var_size, nullptr,
- TARGET_ALLOC_DEFAULT);
-
- // Check that the result is not null
- EXPECT_NE(device_ptr, nullptr);
-
- // Submit data to device asynchronously
- EXPECT_EQ(OFFLOAD_SUCCESS,
- __tgt_rtl_data_submit_async(DEVICE_ID, device_ptr, &test_value,
- var_size, info));
-
- // Wait for async request to process
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_synchronize(DEVICE_ID, info));
-
- // Read data from device
- EXPECT_EQ(OFFLOAD_SUCCESS,
- __tgt_rtl_data_retrieve_async(DEVICE_ID, &host_value, device_ptr,
- var_size, info));
-
- // Wait for async request to process
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_synchronize(DEVICE_ID, info));
-
- // Compare values
- EXPECT_EQ(host_value, test_value);
-
- // Cleanup data
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_delete(DEVICE_ID, device_ptr,
- TARGET_ALLOC_DEFAULT));
- }
-}
-
-// Test GPU data exchange
-TEST(NextgenPluginsTest, PluginDataSwap) {
- int32_t test_value = 23;
- int32_t host_value = -1;
- int64_t var_size = sizeof(int32_t);
-
- // Look for compatible device
- int DEVICE_TWO = -1;
- for (int i = 1; i < __tgt_rtl_number_of_devices(); i++) {
- if (__tgt_rtl_is_data_exchangable(DEVICE_ID, i)) {
- DEVICE_TWO = i;
- break;
- }
- }
-
- // Only run test if we have multiple GPUs to test
- // GPUs must be compatible for test to work
- if (DEVICE_TWO >= 1) {
- // Init both GPUs
- EXPECT_EQ(OFFLOAD_SUCCESS, init_test_device(DEVICE_ID));
- EXPECT_EQ(OFFLOAD_SUCCESS, init_test_device(DEVICE_TWO));
-
- // Allocate memory on both GPUs
- // DEVICE_ID will be the source
- // DEVICE_TWO will be the destination
- void *source_ptr = __tgt_rtl_data_alloc(DEVICE_ID, var_size, nullptr,
- TARGET_ALLOC_DEFAULT);
- void *dest_ptr = __tgt_rtl_data_alloc(DEVICE_TWO, var_size, nullptr,
- TARGET_ALLOC_DEFAULT);
-
- // Check for success in allocation
- EXPECT_NE(source_ptr, nullptr);
- EXPECT_NE(dest_ptr, nullptr);
-
- // Write data to source
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_submit(DEVICE_ID, source_ptr,
- &test_value, var_size));
-
- // Transfer data between devices
- EXPECT_EQ(OFFLOAD_SUCCESS,
- __tgt_rtl_data_exchange(DEVICE_ID, source_ptr, DEVICE_TWO,
- dest_ptr, var_size));
-
- // Read from destination device (DEVICE_TWO) memory
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_retrieve(DEVICE_TWO, &host_value,
- dest_ptr, var_size));
-
- // Ensure match
- EXPECT_EQ(host_value, test_value);
-
- // Cleanup
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_delete(DEVICE_ID, source_ptr,
- TARGET_ALLOC_DEFAULT));
- EXPECT_EQ(OFFLOAD_SUCCESS, __tgt_rtl_data_delete(DEVICE_TWO, dest_ptr,
- TARGET_ALLOC_DEFAULT));
- }
-}