diff --git a/test/conformance/platform/CMakeLists.txt b/test/conformance/platform/CMakeLists.txt index 91c0ac327a..92e95018e4 100644 --- a/test/conformance/platform/CMakeLists.txt +++ b/test/conformance/platform/CMakeLists.txt @@ -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) diff --git a/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp b/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp new file mode 100644 index 0000000000..00d8ce78ea --- /dev/null +++ b/test/conformance/platform/urPlatformCreateWithNativeHandle.cpp @@ -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)); +} diff --git a/test/conformance/platform/urPlatformGetNativeHandle.cpp b/test/conformance/platform/urPlatformGetNativeHandle.cpp new file mode 100644 index 0000000000..77ae08bc78 --- /dev/null +++ b/test/conformance/platform/urPlatformGetNativeHandle.cpp @@ -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)); + } +}