Skip to content

Commit c46db28

Browse files
committed
[ur] Update CTS to match native handle nocheck
Follow up from #720 where the `nocheck` option was added to the `ur_native_handle_t` arguments of `ur<Object>CreateWithNativeHandle`. This patch removes tests which assumed that `ur_native_handle_t` must not be `nullptr` which is an incorrect assumption.
1 parent 3f7f99c commit c46db28

20 files changed

+192
-216
lines changed

test/conformance/context/urContextCreateWithNativeHandle.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55

66
#include <uur/fixtures.h>
77

8-
using urContextCreateWithNativeHandleTest = uur::urDeviceTest;
9-
8+
using urContextCreateWithNativeHandleTest = uur::urContextTest;
109
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urContextCreateWithNativeHandleTest);
1110

12-
TEST_P(urContextCreateWithNativeHandleTest, InvalidNullHandleNativeHandle) {
13-
ur_context_handle_t context = nullptr;
11+
TEST_P(urContextCreateWithNativeHandleTest, Success) {
12+
ur_native_handle_t native_context = nullptr;
13+
ASSERT_SUCCESS(urContextGetNativeHandle(context, &native_context));
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 handle
18+
// and perform some query on it to verify that it works.
19+
ur_context_handle_t ctx = nullptr;
1420
ur_context_native_properties_t props{};
15-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
16-
urContextCreateWithNativeHandle(nullptr, 0u, nullptr,
17-
&props, &context));
21+
ASSERT_SUCCESS(urContextCreateWithNativeHandle(native_context, 0, nullptr,
22+
&props, &ctx));
23+
ASSERT_NE(ctx, nullptr);
24+
25+
uint32_t n_devices = 0;
26+
ASSERT_SUCCESS(urContextGetInfo(ctx, UR_CONTEXT_INFO_NUM_DEVICES,
27+
sizeof(uint32_t), &n_devices, nullptr));
1828
}

test/conformance/context/urContextGetNativeHandle.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,11 @@
66
#include <uur/fixtures.h>
77

88
using urContextGetNativeHandleTest = uur::urContextTest;
9-
109
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urContextGetNativeHandleTest);
1110

1211
TEST_P(urContextGetNativeHandleTest, Success) {
1312
ur_native_handle_t native_context = nullptr;
1413
ASSERT_SUCCESS(urContextGetNativeHandle(context, &native_context));
15-
16-
// We cannot assume anything about a native_handle, not even if it's
17-
// `nullptr` since this could be a valid representation within a backend.
18-
// We can however convert the native_handle back into a unified-runtime handle
19-
// and perform some query on it to verify that it works.
20-
ur_context_handle_t ctx = nullptr;
21-
ur_context_native_properties_t props{};
22-
ASSERT_SUCCESS(urContextCreateWithNativeHandle(native_context, 0, nullptr,
23-
&props, &ctx));
24-
ASSERT_NE(ctx, nullptr);
25-
26-
uint32_t n_devices = 0;
27-
ASSERT_SUCCESS(urContextGetInfo(ctx, UR_CONTEXT_INFO_NUM_DEVICES,
28-
sizeof(uint32_t), &n_devices, nullptr));
2914
}
3015

