Skip to content

Commit cb804bc

Browse files
authored
Merge pull request #2523 from martygrant/martin/platform-info-unswitch
Rework urPlatformGetInfo test into individual tests instead of a switch
2 parents 6d83d05 + 8c241a0 commit cb804bc

File tree

1 file changed

+113
-63
lines changed

1 file changed

+113
-63
lines changed

test/conformance/platform/urPlatformGetInfo.cpp

Lines changed: 113 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,97 +8,147 @@
88
#include "uur/fixtures.h"
99
#include <cstring>
1010

11-
using urPlatformGetInfoTest =
12-
uur::platform::urPlatformTestWithParam<ur_platform_info_t>;
13-
14-
UUR_PLATFORM_TEST_SUITE_P(
15-
urPlatformGetInfoTest,
16-
::testing::Values(UR_PLATFORM_INFO_NAME, UR_PLATFORM_INFO_VENDOR_NAME,
17-
UR_PLATFORM_INFO_VERSION, UR_PLATFORM_INFO_EXTENSIONS,
18-
UR_PLATFORM_INFO_PROFILE, UR_PLATFORM_INFO_BACKEND,
19-
UR_PLATFORM_INFO_ADAPTER),
20-
ur_platform_info_t);
21-
22-
TEST_P(urPlatformGetInfoTest, Success) {
11+
using urPlatformGetInfoTest = uur::urPlatformTest;
12+
UUR_INSTANTIATE_PLATFORM_TEST_SUITE_P(urPlatformGetInfoTest);
13+
14+
TEST_P(urPlatformGetInfoTest, SuccessName) {
15+
ur_platform_info_t info_type = UR_PLATFORM_INFO_NAME;
2316
size_t size = 0;
24-
ur_platform_info_t info_type = getParam();
25-
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
26-
urPlatformGetInfo(platform, info_type, 0, nullptr, &size), info_type);
27-
if (info_type == UR_PLATFORM_INFO_BACKEND) {
28-
ASSERT_EQ(size, sizeof(ur_platform_backend_t));
29-
} else {
30-
ASSERT_NE(size, 0);
31-
}
32-
std::vector<char> name(size);
33-
ASSERT_SUCCESS(
34-
urPlatformGetInfo(platform, info_type, size, name.data(), nullptr));
35-
switch (info_type) {
36-
case UR_PLATFORM_INFO_NAME:
37-
case UR_PLATFORM_INFO_VENDOR_NAME:
38-
case UR_PLATFORM_INFO_VERSION:
39-
case UR_PLATFORM_INFO_EXTENSIONS:
40-
case UR_PLATFORM_INFO_PROFILE: {
41-
ASSERT_EQ(size, std::strlen(name.data()) + 1);
42-
break;
43-
}
44-
case UR_PLATFORM_INFO_BACKEND: {
45-
ASSERT_EQ(size, sizeof(ur_platform_backend_t));
46-
break;
47-
}
48-
case UR_PLATFORM_INFO_ADAPTER: {
49-
auto queried_adapter =
50-
*reinterpret_cast<ur_adapter_handle_t *>(name.data());
51-
auto adapter_found =
52-
std::find(uur::PlatformEnvironment::instance->adapters.begin(),
53-
uur::PlatformEnvironment::instance->adapters.end(),
54-
queried_adapter);
55-
ASSERT_NE(adapter_found,
56-
uur::AdapterEnvironment::instance->adapters.end());
57-
break;
58-
}
59-
default:
60-
break;
61-
}
17+
18+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
19+
ASSERT_GT(size, 0);
20+
21+
std::vector<char> returned_name(size);
22+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
23+
returned_name.data(), nullptr));
24+
25+
ASSERT_EQ(size, returned_name.size());
6226
}
6327

64-
TEST_P(urPlatformGetInfoTest, InvalidNullHandlePlatform) {
28+
TEST_P(urPlatformGetInfoTest, SuccessVendorName) {
29+
ur_platform_info_t info_type = UR_PLATFORM_INFO_VENDOR_NAME;
6530
size_t size = 0;
66-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
67-
urPlatformGetInfo(nullptr, getParam(), 0, nullptr, &size));
31+
32+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
33+
ASSERT_GT(size, 0);
34+
35+
std::vector<char> returned_vendor_name(size);
36+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
37+
returned_vendor_name.data(), nullptr));
38+
39+
ASSERT_EQ(size, returned_vendor_name.size());
6840
}
6941

