[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.
This commit is contained in:
Callum Fare
2025-04-29 17:21:59 +01:00
committed by GitHub
parent 7b70fc74d0
commit 6022a5214b
29 changed files with 327 additions and 403 deletions

View File

@@ -142,6 +142,9 @@ void initPlugins() {
// Preemptively initialize all devices in the plugin // Preemptively initialize all devices in the plugin
for (auto &Platform : Platforms()) { 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(); auto Err = Platform.Plugin->init();
[[maybe_unused]] std::string InfoMsg = toString(std::move(Err)); [[maybe_unused]] std::string InfoMsg = toString(std::move(Err));
for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices(); for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();

View File

@@ -63,3 +63,15 @@ add_offload_testsuite(check-offload
EXCLUDE_FROM_CHECK_ALL EXCLUDE_FROM_CHECK_ALL
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS} DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST}) 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)

View File

@@ -69,7 +69,7 @@ config.name = 'libomptarget :: ' + config.libomptarget_current_target
config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td'] config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
# excludes: A list of directories to exclude from the testuites. # 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. # test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__) config.test_source_root = os.path.dirname(__file__)

View File

@@ -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")

View File

@@ -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")

View File

@@ -1,9 +1,8 @@
add_custom_target(LibomptUnitTests) add_custom_target(OffloadUnitTests)
set_target_properties(LibomptUnitTests PROPERTIES FOLDER "Tests/UnitTests") set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")
function(add_libompt_unittest test_dirname) function(add_offload_unittest test_dirname)
add_unittest(LibomptUnitTests ${test_dirname} ${ARGN}) add_unittest(OffloadUnitTests ${test_dirname} ${ARGN})
endfunction() endfunction()
# add_subdirectory(Plugins)
add_subdirectory(OffloadAPI) add_subdirectory(OffloadAPI)

View File

@@ -4,7 +4,7 @@ set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
add_subdirectory(device_code) add_subdirectory(device_code)
message(${OFFLOAD_TEST_DEVICE_CODE_PATH}) 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}/common/Environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/platform/olGetPlatformInfoSize.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/olGetKernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.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_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON}) target_link_libraries("offload.unittests" PRIVATE ${PLUGINS_TEST_COMMON})
target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE}) target_include_directories("offload.unittests" PRIVATE ${PLUGINS_TEST_INCLUDE})

View File

