|
| 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