@@ -10,8 +10,9 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urContextCreateWithNativeHandleTest);
1010
1111TEST_P (urContextCreateWithNativeHandleTest, Success) {
1212 ur_native_handle_t native_context = nullptr ;
13- if (urContextGetNativeHandle (context, &native_context)) {
14- GTEST_SKIP ();
13+ {
14+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (
15+ urContextGetNativeHandle (context, &native_context));
1516 }
1617
1718 // We cannot assume anything about a native_handle, not even if it's
@@ -20,8 +21,8 @@ TEST_P(urContextCreateWithNativeHandleTest, Success) {
2021 // and perform some query on it to verify that it works.
2122 ur_context_handle_t ctx = nullptr ;
2223 ur_context_native_properties_t props{};
23- ASSERT_SUCCESS (urContextCreateWithNativeHandle (native_context, 1 , &device,
24- &props, &ctx));
24+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (urContextCreateWithNativeHandle (
25+ native_context, 1 , &device, &props, &ctx));
2526 ASSERT_NE (ctx, nullptr );
2627
2728 uint32_t n_devices = 0 ;
@@ -30,3 +31,64 @@ TEST_P(urContextCreateWithNativeHandleTest, Success) {
3031
3132 ASSERT_SUCCESS (urContextRelease (ctx));
3233}
34+
35+ TEST_P (urContextCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
36+ ur_native_handle_t native_context = nullptr ;
37+ {
38+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (
39+ urContextGetNativeHandle (context, &native_context));
40+ }
41+
42+ ur_context_handle_t ctx = nullptr ;
43+ ur_context_native_properties_t props{
44+ UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES, nullptr , true };
45+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (urContextCreateWithNativeHandle (
46+ native_context, 1 , &device, &props, &ctx));
47+ ASSERT_NE (ctx, nullptr );
48+
49+ uint32_t ref_count = 0 ;
50+ ASSERT_SUCCESS (urContextGetInfo (ctx, UR_CONTEXT_INFO_REFERENCE_COUNT,
51+ sizeof (uint32_t ), &ref_count, nullptr ));
52+ ASSERT_EQ (ref_count, 1 );
53+ }
54+
55+ TEST_P (urContextCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
56+ ur_native_handle_t native_context = nullptr ;
57+ {
58+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (
59+ urContextGetNativeHandle (context, &native_context));
60+ }
61+
62+ ur_context_handle_t ctx = nullptr ;
63+ ur_context_native_properties_t props{
64+ UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES, nullptr , false };
65+ UUR_ASSERT_SUCCESS_OR_UNSUPPORTED (urContextCreateWithNativeHandle (
66+ native_context, 1 , &device, &props, &ctx));
67+ ASSERT_NE (ctx, nullptr );
68+
69+ uint32_t ref_count = 0 ;
70+ ASSERT_SUCCESS (urContextGetInfo (ctx, UR_CONTEXT_INFO_REFERENCE_COUNT,
71+ sizeof (uint32_t ), &ref_count, nullptr ));
72+ ASSERT_EQ (ref_count, 2 );
73+
74+ ASSERT_SUCCESS (urContextRelease (ctx));
75+ }
76+
77+ TEST_P (urContextCreateWithNativeHandleTest, InvalidNullPointerDevices) {
78+ ur_native_handle_t native_context = nullptr ;
79+ ASSERT_SUCCESS (urContextGetNativeHandle (context, &native_context));
80+
81+ ur_context_handle_t ctx = nullptr ;
82+ ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_POINTER,
83+ urContextCreateWithNativeHandle (native_context, 1 , nullptr ,
84+ nullptr , &ctx));
85+ }
86+
87+ TEST_P (urContextCreateWithNativeHandleTest, InvalidNullPointerContext) {
88+ ur_native_handle_t native_context = nullptr ;
89+ ASSERT_SUCCESS (urContextGetNativeHandle (context, &native_context));
90+
91+ ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_NULL_POINTER,
92+ urContextCreateWithNativeHandle (native_context, 1 , &device,
93+ nullptr , nullptr ));
94+ }
0 commit comments