Skip to content

Commit 7bc16a0

Browse files
authored
[Offload] Adding missing Offload unit tests for event entry points (#137315)
A couple of liboffload entry points were missed out from the tests, and unsurprisingly a crash in one of them made it in. Add the tests and fix the unchecked error in `olDestroyEvent`.
1 parent 7495f92 commit 7bc16a0

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-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
};
@@ -381,6 +380,10 @@ ol_impl_result_t olWaitEvent_impl(ol_event_handle_t Event) {
381380
}
382381

383382
ol_impl_result_t olDestroyEvent_impl(ol_event_handle_t Event) {
383+
auto Res = Event->Queue->Device->Device->destroyEvent(Event->EventInfo);
384+
if (Res)
385+
return {OL_ERRC_INVALID_EVENT, "The event could not be destroyed"};
386+
384387
return olDestroy(Event);
385388
}
386389

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ add_offload_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} OffloadUnitTestsDeviceBins)
2628
target_compile_definitions("offload.unittests" PRIVATE DEVICE_CODE_PATH="${OFFLOAD_TEST_DEVICE_CODE_PATH}")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olDestroyEventTest);
15+
16+
TEST_P(olDestroyEventTest, Success) {
17+
uint32_t Src = 42;
18+
void *DstPtr;
19+
20+
ol_event_handle_t Event = nullptr;
21+
ASSERT_SUCCESS(
22+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
23+
ASSERT_SUCCESS(
24+
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
25+
ASSERT_NE(Event, nullptr);
26+
ASSERT_SUCCESS(olWaitQueue(Queue));
27+
ASSERT_SUCCESS(olDestroyEvent(Event));
28+
}
29+
30+
TEST_P(olDestroyEventTest, InvalidNullEvent) {
31+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olDestroyEvent(nullptr));
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olWaitEventTest);
15+
16+
TEST_P(olWaitEventTest, Success) {
17+
uint32_t Src = 42;
18+
void *DstPtr;
19+
20+
ol_event_handle_t Event = nullptr;
21+
ASSERT_SUCCESS(
22+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(uint32_t), &DstPtr));
23+
ASSERT_SUCCESS(
24+
olMemcpy(Queue, DstPtr, Device, &Src, Host, sizeof(Src), &Event));
25+
ASSERT_NE(Event, nullptr);
26+
ASSERT_SUCCESS(olWaitEvent(Event));
27+
ASSERT_SUCCESS(olDestroyEvent(Event));
28+
}
29+
30+
TEST_P(olWaitEventTest, InvalidNullEvent) {
31+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, olWaitEvent(nullptr));
32+
}

0 commit comments

Comments
 (0)