3116
TEST_P(urContextGetNativeHandleTest, InvalidNullHandleContext) {

test/conformance/device/urDeviceCreateWithNativeHandle.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
#include <uur/fixtures.h>
66

7-
using urDeviceCreateWithNativeHandleTest = uur::urPlatformTest;
7+
using urDeviceCreateWithNativeHandleTest = uur::urAllDevicesTest;
88

9-
TEST_F(urDeviceCreateWithNativeHandleTest, InvalidNullHandleNativeDevice) {
10-
ur_device_handle_t device = nullptr;
11-
ASSERT_EQ_RESULT(
12-
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
13-
urDeviceCreateWithNativeHandle(nullptr, platform, nullptr, &device));
9+
TEST_F(urDeviceCreateWithNativeHandleTest, Success) {
10+
for (auto device : devices) {
11+
ur_native_handle_t native_handle = nullptr;
12+
ASSERT_SUCCESS(urDeviceGetNativeHandle(device, &native_handle));
13+
14+
// We cannot assume anything about a native_handle, not even if it's
15+
// `nullptr` since this could be a valid representation within a backend.
16+
// We can however convert the native_handle back into a unified-runtime handle
17+
// and perform some query on it to verify that it works.
18+
ur_device_handle_t dev = nullptr;
19+
ASSERT_SUCCESS(urDeviceCreateWithNativeHandle(native_handle, platform,
20+
nullptr, &dev));
21+
ASSERT_NE(dev, nullptr);
22+
23+
uint32_t dev_id = 0;
24+
ASSERT_SUCCESS(urDeviceGetInfo(dev, UR_DEVICE_INFO_TYPE,
25+
sizeof(uint32_t), &dev_id, nullptr));
26+
}
1427
}

test/conformance/device/urDeviceGetNativeHandle.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ TEST_F(urDeviceGetNativeHandleTest, Success) {
1010
for (auto device : devices) {
1111
ur_native_handle_t native_handle = nullptr;
1212
ASSERT_SUCCESS(urDeviceGetNativeHandle(device, &native_handle));
13-
14-
// We cannot assume anything about a native_handle, not even if it's
15-
// `nullptr` since this could be a valid representation within a backend.
16-
// We can however convert the native_handle back into a unified-runtime handle
17-
// and perform some query on it to verify that it works.
18-
ur_device_handle_t dev = nullptr;
19-
ASSERT_SUCCESS(urDeviceCreateWithNativeHandle(native_handle, platform,
20-
nullptr, &dev));
21-
ASSERT_NE(dev, nullptr);
22-
23-
uint32_t dev_id = 0;
24-
ASSERT_SUCCESS(urDeviceGetInfo(dev, UR_DEVICE_INFO_TYPE,
25-
sizeof(uint32_t), &dev_id, nullptr));
2613
}
2714
}
2815

test/conformance/event/urEventCreateWithNativeHandle.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@
33
// See LICENSE.TXT
44
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6-
#include <uur/fixtures.h>
6+
#include "fixtures.h"
77

8-
using urEventCreateWithNativeHandleTest = uur::urContextTest;
8+
using urEventCreateWithNativeHandleTest = uur::event::urEventTest;
99
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEventCreateWithNativeHandleTest);
1010

11-
TEST_P(urEventCreateWithNativeHandleTest, InvalidNullHandleNativeEvent) {
12-
ur_event_handle_t event = nullptr;
13-
ASSERT_EQ_RESULT(
14-
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
15-
urEventCreateWithNativeHandle(nullptr, context, nullptr, &event));
11+
TEST_P(urEventCreateWithNativeHandleTest, Success) {
12+
ur_native_handle_t native_event = nullptr;
13+
ASSERT_SUCCESS(urEventGetNativeHandle(event, &native_event));
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 handle
18+
// and perform some query on it to verify that it works.
19+
ur_event_handle_t evt = nullptr;
20+
ASSERT_SUCCESS(
21+
urEventCreateWithNativeHandle(native_event, context, nullptr, &evt));
22+
ASSERT_NE(evt, nullptr);
23+
24+
ur_execution_info_t exec_info;
25+
ASSERT_SUCCESS(urEventGetInfo(evt, UR_EVENT_INFO_COMMAND_EXECUTION_STATUS,
26+
sizeof(ur_execution_info_t), &exec_info,
27+
nullptr));
28+
29+
ASSERT_SUCCESS(urEventRelease(evt));
1630
}

test/conformance/event/urEventGetNativeHandle.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEventGetNativeHandleTest);
1111
TEST_P(urEventGetNativeHandleTest, Success) {
1212
ur_native_handle_t native_event = nullptr;
1313
ASSERT_SUCCESS(urEventGetNativeHandle(event, &native_event));
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 handle
18-
// and perform some query on it to verify that it works.
19-
ur_event_handle_t evt = nullptr;
20-
ASSERT_SUCCESS(
21-
urEventCreateWithNativeHandle(native_event, context, nullptr, &evt));
22-
ASSERT_NE(evt, nullptr);
23-
24-
ur_execution_info_t exec_info;
25-
ASSERT_SUCCESS(urEventGetInfo(evt, UR_EVENT_INFO_COMMAND_EXECUTION_STATUS,
26-
sizeof(ur_execution_info_t), &exec_info,
27-
nullptr));
28-
29-
ASSERT_SUCCESS(urEventRelease(evt));
3014
}
3115

3216
TEST_P(urEventGetNativeHandleTest, InvalidNullHandleEvent) {

test/conformance/kernel/urKernelCreateWithNativeHandle.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullHandleProgram) {
5454
&properties, &native_kernel));
5555
}
5656

