Skip to content

Commit bee9f64

Browse files
authored
Merge pull request #684 from callumfare/callum/cts-urPlatformNativeHandle
[UR][CTS] Add tests for urPlatformGetNaitiveHandle and urPlatformCreateWithNativeHandle
2 parents b6109c8 + 5372d3b commit bee9f64

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

test/conformance/platform/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
add_conformance_test(platform
77
urInit.cpp
8+
urPlatformCreateWithNativeHandle.cpp
89
urPlatformGet.cpp
910
urPlatformGetApiVersion.cpp
1011
urPlatformGetBackendOption.cpp
1112
urPlatformGetInfo.cpp
1213
urPlatformGetLastError.cpp
14+
urPlatformGetNativeHandle.cpp
1315
urTearDown.cpp)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2022-2023 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include "fixtures.h"
7+
8+
using urPlatformCreateWithNativeHandleTest = uur::platform::urPlatformTest;
9+
10+
TEST_F(urPlatformCreateWithNativeHandleTest, InvalidNullPointerPlatform) {
11+
ur_native_handle_t native_handle = nullptr;
12+
ASSERT_SUCCESS(urPlatformGetNativeHandle(platform, &native_handle));
13+
ASSERT_EQ_RESULT(
14+
UR_RESULT_ERROR_INVALID_NULL_POINTER,
15+
urPlatformCreateWithNativeHandle(native_handle, nullptr, nullptr));
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2022-2023 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include "fixtures.h"
7+
8+
using urPlatformGetNativeHandleTest = uur::platform::urPlatformsTest;
9+
10+
TEST_F(urPlatformGetNativeHandleTest, Success) {
11+
for (auto platform : platforms) {
12+
ur_native_handle_t native_handle = nullptr;
13+
ASSERT_SUCCESS(urPlatformGetNativeHandle(platform, &native_handle));
14+
15+
// We cannot assume anything about a native_handle, not even if it's
16+
// `nullptr` since this could be a valid representation within a backend.
17+
// We can however convert the native_handle back into a unified-runtime
18+
// handle and perform some query on it to verify that it works.
19+
ur_platform_handle_t plat = nullptr;
20+
ASSERT_SUCCESS(
21+
urPlatformCreateWithNativeHandle(native_handle, nullptr, &plat));
22+
ASSERT_NE(plat, nullptr);
23+
24+
ur_platform_backend_t backend;
25+
ASSERT_SUCCESS(urPlatformGetInfo(plat, UR_PLATFORM_INFO_BACKEND,
26+
sizeof(ur_platform_backend_t),
27+
&backend, nullptr));
28+
}
29+
}
30+
31+
TEST_F(urPlatformGetNativeHandleTest, InvalidNullHandlePlatform) {
32+
ur_native_handle_t native_handle = nullptr;
33+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
34+
urPlatformGetNativeHandle(nullptr, &native_handle));
35+
}
36+
37+
TEST_F(urPlatformGetNativeHandleTest, InvalidNullPointerNativePlatform) {
38+
for (auto platform : platforms) {
39+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
40+
urPlatformGetNativeHandle(platform, nullptr));
41+
}
42+
}

0 commit comments

Comments
 (0)