[llvm] [Offload] Add check-offload-unit for liboffload unittests (PR #137312)
Callum Fare via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 29 07:10:27 PDT 2025
https://github.com/callumfare updated https://github.com/llvm/llvm-project/pull/137312
>From ea0ea57e5784599770758dfce05cac583a3c3a76 Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Thu, 24 Apr 2025 15:19:49 +0100
Subject: [PATCH 1/2] [Offload] Add check-offload-unit for liboffload unittests
---
offload/test/CMakeLists.txt | 34 ++++
offload/test/lit.cfg | 2 +-
offload/test/unit/lit.cfg.py | 24 +++
offload/test/unit/lit.site.cfg.in | 9 +
offload/unittests/CMakeLists.txt | 9 +-
offload/unittests/OffloadAPI/CMakeLists.txt | 4 +-
.../OffloadAPI/common/Environment.cpp | 7 +
.../OffloadAPI/device_code/CMakeLists.txt | 2 +-
offload/unittests/Plugins/CMakeLists.txt | 11 --
.../unittests/Plugins/NextgenPluginsTest.cpp | 167 ------------------
10 files changed, 82 insertions(+), 187 deletions(-)
create mode 100644 offload/test/unit/lit.cfg.py
create mode 100644 offload/test/unit/lit.site.cfg.in
delete mode 100644 offload/unittests/Plugins/CMakeLists.txt
delete mode 100644 offload/unittests/Plugins/NextgenPluginsTest.cpp
diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index 4768d9ccf223b..6e103ccc720c8 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -63,3 +63,37 @@ add_offload_testsuite(check-offload
EXCLUDE_FROM_CHECK_ALL
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
+
+# Add liboffload unit tests based on available devices rather than configured targets
+macro(add_offload_unittest_suite target_name)
+ set(OFFLOAD_PLATFORM ${target_name})
+ string(TOLOWER "${OFFLOAD_PLATFORM}" SUITE_NAME)
+
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}/lit.site.cfg
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
+
+ add_lit_testsuite(check-offload-unit-${SUITE_NAME} "Running offload unittest suite for ${SUITE_NAME}"
+ ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}
+ EXCLUDE_FROM_CHECK_ALL
+ DEPENDS OffloadUnitTests)
+
+ list(APPEND OFFLOAD_UNIT_TEST_SUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME})
+endmacro()
+
+set (OFFLOAD_UNIT_TEST_SUITES "")
+
+if (LIBOMPTARGET_FOUND_NVIDIA_GPU)
+ add_offload_unittest_suite("CUDA")
+endif()
+
+if (LIBOMPTARGET_FOUND_AMDGPU_GPU)
+ add_offload_unittest_suite("AMDGPU")
+endif()
+
+add_lit_testsuite(check-offload-unit "Running offload unittest suites"
+ ${OFFLOAD_UNIT_TEST_SUITES}
+ EXCLUDE_FROM_CHECK_ALL
+ DEPENDS LLVMOffload OffloadUnitTests)
diff --git a/offload/test/lit.cfg b/offload/test/lit.cfg
index f7ed287e7aece..0725b56f0f05d 100644
--- a/offload/test/lit.cfg
+++ b/offload/test/lit.cfg
@@ -69,7 +69,7 @@ config.name = 'libomptarget :: ' + config.libomptarget_current_target
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 0000000000000..08541f7dd7688
--- /dev/null
+++ b/offload/test/unit/lit.cfg.py
@@ -0,0 +1,24 @@
+# -*- 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-{}".format(config.offload_platform)
+
+# suffixes: A list of file extensions to treat as test files.
+config.suffixes = []
+
+config.environment = {"OFFLOAD_UNITTEST_PLATFORM": config.offload_platform}
+
+# 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 0000000000000..aa1484058b576
--- /dev/null
+++ b/offload/test/unit/lit.site.cfg.in
@@ -0,0 +1,9 @@
+ at AUTO_GEN_COMMENT@
+
+config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
+config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
+config.offload_platform = "@OFFLOAD_PLATFORM@"
+
+# 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 25ac4b2fa3675..f9cb56ae0c024 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 c4d628a5a87f8..fb480e0443583 100644
--- a/offload/unittests/OffloadAPI/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/CMakeLists.txt
@@ -4,7 +4,7 @@ set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
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 @@ add_libompt_unittest("offload.unittests"
${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 88cf33e45f3d5..7c2e86c0ec931 100644
--- a/offload/unittests/OffloadAPI/common/Environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -65,6 +65,13 @@ ol_device_handle_t TestEnvironment::getDevice() {
static ol_device_handle_t Device = nullptr;
if (!Device) {
+ 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 (SelectedPlatform != "") {
olIterateDevices(
[](ol_device_handle_t D, void *Data) {
diff --git a/offload/unittests/OffloadAPI/device_code/CMakeLists.txt b/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
index ded555b3a3cf4..5814943e4aaa9 100644
--- a/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
+++ b/offload/unittests/OffloadAPI/device_code/CMakeLists.txt
@@ -62,6 +62,6 @@ endif()
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/Plugins/CMakeLists.txt b/offload/unittests/Plugins/CMakeLists.txt
deleted file mode 100644
index 06e5288ad6f6b..0000000000000
--- 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 479b3f614aed2..0000000000000
--- 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));
- }
-}
>From 16e71f733dfab6b8c64f8c09f554cb9501ccfa0c Mon Sep 17 00:00:00 2001
From: Callum Fare <callum at codeplay.com>
Date: Tue, 29 Apr 2025 14:52:30 +0100
Subject: [PATCH 2/2] Parameterize offload unit tests on all devices
---
offload/liboffload/src/OffloadImpl.cpp | 3 +
offload/test/CMakeLists.txt | 36 ++-------
offload/test/unit/lit.cfg.py | 4 +-
offload/test/unit/lit.site.cfg.in | 1 -
.../OffloadAPI/common/Environment.cpp | 64 +++++++++------
.../OffloadAPI/common/Environment.hpp | 8 +-
.../unittests/OffloadAPI/common/Fixtures.hpp | 22 +++++-
.../OffloadAPI/device/olDeviceInfo.hpp | 21 -----
.../OffloadAPI/device/olGetDeviceInfo.cpp | 77 ++++++++++++-------
.../OffloadAPI/device/olGetDeviceInfoSize.cpp | 64 +++++++--------
.../OffloadAPI/kernel/olGetKernel.cpp | 7 +-
.../OffloadAPI/kernel/olLaunchKernel.cpp | 6 +-
.../OffloadAPI/memory/olMemAlloc.cpp | 11 +--
.../unittests/OffloadAPI/memory/olMemFree.cpp | 9 ++-
.../unittests/OffloadAPI/memory/olMemcpy.cpp | 13 ++--
.../OffloadAPI/platform/olGetPlatformInfo.cpp | 70 ++++++++++-------
.../platform/olGetPlatformInfoSize.cpp | 59 +++++++-------
.../OffloadAPI/platform/olPlatformInfo.hpp | 21 -----
.../OffloadAPI/program/olCreateProgram.cpp | 3 +-
.../OffloadAPI/program/olDestroyProgram.cpp | 5 +-
.../OffloadAPI/queue/olCreateQueue.cpp | 7 +-
.../OffloadAPI/queue/olDestroyQueue.cpp | 5 +-
.../OffloadAPI/queue/olWaitQueue.cpp | 3 +-
23 files changed, 274 insertions(+), 245 deletions(-)
delete mode 100644 offload/unittests/OffloadAPI/device/olDeviceInfo.hpp
delete mode 100644 offload/unittests/OffloadAPI/platform/olPlatformInfo.hpp
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index d956d274b5eb1..705ae8a226f67 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -142,6 +142,9 @@ void initPlugins() {
// 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 6e103ccc720c8..711621de9075d 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -64,36 +64,14 @@ add_offload_testsuite(check-offload
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
-# Add liboffload unit tests based on available devices rather than configured targets
-macro(add_offload_unittest_suite target_name)
- set(OFFLOAD_PLATFORM ${target_name})
- string(TOLOWER "${OFFLOAD_PLATFORM}" SUITE_NAME)
-
- configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}/lit.site.cfg
- MAIN_CONFIG
- ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.cfg.py)
-
- add_lit_testsuite(check-offload-unit-${SUITE_NAME} "Running offload unittest suite for ${SUITE_NAME}"
- ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME}
- EXCLUDE_FROM_CHECK_ALL
- DEPENDS OffloadUnitTests)
-
- list(APPEND OFFLOAD_UNIT_TEST_SUITES ${CMAKE_CURRENT_BINARY_DIR}/unit/${SUITE_NAME})
-endmacro()
-
-set (OFFLOAD_UNIT_TEST_SUITES "")
-
-if (LIBOMPTARGET_FOUND_NVIDIA_GPU)
- add_offload_unittest_suite("CUDA")
-endif()
-
-if (LIBOMPTARGET_FOUND_AMDGPU_GPU)
- add_offload_unittest_suite("AMDGPU")
-endif()
+# 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"
- ${OFFLOAD_UNIT_TEST_SUITES}
+ ${CMAKE_CURRENT_BINARY_DIR}/unit
EXCLUDE_FROM_CHECK_ALL
DEPENDS LLVMOffload OffloadUnitTests)
diff --git a/offload/test/unit/lit.cfg.py b/offload/test/unit/lit.cfg.py
index 08541f7dd7688..5c68f6be0009a 100644
--- a/offload/test/unit/lit.cfg.py
+++ b/offload/test/unit/lit.cfg.py
@@ -8,13 +8,11 @@
import lit.formats
# name: The name of this test suite.
-config.name = "Offload-Unit-{}".format(config.offload_platform)
+config.name = "Offload-Unit"
# suffixes: A list of file extensions to treat as test files.
config.suffixes = []
-config.environment = {"OFFLOAD_UNITTEST_PLATFORM": config.offload_platform}
-
# 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")
diff --git a/offload/test/unit/lit.site.cfg.in b/offload/test/unit/lit.site.cfg.in
index aa1484058b576..8019878fae424 100644
--- a/offload/test/unit/lit.site.cfg.in
+++ b/offload/test/unit/lit.site.cfg.in
@@ -2,7 +2,6 @@
config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
-config.offload_platform = "@OFFLOAD_PLATFORM@"
# 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/OffloadAPI/common/Environment.cpp b/offload/unittests/OffloadAPI/common/Environment.cpp
index 7c2e86c0ec931..943347246b6d2 100644
--- a/offload/unittests/OffloadAPI/common/Environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -37,6 +37,15 @@ raw_ostream &operator<<(raw_ostream &Out,
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,10 +70,10 @@ void printPlatforms() {
}
}
-ol_device_handle_t TestEnvironment::getDevice() {
- static ol_device_handle_t Device = nullptr;
-
- if (!Device) {
+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 "
@@ -78,38 +87,47 @@ ol_device_handle_t TestEnvironment::getDevice() {
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 a0bf688b45515..7946a827fe2f4 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 028ebf43d5cda..2303601feb933 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 @@ struct OffloadQueueTest : OffloadDeviceTest {
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 06915258da384..0000000000000
--- 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 f71f60a2c057f..46ed622fa8b81 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()); }
-};
+TEST_P(olGetDeviceInfoTest, SuccessType) {
+ ol_device_type_t DeviceType;
+ ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE,
+ sizeof(ol_device_type_t), &DeviceType));
+}
-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, 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, Success) {
- ol_device_info_t InfoType = GetParam();
+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);
+}
- ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
-
- std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(olGetDeviceInfo(Device, InfoType, Size, InfoData.data()));
+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);
+}
- if (InfoType == OL_DEVICE_INFO_PLATFORM) {
- auto *ReturnedPlatform =
- reinterpret_cast<ol_platform_handle_t *>(InfoData.data());
- ASSERT_NE(nullptr, *ReturnedPlatform);
- }
+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_F(olGetDeviceInfoTest, InvalidNullHandleDevice) {
+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 b4b5042dbfd87..edd2704a722dd 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> {
-
- 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();
+
+using olGetDeviceInfoSizeTest = OffloadDeviceTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetDeviceInfoSizeTest);
+
+TEST_P(olGetDeviceInfoSizeTest, SuccessType) {
size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, &Size));
+ ASSERT_EQ(Size, sizeof(ol_device_type_t));
+}
- 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);
- }
+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_F(olGetDeviceInfoSizeTest, InvalidNullHandle) {
+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/kernel/olGetKernel.cpp b/offload/unittests/OffloadAPI/kernel/olGetKernel.cpp
index f320d191ad58f..097439e19156b 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 2e51a48b9a7a8..20462e22fd73f 100644
--- a/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
+++ b/offload/unittests/OffloadAPI/kernel/olLaunchKernel.cpp
@@ -43,7 +43,9 @@ struct olLaunchKernelTest : OffloadQueueTest {
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 @@ TEST_F(olLaunchKernelTest, Success) {
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 580ba022954e6..00e428ec2abc7 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 99ad389f27fbc..dfaf9bdef3189 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 b00ded9b53ed9..c1762b451b81d 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 @@ TEST_F(olMemcpyTest, SuccessHtoD) {
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 @@ TEST_F(olMemcpyTest, SuccessDtoH) {
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 @@ TEST_F(olMemcpyTest, SuccessDtoD) {
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, SuccessHtoHSync) {
}
}
-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 @@ TEST_F(olMemcpyTest, SuccessDtoHSync) {
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 bd6ad3f84e776..862b008fb9e85 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, SuccessName) {
+ size_t Size = 0;
+ 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_P(olGetPlatformInfoTest, Success) {
+TEST_P(olGetPlatformInfoTest, SuccessVendorName) {
size_t Size = 0;
- ol_platform_info_t InfoType = GetParam();
+ 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);
+}
- ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size));
- std::vector<char> InfoData(Size);
- ASSERT_SUCCESS(olGetPlatformInfo(Platform, InfoType, Size, InfoData.data()));
+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);
+}
- // 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);
- }
+TEST_P(olGetPlatformInfoTest, SuccessBackend) {
+ ol_platform_backend_t Backend;
+ ASSERT_SUCCESS(olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
+ sizeof(ol_platform_backend_t), &Backend));
}
-TEST_F(olGetPlatformInfoTest, InvalidNullHandle) {
+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 5f6067e2e2591..9ed9835ff945e 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> {};
-
-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) {
+
+using olGetPlatformInfoSizeTest = OffloadPlatformTest;
+OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetPlatformInfoSizeTest);
+
+TEST_P(olGetPlatformInfoSizeTest, SuccessName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size));
+ ASSERT_NE(Size, 0ul);
+}
+
+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;
- 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_BACKEND, &Size));
+ ASSERT_EQ(Size, sizeof(ol_platform_backend_t));
}
-TEST_F(olGetPlatformInfoSizeTest, InvalidNullHandle) {
+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 f61bca0cf52f0..0000000000000
--- 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 c586c04596201..5363957e78453 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 ea21dadb59c49..d7fc73b2ec0d9 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 0534debed055a..8a2b964c6ed42 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 b54694e0c798c..0dc8527df5323 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 07ef774583ae0..50794446b5ddb 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));
}
More information about the llvm-commits
mailing list