| 1 | //===------- Offload API tests - olIterateDevices -------------------------===// |
| 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 olIterateDevicesTest = OffloadTest; |
| 14 | |
| 15 | TEST_F(olIterateDevicesTest, SuccessEmptyCallback) { |
| 16 | ASSERT_SUCCESS(olIterateDevices( |
| 17 | [](ol_device_handle_t, void *) { return false; }, nullptr)); |
| 18 | } |
| 19 | |
| 20 | TEST_F(olIterateDevicesTest, SuccessGetDevice) { |
| 21 | uint32_t DeviceCount = 0; |
| 22 | ol_device_handle_t Device = nullptr; |
| 23 | |
| 24 | ASSERT_SUCCESS(olIterateDevices( |
| 25 | [](ol_device_handle_t, void *Data) { |
| 26 | auto Count = static_cast<uint32_t *>(Data); |
| 27 | *Count += 1; |
| 28 | return false; |
| 29 | }, |
| 30 | &DeviceCount)); |
| 31 | |
| 32 | if (DeviceCount == 0) { |
| 33 | GTEST_SKIP() << "No available devices." ; |
| 34 | } |
| 35 | |
| 36 | ASSERT_SUCCESS(olIterateDevices( |
| 37 | [](ol_device_handle_t D, void *Data) { |
| 38 | auto DevicePtr = static_cast<ol_device_handle_t *>(Data); |
| 39 | *DevicePtr = D; |
| 40 | return true; |
| 41 | }, |
| 42 | &Device)); |
| 43 | |
| 44 | ASSERT_NE(Device, nullptr); |
| 45 | } |
| 46 | |