Skip to content

Commit

Permalink
Merge pull request #684 from callumfare/callum/cts-urPlatformNativeHa…
Browse files Browse the repository at this point in the history
…ndle

[UR][CTS] Add tests for urPlatformGetNaitiveHandle and urPlatformCreateWithNativeHandle
  • Loading branch information
callumfare committed Jul 5, 2023
2 parents b6109c8 + 5372d3b commit bee9f64
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/conformance/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

add_conformance_test(platform
urInit.cpp
urPlatformCreateWithNativeHandle.cpp
urPlatformGet.cpp
urPlatformGetApiVersion.cpp
urPlatformGetBackendOption.cpp
urPlatformGetInfo.cpp
urPlatformGetLastError.cpp
urPlatformGetNativeHandle.cpp
urTearDown.cpp)
16 changes: 16 additions & 0 deletions test/conformance/platform/urPlatformCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2022-2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"

using urPlatformCreateWithNativeHandleTest = uur::platform::urPlatformTest;

TEST_F(urPlatformCreateWithNativeHandleTest, InvalidNullPointerPlatform) {
ur_native_handle_t native_handle = nullptr;
ASSERT_SUCCESS(urPlatformGetNativeHandle(platform, &native_handle));
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urPlatformCreateWithNativeHandle(native_handle, nullptr, nullptr));
}
42 changes: 42 additions & 0 deletions test/conformance/platform/urPlatformGetNativeHandle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2022-2023 Intel Corporation
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"

using urPlatformGetNativeHandleTest = uur::platform::urPlatformsTest;

TEST_F(urPlatformGetNativeHandleTest, Success) {
for (auto platform : platforms) {
ur_native_handle_t native_handle = nullptr;
ASSERT_SUCCESS(urPlatformGetNativeHandle(platform, &native_handle));

// We cannot assume anything about a native_handle, not even if it's
// `nullptr` since this could be a valid representation within a backend.
// We can however convert the native_handle back into a unified-runtime
// handle and perform some query on it to verify that it works.
ur_platform_handle_t plat = nullptr;
ASSERT_SUCCESS(
urPlatformCreateWithNativeHandle(native_handle, nullptr, &plat));
ASSERT_NE(plat, nullptr);

ur_platform_backend_t backend;
ASSERT_SUCCESS(urPlatformGetInfo(plat, UR_PLATFORM_INFO_BACKEND,
sizeof(ur_platform_backend_t),
&backend, nullptr));
}
}

TEST_F(urPlatformGetNativeHandleTest, InvalidNullHandlePlatform) {
ur_native_handle_t native_handle = nullptr;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urPlatformGetNativeHandle(nullptr, &native_handle));
}

TEST_F(urPlatformGetNativeHandleTest, InvalidNullPointerNativePlatform) {
for (auto platform : platforms) {
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
urPlatformGetNativeHandle(platform, nullptr));
}
}

0 comments on commit bee9f64

Please sign in to comment.