diff --git a/sycl/unittests/queue/Wait.cpp b/sycl/unittests/queue/Wait.cpp index 8765a06a0b2fd..8b2d72055d847 100644 --- a/sycl/unittests/queue/Wait.cpp +++ b/sycl/unittests/queue/Wait.cpp @@ -75,6 +75,13 @@ pi_result redefinedEventRelease(pi_event event) { return PI_SUCCESS; } +event submitTask(queue &Q, buffer &Buf) { + return Q.submit([&](handler &Cgh) { + auto Acc = Buf.template get_access(Cgh); + Cgh.fill(Acc, 42); + }); +} + TEST(QueueWait, QueueWaitTest) { sycl::unittest::PiMock Mock; sycl::platform Plt = Mock.getPlatform(); @@ -105,11 +112,8 @@ TEST(QueueWait, QueueWaitTest) { // Events with temporary ownership { TestContext = {}; - buffer buf{range<1>(1)}; - Q.submit([&](handler &Cgh) { - auto acc = buf.template get_access(Cgh); - Cgh.fill(acc, 42); - }); + buffer Buf{range<1>(1)}; + submitTask(Q, Buf); Q.wait(); // Still owned by the execution graph ASSERT_EQ(TestContext.EventReferenceCount, 1); @@ -120,37 +124,21 @@ TEST(QueueWait, QueueWaitTest) { // Blocked commands { TestContext = {}; - buffer buf{range<1>(1)}; - - std::mutex m; - std::unique_lock TestLock(m, std::defer_lock); - TestLock.lock(); - - event HostTaskEvent = Q.submit([&](handler &Cgh) { - auto acc = buf.template get_access(Cgh); - Cgh.host_task([=, &m]() { - (void)acc; - std::unique_lock InsideHostTaskLock(m); - }); - }); - std::shared_ptr HostTaskEventImpl = - detail::getSyclObjImpl(HostTaskEvent); - auto *Cmd = static_cast(HostTaskEventImpl->getCommand()); - EXPECT_EQ(Cmd->MUsers.size(), 0u); - EXPECT_TRUE(Cmd->isHostTask()); - - // Use the host task to block the next commands - Q.submit([&](handler &Cgh) { - auto acc = buf.template get_access(Cgh); - Cgh.fill(acc, 42); - }); - Q.submit([&](handler &Cgh) { - auto acc = buf.template get_access(Cgh); - Cgh.fill(acc, 42); - }); - // Unblock the host task to allow the submitted events to complete once - // enqueued. - TestLock.unlock(); + buffer Buf{range<1>(1)}; + + event DepEvent = submitTask(Q, Buf); + + // Manually block the next commands. + std::shared_ptr DepEventImpl = + detail::getSyclObjImpl(DepEvent); + auto *Cmd = static_cast(DepEventImpl->getCommand()); + Cmd->MIsBlockable = true; + Cmd->MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; + + submitTask(Q, Buf); + submitTask(Q, Buf); + + Cmd->MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueSuccess; Q.wait(); // Only a single event (the last one) should be waited for here. ASSERT_EQ(TestContext.NEventsWaitedFor, 1);