Skip to content

[Offload] Adding missing Offload unit tests for event entry points #137315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion offload/liboffload/src/OffloadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ struct ol_queue_impl_t {
struct ol_event_impl_t {
ol_event_impl_t(void *EventInfo, ol_queue_handle_t Queue)
: EventInfo(EventInfo), Queue(Queue) {}
~ol_event_impl_t() { (void)Queue->Device->Device->destroyEvent(EventInfo); }
void *EventInfo;
ol_queue_handle_t Queue;
};
Expand Down Expand Up @@ -381,6 +380,10 @@ ol_impl_result_t olWaitEvent_impl(ol_event_handle_t Event) {
}

ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
auto Res = Event->Queue->Device->Device->destroyEvent(Event->EventInfo);
if (Res)
return {OL_ERRC_INVALID_EVENT, "The event could not be destroyed"};

return olDestroy(Event);
}

Expand Down
2 changes: 2 additions & 0 deletions offload/unittests/OffloadAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ add_offload_unittest("offload.unittests"
${CMAKE_CURRENT_SOURCE_DIR}/program/olDestroyProgram.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/event/olDestroyEvent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/event/olWaitEvent.cpp
)
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} OffloadUnitTestsDeviceBins)
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
Expand Down
32 changes: 32 additions & 0 deletions offload/unittests/OffloadAPI/event/olDestroyEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===------- Offload API tests - olDestroyEvent ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "../common/Fixtures.hpp"
#include <OffloadAPI.h>
#include <gtest/gtest.h>

using olDestroyEventTest = OffloadQueueTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyEventTest);

TEST_P(olDestroyEventTest, Success) {
uint32_t Src = 42;
void *DstPtr;

ol_event_handle_t Event = nullptr;
ASSERT_SUCCESS(
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
ASSERT_SUCCESS(
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
ASSERT_NE(Event, nullptr);
ASSERT_SUCCESS(olWaitQueue(Queue));
ASSERT_SUCCESS(olDestroyEvent(Event));
}

TEST_P(olDestroyEventTest, InvalidNullEvent) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyEvent(nullptr));
}
32 changes: 32 additions & 0 deletions offload/unittests/OffloadAPI/event/olWaitEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===------- Offload API tests - olWaitEvent -====-------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "../common/Fixtures.hpp"
#include <OffloadAPI.h>
#include <gtest/gtest.h>

using olWaitEventTest = OffloadQueueTest;
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olWaitEventTest);

TEST_P(olWaitEventTest, Success) {
uint32_t Src = 42;
void *DstPtr;

ol_event_handle_t Event = nullptr;
ASSERT_SUCCESS(
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
ASSERT_SUCCESS(
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
ASSERT_NE(Event, nullptr);
ASSERT_SUCCESS(olWaitEvent(Event));
ASSERT_SUCCESS(olDestroyEvent(Event));
}

TEST_P(olWaitEventTest, InvalidNullEvent) {
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr));
}
Loading