| 
 | 1 | +//==------------------------- GetLastEvent.cpp -----------------------------==//  | 
 | 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 | +// Tests the behavior of queue::ext_oneapi_get_last_event.  | 
 | 9 | + | 
 | 10 | +#include <detail/event_impl.hpp>  | 
 | 11 | +#include <gtest/gtest.h>  | 
 | 12 | +#include <helpers/TestKernel.hpp>  | 
 | 13 | +#include <helpers/UrMock.hpp>  | 
 | 14 | +#include <sycl/ext/oneapi/experimental/enqueue_functions.hpp>  | 
 | 15 | +#include <sycl/properties/queue_properties.hpp>  | 
 | 16 | +#include <sycl/queue.hpp>  | 
 | 17 | + | 
 | 18 | +using namespace sycl;  | 
 | 19 | + | 
 | 20 | +thread_local ur_event_handle_t MarkerEventLatest = nullptr;  | 
 | 21 | +static ur_result_t redefinedEnqueueEventsWaitAfter(void *pParams) {  | 
 | 22 | +  auto params = *static_cast<ur_enqueue_events_wait_params_t *>(pParams);  | 
 | 23 | +  MarkerEventLatest = **(params.pphEvent);  | 
 | 24 | +  return UR_RESULT_SUCCESS;  | 
 | 25 | +}  | 
 | 26 | +static ur_result_t redefinedEventRelease(void *) { return UR_RESULT_SUCCESS; }  | 
 | 27 | + | 
 | 28 | +TEST(GetLastEventEmptyQueue, CheckEmptyQueueLastEvent) {  | 
 | 29 | +  unittest::UrMock<> Mock;  | 
 | 30 | +  platform Plt = sycl::platform();  | 
 | 31 | + | 
 | 32 | +  MarkerEventLatest = nullptr;  | 
 | 33 | +  mock::getCallbacks().set_after_callback("urEnqueueEventsWait",  | 
 | 34 | +                                          &redefinedEnqueueEventsWaitAfter);  | 
 | 35 | +  mock::getCallbacks().set_before_callback("urEventRelease",  | 
 | 36 | +                                           &redefinedEventRelease);  | 
 | 37 | + | 
 | 38 | +  queue Q{property::queue::in_order{}};  | 
 | 39 | +  event E = Q.ext_oneapi_get_last_event();  | 
 | 40 | +  ur_event_handle_t UREvent = detail::getSyclObjImpl(E)->getHandle();  | 
 | 41 | +  ASSERT_NE(MarkerEventLatest, ur_event_handle_t{nullptr});  | 
 | 42 | +  ASSERT_EQ(UREvent, MarkerEventLatest);  | 
 | 43 | +}  | 
 | 44 | + | 
 | 45 | +TEST(GetLastEventEmptyQueue, CheckEventlessWorkQueue) {  | 
 | 46 | +  unittest::UrMock<> Mock;  | 
 | 47 | +  platform Plt = sycl::platform();  | 
 | 48 | + | 
 | 49 | +  MarkerEventLatest = nullptr;  | 
 | 50 | +  mock::getCallbacks().set_after_callback("urEnqueueEventsWait",  | 
 | 51 | +                                          &redefinedEnqueueEventsWaitAfter);  | 
 | 52 | +  mock::getCallbacks().set_before_callback("urEventRelease",  | 
 | 53 | +                                           &redefinedEventRelease);  | 
 | 54 | + | 
 | 55 | +  queue Q{property::queue::in_order{}};  | 
 | 56 | + | 
 | 57 | +  // The following single_task does not return an event, so it is expected that  | 
 | 58 | +  // the last event query creates a new marker event.  | 
 | 59 | +  sycl::ext::oneapi::experimental::single_task<TestKernel<>>(Q, []() {});  | 
 | 60 | +  event E = Q.ext_oneapi_get_last_event();  | 
 | 61 | +  ur_event_handle_t UREvent = detail::getSyclObjImpl(E)->getHandle();  | 
 | 62 | +  ASSERT_NE(MarkerEventLatest, ur_event_handle_t{nullptr});  | 
 | 63 | +  ASSERT_EQ(UREvent, MarkerEventLatest);  | 
 | 64 | +}  | 
0 commit comments