@@ -81,6 +81,11 @@ class PersistenDeviceCodeCache : public ::testing::Test {
81
81
return _putenv_s (name, value);
82
82
}
83
83
#endif
84
+ virtual void SetUp () {
85
+ EXPECT_NE (getenv (" SYCL_CACHE_DIR" ), nullptr )
86
+ << " Please set SYCL_CACHE_DIR environment variable pointing to cache "
87
+ " location." ;
88
+ }
84
89
85
90
PersistenDeviceCodeCache () : Plt{default_selector ()} {
86
91
@@ -134,8 +139,8 @@ class PersistenDeviceCodeCache : public ::testing::Test {
134
139
BuildOptions);
135
140
for (size_t i = 0 ; i < Res.size (); ++i) {
136
141
for (size_t j = 0 ; j < Res[i].size (); ++j) {
137
- assert (Res[i][j] == static_cast <char >(i) &&
138
- " Corrupted image loaded from persistent cache" ) ;
142
+ EXPECT_EQ (Res[i][j], static_cast <char >(i))
143
+ << " Corrupted image loaded from persistent cache" ;
139
144
}
140
145
}
141
146
};
@@ -189,12 +194,13 @@ TEST_F(PersistenDeviceCodeCache, KeysWithNullTermSymbol) {
189
194
NativeProg);
190
195
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img,
191
196
SpecConst, Key);
192
- assert (Res.size () != 0 && " Failed to load cache item" ) ;
197
+ EXPECT_NE (Res.size (), static_cast < size_t >( 0 )) << " Failed to load cache item" ;
193
198
for (size_t i = 0 ; i < Res.size (); ++i) {
194
- assert (Res[i].size () != 0 && " Failed to device image" );
199
+ EXPECT_NE (Res[i].size (), static_cast <size_t >(0 ))
200
+ << " Failed to load device image" ;
195
201
for (size_t j = 0 ; j < Res[i].size (); ++j) {
196
- assert (Res[i][j] == static_cast <char >(i) &&
197
- " Corrupted image loaded from persistent cache" ) ;
202
+ EXPECT_EQ (Res[i][j], static_cast <unsigned char >(i))
203
+ << " Corrupted image loaded from persistent cache" ;
198
204
}
199
205
}
200
206
@@ -245,21 +251,23 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
245
251
// Only source file is present
246
252
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
247
253
NativeProg);
248
- assert (! llvm::sys::fs::remove (ItemDir + " /0.bin" ) &&
249
- " Failed to remove binary file" ) ;
254
+ EXPECT_FALSE ( llvm::sys::fs::remove (ItemDir + " /0.bin" ))
255
+ << " Failed to remove binary file" ;
250
256
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
251
257
BuildOptions);
252
- assert (Res.size () == 0 && " Item with missed binary file was read" );
258
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
259
+ << " Item with missed binary file was read" ;
253
260
llvm::sys::fs::remove_directories (ItemDir);
254
261
255
262
// Only binary file is present
256
263
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
257
264
NativeProg);
258
- assert (! llvm::sys::fs::remove (ItemDir + " /0.src" ) &&
259
- " Failed to remove source file" ) ;
265
+ EXPECT_FALSE ( llvm::sys::fs::remove (ItemDir + " /0.src" ))
266
+ << " Failed to remove source file" ;
260
267
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
261
268
BuildOptions);
262
- assert (Res.size () == 0 && " Item with missed source file was read" );
269
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
270
+ << " Item with missed source file was read" ;
263
271
llvm::sys::fs::remove_directories (ItemDir);
264
272
265
273
// Binary file is corrupted
@@ -272,10 +280,11 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
272
280
*/
273
281
FileStream << 2 << 12 << " 123456789012" << 23 << " 1234" ;
274
282
FileStream.close ();
275
- assert ((! FileStream.fail ()) && " Failed to create trancated binary file" ) ;
283
+ EXPECT_FALSE ( FileStream.fail ()) << " Failed to create trancated binary file" ;
276
284
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
277
285
BuildOptions);
278
- assert (Res.size () == 0 && " Item with corrupted binary file was read" );
286
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
287
+ << " Item with corrupted binary file was read" ;
279
288
280
289
llvm::sys::fs::remove_directories (ItemDir);
281
290
@@ -288,7 +297,8 @@ TEST_F(PersistenDeviceCodeCache, CorruptedCacheFiles) {
288
297
}
289
298
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
290
299
BuildOptions);
291
- assert (Res.size () == 0 && " Item with corrupted binary file was read" );
300
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
301
+ << " Item with corrupted binary file was read" ;
292
302
llvm::sys::fs::remove_directories (ItemDir);
293
303
}
294
304
@@ -312,37 +322,38 @@ TEST_F(PersistenDeviceCodeCache, LockFile) {
312
322
// Create 1st cahe item
313
323
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
314
324
NativeProg);
315
- assert (llvm::sys::fs::exists (ItemDir + " /0.bin" ) && " No file created" ) ;
325
+ EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /0.bin" )) << " No file created" ;
316
326
std::string LockFile = ItemDir + " /0.lock" ;
317
- assert (! llvm::sys::fs::exists (LockFile) && " Cache item locked" ) ;
327
+ EXPECT_FALSE ( llvm::sys::fs::exists (LockFile)) << " Cache item locked" ;
318
328
319
329
// Create lock file for the 1st cache item
320
330
{ std::ofstream File{LockFile}; }
321
331
322
332
// Cache item is locked, cache miss happens on read
323
333
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
324
334
BuildOptions);
325
- assert (Res.size () == 0 && " Locked item was read" ) ;
335
+ EXPECT_EQ (Res.size (), static_cast < size_t >( 0 )) << " Locked item was read" ;
326
336
327
337
// Cache item is locked - new cache item to be created
328
338
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
329
339
NativeProg);
330
- assert (llvm::sys::fs::exists (ItemDir + " /1.bin" ) && " No file created" ) ;
340
+ EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /1.bin" )) << " No file created" ;
331
341
332
342
// Second cache item is locked, cache miss happens on read
333
343
{ std::ofstream File{ItemDir + " /1.lock" }; }
334
344
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
335
345
BuildOptions);
336
- assert (Res.size () == 0 && " Locked item was read" );
346
+
347
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 )) << " Locked item was read" ;
337
348
338
349
// First cache item was unlocked and successfully read
339
350
std::remove (LockFile.c_str ());
340
351
Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
341
352
BuildOptions);
342
353
for (size_t i = 0 ; i < Res.size (); ++i) {
343
354
for (size_t j = 0 ; j < Res[i].size (); ++j) {
344
- assert (Res[i][j] == static_cast <char >(i) &&
345
- " Corrupted image loaded from persistent cache" ) ;
355
+ EXPECT_EQ (Res[i][j], static_cast <unsigned char >(i))
356
+ << " Corrupted image loaded from persistent cache" ;
346
357
}
347
358
}
348
359
llvm::sys::fs::remove_directories (ItemDir);
@@ -366,19 +377,20 @@ TEST_F(PersistenDeviceCodeCache, AccessDeniedForCacheDir) {
366
377
llvm::sys::fs::remove_directories (ItemDir);
367
378
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
368
379
NativeProg);
369
- assert (llvm::sys::fs::exists (ItemDir + " /0.bin" ) && " No file created" ) ;
380
+ EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /0.bin" )) << " No file created" ;
370
381
llvm::sys::fs::setPermissions (ItemDir + " /0.bin" , llvm::sys::fs::no_perms);
371
382
// No access to binary file new cache item to be created
372
383
detail::PersistentDeviceCodeCache::putItemToDisc (Dev, Img, {}, BuildOptions,
373
384
NativeProg);
374
- assert (llvm::sys::fs::exists (ItemDir + " /1.bin" ) && " No file created" ) ;
385
+ EXPECT_TRUE (llvm::sys::fs::exists (ItemDir + " /1.bin" )) << " No file created" ;
375
386
376
387
llvm::sys::fs::setPermissions (ItemDir + " /1.bin" , llvm::sys::fs::no_perms);
377
388
auto Res = detail::PersistentDeviceCodeCache::getItemFromDisc (Dev, Img, {},
378
389
BuildOptions);
379
390
380
- // No image to be read due to lack of permissions fro source file
381
- assert (Res.size () == 0 );
391
+ // No image to be read due to lack of permissions from source file
392
+ EXPECT_EQ (Res.size (), static_cast <size_t >(0 ))
393
+ << " Read from the file without permissions." ;
382
394
383
395
llvm::sys::fs::setPermissions (ItemDir + " /0.bin" , llvm::sys::fs::all_perms);
384
396
llvm::sys::fs::setPermissions (ItemDir + " /1.bin" , llvm::sys::fs::all_perms);
@@ -388,8 +400,8 @@ TEST_F(PersistenDeviceCodeCache, AccessDeniedForCacheDir) {
388
400
// Image should be successfully read
389
401
for (size_t i = 0 ; i < Res.size (); ++i) {
390
402
for (size_t j = 0 ; j < Res[i].size (); ++j) {
391
- assert (Res[i][j] == static_cast <char >(i) &&
392
- " Corrupted image loaded from persistent cache" ) ;
403
+ EXPECT_EQ (Res[i][j], static_cast <unsigned char >(i))
404
+ << " Corrupted image loaded from persistent cache" ;
393
405
}
394
406
}
395
407
llvm::sys::fs::remove_directories (ItemDir);
0 commit comments