@@ -37,6 +37,15 @@ raw_ostream &operator<<(raw_ostream &Out,
return 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() { void printPlatforms() {
SmallDenseSet<ol_platform_handle_t> Platforms; SmallDenseSet<ol_platform_handle_t> Platforms;
using DeviceVecT = SmallVector<ol_device_handle_t, 8>; using DeviceVecT = SmallVector<ol_device_handle_t, 8>;
@@ -61,48 +70,64 @@ void printPlatforms() {
} }
} }
ol_device_handle_t TestEnvironment::getDevice() { const std::vector<TestEnvironment::Device> &TestEnvironment::getDevices() {
static ol_device_handle_t Device = nullptr; 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 != "") { if (SelectedPlatform != "") {
olIterateDevices( olIterateDevices(
[](ol_device_handle_t D, void *Data) { [](ol_device_handle_t D, void *Data) {
ol_platform_handle_t Platform; ol_platform_handle_t Platform;
olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform), olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform),
&Platform); &Platform);
ol_platform_backend_t Backend;
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
sizeof(Backend), &Backend);
std::string PlatformName; std::string PlatformName;
raw_string_ostream S(PlatformName); raw_string_ostream S(PlatformName);
S << Platform; S << Platform;
if (PlatformName == SelectedPlatform &&
if (PlatformName == SelectedPlatform) { Backend != OL_PLATFORM_BACKEND_HOST) {
*(static_cast<ol_device_handle_t *>(Data)) = D; std::string Name;
return false; raw_string_ostream NameStr(Name);
NameStr << PlatformName << "_" << D;
static_cast<std::vector<TestEnvironment::Device> *>(Data)
->push_back({D, Name});
} }
return true; return true;
}, },
&Device); &Devices);
if (Device == nullptr) {
errs() << "No device found with the platform \"" << SelectedPlatform
<< "\". Choose from:"
<< "\n";
printPlatforms();
std::exit(1);
}
} else { } else {
// No platform specified, discover every device that isn't the host.
olIterateDevices( olIterateDevices(
[](ol_device_handle_t D, void *Data) { [](ol_device_handle_t D, void *Data) {
*(static_cast<ol_device_handle_t *>(Data)) = D; ol_platform_handle_t Platform;
return false; 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() { ol_device_handle_t TestEnvironment::getHostDevice() {

View File

@@ -13,7 +13,13 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace TestEnvironment { 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(); ol_device_handle_t getHostDevice();
bool loadDeviceBinary(const std::string &BinaryName, ol_device_handle_t Device, bool loadDeviceBinary(const std::string &BinaryName, ol_device_handle_t Device,
std::unique_ptr<llvm::MemoryBuffer> &BinaryOut); std::unique_ptr<llvm::MemoryBuffer> &BinaryOut);

View File

@@ -42,15 +42,26 @@
} \ } \
(void)0 (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 { struct OffloadTest : ::testing::Test {
ol_device_handle_t Host = TestEnvironment::getHostDevice(); ol_device_handle_t Host = TestEnvironment::getHostDevice();
}; };
struct OffloadDeviceTest : OffloadTest { struct OffloadDeviceTest
: OffloadTest,
::testing::WithParamInterface<TestEnvironment::Device> {
void SetUp() override { void SetUp() override {
RETURN_ON_FATAL_FAILURE(OffloadTest::SetUp()); RETURN_ON_FATAL_FAILURE(OffloadTest::SetUp());
Device = TestEnvironment::getDevice(); auto DeviceParam = GetParam();
Device = DeviceParam.Handle;
if (Device == nullptr) if (Device == nullptr)
GTEST_SKIP() << "No available devices."; GTEST_SKIP() << "No available devices.";
} }
@@ -120,3 +131,10 @@ struct OffloadQueueTest : OffloadDeviceTest {
ol_queue_handle_t Queue = nullptr; 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); \
})

View File

@@ -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)},
};

View File

@@ -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. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information. // See https://llvm.org/LICENSE.txt for license information.
@@ -7,68 +7,87 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "../common/Fixtures.hpp" #include "../common/Fixtures.hpp"
#include "olDeviceInfo.hpp"
#include <OffloadAPI.h> #include <OffloadAPI.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
struct olGetDeviceInfoTest : OffloadDeviceTest, using olGetDeviceInfoTest = OffloadDeviceTest;
::testing::WithParamInterface<ol_device_info_t> { 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,
INSTANTIATE_TEST_SUITE_P( sizeof(ol_device_type_t), &DeviceType));
, 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_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; ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetDeviceInfo(nullptr, OL_DEVICE_INFO_TYPE, olGetDeviceInfo(nullptr, OL_DEVICE_INFO_TYPE,
sizeof(ol_device_type_t), &DeviceType)); sizeof(ol_device_type_t), &DeviceType));
} }
TEST_F(olGetDeviceInfoTest, InvalidEnumerationInfoType) { TEST_P(olGetDeviceInfoTest, InvalidEnumerationInfoType) {
ol_device_type_t DeviceType; ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION, ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetDeviceInfo(Device, OL_DEVICE_INFO_FORCE_UINT32, olGetDeviceInfo(Device, OL_DEVICE_INFO_FORCE_UINT32,
sizeof(ol_device_type_t), &DeviceType)); sizeof(ol_device_type_t), &DeviceType));
} }
TEST_F(olGetDeviceInfoTest, InvalidSizePropSize) { TEST_P(olGetDeviceInfoTest, InvalidSizePropSize) {
ol_device_type_t DeviceType; ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE, ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 0, &DeviceType)); olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 0, &DeviceType));
} }
TEST_F(olGetDeviceInfoTest, InvalidSizePropSizeSmall) { TEST_P(olGetDeviceInfoTest, InvalidSizePropSizeSmall) {
ol_device_type_t DeviceType; ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE, ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE,
sizeof(DeviceType) - 1, &DeviceType)); sizeof(DeviceType) - 1, &DeviceType));
} }
TEST_F(olGetDeviceInfoTest, InvalidNullPointerPropValue) { TEST_P(olGetDeviceInfoTest, InvalidNullPointerPropValue) {
ol_device_type_t DeviceType; ol_device_type_t DeviceType;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, sizeof(DeviceType), olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, sizeof(DeviceType),

View File

@@ -9,50 +9,54 @@
#include <OffloadAPI.h> #include <OffloadAPI.h>
#include "../common/Fixtures.hpp" #include "../common/Fixtures.hpp"
#include "olDeviceInfo.hpp"
struct olGetDeviceInfoSizeTest using olGetDeviceInfoSizeTest = OffloadDeviceTest;
: OffloadDeviceTest, OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetDeviceInfoSizeTest);
::testing::WithParamInterface<ol_device_info_t> {
void SetUp() override { RETURN_ON_FATAL_FAILURE(OffloadDeviceTest::SetUp()); } TEST_P(olGetDeviceInfoSizeTest, SuccessType) {
};
// 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();
size_t Size = 0; size_t Size = 0;
ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, &Size));
ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size)); ASSERT_EQ(Size, sizeof(ol_device_type_t));
auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
if (ExpectedSize != DeviceInfoSizeMap.end()) {
ASSERT_EQ(Size, ExpectedSize->second);
} else {
ASSERT_NE(Size, 0lu);
}
} }
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; size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetDeviceInfoSize(nullptr, OL_DEVICE_INFO_TYPE, &Size)); olGetDeviceInfoSize(nullptr, OL_DEVICE_INFO_TYPE, &Size));
} }
TEST_F(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) { TEST_P(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) {
size_t Size = 0; size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION, ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetDeviceInfoSize(Device, OL_DEVICE_INFO_FORCE_UINT32, &Size)); olGetDeviceInfoSize(Device, OL_DEVICE_INFO_FORCE_UINT32, &Size));
} }
TEST_F(olGetDeviceInfoSizeTest, InvalidNullPointer) { TEST_P(olGetDeviceInfoSizeTest, InvalidNullPointer) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, nullptr)); olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, nullptr));
} }

