Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable adapter tests to run on all discovered adapters. #2376

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/adapters/native_cpu/ur_interface_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetGlobalProcAddrTable(
pDdiTable->pfnAdapterGetInfo = urAdapterGetInfo;
pDdiTable->pfnAdapterRelease = urAdapterRelease;
pDdiTable->pfnAdapterRetain = urAdapterRetain;
pDdiTable->pfnAdapterGetLastError = urAdapterGetLastError;
return UR_RESULT_SUCCESS;
}

Expand Down
5 changes: 0 additions & 5 deletions test/conformance/adapter/adapter_adapter_native_cpu.match

This file was deleted.

53 changes: 0 additions & 53 deletions test/conformance/adapter/fixtures.h

This file was deleted.

21 changes: 19 additions & 2 deletions test/conformance/adapter/urAdapterGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include <uur/fixtures.h>

using urAdapterGetTest = uur::runtime::urTest;
struct urAdapterGetTest : ::testing::Test {
void SetUp() override {
ur_device_init_flags_t device_flags = 0;
ASSERT_SUCCESS(urLoaderConfigCreate(&loader_config));
ASSERT_SUCCESS(urLoaderConfigEnableLayer(loader_config,
"UR_LAYER_FULL_VALIDATION"));
ASSERT_SUCCESS(urLoaderInit(device_flags, loader_config));
}

void TearDown() override {
if (loader_config) {
ASSERT_SUCCESS(urLoaderConfigRelease(loader_config));
}
ASSERT_SUCCESS(urLoaderTearDown());
}

ur_loader_config_handle_t loader_config = nullptr;
};

TEST_F(urAdapterGetTest, Success) {
uint32_t adapter_count;
Expand Down
74 changes: 31 additions & 43 deletions test/conformance/adapter/urAdapterGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,83 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include <uur/fixtures.h>

#include <cstring>

struct urAdapterGetInfoTest : uur::runtime::urAdapterTest,
::testing::WithParamInterface<ur_adapter_info_t> {

void SetUp() {
UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp());
adapter = adapters[0];
}

ur_adapter_handle_t adapter;
};

std::unordered_map<ur_adapter_info_t, size_t> adapter_info_size_map = {
{UR_ADAPTER_INFO_BACKEND, sizeof(ur_adapter_backend_t)},
{UR_ADAPTER_INFO_VERSION, sizeof(uint32_t)},
{UR_ADAPTER_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
};

INSTANTIATE_TEST_SUITE_P(
urAdapterGetInfo, urAdapterGetInfoTest,
::testing::Values(UR_ADAPTER_INFO_BACKEND, UR_ADAPTER_INFO_VERSION,
UR_ADAPTER_INFO_REFERENCE_COUNT),
[](const ::testing::TestParamInfo<ur_adapter_info_t> &info) {
std::stringstream ss;
ss << info.param;
return ss.str();
});

TEST_P(urAdapterGetInfoTest, Success) {
using urAdapterGetInfoTest = uur::urAdapterTest;

UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterGetInfoTest);

TEST_P(urAdapterGetInfoTest, Backend) {
auto info_type = UR_ADAPTER_INFO_BACKEND;
size_t size = 0;
ur_adapter_info_t info_type = GetParam();
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), info_type);
ASSERT_NE(size, 0);

if (const auto expected_size = adapter_info_size_map.find(info_type);
expected_size != adapter_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
}
ASSERT_EQ(size, sizeof(ur_adapter_backend_t));

std::vector<char> info_data(size);
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, info_data.data(), nullptr));
}

TEST_P(urAdapterGetInfoTest, ReferenceCount) {
auto info_type = UR_ADAPTER_INFO_REFERENCE_COUNT;
size_t size = 0;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), info_type);
ASSERT_EQ(size, sizeof(uint32_t));

uint32_t reference_count = 0;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, &reference_count, nullptr));
ASSERT_GE(reference_count, 0);
}

TEST_P(urAdapterGetInfoTest, InvalidNullHandleAdapter) {
size_t size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterGetInfo(nullptr, GetParam(), 0, nullptr, &size));
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterGetInfo(nullptr, UR_ADAPTER_INFO_BACKEND, 0, nullptr, &size));
}

TEST_F(urAdapterGetInfoTest, InvalidEnumerationAdapterInfoType) {
TEST_P(urAdapterGetInfoTest, InvalidEnumerationAdapterInfoType) {
size_t size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_FORCE_UINT32, 0,
nullptr, &size));
}

