Skip to content

Commit 8f0b9b6

Browse files
committed
[SYCL] Add unittest
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 8055c91 commit 8f0b9b6

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

sycl/unittests/pi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_sycl_unittest(PiTests OBJECT
77
PiMock.cpp
88
PlatformTest.cpp
99
pi_arguments_handler.cpp
10+
piInteropRetain.cpp
1011
)
1112

1213
add_dependencies(PiTests sycl)

sycl/unittests/pi/piInteropRetain.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//==--------------------- Wait.cpp --- queue unit tests --------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <CL/opencl.h>
10+
#include <CL/sycl.hpp>
11+
#include <CL/sycl/backend/opencl.hpp>
12+
13+
#include <gtest/gtest.h>
14+
#include <helpers/PiMock.hpp>
15+
#include <detail/queue_impl.hpp>
16+
17+
namespace {
18+
using namespace cl::sycl;
19+
20+
static bool QueueRetainCalled;
21+
pi_result unexpectedQueueRetain(pi_queue Queue) { return PI_INVALID_QUEUE; }
22+
pi_result expectedQueueRetain(pi_queue Queue) { QueueRetainCalled = true; return PI_SUCCESS; }
23+
24+
bool preparePiMock(platform &Plt) {
25+
if (Plt.is_host()) {
26+
std::cout << "Not run on host - no PI events created in that case"
27+
<< std::endl;
28+
return false;
29+
}
30+
if (detail::getSyclObjImpl(Plt)->getPlugin().getBackend() !=
31+
backend::opencl) {
32+
std::cout << "Not run on non-OpenCL backend"
33+
<< std::endl;
34+
return false;
35+
}
36+
return true;
37+
}
38+
39+
TEST(PiInteropTest, CheckRetain) {
40+
platform Plt{default_selector()};
41+
if (!preparePiMock(Plt))
42+
return;
43+
context Ctx{Plt.get_devices()[0]};
44+
45+
unittest::PiMock Mock{Plt};
46+
47+
// The queue construction should not call to piQueueRetain. Instead piQueueCreate should return the "retained" queue.
48+
QueueRetainCalled = false;
49+
Mock.redefine<detail::PiApiKind::piQueueRetain>(unexpectedQueueRetain);
50+
queue Q{Ctx, default_selector()};
51+
EXPECT_FALSE(QueueRetainCalled);
52+
53+
QueueRetainCalled = false;
54+
Mock.redefine<detail::PiApiKind::piQueueRetain>(expectedQueueRetain);
55+
cl_command_queue OCLQ = get_native<backend::opencl>(Q);
56+
EXPECT_TRUE(QueueRetainCalled);
57+
58+
// The make_queue should not call to piQueueRetain. The piextCreateQueueWithNative handle should do the "retain" if needed.
59+
QueueRetainCalled = false;
60+
Mock.redefine<detail::PiApiKind::piQueueRetain>(unexpectedQueueRetain);
61+
queue Q1 = make_queue<backend::opencl>(OCLQ, Ctx);
62+
EXPECT_FALSE(QueueRetainCalled);
63+
}
64+
65+
} // namespace

0 commit comments

Comments
 (0)