View File

@@ -62,6 +62,6 @@ endif()
add_offload_test_device_code(foo.c foo) add_offload_test_device_code(foo.c foo)
add_offload_test_device_code(bar.c bar) 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) set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

View File

@@ -11,20 +11,21 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olGetKernelTest = OffloadProgramTest; using olGetKernelTest = OffloadProgramTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetKernelTest);
TEST_F(olGetKernelTest, Success) { TEST_P(olGetKernelTest, Success) {
ol_kernel_handle_t Kernel = nullptr; ol_kernel_handle_t Kernel = nullptr;
ASSERT_SUCCESS(olGetKernel(Program, "foo", &Kernel)); ASSERT_SUCCESS(olGetKernel(Program, "foo", &Kernel));
ASSERT_NE(Kernel, nullptr); ASSERT_NE(Kernel, nullptr);
} }
TEST_F(olGetKernelTest, InvalidNullProgram) { TEST_P(olGetKernelTest, InvalidNullProgram) {
ol_kernel_handle_t Kernel = nullptr; ol_kernel_handle_t Kernel = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetKernel(nullptr, "foo", &Kernel)); olGetKernel(nullptr, "foo", &Kernel));
} }
TEST_F(olGetKernelTest, InvalidNullKernelPointer) { TEST_P(olGetKernelTest, InvalidNullKernelPointer) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetKernel(Program, "foo", nullptr)); olGetKernel(Program, "foo", nullptr));
} }

View File

@@ -43,7 +43,9 @@ struct olLaunchKernelTest : OffloadQueueTest {
ol_kernel_launch_size_args_t LaunchArgs{}; ol_kernel_launch_size_args_t LaunchArgs{};
}; };
TEST_F(olLaunchKernelTest, Success) { OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olLaunchKernelTest);
TEST_P(olLaunchKernelTest, Success) {
void *Mem; void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem));
struct { struct {
@@ -63,7 +65,7 @@ TEST_F(olLaunchKernelTest, Success) {
ASSERT_SUCCESS(olMemFree(Mem)); ASSERT_SUCCESS(olMemFree(Mem));
} }
TEST_F(olLaunchKernelTest, SuccessSynchronous) { TEST_P(olLaunchKernelTest, SuccessSynchronous) {
void *Mem; void *Mem;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 64, &Mem));

View File

@@ -11,35 +11,36 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olMemAllocTest = OffloadDeviceTest; using olMemAllocTest = OffloadDeviceTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemAllocTest);
TEST_F(olMemAllocTest, SuccessAllocManaged) { TEST_P(olMemAllocTest, SuccessAllocManaged) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr); ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc); olMemFree(Alloc);
} }
TEST_F(olMemAllocTest, SuccessAllocHost) { TEST_P(olMemAllocTest, SuccessAllocHost) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr); ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc); olMemFree(Alloc);
} }
TEST_F(olMemAllocTest, SuccessAllocDevice) { TEST_P(olMemAllocTest, SuccessAllocDevice) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_NE(Alloc, nullptr); ASSERT_NE(Alloc, nullptr);
olMemFree(Alloc); olMemFree(Alloc);
} }
TEST_F(olMemAllocTest, InvalidNullDevice) { TEST_P(olMemAllocTest, InvalidNullDevice) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olMemAlloc(nullptr, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc)); olMemAlloc(nullptr, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
} }
TEST_F(olMemAllocTest, InvalidNullOutPtr) { TEST_P(olMemAllocTest, InvalidNullOutPtr) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, nullptr)); olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, nullptr));
} }

