Skip to content

Commit 7541da3

Browse files
committed
Adding missing Offload unit tests for event entry points
1 parent d775b91 commit 7541da3

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct ol_queue_impl_t {
6969
struct ol_event_impl_t {
7070
ol_event_impl_t(void *EventInfo, ol_queue_handle_t Queue)
7171
: EventInfo(EventInfo), Queue(Queue) {}
72-
~ol_event_impl_t() { (void)Queue->Device->Device->destroyEvent(EventInfo); }
7372
void *EventInfo;
7473
ol_queue_handle_t Queue;
7574
};
@@ -378,6 +377,10 @@ ol_impl_result_t olWaitEvent_impl(ol_event_handle_t Event) {
378377
}
379378

380379
ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
380+
auto Res = Event->Queue->Device->Device->destroyEvent(Event->EventInfo);
381+
if (Res)
382+
return {OL_ERRC_INVALID_EVENT, "The event could not be destroyed"};
383+
381384
return olDestroy(Event);
382385
}
383386

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ add_libompt_unittest("offload.unittests"
2121
${CMAKE_CURRENT_SOURCE_DIR}/program/olDestroyProgram.cpp
2222
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olGetKernel.cpp
2323
${CMAKE_CURRENT_SOURCE_DIR}/kernel/olLaunchKernel.cpp
24+
${CMAKE_CURRENT_SOURCE_DIR}/event/olDestroyEvent.cpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/event/olWaitEvent.cpp
2426
)
2527
add_dependencies("offload.unittests" ${PLUGINS_TEST_COMMON} LibomptUnitTestsDeviceBins)
2628
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===------- Offload API tests - olDestroyEvent ---------------------------===//
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 "../common/Fixtures.hpp"
10+
#include <OffloadAPI.h>
11+
#include <gtest/gtest.h>
12+
13+
using olDestroyEventTest = OffloadQueueTest;
14+
15+
TEST_F(olDestroyEventTest, Success) {
16+
uint32_t Src = 42;
17+
void *DstPtr;
18+
19+
ol_event_handle_t Event = nullptr;
20+
ASSERT_SUCCESS(
21+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
22+
ASSERT_SUCCESS(
23+
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
24+
ASSERT_NE(Event, nullptr);
25+
ASSERT_SUCCESS(olWaitQueue(Queue));
26+
ASSERT_SUCCESS(olDestroyEvent(Event));
27+
}
28+
29+
TEST_F(olDestroyEventTest, InvalidNullEvent) {
30+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyEvent(nullptr));
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===------- Offload API tests - olWaitEvent -====-------------------------===//
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 "../common/Fixtures.hpp"
10+
#include <OffloadAPI.h>
11+
#include <gtest/gtest.h>
12+
13+
using olWaitEventTest = OffloadQueueTest;
14+
15+
TEST_F(olWaitEventTest, Success) {
16+
uint32_t Src = 42;
17+
void *DstPtr;
18+
19+
ol_event_handle_t Event = nullptr;
20+
ASSERT_SUCCESS(
21+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
22+
ASSERT_SUCCESS(
23+
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
24+
ASSERT_NE(Event, nullptr);
25+
ASSERT_SUCCESS(olWaitEvent(Event));
26+
ASSERT_SUCCESS(olDestroyEvent(Event));
27+
}
28+
29+
TEST_F(olWaitEventTest, InvalidNullEvent) {
30+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr));
31+
}

0 commit comments

Comments
 (0)