Skip to content

Commit

Permalink
Fix successWithNativeHandle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Oct 9, 2024
1 parent 0112320 commit 65dd776
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
ur_context_handle_t *phContext) {

*phContext = reinterpret_cast<ur_context_handle_t>(hNativeContext);
CL_RETURN_ON_FAILURE(
clRetainContext(reinterpret_cast<cl_context>(hNativeContext)));
if (!pProperties || !pProperties->isNativeHandleOwned) {
return urContextRetain(*phContext);
}
Expand Down
2 changes: 2 additions & 0 deletions test/conformance/context/context_adapter_opencl.match
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
urContextCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urContextCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
23 changes: 12 additions & 11 deletions test/conformance/context/urContextCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "uur/environment.h"
#include "uur/raii.h"
#include <uur/fixtures.h>

using urContextCreateWithNativeHandleTest = uur::urContextTest;
Expand Down Expand Up @@ -40,15 +41,16 @@ TEST_P(urContextCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
urContextGetNativeHandle(context, &native_context));
}

ur_context_handle_t ctx = nullptr;
uur::raii::Context hContext = nullptr;
ur_context_native_properties_t props{
UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES, nullptr, true};
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urContextCreateWithNativeHandle(
native_context, adapter, 1, &device, &props, &ctx));
ASSERT_NE(ctx, nullptr);
native_context, adapter, 1, &device, &props, hContext.ptr()));
ASSERT_NE(hContext, nullptr);

uint32_t ref_count = 0;
ASSERT_SUCCESS(urContextGetInfo(ctx, UR_CONTEXT_INFO_REFERENCE_COUNT,
ASSERT_SUCCESS(urContextGetInfo(hContext.handle,
UR_CONTEXT_INFO_REFERENCE_COUNT,
sizeof(uint32_t), &ref_count, nullptr));
ASSERT_EQ(ref_count, 1);
}
Expand All @@ -60,19 +62,18 @@ TEST_P(urContextCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
urContextGetNativeHandle(context, &native_context));
}

ur_context_handle_t ctx = nullptr;
uur::raii::Context hContext = nullptr;
ur_context_native_properties_t props{
UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES, nullptr, false};
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(urContextCreateWithNativeHandle(
native_context, adapter, 1, &device, &props, &ctx));
ASSERT_NE(ctx, nullptr);
native_context, adapter, 1, &device, &props, hContext.ptr()));
ASSERT_NE(hContext, nullptr);

uint32_t ref_count = 0;
ASSERT_SUCCESS(urContextGetInfo(ctx, UR_CONTEXT_INFO_REFERENCE_COUNT,
ASSERT_SUCCESS(urContextGetInfo(hContext.handle,
UR_CONTEXT_INFO_REFERENCE_COUNT,
sizeof(uint32_t), &ref_count, nullptr));
ASSERT_EQ(ref_count, 2);

ASSERT_SUCCESS(urContextRelease(ctx));
ASSERT_EQ(ref_count, 1);
}

TEST_P(urContextCreateWithNativeHandleTest, InvalidNullHandleAdapter) {
Expand Down
4 changes: 3 additions & 1 deletion test/conformance/device/urDeviceCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ TEST_F(urDeviceCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
sizeof(uint32_t), &ref_count, nullptr));

ASSERT_EQ(ref_count, 1);
ASSERT_SUCCESS(urDeviceRelease(dev));
}
}

Expand All @@ -71,7 +72,8 @@ TEST_F(urDeviceCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
ASSERT_SUCCESS(urDeviceGetInfo(dev, UR_DEVICE_INFO_REFERENCE_COUNT,
sizeof(uint32_t), &ref_count, nullptr));

ASSERT_EQ(ref_count, 2);
ASSERT_EQ(ref_count, 1);
ASSERT_SUCCESS(urDeviceRelease(dev));
}
}

Expand Down

0 comments on commit 65dd776

Please sign in to comment.