TEST_F(urAdapterGetInfoTest, InvalidSizeZero) {
TEST_P(urAdapterGetInfoTest, InvalidSizeZero) {
ur_adapter_backend_t backend;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0,
&backend, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_F(urAdapterGetInfoTest, InvalidSizeSmall) {
TEST_P(urAdapterGetInfoTest, InvalidSizeSmall) {
ur_adapter_backend_t backend;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend) - 1, &backend, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_F(urAdapterGetInfoTest, InvalidNullPointerPropValue) {
TEST_P(urAdapterGetInfoTest, InvalidNullPointerPropValue) {
ur_adapter_backend_t backend;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend), nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_F(urAdapterGetInfoTest, InvalidNullPointerPropSizeRet) {
TEST_P(urAdapterGetInfoTest, InvalidNullPointerPropSizeRet) {
ASSERT_EQ_RESULT(
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_F(urAdapterGetInfoTest, ReferenceCountNotZero) {
TEST_P(urAdapterGetInfoTest, ReferenceCountNotZero) {
uint32_t referenceCount = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
Expand All @@ -100,7 +88,7 @@ TEST_F(urAdapterGetInfoTest, ReferenceCountNotZero) {
ASSERT_GT(referenceCount, 0);
}

TEST_F(urAdapterGetInfoTest, ValidAdapterBackend) {
TEST_P(urAdapterGetInfoTest, ValidAdapterBackend) {
ur_adapter_backend_t backend;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend), &backend, nullptr));
Expand Down
20 changes: 11 additions & 9 deletions test/conformance/adapter/urAdapterGetLastError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include <uur/fixtures.h>

struct urAdapterGetLastErrorTest : uur::runtime::urAdapterTest {
struct urAdapterGetLastErrorTest : uur::urAdapterTest {
int32_t error;
const char *message = nullptr;
};

TEST_F(urAdapterGetLastErrorTest, Success) {
UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterGetLastErrorTest);

TEST_P(urAdapterGetLastErrorTest, Success) {
// We can't reliably generate a UR_RESULT_ERROR_ADAPTER_SPECIFIC error to
// test the full functionality of this entry point, so instead do a minimal
// smoke test and check that the call returns successfully, even if no
// actual error was set.
ASSERT_EQ_RESULT(UR_RESULT_SUCCESS,
urAdapterGetLastError(adapters[0], &message, &error));
urAdapterGetLastError(adapter, &message, &error));
}

TEST_F(urAdapterGetLastErrorTest, InvalidHandle) {
TEST_P(urAdapterGetLastErrorTest, InvalidHandle) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterGetLastError(nullptr, &message, &error));
}

TEST_F(urAdapterGetLastErrorTest, InvalidMessagePtr) {
TEST_P(urAdapterGetLastErrorTest, InvalidMessagePtr) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urAdapterGetLastError(adapters[0], nullptr, &error));
urAdapterGetLastError(adapter, nullptr, &error));
}

TEST_F(urAdapterGetLastErrorTest, InvalidErrorPtr) {
TEST_P(urAdapterGetLastErrorTest, InvalidErrorPtr) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urAdapterGetLastError(adapters[0], &message, nullptr));
urAdapterGetLastError(adapter, &message, nullptr));
}
16 changes: 5 additions & 11 deletions test/conformance/adapter/urAdapterRelease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include <uur/fixtures.h>

struct urAdapterReleaseTest : uur::runtime::urAdapterTest {
void SetUp() {
UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp());
adapter = adapters[0];
}
using urAdapterReleaseTest = uur::urAdapterTest;
UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterReleaseTest);

ur_adapter_handle_t adapter;
};

TEST_F(urAdapterReleaseTest, Success) {
TEST_P(urAdapterReleaseTest, Success) {
uint32_t referenceCountBefore = 0;
ASSERT_SUCCESS(urAdapterRetain(adapter));

Expand All @@ -31,7 +25,7 @@ TEST_F(urAdapterReleaseTest, Success) {
ASSERT_LE(referenceCountAfter, referenceCountBefore);
}

TEST_F(urAdapterReleaseTest, InvalidNullHandleAdapter) {
TEST_P(urAdapterReleaseTest, InvalidNullHandleAdapter) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterRelease(nullptr));
}
16 changes: 5 additions & 11 deletions test/conformance/adapter/urAdapterRetain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include <uur/fixtures.h>

struct urAdapterRetainTest : uur::runtime::urAdapterTest {
void SetUp() {
UUR_RETURN_ON_FATAL_FAILURE(uur::runtime::urAdapterTest::SetUp());
adapter = adapters[0];
}
using urAdapterRetainTest = uur::urAdapterTest;
UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterRetainTest);

ur_adapter_handle_t adapter;
};

TEST_F(urAdapterRetainTest, Success) {
TEST_P(urAdapterRetainTest, Success) {
uint32_t referenceCountBefore = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
Expand All @@ -30,7 +24,7 @@ TEST_F(urAdapterRetainTest, Success) {
ASSERT_GT(referenceCountAfter, referenceCountBefore);
}

TEST_F(urAdapterRetainTest, InvalidNullHandleAdapter) {
TEST_P(urAdapterRetainTest, InvalidNullHandleAdapter) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urAdapterRetain(nullptr));
}
8 changes: 8 additions & 0 deletions test/conformance/platform/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ struct urPlatformTest : urPlatformsTest {
ur_platform_handle_t platform;
};

#define UUR_INSTANTIATE_PLATFORM_TEST_SUITE_P(FIXTURE) \
INSTANTIATE_TEST_SUITE_P( \
, FIXTURE, \
::testing::ValuesIn(uur::DevicesEnvironment::instance->devices), \
[](const ::testing::TestParamInfo<ur_device_handle_t> &info) { \
return uur::GetPlatformAndDeviceName(info.param); \
})

} // namespace platform
} // namespace uur

Expand Down
Loading
Loading