Skip to content

Commit 97961a0

Browse files
authored
[SYCL] Fix post-commit failures (#7258)
1. Replaced assert with EXPECT_EQ to avoid unused variable error 2. Fully reset PI mock functions 3. Update new test to use new PI mock utility API
1 parent 5d0d4ef commit 97961a0

File tree

7 files changed

+17
-50
lines changed

7 files changed

+17
-50
lines changed

sycl/unittests/assert/assert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static pi_result redefinedKernelGetInfo(pi_kernel Kernel,
290290
pi_program PIProgram = nullptr;
291291
pi_result Res = mock_piProgramCreate(/*pi_context=*/0x0, /**il*/ nullptr,
292292
/*length=*/0, &PIProgram);
293-
assert(PI_SUCCESS == Res);
293+
EXPECT_TRUE(PI_SUCCESS == Res);
294294

295295
if (ParamValue)
296296
memcpy(ParamValue, &PIProgram, sizeof(PIProgram));
@@ -553,7 +553,7 @@ TEST(Assert, TestInteropKernelNegative) {
553553

554554
pi_result Res = mock_piKernelCreate(
555555
/*pi_program=*/0x0, /*kernel_name=*/"dummy_kernel", &PIKernel);
556-
assert(PI_SUCCESS == Res);
556+
EXPECT_TRUE(PI_SUCCESS == Res);
557557

558558
// TODO use make_kernel. This requires a fix in backend.cpp to get plugin
559559
// from context instead of free getPlugin to alllow for mocking of its methods

sycl/unittests/helpers/PiMock.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ inline void clearRedefinedCalls() {
139139
for (size_t I = 0; I < CallStackSize; ++I) {
140140
#define _PI_API(api) \
141141
CallBefore_##api[I] = nullptr; \
142+
CallOriginal_##api = mock_##api; \
142143
CallAfter_##api[I] = nullptr;
143144
#include <sycl/detail/pi.def>
144145
#undef _PI_API

sycl/unittests/queue/DeviceCheck.cpp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ namespace {
2020
inline constexpr auto EnableDefaultContextsName =
2121
"SYCL_ENABLE_DEFAULT_CONTEXTS";
2222

23-
pi_result redefinedContextCreate(const pi_context_properties *properties,
24-
pi_uint32 num_devices,
25-
const pi_device *devices,
26-
void (*pfn_notify)(const char *errinfo,
27-
const void *private_info,
28-
size_t cb, void *user_data),
29-
void *user_data, pi_context *ret_context) {
30-
*ret_context = reinterpret_cast<pi_context>(1);
31-
return PI_SUCCESS;
32-
}
33-
34-
pi_result redefinedContextRelease(pi_context context) { return PI_SUCCESS; }
35-
3623
pi_device ParentDevice = nullptr;
3724
pi_platform PiPlatform = nullptr;
3825

@@ -66,7 +53,7 @@ pi_result redefinedDeviceGetInfoAfter(pi_device device,
6653
return PI_SUCCESS;
6754
}
6855

69-
pi_result redefinedDevicePartition(
56+
pi_result redefinedDevicePartitionAfter(
7057
pi_device device, const pi_device_partition_property *properties,
7158
pi_uint32 num_devices, pi_device *out_devices, pi_uint32 *out_num_devices) {
7259
if (out_devices) {
@@ -79,18 +66,6 @@ pi_result redefinedDevicePartition(
7966
return PI_SUCCESS;
8067
}
8168

82-
pi_result redefinedDeviceRetain(pi_device device) { return PI_SUCCESS; }
83-
84-
pi_result redefinedDeviceRelease(pi_device device) { return PI_SUCCESS; }
85-
86-
pi_result redefinedQueueCreate(pi_context context, pi_device device,
87-
pi_queue_properties properties,
88-
pi_queue *queue) {
89-
return PI_SUCCESS;
90-
}
91-
92-
pi_result redefinedQueueRelease(pi_queue queue) { return PI_SUCCESS; }
93-
9469
// Check that the device is verified to be either a member of the context or a
9570
// descendant of its member.
9671
TEST(QueueDeviceCheck, CheckDeviceRestriction) {
@@ -105,19 +80,10 @@ TEST(QueueDeviceCheck, CheckDeviceRestriction) {
10580
context DefaultCtx = Plt.ext_oneapi_get_default_context();
10681
device Dev = DefaultCtx.get_devices()[0];
10782

108-
Mock.redefineBefore<detail::PiApiKind::piContextCreate>(
109-
redefinedContextCreate);
110-
Mock.redefineBefore<detail::PiApiKind::piContextRelease>(
111-
redefinedContextRelease);
11283
Mock.redefineAfter<detail::PiApiKind::piDeviceGetInfo>(
11384
redefinedDeviceGetInfoAfter);
114-
Mock.redefineBefore<detail::PiApiKind::piDevicePartition>(
115-
redefinedDevicePartition);
116-
Mock.redefineBefore<detail::PiApiKind::piDeviceRelease>(
117-
redefinedDeviceRelease);
118-
Mock.redefineBefore<detail::PiApiKind::piDeviceRetain>(redefinedDeviceRetain);
119-
Mock.redefineBefore<detail::PiApiKind::piQueueCreate>(redefinedQueueCreate);
120-
Mock.redefineBefore<detail::PiApiKind::piQueueRelease>(redefinedQueueRelease);
85+
Mock.redefineAfter<detail::PiApiKind::piDevicePartition>(
86+
redefinedDevicePartitionAfter);
12187

12288
// Device is a member of the context.
12389
{

sycl/unittests/scheduler/Commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST_F(SchedulerTest, WaitEmptyEventWithBarrier) {
6565

6666
pi_event PIEvent = nullptr;
6767
pi_result Res = mock_piEventCreate(/*context = */ (pi_context)0x1, &PIEvent);
68-
assert(PI_SUCCESS == Res);
68+
EXPECT_TRUE(PI_SUCCESS == Res);
6969

7070
auto Event =
7171
std::make_shared<detail::event_impl>(PIEvent, Queue.get_context());

sycl/unittests/scheduler/CommandsWaitForEvents.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ struct TestCtx {
3434
Ctx2{detail::getSyclObjImpl(Q2.get_context())} {
3535

3636
pi_result Res = mock_piEventCreate((pi_context)0x0, &EventCtx1);
37-
assert(PI_SUCCESS == Res);
37+
EXPECT_TRUE(PI_SUCCESS == Res);
3838

3939
Res = mock_piEventCreate((pi_context)0x0, &EventCtx2);
40-
assert(PI_SUCCESS == Res);
40+
EXPECT_TRUE(PI_SUCCESS == Res);
4141
}
4242
};
4343

sycl/unittests/scheduler/NoHostUnifiedMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) {
205205
pi_result PIRes = mock_piMemBufferCreate(
206206
/*pi_context=*/0x0, /*pi_mem_flags=*/PI_MEM_FLAGS_ACCESS_RW, /*size=*/1,
207207
/*host_ptr=*/nullptr, &MockInteropBuffer);
208-
assert(PI_SUCCESS == PIRes);
208+
EXPECT_TRUE(PI_SUCCESS == PIRes);
209209

210210
context InteropContext = Q.get_context();
211211
InteropPiContext = detail::getSyclObjImpl(InteropContext)->getHandleRef();

sycl/unittests/scheduler/QueueFlushing.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void addDepAndEnqueue(detail::Command *Cmd,
5454

5555
pi_event PIEvent = nullptr;
5656
pi_result CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
57-
assert(PI_SUCCESS == CallRet);
57+
EXPECT_TRUE(PI_SUCCESS == CallRet);
5858

5959
DepCmd.getEvent()->getHandleRef() = PIEvent;
6060
(void)Cmd->addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp);
@@ -104,7 +104,7 @@ TEST_F(SchedulerTest, QueueFlushing) {
104104
pi_result Ret = mock_piMemBufferCreate(/*pi_context=*/0x0,
105105
PI_MEM_FLAGS_ACCESS_RW, /*size=*/1,
106106
/*host_ptr=*/nullptr, &PIBuf);
107-
assert(Ret == PI_SUCCESS);
107+
EXPECT_TRUE(Ret == PI_SUCCESS);
108108

109109
detail::AllocaCommand AllocaCmd = detail::AllocaCommand(QueueImplA, MockReq);
110110
AllocaCmd.MMemAllocation = PIBuf;
@@ -162,7 +162,7 @@ TEST_F(SchedulerTest, QueueFlushing) {
162162

163163
pi_event PIEvent = nullptr;
164164
pi_result CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
165-
assert(PI_SUCCESS == CallRet);
165+
EXPECT_TRUE(PI_SUCCESS == CallRet);
166166

167167
DepEvent->getHandleRef() = PIEvent;
168168
(void)Cmd.addDep(DepEvent, ToCleanUp);
@@ -184,7 +184,7 @@ TEST_F(SchedulerTest, QueueFlushing) {
184184

185185
pi_event PIEvent = nullptr;
186186
pi_result CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
187-
assert(PI_SUCCESS == CallRet);
187+
EXPECT_TRUE(PI_SUCCESS == CallRet);
188188

189189
DepEvent->getHandleRef() = PIEvent;
190190
}
@@ -210,15 +210,15 @@ TEST_F(SchedulerTest, QueueFlushing) {
210210

211211
pi_event PIEvent = nullptr;
212212
pi_result CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
213-
assert(PI_SUCCESS == CallRet);
213+
EXPECT_TRUE(PI_SUCCESS == CallRet);
214214

215215
DepCmdA.getEvent()->getHandleRef() = PIEvent;
216216
(void)Cmd.addDep(detail::DepDesc{&DepCmdA, &MockReq, nullptr}, ToCleanUp);
217217
MockCommand DepCmdB(QueueImplB);
218218

219219
PIEvent = nullptr;
220220
CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
221-
assert(PI_SUCCESS == CallRet);
221+
EXPECT_TRUE(PI_SUCCESS == CallRet);
222222

223223
DepCmdB.getEvent()->getHandleRef() = PIEvent;
224224
(void)Cmd.addDep(detail::DepDesc{&DepCmdB, &MockReq, nullptr}, ToCleanUp);
@@ -235,7 +235,7 @@ TEST_F(SchedulerTest, QueueFlushing) {
235235

236236
pi_event PIEvent = nullptr;
237237
pi_result CallRet = mock_piEventCreate(/*pi_context=*/0x0, &PIEvent);
238-
assert(PI_SUCCESS == CallRet);
238+
EXPECT_TRUE(PI_SUCCESS == CallRet);
239239

240240
DepCmd.getEvent()->getHandleRef() = PIEvent;
241241
(void)CmdA.addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp);

0 commit comments

Comments
 (0)