6
6
7
7
#include < uur/fixtures.h>
8
8
9
+ #ifdef _MSC_VER
10
+ #include < Windows.h>
11
+ #endif
12
+
13
+ namespace uur {
14
+ static int set_env (const char *name, const char *value) {
15
+ #ifdef _MSC_VER
16
+ return _putenv_s (name, value);
17
+ #else
18
+ return setenv (name, value, 1 );
19
+ #endif
20
+ }
21
+
22
+ static int unset_env (const char *name) {
23
+ #ifdef _MSC_VER
24
+ return _putenv_s (name, " " );
25
+ #else
26
+ return unsetenv (name);
27
+ #endif
28
+ }
29
+
30
+ } // namespace uur
31
+
9
32
using urDeviceGetSelectedTest = uur::urPlatformTest;
10
33
UUR_INSTANTIATE_PLATFORM_TEST_SUITE (urDeviceGetSelectedTest);
11
34
12
35
/* adpater agnostic tests -- none assume the existence or support of any
13
36
* specific adapter */
14
37
15
38
TEST_P (urDeviceGetSelectedTest, Success) {
16
- unsetenv (" ONEAPI_DEVICE_SELECTOR" );
39
+ uur::unset_env (" ONEAPI_DEVICE_SELECTOR" );
17
40
uint32_t count = 0 ;
18
41
ASSERT_SUCCESS (
19
42
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -27,7 +50,7 @@ TEST_P(urDeviceGetSelectedTest, Success) {
27
50
}
28
51
29
52
TEST_P (urDeviceGetSelectedTest, SuccessSubsetOfDevices) {
30
- unsetenv (" ONEAPI_DEVICE_SELECTOR" );
53
+ uur::unset_env (" ONEAPI_DEVICE_SELECTOR" );
31
54
uint32_t count = 0 ;
32
55
ASSERT_SUCCESS (
33
56
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -38,13 +61,13 @@ TEST_P(urDeviceGetSelectedTest, SuccessSubsetOfDevices) {
38
61
std::vector<ur_device_handle_t > devices (count - 1 );
39
62
ASSERT_SUCCESS (urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, count - 1 ,
40
63
devices.data (), nullptr ));
41
- for (auto device : devices) {
64
+ for (auto * device : devices) {
42
65
ASSERT_NE (nullptr , device);
43
66
}
44
67
}
45
68
46
69
TEST_P (urDeviceGetSelectedTest, SuccessSelected_StarColonStar) {
47
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:*" , 1 );
70
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:*" );
48
71
uint32_t count = 0 ;
49
72
ASSERT_SUCCESS (
50
73
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -74,7 +97,7 @@ TEST_P(urDeviceGetSelectedTest, SuccessSelected_StarColonStar) {
74
97
}
75
98
76
99
TEST_P (urDeviceGetSelectedTest, SuccessSelected_StarColonZero) {
77
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0" , 1 );
100
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0" );
78
101
uint32_t count = 0 ;
79
102
ASSERT_SUCCESS (
80
103
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -88,7 +111,7 @@ TEST_P(urDeviceGetSelectedTest, SuccessSelected_StarColonZero) {
88
111
}
89
112
90
113
TEST_P (urDeviceGetSelectedTest, SuccessSelected_StarColonZeroCommaStar) {
91
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0,*" , 1 );
114
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0,*" );
92
115
uint32_t count = 0 ;
93
116
ASSERT_SUCCESS (
94
117
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -102,15 +125,15 @@ TEST_P(urDeviceGetSelectedTest, SuccessSelected_StarColonZeroCommaStar) {
102
125
}
103
126
104
127
TEST_P (urDeviceGetSelectedTest, SuccessSelected_DiscardStarColonStar) {
105
- setenv (" ONEAPI_DEVICE_SELECTOR" , " !*:*" , 1 );
128
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " !*:*" );
106
129
uint32_t count = 0 ;
107
130
ASSERT_SUCCESS (
108
131
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
109
132
ASSERT_EQ (count, 0 );
110
133
}
111
134
112
135
TEST_P (urDeviceGetSelectedTest, SuccessSelected_SelectAndDiscard) {
113
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0;!*:*" , 1 );
136
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0;!*:*" );
114
137
uint32_t count = 0 ;
115
138
ASSERT_SUCCESS (
116
139
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -119,7 +142,7 @@ TEST_P(urDeviceGetSelectedTest, SuccessSelected_SelectAndDiscard) {
119
142
120
143
TEST_P (urDeviceGetSelectedTest,
121
144
SuccessSelected_SelectSomethingAndDiscardSomethingElse) {
122
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0;!*:1" , 1 );
145
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0;!*:1" );
123
146
uint32_t count = 0 ;
124
147
ASSERT_SUCCESS (
125
148
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -133,23 +156,23 @@ TEST_P(urDeviceGetSelectedTest,
133
156
}
134
157
135
158
TEST_P (urDeviceGetSelectedTest, InvalidNullHandlePlatform) {
136
- unsetenv (" ONEAPI_DEVICE_SELECTOR" );
159
+ uur::unset_env (" ONEAPI_DEVICE_SELECTOR" );
137
160
uint32_t count = 0 ;
138
161
ASSERT_EQ_RESULT (
139
162
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
140
163
urDeviceGetSelected (nullptr , UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
141
164
}
142
165
143
166
TEST_P (urDeviceGetSelectedTest, InvalidEnumerationDevicesType) {
144
- unsetenv (" ONEAPI_DEVICE_SELECTOR" );
167
+ uur::unset_env (" ONEAPI_DEVICE_SELECTOR" );
145
168
uint32_t count = 0 ;
146
169
ASSERT_EQ_RESULT (UR_RESULT_ERROR_INVALID_ENUMERATION,
147
170
urDeviceGetSelected (platform, UR_DEVICE_TYPE_FORCE_UINT32, 0 ,
148
171
nullptr , &count));
149
172
}
150
173
151
174
TEST_P (urDeviceGetSelectedTest, InvalidValueNumEntries) {
152
- unsetenv (" ONEAPI_DEVICE_SELECTOR" );
175
+ uur::unset_env (" ONEAPI_DEVICE_SELECTOR" );
153
176
uint32_t count = 0 ;
154
177
ASSERT_SUCCESS (
155
178
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
@@ -161,7 +184,7 @@ TEST_P(urDeviceGetSelectedTest, InvalidValueNumEntries) {
161
184
}
162
185
163
186
TEST_P (urDeviceGetSelectedTest, InvalidMissingBackend) {
164
- setenv (" ONEAPI_DEVICE_SELECTOR" , " :garbage" , 1 );
187
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " :garbage" );
165
188
uint32_t count = 0 ;
166
189
ASSERT_EQ_RESULT (
167
190
UR_RESULT_ERROR_UNKNOWN,
@@ -170,7 +193,7 @@ TEST_P(urDeviceGetSelectedTest, InvalidMissingBackend) {
170
193
}
171
194
172
195
TEST_P (urDeviceGetSelectedTest, InvalidGarbageBackendString) {
173
- setenv (" ONEAPI_DEVICE_SELECTOR" , " garbage:0" , 1 );
196
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " garbage:0" );
174
197
uint32_t count = 0 ;
175
198
ASSERT_EQ_RESULT (
176
199
UR_RESULT_ERROR_INVALID_VALUE,
@@ -179,20 +202,20 @@ TEST_P(urDeviceGetSelectedTest, InvalidGarbageBackendString) {
179
202
}
180
203
181
204
TEST_P (urDeviceGetSelectedTest, SuccessCaseSensitive) {
182
- setenv (" ONEAPI_DEVICE_SELECTOR" , " OpEnCl:0" , 1 );
205
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " OpEnCl:0" );
183
206
uint32_t count = 0 ;
184
207
ASSERT_SUCCESS (
185
208
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
186
209
}
187
210
188
211
TEST_P (urDeviceGetSelectedTest, InvalidMissingFilterStrings) {
189
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *" , 1 );
212
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *" );
190
213
uint32_t count = 0 ;
191
214
ASSERT_EQ_RESULT (
192
215
UR_RESULT_ERROR_INVALID_VALUE,
193
216
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
194
217
ASSERT_EQ (count, 0 );
195
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:" , 1 );
218
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:" );
196
219
uint32_t count2 = 0 ;
197
220
ASSERT_EQ_RESULT (
198
221
UR_RESULT_ERROR_INVALID_VALUE,
@@ -201,7 +224,7 @@ TEST_P(urDeviceGetSelectedTest, InvalidMissingFilterStrings) {
201
224
}
202
225
203
226
TEST_P (urDeviceGetSelectedTest, InvalidMissingFilterString) {
204
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0,,2" , 1 );
227
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0,,2" );
205
228
uint32_t count = 0 ;
206
229
ASSERT_EQ_RESULT (
207
230
UR_RESULT_ERROR_UNKNOWN,
@@ -210,7 +233,7 @@ TEST_P(urDeviceGetSelectedTest, InvalidMissingFilterString) {
210
233
}
211
234
212
235
TEST_P (urDeviceGetSelectedTest, InvalidTooManyDotsInFilterString) {
213
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0.1.2.3" , 1 );
236
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0.1.2.3" );
214
237
uint32_t count = 0 ;
215
238
ASSERT_EQ_RESULT (
216
239
UR_RESULT_ERROR_INVALID_VALUE,
@@ -219,13 +242,13 @@ TEST_P(urDeviceGetSelectedTest, InvalidTooManyDotsInFilterString) {
219
242
}
220
243
221
244
TEST_P (urDeviceGetSelectedTest, InvalidBadWildardInFilterString) {
222
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:*." , 1 );
245
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:*." );
223
246
uint32_t count = 0 ;
224
247
ASSERT_EQ_RESULT (
225
248
UR_RESULT_ERROR_INVALID_VALUE,
226
249
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
227
250
ASSERT_EQ (count, 0 );
228
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:*.0" , 1 );
251
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:*.0" );
229
252
uint32_t count2 = 0 ;
230
253
ASSERT_EQ_RESULT (
231
254
UR_RESULT_ERROR_INVALID_VALUE,
@@ -234,23 +257,23 @@ TEST_P(urDeviceGetSelectedTest, InvalidBadWildardInFilterString) {
234
257
}
235
258
236
259
TEST_P (urDeviceGetSelectedTest, InvalidSelectingNonexistentDevice) {
237
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:4321" , 1 );
260
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:4321" );
238
261
uint32_t count = 0 ;
239
262
ASSERT_SUCCESS (
240
263
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
241
264
ASSERT_EQ (count, 0 );
242
265
}
243
266
244
267
TEST_P (urDeviceGetSelectedTest, InvalidSelectingNonexistentSubDevice) {
245
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0.4321" , 1 );
268
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0.4321" );
246
269
uint32_t count = 0 ;
247
270
ASSERT_SUCCESS (
248
271
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
249
272
ASSERT_EQ (count, 0 );
250
273
}
251
274
252
275
TEST_P (urDeviceGetSelectedTest, InvalidSelectingNonexistentSubSubDevice) {
253
- setenv (" ONEAPI_DEVICE_SELECTOR" , " *:0.0.4321" , 1 );
276
+ uur::set_env (" ONEAPI_DEVICE_SELECTOR" , " *:0.0.4321" );
254
277
uint32_t count = 0 ;
255
278
ASSERT_SUCCESS (
256
279
urDeviceGetSelected (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr , &count));
0 commit comments