70-
using urPlatformGetInfoNegativeTest = uur::urPlatformTest;
71-
UUR_INSTANTIATE_PLATFORM_TEST_SUITE_P(urPlatformGetInfoNegativeTest);
42+
TEST_P(urPlatformGetInfoTest, SuccessVersion) {
43+
ur_platform_info_t info_type = UR_PLATFORM_INFO_VERSION;
44+
size_t size = 0;
45+
46+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
47+
ASSERT_GT(size, 0);
48+
49+
std::vector<char> returned_version(size);
50+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
51+
returned_version.data(), nullptr));
52+
53+
ASSERT_EQ(size, returned_version.size());
54+
}
55+
56+
TEST_P(urPlatformGetInfoTest, SuccessExtensions) {
57+
ur_platform_info_t info_type = UR_PLATFORM_INFO_EXTENSIONS;
58+
size_t size = 0;
59+
60+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
61+
ASSERT_GT(size, 0);
62+
63+
std::vector<char> returned_extensions(size);
64+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
65+
returned_extensions.data(), nullptr));
66+
67+
ASSERT_EQ(size, returned_extensions.size());
68+
}
69+
70+
TEST_P(urPlatformGetInfoTest, SuccessProfile) {
71+
ur_platform_info_t info_type = UR_PLATFORM_INFO_PROFILE;
72+
size_t size = 0;
73+
74+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
75+
ASSERT_GT(size, 0);
76+
77+
std::vector<char> returned_profile(size);
78+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
79+
returned_profile.data(), nullptr));
80+
81+
ASSERT_EQ(size, returned_profile.size());
82+
}
83+
84+
TEST_P(urPlatformGetInfoTest, SuccessBackend) {
85+
ur_platform_info_t info_type = UR_PLATFORM_INFO_BACKEND;
86+
size_t size = 0;
87+
88+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
89+
ASSERT_EQ(size, sizeof(ur_platform_backend_t));
90+
91+
ur_platform_backend_t returned_backend = UR_PLATFORM_BACKEND_UNKNOWN;
92+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
93+
&returned_backend, nullptr));
94+
95+
ASSERT_TRUE(returned_backend >= UR_PLATFORM_BACKEND_LEVEL_ZERO &&
96+
returned_backend <= UR_PLATFORM_BACKEND_NATIVE_CPU);
97+
}
98+
99+
TEST_P(urPlatformGetInfoTest, SuccessAdapter) {
100+
ur_platform_info_t info_type = UR_PLATFORM_INFO_ADAPTER;
101+
size_t size = 0;
102+
103+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, 0, nullptr, &size));
104+
ASSERT_EQ(size, sizeof(ur_adapter_handle_t));
105+
106+
ur_adapter_handle_t returned_adapter = nullptr;
107+
ASSERT_SUCCESS(urPlatformGetInfo(platform, info_type, size,
108+
&returned_adapter, nullptr));
109+
110+
auto adapter_found = std::find(
111+
uur::PlatformEnvironment::instance->adapters.begin(),
112+
uur::PlatformEnvironment::instance->adapters.end(), returned_adapter);
113+
ASSERT_NE(adapter_found, uur::AdapterEnvironment::instance->adapters.end());
114+
}
115+
116+
TEST_P(urPlatformGetInfoTest, InvalidNullHandlePlatform) {
117+
size_t size = 0;
118+
ASSERT_EQ_RESULT(
119+
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
120+
urPlatformGetInfo(nullptr, UR_PLATFORM_INFO_NAME, 0, nullptr, &size));
121+
}
72122

73-
TEST_P(urPlatformGetInfoNegativeTest, InvalidEnumerationPlatformInfoType) {
123+
TEST_P(urPlatformGetInfoTest, InvalidEnumerationPlatformInfoType) {
74124
size_t size = 0;
75125
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION,
76126
urPlatformGetInfo(platform, UR_PLATFORM_INFO_FORCE_UINT32,
77127
0, nullptr, &size));
78128
}
79129

80-
TEST_P(urPlatformGetInfoNegativeTest, InvalidSizeZero) {
81-
ur_platform_backend_t backend;
130+
TEST_P(urPlatformGetInfoTest, InvalidSizeZero) {
131+
ur_platform_backend_t backend = UR_PLATFORM_BACKEND_UNKNOWN;
82132
ASSERT_EQ_RESULT(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND, 0,
83133
&backend, nullptr),
84134
UR_RESULT_ERROR_INVALID_SIZE);
85135
}
86136

87-
TEST_P(urPlatformGetInfoNegativeTest, InvalidSizeSmall) {
88-
ur_platform_backend_t backend;
137+
TEST_P(urPlatformGetInfoTest, InvalidSizeSmall) {
138+
ur_platform_backend_t backend = UR_PLATFORM_BACKEND_UNKNOWN;
89139
ASSERT_EQ_RESULT(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
90140
sizeof(backend) - 1, &backend, nullptr),
91141
UR_RESULT_ERROR_INVALID_SIZE);
92142
}
93143

94-
TEST_P(urPlatformGetInfoNegativeTest, InvalidNullPointerPropValue) {
95-
ur_platform_backend_t backend;
144+
TEST_P(urPlatformGetInfoTest, InvalidNullPointerPropValue) {
145+
ur_platform_backend_t backend = UR_PLATFORM_BACKEND_UNKNOWN;
96146
ASSERT_EQ_RESULT(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
97147
sizeof(backend), nullptr, nullptr),
98148
UR_RESULT_ERROR_INVALID_NULL_POINTER);
99149
}
100150

101-
TEST_P(urPlatformGetInfoNegativeTest, InvalidNullPointerPropSizeRet) {
151+
TEST_P(urPlatformGetInfoTest, InvalidNullPointerPropSizeRet) {
102152
ASSERT_EQ_RESULT(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND, 0,
103153
nullptr, nullptr),
104154
UR_RESULT_ERROR_INVALID_NULL_POINTER);

0 commit comments

Comments
 (0)