57-
TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullHandleNativeKernel) {
58-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
59-
urKernelCreateWithNativeHandle(nullptr, context, program,
60-
&properties,
61-
&native_kernel));
62-
}
63-
6457
TEST_P(urKernelCreateWithNativeHandleTest, InvalidNullPointerProperties) {
6558
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
6659
urKernelCreateWithNativeHandle(native_kernel_handle,

test/conformance/kernel/urKernelGetNativeHandle.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@ UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelGetNativeHandleTest);
1111
TEST_P(urKernelGetNativeHandleTest, Success) {
1212
ur_native_handle_t native_kernel_handle = nullptr;
1313
ASSERT_SUCCESS(urKernelGetNativeHandle(kernel, &native_kernel_handle));
14-
15-
ur_kernel_handle_t native_kernel = nullptr;
16-
17-
ur_kernel_native_properties_t properties = {
18-
UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES, /*sType*/
19-
nullptr, /*pNext*/
20-
true /*isNativeHandleOwned*/
21-
};
22-
ASSERT_SUCCESS(urKernelCreateWithNativeHandle(
23-
native_kernel_handle, context, program, &properties, &native_kernel));
24-
25-
uint32_t ref_count = 0;
26-
ASSERT_SUCCESS(urKernelGetInfo(native_kernel,
27-
UR_KERNEL_INFO_REFERENCE_COUNT,
28-
sizeof(ref_count), &ref_count, nullptr));
29-
ASSERT_NE(ref_count, 0);
30-
31-
ASSERT_SUCCESS(urKernelRelease(native_kernel));
3214
}
3315

3416
TEST_P(urKernelGetNativeHandleTest, InvalidNullHandleKernel) {

test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,27 @@
88
using urMemBufferCreateWithNativeHandleTest = uur::urMemBufferTest;
99
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateWithNativeHandleTest);
1010

11-
TEST_P(urMemBufferCreateWithNativeHandleTest, InvalidNullHandleNativeMem) {
11+
TEST_P(urMemBufferCreateWithNativeHandleTest, Success) {
12+
ur_native_handle_t hNativeMem = nullptr;
13+
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, &hNativeMem));
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 handle
18+
// and perform some query on it to verify that it works.
1219
ur_mem_handle_t mem = nullptr;
13-
ASSERT_EQ_RESULT(
14-
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
15-
urMemBufferCreateWithNativeHandle(nullptr, context, nullptr, &mem));
20+
ur_mem_native_properties_t props = {
21+
/*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
22+
/*.pNext =*/nullptr,
23+
/*.isNativeHandleOwned =*/false,
24+
};
25+
ASSERT_SUCCESS(
26+
urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem));
27+
ASSERT_NE(mem, nullptr);
28+
29+
size_t alloc_size = 0;
30+
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_SIZE, sizeof(size_t),
31+
&alloc_size, nullptr));
32+
33+
ASSERT_SUCCESS(urMemRelease(mem));
1634
}

test/conformance/memory/urMemGetNativeHandle.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemGetNativeHandleTest);
1010
TEST_P(urMemGetNativeHandleTest, Success) {
1111
ur_native_handle_t hNativeMem = nullptr;
1212
ASSERT_SUCCESS(urMemGetNativeHandle(buffer, &hNativeMem));
13-
14-
// We cannot assume anything about a native_handle, not even if it's
15-
// `nullptr` since this could be a valid representation within a backend.
16-
// We can however convert the native_handle back into a unified-runtime handle
17-
// and perform some query on it to verify that it works.
18-
ur_mem_handle_t mem = nullptr;
19-
ur_mem_native_properties_t props = {
20-
/*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES,
21-
/*.pNext =*/nullptr,
22-
/*.isNativeHandleOwned =*/false,
23-
};
24-
ASSERT_SUCCESS(
25-
urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem));
26-
ASSERT_NE(mem, nullptr);
27-
28-
size_t alloc_size = 0;
29-
ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_SIZE, sizeof(size_t),
30-
&alloc_size, nullptr));
31-
32-
ASSERT_SUCCESS(urMemRelease(mem));
3313
}
3414

3515
TEST_P(urMemGetNativeHandleTest, InvalidNullHandleMem) {

0 commit comments

Comments
 (0)