xref: /llvm-project/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp (revision fd3907ccb583df99e9c19d2fe84e4e7c52d75de9)
1 //===------- Offload API tests - olGetDeviceInfoSize -----------------===//
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 <OffloadAPI.h>
10 
11 #include "../common/Fixtures.hpp"
12 #include "olDeviceInfo.hpp"
13 
14 struct olGetDeviceInfoSizeTest
15     : offloadDeviceTest,
16       ::testing::WithParamInterface<ol_device_info_t> {
17 
18   void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); }
19 };
20 
21 // TODO: We could autogenerate the list of enum values
22 INSTANTIATE_TEST_SUITE_P(
23     , olGetDeviceInfoSizeTest, ::testing::ValuesIn(DeviceQueries),
24     [](const ::testing::TestParamInfo<ol_device_info_t> &info) {
25       std::stringstream ss;
26       ss << info.param;
27       return ss.str();
28     });
29 
30 TEST_P(olGetDeviceInfoSizeTest, Success) {
31   ol_device_info_t InfoType = GetParam();
32   size_t Size = 0;
33 
34   ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size));
35   auto ExpectedSize = DeviceInfoSizeMap.find(InfoType);
36   if (ExpectedSize != DeviceInfoSizeMap.end()) {
37     ASSERT_EQ(Size, ExpectedSize->second);
38   } else {
39     ASSERT_NE(Size, 0lu);
40   }
41 }
42 
43 TEST_F(olGetDeviceInfoSizeTest, InvalidNullHandle) {
44   size_t Size = 0;
45   ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
46                olGetDeviceInfoSize(nullptr, OL_DEVICE_INFO_TYPE, &Size));
47 }
48 
49 TEST_F(olGetDeviceInfoSizeTest, InvalidDeviceInfoEnumeration) {
50   size_t Size = 0;
51   ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
52                olGetDeviceInfoSize(Device, OL_DEVICE_INFO_FORCE_UINT32, &Size));
53 }
54 
55 TEST_F(olGetDeviceInfoSizeTest, InvalidNullPointer) {
56   ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
57                olGetDeviceInfoSize(Device, OL_DEVICE_INFO_TYPE, nullptr));
58 }
59