[llvm] [offload] add parameterized unit tests (PR #209115)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 02:07:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: EuphoricThinking
<details>
<summary>Changes</summary>
This patch adds:
- a new fixture that allows for creating parameterized tests
- new macros for the instantiation of parameterized tests
- a helper header file that contains information related to parameterized tests, including the definition of parameters
- new and refactored printers used in test instantiation
Moreover, selected existing tests are modified and parametrized in order to make the code less repetitive and more concise. Tests with up to two possible parameters are not parameterized.
Previously, the tests were already parameterized with `TestEnvironment::Device`. However, this patch combines `TestEnvironment::Device` with an additional parameter within `OffloadParam = std::tuple<TestEnvironment::Device, T>`. `OffloadParam<T>` is handled by a new fixture
`OffloadDeviceTestWithParam<T>`, which provides the `getTestParam()` method for the parameter extraction. Other functionalities, such as access to the `Host` and to the `Device`, are identical to the previous version of `OffloadDeviceTest`.
In order to avoid code duplication, the unparameterized versions of fixtures are aliases for parameterized fixtures, with `int` type chosen arbitrarily as an ignored parameter type, for example: `using OffloadDeviceTest = OffloadDeviceTestWithParam<int>;`. The single mock parameter of value `0` is combined with the devices in the provided macros, yielding tuples of type `std::tuple<TestEnvironment::Device, int>`. The hidden `int` parameter is not used, but it enables users to instantiate unparameterized tests without knowledge about the implementation details. Moreover, it allows for modifying only one version of the fixture (the one being aliased), without the need to also change the other version: either parameterized or unparameterized.
The following macros are added in this patch:
- `OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM(FIXTURE, VALUES, PRINTER)`: instantiates `FIXTURE` with parameters stored in the provided container `VALUES` (a C-style array or an STL-style container) and with the given printer. The used devices do not include the host.
- `OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE_WITH_PARAM(FIXTURE, VALUES, PRINTER)`: similar to
`OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM`, but includes the `Host` in the tested devices.
- `OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE(FIXTURE)`: instantiates `FIXTURE` without additional parameters, but also includes the `Host` in the used devices.
- `OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES(FIXTURE, DEVICES)`: instantiates `FIXTURE` with the provided devices, internally using a mock parameter. It is not intended for direct use and acts as a helper macro for the instantiation of unparameterized tests.
- `OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES_WITH_PARAM(FIXTURE, VALUES, DEVICES, PRINTER)`: instantiates `FIXTURE` with the provided devices, parameters and the given printer. It is not intended for direct use and acts as a helper macro for the instantiation of parameterized tests.
Since the new macros enable testing the `Host` as part of the used devices, `offload/unittests/OffloadAPI/device/olGetHostInfo.cpp` is deleted and its tests have been moved to
`offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp`.
The new helper header
`offload/unittests/OffloadAPI/common/Properties.hpp` with its implementation `offload/unittests/OffloadAPI/common/Properties.cpp`:
- pairs properties with their sizes for tests similar to `offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp`
- packs selected properties into containers or arrays for easier access and instantiation of fixtures
---
Patch is 74.38 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/209115.diff
16 Files Affected:
- (modified) offload/unittests/CMakeLists.txt (+1)
- (modified) offload/unittests/OffloadAPI/CMakeLists.txt (+1-2)
- (modified) offload/unittests/OffloadAPI/common/Fixtures.hpp (+105-20)
- (added) offload/unittests/OffloadAPI/common/Properties.cpp (+105)
- (added) offload/unittests/OffloadAPI/common/Properties.hpp (+187)
- (modified) offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp (+57-194)
- (modified) offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp (+24-59)
- (removed) offload/unittests/OffloadAPI/device/olGetHostInfo.cpp (-195)
- (modified) offload/unittests/OffloadAPI/memory/olGetMemInfo.cpp (+42-60)
- (modified) offload/unittests/OffloadAPI/memory/olGetMemInfoSize.cpp (+25-22)
- (modified) offload/unittests/OffloadAPI/memory/olMemAlloc.cpp (+10-22)
- (modified) offload/unittests/OffloadAPI/memory/olMemAllocAligned.cpp (+13-99)
- (modified) offload/unittests/OffloadAPI/memory/olMemFree.cpp (+7-14)
- (modified) offload/unittests/OffloadAPI/platform/olGetPlatformInfo.cpp (+10-28)
- (modified) offload/unittests/OffloadAPI/platform/olGetPlatformInfoSize.cpp (+8-16)
- (modified) offload/unittests/OffloadAPI/symbol/olGetSymbolInfoSize.cpp (+8-21)
``````````diff
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index b08f7213d5344..a7142ece82e66 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -141,6 +141,7 @@ function(add_offload_unittest test_dirname)
add_unittest(OffloadUnitTests "${target_name}"
${CMAKE_CURRENT_SOURCE_DIR}/common/Environment.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/common/Properties.cpp
${files})
add_dependencies(${target_name} ${PLUGINS_TEST_COMMON} offload_device_binaries)
target_compile_definitions(${target_name} PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
diff --git a/offload/unittests/OffloadAPI/CMakeLists.txt b/offload/unittests/OffloadAPI/CMakeLists.txt
index 16d6b633d885f..44f831cb83ff7 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -6,8 +6,7 @@ add_subdirectory(device_code)
add_offload_unittest("device"
device/olIterateDevices.cpp
device/olGetDeviceInfo.cpp
- device/olGetDeviceInfoSize.cpp
- device/olGetHostInfo.cpp)
+ device/olGetDeviceInfoSize.cpp)
add_offload_unittest("event"
event/olCreateEvent.cpp
diff --git a/offload/unittests/OffloadAPI/common/Fixtures.hpp b/offload/unittests/OffloadAPI/common/Fixtures.hpp
index f6b7502c41882..6d940584faef8 100644
--- a/offload/unittests/OffloadAPI/common/Fixtures.hpp
+++ b/offload/unittests/OffloadAPI/common/Fixtures.hpp
@@ -180,13 +180,16 @@ struct OffloadTest : ::testing::Test {
ol_device_handle_t Host = TestEnvironment::getHostDevice();
};
-struct OffloadDeviceTest
+template <class T> using OffloadParam = std::tuple<TestEnvironment::Device, T>;
+
+template <class T>
+struct OffloadDeviceTestWithParam
: OffloadTest,
- ::testing::WithParamInterface<TestEnvironment::Device> {
+ ::testing::WithParamInterface<OffloadParam<T>> {
void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadTest::SetUp());
- auto DeviceParam = GetParam();
+ auto &DeviceParam = std::get<0>(this->GetParam());
Device = DeviceParam.Handle;
if (Device == nullptr)
GTEST_SKIP() << "No available devices.";
@@ -204,14 +207,31 @@ struct OffloadDeviceTest
return Backend;
}
+ const OffloadParam<T> &getParamTuple() const { return this->GetParam(); }
+
+ const T &getTestParam() { return std::get<1>(getParamTuple()); }
+
ol_device_handle_t Device = nullptr;
};
-struct OffloadPlatformTest : OffloadDeviceTest {
+// In order to avoid code duplication, the unparameterized versions of fixtures
+// are aliases for parameterized fixtures, with `int` type chosen arbitrarily as
+// an ignored parameter type. The single mock parameter of value `0` is combined
+// with the devices in the provided macros, yielding tuples
+// `std::tuple<TestEnvironment::Device, int>`. The hidden `int` parameter is not
+// used, but it enables users to instantiate unparameterized tests without the
+// knowledge about the details related to the implementation of fixtures.
+// Moreover, it allows for modifying only one version of the fixture, without
+// the need to also change the other version: either parameterized or
+// unparameterized.
+using OffloadDeviceTest = OffloadDeviceTestWithParam<int>;
+
+template <typename T>
+struct OffloadPlatformTestWithParam : OffloadDeviceTestWithParam<T> {
void SetUp() override {
- RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp());
+ RETURN_ON_FATAL_FAILURE(OffloadDeviceTestWithParam<T>::SetUp());
- ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_PLATFORM,
+ ASSERT_SUCCESS(olGetDeviceInfo(this->Device, OL_DEVICE_INFO_PLATFORM,
sizeof(Platform), &Platform));
ASSERT_NE(Platform, nullptr);
}
@@ -219,17 +239,20 @@ struct OffloadPlatformTest : OffloadDeviceTest {
ol_platform_handle_t Platform = nullptr;
};
+using OffloadPlatformTest = OffloadPlatformTestWithParam<int>;
+
// Fixture for a generic program test. If you want a different program, use
// offloadQueueTest and create your own program handle with the binary you want.
-struct OffloadProgramTest : OffloadDeviceTest {
+template <typename T>
+struct OffloadProgramTestWithParam : OffloadDeviceTestWithParam<T> {
void SetUp() override { SetUpWith("foo"); }
void SetUpWith(const char *ProgramName) {
- RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp());
- ASSERT_TRUE(
- TestEnvironment::loadDeviceBinary(ProgramName, Device, DeviceBin));
+ RETURN_ON_FATAL_FAILURE(OffloadDeviceTestWithParam<T>::SetUp());
+ ASSERT_TRUE(TestEnvironment::loadDeviceBinary(ProgramName, this->Device,
+ DeviceBin));
ASSERT_GE(DeviceBin->getBufferSize(), 0lu);
- ASSERT_SUCCESS(olCreateProgram(Device, DeviceBin->getBufferStart(),
+ ASSERT_SUCCESS(olCreateProgram(this->Device, DeviceBin->getBufferStart(),
DeviceBin->getBufferSize(), &Program));
}
@@ -237,13 +260,15 @@ struct OffloadProgramTest : OffloadDeviceTest {
if (Program) {
olDestroyProgram(Program);
}
- RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::TearDown());
+ RETURN_ON_FATAL_FAILURE(OffloadDeviceTestWithParam<T>::TearDown());
}
ol_program_handle_t Program = nullptr;
std::unique_ptr<llvm::MemoryBuffer> DeviceBin;
};
+using OffloadProgramTest = OffloadProgramTestWithParam<int>;
+
struct OffloadKernelTest : OffloadProgramTest {
void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadProgramTest::SetUp());
@@ -257,20 +282,24 @@ struct OffloadKernelTest : OffloadProgramTest {
ol_symbol_handle_t Kernel = nullptr;
};
-struct OffloadGlobalTest : OffloadProgramTest {
+template <typename T>
+struct OffloadGlobalTestWithParam : OffloadProgramTestWithParam<T> {
void SetUp() override {
- RETURN_ON_FATAL_FAILURE(OffloadProgramTest::SetUpWith("global"));
- ASSERT_SUCCESS(olGetSymbol(Program, "global",
+ RETURN_ON_FATAL_FAILURE(
+ OffloadProgramTestWithParam<T>::SetUpWith("global"));
+ ASSERT_SUCCESS(olGetSymbol(this->Program, "global",
OL_SYMBOL_KIND_GLOBAL_VARIABLE, &Global));
}
void TearDown() override {
- RETURN_ON_FATAL_FAILURE(OffloadProgramTest::TearDown());
+ RETURN_ON_FATAL_FAILURE(OffloadProgramTestWithParam<T>::TearDown());
}
ol_symbol_handle_t Global = nullptr;
};
+using OffloadGlobalTest = OffloadGlobalTestWithParam<int>;
+
struct OffloadQueueTest : OffloadDeviceTest {
void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp());
@@ -338,13 +367,69 @@ struct LaunchSingleKernelTestBase : LaunchKernelTestBase {
ol_symbol_handle_t Kernel = nullptr;
};
+using DevicesVec = std::vector<TestEnvironment::Device>;
+
+inline DevicesVec getDevicesAndHost() {
+ DevicesVec Res(TestEnvironment::getDevices());
+ TestEnvironment::Device Host{TestEnvironment::getHostDevice(), "HOST"};
+
+ Res.push_back(Host);
+
+ return Res;
+}
+
+template <class T>
+inline std::string
+defaultPrinterWithParam(const ::testing::TestParamInfo<OffloadParam<T>> &info) {
+ auto device = std::get<0>(info.param);
+ auto param = std::get<1>(info.param);
+
+ std::string placeholder;
+ llvm::raw_string_ostream ss(placeholder);
+
+ ss << device.Name << "__" << param;
+
+ return SanitizeString(ss.str());
+}
+
+inline std::string
+defaultPrinter(const ::testing::TestParamInfo<OffloadParam<int>> &info) {
+ auto device = std::get<0>(info.param);
+
+ return SanitizeString(device.Name);
+}
+
// Devices might not be available for offload testing, so allow uninstantiated
// tests (as the device list will be empty). This means that all tests requiring
// a device will be silently skipped.
+#define OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES(FIXTURE, DEVICES) \
+ INSTANTIATE_TEST_SUITE_P( \
+ , FIXTURE, \
+ testing::Combine(::testing::ValuesIn(DEVICES), testing::ValuesIn({0})), \
+ defaultPrinter); \
+ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FIXTURE)
+
#define OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(FIXTURE) \
+ OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES(FIXTURE, TestEnvironment::getDevices())
+
+#define OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE(FIXTURE) \
+ OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES(FIXTURE, getDevicesAndHost())
+
+#define OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES_WITH_PARAM(FIXTURE, VALUES, \
+ DEVICES, PRINTER) \
INSTANTIATE_TEST_SUITE_P( \
- , FIXTURE, ::testing::ValuesIn(TestEnvironment::getDevices()), \
- [](const ::testing::TestParamInfo<TestEnvironment::Device> &info) { \
- return SanitizeString(info.param.Name); \
- }); \
+ , FIXTURE, \
+ testing::Combine(::testing::ValuesIn(TestEnvironment::getDevices()), \
+ ::testing::ValuesIn(VALUES)), \
+ PRINTER); \
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FIXTURE)
+
+#define OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM(FIXTURE, VALUES, \
+ PRINTER) \
+ OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES_WITH_PARAM( \
+ FIXTURE, VALUES, TestEnvironment::getDevices(), PRINTER)
+
+#define OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE_WITH_PARAM( \
+ FIXTURE, VALUES, PRINTER) \
+ OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES_WITH_PARAM( \
+ FIXTURE, VALUES, getDevicesAndHost(), PRINTER)
diff --git a/offload/unittests/OffloadAPI/common/Properties.cpp b/offload/unittests/OffloadAPI/common/Properties.cpp
new file mode 100644
index 0000000000000..4aa1e8e3d2ef8
--- /dev/null
+++ b/offload/unittests/OffloadAPI/common/Properties.cpp
@@ -0,0 +1,105 @@
+#include "Properties.hpp"
+
+// ol_device_info_t
+DeviceInfoProp PropBool{OL_DEVICE_INFO_SINGLE_FP_SUPPORT,
+ OL_DEVICE_INFO_DOUBLE_FP_SUPPORT,
+ OL_DEVICE_INFO_HALF_FP_SUPPORT};
+DeviceInfoProperties BoolProperties =
+ createPropertiesWithSizeContainer(sizeof(bool), PropBool);
+
+DeviceInfoProp PropUint32{OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE,
+ OL_DEVICE_INFO_MAX_WORK_SIZE,
+ OL_DEVICE_INFO_VENDOR_ID,
+ OL_DEVICE_INFO_NUM_COMPUTE_UNITS,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_CHAR,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_SHORT,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_INT,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_LONG,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_FLOAT,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE,
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF,
+ OL_DEVICE_INFO_MAX_CLOCK_FREQUENCY,
+ OL_DEVICE_INFO_MEMORY_CLOCK_RATE,
+ OL_DEVICE_INFO_ADDRESS_BITS};
+DeviceInfoProperties Uint32Properties =
+ createPropertiesWithSizeContainer(sizeof(uint32_t), PropUint32);
+
+DeviceInfoProp PropUint64{OL_DEVICE_INFO_MAX_MEM_ALLOC_SIZE,
+ OL_DEVICE_INFO_GLOBAL_MEM_SIZE,
+ OL_DEVICE_INFO_WORK_GROUP_LOCAL_MEM_SIZE};
+DeviceInfoProperties Uint64Properties =
+ createPropertiesWithSizeContainer(sizeof(uint64_t), PropUint64);
+
+DeviceInfoProp PropCapabilitiesFlags{OL_DEVICE_INFO_SINGLE_FP_CONFIG,
+ OL_DEVICE_INFO_HALF_FP_CONFIG,
+ OL_DEVICE_INFO_DOUBLE_FP_CONFIG};
+// sizeof(ol_device_fp_capability_flags_t) == sizeof(uint32_t)
+DeviceInfoProperties CapabilitesFlagsProperties =
+ createPropertiesWithSizeContainer(sizeof(ol_device_fp_capability_flags_t),
+ PropCapabilitiesFlags);
+
+DeviceInfoProp PropIrrelevantGTCapabilities = {OL_DEVICE_INFO_HALF_FP_CONFIG};
+DeviceInfoProp Prop_RelevantGTCapabilites = removeIrrelevantProperties(
+ PropCapabilitiesFlags, PropIrrelevantGTCapabilities);
+DeviceInfoProperties RelevantGTCapabilitiesProperties =
+ createPropertiesWithSizeContainer(sizeof(ol_device_fp_capability_flags_t),
+ Prop_RelevantGTCapabilites);
+
+DeviceInfoProp PropIrrelevantGTUint32 = {
+ OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF};
+DeviceInfoProp Prop_RelevantGTUint32 =
+ removeIrrelevantProperties(PropUint32, PropIrrelevantGTUint32);
+DeviceInfoProperties RelevantGTUint32Properties =
+ createPropertiesWithSizeContainer(sizeof(uint32_t), Prop_RelevantGTUint32);
+
+DeviceInfoProp PropDeviceType{OL_DEVICE_INFO_TYPE};
+DeviceInfoProperties DeviceTypeProperties =
+ createPropertiesWithSizeContainer(sizeof(ol_device_type_t), PropDeviceType);
+
+DeviceInfoProp PropPlatform{OL_DEVICE_INFO_PLATFORM};
+DeviceInfoProperties PlatformProperties = createPropertiesWithSizeContainer(
+ sizeof(ol_platform_handle_t), PropPlatform);
+
+DeviceInfoProp PropNames{OL_DEVICE_INFO_NAME, OL_DEVICE_INFO_PRODUCT_NAME,
+ OL_DEVICE_INFO_UID, OL_DEVICE_INFO_VENDOR,
+ OL_DEVICE_INFO_DRIVER_VERSION};
+DeviceInfoProperties NamesProperties =
+ createPropertiesWithSizeContainer(0, PropNames);
+
+DeviceInfoProp PropDimensions{OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE_PER_DIMENSION,
+ OL_DEVICE_INFO_MAX_WORK_SIZE_PER_DIMENSION};
+DeviceInfoProperties DimensionsProperties =
+ createPropertiesWithSizeContainer(sizeof(ol_dimensions_t), PropDimensions);
+
+DeviceInfoPropertiesTypes propertiesTypes =
+ createTypesMap({BoolProperties, Uint32Properties, Uint64Properties,
+ CapabilitesFlagsProperties});
+
+// ol_symbol_info_t
+SymbolInfoProp PropSymbolInfoGlobal{OL_SYMBOL_INFO_KIND,
+ OL_SYMBOL_INFO_GLOBAL_VARIABLE_ADDRESS,
+ OL_SYMBOL_INFO_GLOBAL_VARIABLE_SIZE};
+SymbolInfoProperties SymbolGlobalProperties{
+ {sizeof(ol_symbol_kind_t), OL_SYMBOL_INFO_KIND},
+ {sizeof(void *), OL_SYMBOL_INFO_GLOBAL_VARIABLE_ADDRESS},
+ {sizeof(size_t), OL_SYMBOL_INFO_GLOBAL_VARIABLE_SIZE}};
+
+// ol_platform_info_t
+ol_platform_info_t PlatformInfoNames[3] = {OL_PLATFORM_INFO_NAME,
+ OL_PLATFORM_INFO_VENDOR_NAME,
+ OL_PLATFORM_INFO_VERSION};
+
+// ol_alloc_type_t
+ol_alloc_type_t AllocTypes[3] = {OL_ALLOC_TYPE_DEVICE, OL_ALLOC_TYPE_MANAGED,
+ OL_ALLOC_TYPE_HOST};
+
+// ol_mem_info_t
+MemInfoProp PropMemInfo{OL_MEM_INFO_DEVICE, OL_MEM_INFO_BASE, OL_MEM_INFO_SIZE,
+ OL_MEM_INFO_TYPE};
+MemInfoProperties MemInfoSizeProperties{
+ {sizeof(ol_device_handle_t), OL_MEM_INFO_DEVICE},
+ {sizeof(void *), OL_MEM_INFO_BASE},
+ {sizeof(size_t), OL_MEM_INFO_SIZE},
+ {sizeof(ol_alloc_type_t), OL_MEM_INFO_TYPE}};
+
+size_t TestAllocsNum = 1000;
\ No newline at end of file
diff --git a/offload/unittests/OffloadAPI/common/Properties.hpp b/offload/unittests/OffloadAPI/common/Properties.hpp
new file mode 100644
index 0000000000000..c6981f475a58c
--- /dev/null
+++ b/offload/unittests/OffloadAPI/common/Properties.hpp
@@ -0,0 +1,187 @@
+#pragma once
+
+#include "Fixtures.hpp"
+#include "OffloadAPI.h"
+
+inline constexpr size_t MAX_DEVICE_INFO_BYTES = 8;
+
+inline constexpr char zeroArray[MAX_DEVICE_INFO_BYTES] = {};
+
+template <typename T> struct SizedProperty {
+ size_t size;
+ T property;
+};
+
+template <typename T>
+using PropertiesWithSizeContainer = std::vector<SizedProperty<T>>;
+template <typename T> using PropertiesContainer = std::set<T>;
+template <typename T>
+using PropertiesTypes = std::unordered_map<T, SizedProperty<T>>;
+
+template <typename T>
+auto createPropertiesWithSizeContainer(
+ size_t PropSize, PropertiesContainer<T> SelectedProperties)
+ -> PropertiesWithSizeContainer<T> {
+ PropertiesWithSizeContainer<T> Res;
+ for (auto p : SelectedProperties) {
+ Res.push_back({PropSize, p});
+ }
+
+ return Res;
+}
+
+template <typename T>
+auto mergeProperties(std::initializer_list<PropertiesWithSizeContainer<T>>
+ properties) -> PropertiesWithSizeContainer<T> {
+ PropertiesWithSizeContainer<T> finalProperties;
+
+ for (auto prop : properties) {
+ finalProperties.insert(finalProperties.end(), prop.begin(), prop.end());
+ }
+
+ return finalProperties;
+}
+
+template <typename T>
+PropertiesContainer<T>
+removeIrrelevantProperties(PropertiesContainer<T> base,
+ PropertiesContainer<T> unwanted) {
+ PropertiesContainer<T> res(base);
+
+ for (auto prop : unwanted) {
+ res.erase(prop);
+ }
+
+ return res;
+}
+
+template <typename T>
+PropertiesTypes<T> inline createTypesMap(
+ std::initializer_list<PropertiesWithSizeContainer<T>> properties) {
+ PropertiesTypes<T> Res;
+
+ for (auto container : properties) {
+ for (auto prop : container) {
+ Res.insert({prop.property, prop});
+ }
+ }
+
+ return Res;
+}
+
+// ol_device_info_t
+using DeviceInfoProp = PropertiesContainer<ol_device_info_t>;
+using DeviceInfoProperties = PropertiesWithSizeContainer<ol_device_info_t>;
+using DeviceInfoPropertiesTypes = PropertiesTypes<ol_device_info_t>;
+
+extern DeviceInfoProp PropBool;
+extern DeviceInfoProperties BoolProperties;
+
+extern DeviceInfoProp PropUint32;
+extern DeviceInfoProperties Uint32Properties;
+
+extern DeviceInfoProp PropUint64;
+extern DeviceInfoProperties Uint64Properties;
+
+extern DeviceInfoProp PropCapabilitiesFlags;
+// sizeof(ol_device_fp_capability_flags_t) == sizeof(uint32_t)
+extern DeviceInfoProperties CapabilitesFlagsProperties;
+
+extern DeviceInfoProp PropDeviceType;
+extern DeviceInfoProperties DeviceTypeProperties;
+
+extern DeviceInfoProp PropPlatform;
+extern DeviceInfoProperties PlatformProperties;
+
+extern DeviceInfoProp PropNames;
+extern DeviceInfoProperties NamesProperties;
+
+extern DeviceInfoProp PropDimensions;
+extern DeviceInfoProperties DimensionsProperties;
+
+extern DeviceInfoProperties RelevantGTCapabilitiesProperties;
+extern DeviceInfoProperties RelevantGTUint32Properties;
+
+extern DeviceInfoPropertiesTypes propertiesTypes;
+
+inline bool defaultCheckIsNonZero(char *buffer) {
+ return memcmp(buffer, zeroArray, MAX_DEVICE_INFO_BYTES) != 0;
+}
+
+template <typename T>
+inline std::string defaultPropertyTestPrinter(
+ const ::testing::TestParamInfo<OffloadParam<SizedProperty<T>>> &info) {
+ auto device = std::get<0>(info.param);
+ auto paramData = std::get<1>(info.param);
+
+ std::string ss;
+ llvm::raw_string_ostream finalName(ss);
+
+ auto property = paramData.property;
+ finalName << device.Name << "__" << property;
+
+ return SanitizeString(finalName.str());
+}
+
+template <typename T>
+struct olPropertyTest : OffloadDeviceTestWithParam<SizedProperty<T>> {
+ void SetUp() override {
+ RETURN_ON_FATAL_FAILURE(
+ OffloadDeviceTestWithParam<SizedProperty<T>>::SetUp());
+
+ auto paramData = this->getTestParam();
+ PropertySize = paramData.size;
+ Property = paramData.property;
+ }
+
+ size_t PropertySize = 0;
+ T Property;
+};
+
+struct olGetHostDeviceInfoPropertyTest : olPropertyTest<ol_device_info_t> {
+ bool isHost() { return Host == this->Device; }
+};
+
+struct olGetHostDeviceInfoTest : OffloadDeviceTest {
+ void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); }
+
+ bool isHost() { return Host == this->Device; }
+};
+
+// ol_symbol_info
+using SymbolInfoTuple = SizedProperty<ol_symbol_info_t>;
+using SymbolInfoProp = PropertiesContainer<ol_symbol_info_t>;
+using SymbolInfoProperties = PropertiesWithSizeContainer<ol_symbol_info_t>;
+
+extern SymbolInfoProp PropSymbolInfoGlobal;
+extern SymbolInfoProperti...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/209115
More information about the llvm-commits
mailing list