View File

@@ -11,26 +11,27 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olMemFreeTest = OffloadDeviceTest; using olMemFreeTest = OffloadDeviceTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemFreeTest);
TEST_F(olMemFreeTest, SuccessFreeManaged) { TEST_P(olMemFreeTest, SuccessFreeManaged) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_MANAGED, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc)); ASSERT_SUCCESS(olMemFree(Alloc));
} }
TEST_F(olMemFreeTest, SuccessFreeHost) { TEST_P(olMemFreeTest, SuccessFreeHost) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_HOST, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc)); ASSERT_SUCCESS(olMemFree(Alloc));
} }
TEST_F(olMemFreeTest, SuccessFreeDevice) { TEST_P(olMemFreeTest, SuccessFreeDevice) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_SUCCESS(olMemFree(Alloc)); ASSERT_SUCCESS(olMemFree(Alloc));
} }
TEST_F(olMemFreeTest, InvalidNullPtr) { TEST_P(olMemFreeTest, InvalidNullPtr) {
void *Alloc = nullptr; void *Alloc = nullptr;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, 1024, &Alloc));
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olMemFree(nullptr)); ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olMemFree(nullptr));

View File

@@ -11,8 +11,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olMemcpyTest = OffloadQueueTest; using olMemcpyTest = OffloadQueueTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemcpyTest);
TEST_F(olMemcpyTest, SuccessHtoD) { TEST_P(olMemcpyTest, SuccessHtoD) {
constexpr size_t Size = 1024; constexpr size_t Size = 1024;
void *Alloc; void *Alloc;
ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, Size, &Alloc)); ASSERT_SUCCESS(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, Size, &Alloc));
@@ -23,7 +24,7 @@ TEST_F(olMemcpyTest, SuccessHtoD) {
olMemFree(Alloc); olMemFree(Alloc);
} }
TEST_F(olMemcpyTest, SuccessDtoH) { TEST_P(olMemcpyTest, SuccessDtoH) {
constexpr size_t Size = 1024; constexpr size_t Size = 1024;
void *Alloc; void *Alloc;
std::vector<uint8_t> Input(Size, 42); std::vector<uint8_t> Input(Size, 42);
@@ -41,7 +42,7 @@ TEST_F(olMemcpyTest, SuccessDtoH) {
ASSERT_SUCCESS(olMemFree(Alloc)); ASSERT_SUCCESS(olMemFree(Alloc));
} }
TEST_F(olMemcpyTest, SuccessDtoD) { TEST_P(olMemcpyTest, SuccessDtoD) {
constexpr size_t Size = 1024; constexpr size_t Size = 1024;
void *AllocA; void *AllocA;
void *AllocB; void *AllocB;
@@ -64,7 +65,7 @@ TEST_F(olMemcpyTest, SuccessDtoD) {
ASSERT_SUCCESS(olMemFree(AllocB)); ASSERT_SUCCESS(olMemFree(AllocB));
} }
TEST_F(olMemcpyTest, SuccessHtoHSync) { TEST_P(olMemcpyTest, SuccessHtoHSync) {
constexpr size_t Size = 1024; constexpr size_t Size = 1024;
std::vector<uint8_t> Input(Size, 42); std::vector<uint8_t> Input(Size, 42);
std::vector<uint8_t> Output(Size, 0); 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; constexpr size_t Size = 1024;
void *Alloc; void *Alloc;
std::vector<uint8_t> Input(Size, 42); std::vector<uint8_t> Input(Size, 42);
@@ -94,7 +95,7 @@ TEST_F(olMemcpyTest, SuccessDtoHSync) {
ASSERT_SUCCESS(olMemFree(Alloc)); ASSERT_SUCCESS(olMemFree(Alloc));
} }
TEST_F(olMemcpyTest, SuccessSizeZero) { TEST_P(olMemcpyTest, SuccessSizeZero) {
constexpr size_t Size = 1024; constexpr size_t Size = 1024;
std::vector<uint8_t> Input(Size, 42); std::vector<uint8_t> Input(Size, 42);
std::vector<uint8_t> Output(Size, 0); std::vector<uint8_t> Output(Size, 0);

View File

@@ -9,66 +9,80 @@
#include <OffloadAPI.h> #include <OffloadAPI.h>
#include "../common/Fixtures.hpp" #include "../common/Fixtures.hpp"
#include "olPlatformInfo.hpp"
struct olGetPlatformInfoTest using olGetPlatformInfoTest = OffloadPlatformTest;
: OffloadPlatformTest, OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetPlatformInfoTest);
::testing::WithParamInterface<ol_platform_info_t> {};
INSTANTIATE_TEST_SUITE_P( TEST_P(olGetPlatformInfoTest, SuccessName) {
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) {
size_t Size = 0; size_t Size = 0;
ol_platform_info_t InfoType = GetParam(); ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size));
ASSERT_GT(Size, 0ul);
ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size)); std::vector<char> Name;
std::vector<char> InfoData(Size); Name.resize(Size);
ASSERT_SUCCESS(olGetPlatformInfo(Platform, InfoType, Size, InfoData.data())); ASSERT_SUCCESS(
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_NAME, Size, Name.data()));
// Info types with a dynamic size are all char[] so we can verify the returned ASSERT_EQ(std::strlen(Name.data()), Size - 1);
// string is the expected size.
auto ExpectedSize = PlatformInfoSizeMap.find(InfoType);
if (ExpectedSize == PlatformInfoSizeMap.end()) {
ASSERT_EQ(Size, strlen(InfoData.data()) + 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; ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetPlatformInfo(nullptr, OL_PLATFORM_INFO_BACKEND, olGetPlatformInfo(nullptr, OL_PLATFORM_INFO_BACKEND,
sizeof(Backend), &Backend)); sizeof(Backend), &Backend));
} }
TEST_F(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) { TEST_P(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) {
ol_platform_backend_t Backend; ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION, ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_FORCE_UINT32, olGetPlatformInfo(Platform, OL_PLATFORM_INFO_FORCE_UINT32,
sizeof(Backend), &Backend)); sizeof(Backend), &Backend));
} }
TEST_F(olGetPlatformInfoTest, InvalidSizeZero) { TEST_P(olGetPlatformInfoTest, InvalidSizeZero) {
ol_platform_backend_t Backend; ol_platform_backend_t Backend;
ASSERT_ERROR( ASSERT_ERROR(
OL_ERRC_INVALID_SIZE, OL_ERRC_INVALID_SIZE,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 0, &Backend)); olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 0, &Backend));
} }
TEST_F(olGetPlatformInfoTest, InvalidSizeSmall) { TEST_P(olGetPlatformInfoTest, InvalidSizeSmall) {
ol_platform_backend_t Backend; ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_SIZE, ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,
sizeof(Backend) - 1, &Backend)); sizeof(Backend) - 1, &Backend));
} }
TEST_F(olGetPlatformInfoTest, InvalidNullPointerPropValue) { TEST_P(olGetPlatformInfoTest, InvalidNullPointerPropValue) {
ol_platform_backend_t Backend; ol_platform_backend_t Backend;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND,

View File

@@ -9,48 +9,51 @@
#include <OffloadAPI.h> #include <OffloadAPI.h>
#include "../common/Fixtures.hpp" #include "../common/Fixtures.hpp"
#include "olPlatformInfo.hpp"
struct olGetPlatformInfoSizeTest using olGetPlatformInfoSizeTest = OffloadPlatformTest;
: OffloadPlatformTest, OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetPlatformInfoSizeTest);
::testing::WithParamInterface<ol_platform_info_t> {};
INSTANTIATE_TEST_SUITE_P( TEST_P(olGetPlatformInfoSizeTest, SuccessName) {
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) {
size_t Size = 0; size_t Size = 0;
ol_platform_info_t InfoType = GetParam(); ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_NAME, &Size));
ASSERT_NE(Size, 0ul);
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);
}
} }
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; size_t Size = 0;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
olGetPlatformInfoSize(nullptr, OL_PLATFORM_INFO_BACKEND, &Size)); olGetPlatformInfoSize(nullptr, OL_PLATFORM_INFO_BACKEND, &Size));
} }
TEST_F(olGetPlatformInfoSizeTest, InvalidPlatformInfoEnumeration) { TEST_P(olGetPlatformInfoSizeTest, InvalidPlatformInfoEnumeration) {
size_t Size = 0; size_t Size = 0;
ASSERT_ERROR( ASSERT_ERROR(
OL_ERRC_INVALID_ENUMERATION, OL_ERRC_INVALID_ENUMERATION,
olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_FORCE_UINT32, &Size)); olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_FORCE_UINT32, &Size));
} }
TEST_F(olGetPlatformInfoSizeTest, InvalidNullPointer) { TEST_P(olGetPlatformInfoSizeTest, InvalidNullPointer) {
ASSERT_ERROR( ASSERT_ERROR(
OL_ERRC_INVALID_NULL_POINTER, OL_ERRC_INVALID_NULL_POINTER,
olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_BACKEND, nullptr)); olGetPlatformInfoSize(Platform, OL_PLATFORM_INFO_BACKEND, nullptr));

View File

@@ -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)},
};

