aboutsummaryrefslogtreecommitdiff
path: root/offload/unittests/OffloadAPI/device/olIterateDevices.cpp
blob: 5bdbd17e9e97247c0b156b746b4f24c86186616e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//===------- Offload API tests - olIterateDevices -------------------------===//
//
// 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 olIterateDevicesTest = OffloadTest;

TEST_F(olIterateDevicesTest, SuccessEmptyCallback) {
  ASSERT_SUCCESS(olIterateDevices(
      [](ol_device_handle_t, void *) { return false; }, nullptr));
}

TEST_F(olIterateDevicesTest, SuccessGetDevice) {
  uint32_t DeviceCount = 0;
  ol_device_handle_t Device = nullptr;

  ASSERT_SUCCESS(olIterateDevices(
      [](ol_device_handle_t, void *Data) {
        auto Count = static_cast<uint32_t *>(Data);
        *Count += 1;
        return false;
      },
      &DeviceCount));

  if (DeviceCount == 0) {
    GTEST_SKIP() << "No available devices.";
  }

  ASSERT_SUCCESS(olIterateDevices(
      [](ol_device_handle_t D, void *Data) {
        auto DevicePtr = static_cast<ol_device_handle_t *>(Data);
        *DevicePtr = D;
        return true;
      },
      &Device));

  ASSERT_NE(Device, nullptr);
}