1 //===------- Offload API tests - olGetDeviceInfo ---------------------===// 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 "olDeviceInfo.hpp" 11 #include <OffloadAPI.h> 12 #include <gtest/gtest.h> 13 14 struct olGetDeviceInfoTest : offloadDeviceTest, 15 ::testing::WithParamInterface<ol_device_info_t> { 16 17 void SetUp() override { RETURN_ON_FATAL_FAILURE(offloadDeviceTest::SetUp()); } 18 }; 19 20 INSTANTIATE_TEST_SUITE_P( 21 , olGetDeviceInfoTest, ::testing::ValuesIn(DeviceQueries), 22 [](const ::testing::TestParamInfo<ol_device_info_t> &info) { 23 std::stringstream ss; 24 ss << info.param; 25 return ss.str(); 26 }); 27 28 TEST_P(olGetDeviceInfoTest, Success) { 29 ol_device_info_t InfoType = GetParam(); 30 size_t Size = 0; 31 32 ASSERT_SUCCESS(olGetDeviceInfoSize(Device, InfoType, &Size)); 33 34 std::vector<char> InfoData(Size); 35 ASSERT_SUCCESS(olGetDeviceInfo(Device, InfoType, Size, InfoData.data())); 36 37 if (InfoType == OL_DEVICE_INFO_PLATFORM) { 38 auto *ReturnedPlatform = 39 reinterpret_cast<ol_platform_handle_t *>(InfoData.data()); 40 ASSERT_EQ(Platform, *ReturnedPlatform); 41 } 42 } 43 44 TEST_F(olGetDeviceInfoTest, InvalidNullHandleDevice) { 45 ol_device_type_t DeviceType; 46 ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, 47 olGetDeviceInfo(nullptr, OL_DEVICE_INFO_TYPE, 48 sizeof(ol_device_type_t), &DeviceType)); 49 } 50 51 TEST_F(olGetDeviceInfoTest, InvalidEnumerationInfoType) { 52 ol_device_type_t DeviceType; 53 ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION, 54 olGetDeviceInfo(Device, OL_DEVICE_INFO_FORCE_UINT32, 55 sizeof(ol_device_type_t), &DeviceType)); 56 } 57 58 TEST_F(olGetDeviceInfoTest, InvalidSizePropSize) { 59 ol_device_type_t DeviceType; 60 ASSERT_ERROR(OL_ERRC_INVALID_SIZE, 61 olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 0, &DeviceType)); 62 } 63 64 TEST_F(olGetDeviceInfoTest, InvalidSizePropSizeSmall) { 65 ol_device_type_t DeviceType; 66 ASSERT_ERROR(OL_ERRC_INVALID_SIZE, 67 olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, 68 sizeof(DeviceType) - 1, &DeviceType)); 69 } 70 71 TEST_F(olGetDeviceInfoTest, InvalidNullPointerPropValue) { 72 ol_device_type_t DeviceType; 73 ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, 74 olGetDeviceInfo(Device, OL_DEVICE_INFO_TYPE, sizeof(DeviceType), 75 nullptr)); 76 } 77