18
18
#include < llvm/Support/FileSystem.h>
19
19
#include < vector>
20
20
21
+ #define ASSERT_NO_ERROR (x ) \
22
+ if (std::error_code EC = x) { \
23
+ FAIL () << #x " : did not return errc::success.\n " \
24
+ << " error number: " << EC.value () << " \n " \
25
+ << " error message: " << EC.message () << " \n " ; \
26
+ }
27
+
21
28
// TODO: Introduce common unit tests header and move it there
22
29
static void set_env (const char *name, const char *value) {
23
30
#ifdef _WIN32
@@ -121,7 +128,7 @@ class PersistenDeviceCodeCache : public ::testing::Test {
121
128
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
122
129
Dev, Img, {' S' , ' p' , ' e' , ' c' , ' C' , ' o' , ' n' , ' s' , ' t' , ProgramID},
123
130
BuildOptions);
124
- llvm::sys::fs::remove_directories (ItemDir);
131
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
125
132
126
133
Barrier b (ThreadCount);
127
134
{
@@ -147,7 +154,7 @@ class PersistenDeviceCodeCache : public ::testing::Test {
147
154
148
155
ThreadPool MPool (ThreadCount, testLambda);
149
156
}
150
- llvm::sys::fs::remove_directories (ItemDir);
157
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
151
158
}
152
159
153
160
protected:
@@ -188,7 +195,7 @@ TEST_F(PersistenDeviceCodeCache, KeysWithNullTermSymbol) {
188
195
std::vector<unsigned char > SpecConst (Key.begin (), Key.end ());
189
196
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
190
197
Dev, Img, SpecConst, Key);
191
- llvm::sys::fs::remove_directories (ItemDir);
198
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
192
199
193
200
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, SpecConst, Key,
194
201
NativeProg);
@@ -204,7 +211,7 @@ TEST_F(PersistenDeviceCodeCache, KeysWithNullTermSymbol) {
204
211
}
205
212
}
206
213
207
- llvm::sys::fs::remove_directories (ItemDir);
214
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
208
215
}
209
216
210
217
/* Do read/write for the same cache item to/from 300 threads for small device
@@ -246,7 +253,7 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
246
253
std::string BuildOptions{" --corrupted-file" };
247
254
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
248
255
Dev, Img, {}, BuildOptions);
249
- llvm::sys::fs::remove_directories (ItemDir);
256
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
250
257
251
258
// Only source file is present
252
259
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
@@ -257,7 +264,7 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
257
264
BuildOptions);
258
265
EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
259
266
<< " Item with missed binary file was read" ;
260
- llvm::sys::fs::remove_directories (ItemDir);
267
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
261
268
262
269
// Only binary file is present
263
270
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
@@ -268,7 +275,7 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
268
275
BuildOptions);
269
276
EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
270
277
<< " Item with missed source file was read" ;
271
- llvm::sys::fs::remove_directories (ItemDir);
278
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
272
279
273
280
// Binary file is corrupted
274
281
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
@@ -286,7 +293,7 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
286
293
EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
287
294
<< " Item with corrupted binary file was read" ;
288
295
289
- llvm::sys::fs::remove_directories (ItemDir);
296
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
290
297
291
298
// Source file is empty
292
299
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
@@ -299,7 +306,7 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
299
306
BuildOptions);
300
307
EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
301
308
<< " Item with corrupted binary file was read" ;
302
- llvm::sys::fs::remove_directories (ItemDir);
309
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
303
310
}
304
311
305
312
/* Checks that lock file affects cache operations as expected:
@@ -317,7 +324,7 @@ TEST_F(PersistenDeviceCodeCache, LockFile) {
317
324
std::string BuildOptions{" --obsolete-lock" };
318
325
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
319
326
Dev, Img, {}, BuildOptions);
320
- llvm::sys::fs::remove_directories (ItemDir);
327
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
321
328
322
329
// Create 1st cahe item
323
330
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
@@ -356,7 +363,7 @@ TEST_F(PersistenDeviceCodeCache, LockFile) {
356
363
<< " Corrupted image loaded from persistent cache" ;
357
364
}
358
365
}
359
- llvm::sys::fs::remove_directories (ItemDir);
366
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
360
367
}
361
368
362
369
#ifndef _WIN32
@@ -374,26 +381,30 @@ TEST_F(PersistenDeviceCodeCache, AccessDeniedForCacheDir) {
374
381
std::string BuildOptions{" --build-options" };
375
382
std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
376
383
Dev, Img, {}, BuildOptions);
377
- llvm::sys::fs::remove_directories (ItemDir);
384
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
378
385
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
379
386
NativeProg);
380
387
EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /0.bin" )) << " No file created" ;
381
- llvm::sys::fs::setPermissions (ItemDir + " /0.bin" , llvm::sys::fs::no_perms);
388
+ ASSERT_NO_ERROR (llvm::sys::fs::setPermissions (ItemDir + " /0.bin" ,
389
+ llvm::sys::fs::no_perms));
382
390
// No access to binary file new cache item to be created
383
391
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
384
392
NativeProg);
385
393
EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /1.bin" )) << " No file created" ;
386
394
387
- llvm::sys::fs::setPermissions (ItemDir + " /1.bin" , llvm::sys::fs::no_perms);
395
+ ASSERT_NO_ERROR (llvm::sys::fs::setPermissions (ItemDir + " /1.bin" ,
396
+ llvm::sys::fs::no_perms));
388
397
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
389
398
BuildOptions);
390
399
391
400
// No image to be read due to lack of permissions from source file
392
401
EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
393
402
<< " Read from the file without permissions." ;
394
403
395
- llvm::sys::fs::setPermissions (ItemDir + " /0.bin" , llvm::sys::fs::all_perms);
396
- llvm::sys::fs::setPermissions (ItemDir + " /1.bin" , llvm::sys::fs::all_perms);
404
+ ASSERT_NO_ERROR (llvm::sys::fs::setPermissions (ItemDir + " /0.bin" ,
405
+ llvm::sys::fs::all_perms));
406
+ ASSERT_NO_ERROR (llvm::sys::fs::setPermissions (ItemDir + " /1.bin" ,
407
+ llvm::sys::fs::all_perms));
397
408
398
409
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
399
410
BuildOptions);
@@ -404,7 +415,7 @@ TEST_F(PersistenDeviceCodeCache, AccessDeniedForCacheDir) {
404
415
<< " Corrupted image loaded from persistent cache" ;
405
416
}
406
417
}
407
- llvm::sys::fs::remove_directories (ItemDir);
418
+ ASSERT_NO_ERROR ( llvm::sys::fs::remove_directories (ItemDir) );
408
419
}
409
420
#endif // _WIN32
410
421
} // namespace
0 commit comments