View File

@@ -11,8 +11,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olCreateProgramTest = OffloadDeviceTest; using olCreateProgramTest = OffloadDeviceTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCreateProgramTest);
TEST_F(olCreateProgramTest, Success) { TEST_P(olCreateProgramTest, Success) {
std::unique_ptr<llvm::MemoryBuffer> DeviceBin; std::unique_ptr<llvm::MemoryBuffer> DeviceBin;
ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin)); ASSERT_TRUE(TestEnvironment::loadDeviceBinary("foo", Device, DeviceBin));

View File

@@ -11,12 +11,13 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olDestroyProgramTest = OffloadProgramTest; using olDestroyProgramTest = OffloadProgramTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyProgramTest);
TEST_F(olDestroyProgramTest, Success) { TEST_P(olDestroyProgramTest, Success) {
ASSERT_SUCCESS(olDestroyProgram(Program)); ASSERT_SUCCESS(olDestroyProgram(Program));
Program = nullptr; Program = nullptr;
} }
TEST_F(olDestroyProgramTest, InvalidNullHandle) { TEST_P(olDestroyProgramTest, InvalidNullHandle) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyProgram(nullptr)); ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyProgram(nullptr));
} }

View File

@@ -11,18 +11,19 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olCreateQueueTest = OffloadDeviceTest; using olCreateQueueTest = OffloadDeviceTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olCreateQueueTest);
TEST_F(olCreateQueueTest, Success) { TEST_P(olCreateQueueTest, Success) {
ol_queue_handle_t Queue = nullptr; ol_queue_handle_t Queue = nullptr;
ASSERT_SUCCESS(olCreateQueue(Device, &Queue)); ASSERT_SUCCESS(olCreateQueue(Device, &Queue));
ASSERT_NE(Queue, nullptr); ASSERT_NE(Queue, nullptr);
} }
TEST_F(olCreateQueueTest, InvalidNullHandleDevice) { TEST_P(olCreateQueueTest, InvalidNullHandleDevice) {
ol_queue_handle_t Queue = nullptr; ol_queue_handle_t Queue = nullptr;
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olCreateQueue(nullptr, &Queue)); 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)); ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olCreateQueue(Device, nullptr));
} }

View File

@@ -11,12 +11,13 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olDestroyQueueTest = OffloadQueueTest; using olDestroyQueueTest = OffloadQueueTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyQueueTest);
TEST_F(olDestroyQueueTest, Success) { TEST_P(olDestroyQueueTest, Success) {
ASSERT_SUCCESS(olDestroyQueue(Queue)); ASSERT_SUCCESS(olDestroyQueue(Queue));
Queue = nullptr; Queue = nullptr;
} }
TEST_F(olDestroyQueueTest, InvalidNullHandle) { TEST_P(olDestroyQueueTest, InvalidNullHandle) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyQueue(nullptr)); ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyQueue(nullptr));
} }

View File

@@ -11,7 +11,8 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
using olWaitQueueTest = OffloadQueueTest; using olWaitQueueTest = OffloadQueueTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olWaitQueueTest);
TEST_F(olWaitQueueTest, SuccessEmptyQueue) { TEST_P(olWaitQueueTest, SuccessEmptyQueue) {
ASSERT_SUCCESS(olWaitQueue(Queue)); ASSERT_SUCCESS(olWaitQueue(Queue));
} }

View File

@@ -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()

View File

@@ -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));
}
}