| 1 |
//===------- Offload API tests - olMemRegister ----------------------------===// |
| 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 olMemRegisterTest = OffloadDeviceTest; |
| 14 |
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olMemRegisterTest); |
| 15 |
|
| 16 |
TEST_P(olMemRegisterTest, SuccessRegister) { |
| 17 |
int Arr[50]; |
| 18 |
ol_memory_register_flags_t Flags = {}; |
| 19 |
void *PinnedPtr = nullptr; |
| 20 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr)); |
| 21 |
ASSERT_NE(PinnedPtr, nullptr); |
| 22 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr)); |
| 23 |
} |
| 24 |
|
| 25 |
TEST_P(olMemRegisterTest, SuccessMultipleRegister) { |
| 26 |
int Arr[50]; |
| 27 |
ol_memory_register_flags_t Flags = {}; |
| 28 |
void *PinnedPtr = nullptr; |
| 29 |
void *PinnedPtr1 = nullptr; |
| 30 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr)); |
| 31 |
ASSERT_NE(PinnedPtr, nullptr); |
| 32 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr1)); |
| 33 |
ASSERT_NE(PinnedPtr1, nullptr); |
| 34 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr)); |
| 35 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr1)); |
| 36 |
} |
| 37 |
|
| 38 |
TEST_P(olMemRegisterTest, InvalidSizeRegister) { |
| 39 |
int Arr[50]; |
| 40 |
ol_memory_register_flags_t Flags = {}; |
| 41 |
void *PinnedPtr = nullptr; |
| 42 |
ASSERT_ERROR(OL_ERRC_INVALID_SIZE, |
| 43 |
olMemRegister(Device, Arr, 0, Flags, &PinnedPtr)); |
| 44 |
} |
| 45 |
|
| 46 |
TEST_P(olMemRegisterTest, InvalidPtrRegister) { |
| 47 |
int Arr[50]; |
| 48 |
ol_memory_register_flags_t Flags = {}; |
| 49 |
void *PinnedPtr = nullptr; |
| 50 |
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, |
| 51 |
olMemRegister(Device, nullptr, sizeof(Arr), Flags, &PinnedPtr)); |
| 52 |
} |
| 53 |
|
| 54 |
TEST_P(olMemRegisterTest, InvalidPtrUnRegister) { |
| 55 |
int Arr[50]; |
| 56 |
ol_memory_register_flags_t Flags = {}; |
| 57 |
void *PinnedPtr = nullptr; |
| 58 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr)); |
| 59 |
ASSERT_NE(PinnedPtr, nullptr); |
| 60 |
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, olMemUnregister(Device, nullptr)); |
| 61 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr)); |
| 62 |
} |
| 63 |
|
| 64 |
TEST_P(olMemRegisterTest, UnregisteredPtrUnRegister) { |
| 65 |
int Arr[50]; |
| 66 |
int Arr1[50]; |
| 67 |
ol_memory_register_flags_t Flags = {}; |
| 68 |
void *PinnedPtr = nullptr; |
| 69 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr)); |
| 70 |
ASSERT_NE(PinnedPtr, nullptr); |
| 71 |
ASSERT_ERROR(OL_ERRC_INVALID_ARGUMENT, olMemUnregister(Device, Arr1)); |
| 72 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr)); |
| 73 |
} |
| 74 |
|
| 75 |
TEST_P(olMemRegisterTest, PartialOverlapPtrRegister) { |
| 76 |
int Arr[50]; |
| 77 |
ol_memory_register_flags_t Flags = {}; |
| 78 |
void *PinnedPtr = nullptr; |
| 79 |
ASSERT_SUCCESS(olMemRegister(Device, Arr, sizeof(Arr), Flags, &PinnedPtr)); |
| 80 |
ASSERT_NE(PinnedPtr, nullptr); |
| 81 |
ASSERT_ERROR(OL_ERRC_INVALID_ARGUMENT, |
| 82 |
olMemRegister(Device, Arr + 2, sizeof(Arr), Flags, &PinnedPtr)); |
| 83 |
ASSERT_SUCCESS(olMemUnregister(Device, PinnedPtr)); |
| 84 |
} |