1 //===------- Offload API tests - olGetPlatformInfo -------------------===// 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 "olPlatformInfo.hpp" 13 14 struct olGetPlatformInfoTest 15 : offloadPlatformTest, 16 ::testing::WithParamInterface<ol_platform_info_t> {}; 17 18 INSTANTIATE_TEST_SUITE_P( 19 olGetPlatformInfo, olGetPlatformInfoTest, 20 ::testing::ValuesIn(PlatformQueries), 21 [](const ::testing::TestParamInfo<ol_platform_info_t> &info) { 22 std::stringstream ss; 23 ss << info.param; 24 return ss.str(); 25 }); 26 27 TEST_P(olGetPlatformInfoTest, Success) { 28 size_t Size = 0; 29 ol_platform_info_t InfoType = GetParam(); 30 31 ASSERT_SUCCESS(olGetPlatformInfoSize(Platform, InfoType, &Size)); 32 std::vector<char> InfoData(Size); 33 ASSERT_SUCCESS(olGetPlatformInfo(Platform, InfoType, Size, InfoData.data())); 34 35 // Info types with a dynamic size are all char[] so we can verify the returned 36 // string is the expected size. 37 auto ExpectedSize = PlatformInfoSizeMap.find(InfoType); 38 if (ExpectedSize == PlatformInfoSizeMap.end()) { 39 ASSERT_EQ(Size, strlen(InfoData.data()) + 1); 40 } 41 } 42 43 TEST_F(olGetPlatformInfoTest, InvalidNullHandle) { 44 ol_platform_backend_t Backend; 45 ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, 46 olGetPlatformInfo(nullptr, OL_PLATFORM_INFO_BACKEND, 47 sizeof(Backend), &Backend)); 48 } 49 50 TEST_F(olGetPlatformInfoTest, InvalidPlatformInfoEnumeration) { 51 ol_platform_backend_t Backend; 52 ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION, 53 olGetPlatformInfo(Platform, OL_PLATFORM_INFO_FORCE_UINT32, 54 sizeof(Backend), &Backend)); 55 } 56 57 TEST_F(olGetPlatformInfoTest, InvalidSizeZero) { 58 ol_platform_backend_t Backend; 59 ASSERT_ERROR( 60 OL_ERRC_INVALID_SIZE, 61 olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 0, &Backend)); 62 } 63 64 TEST_F(olGetPlatformInfoTest, InvalidSizeSmall) { 65 ol_platform_backend_t Backend; 66 ASSERT_ERROR(OL_ERRC_INVALID_SIZE, 67 olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 68 sizeof(Backend) - 1, &Backend)); 69 } 70 71 TEST_F(olGetPlatformInfoTest, InvalidNullPointerPropValue) { 72 ol_platform_backend_t Backend; 73 ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER, 74 olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, 75 sizeof(Backend), nullptr)); 76 } 77