MCPcopy Create free account
hub / github.com/catboost/catboost / TestCache

Method TestCache

util/system/file_ut.cpp:338–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336#endif
337
338void TFileTest::TestCache() {
339#ifdef _linux_
340 { // create file in /tmp, current dir could be tmpfs which does not support fadvise
341 TFile file(MakeTempName("/tmp"), OpenAlways | Transient | RdWr | NoReadAhead);
342
343 struct statfs fs;
344 if (!fstatfs(file.GetHandle(), &fs) && fs.f_type == TMPFS_MAGIC) {
345 return;
346 }
347
348 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
349 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 0), 0);
350
351 file.Resize(7);
352 file.PrefetchCache();
353 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
354 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(3, 2), 2);
355
356 file.FlushCache();
357 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
358
359 file.EvictCache();
360 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
361
362 file.PrefetchCache();
363 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
364
365 file.Resize(12345);
366 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 4096);
367 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(4096, 0), 0);
368
369 file.PrefetchCache();
370 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 12345);
371
372 file.FlushCache();
373 file.EvictCache();
374 UNIT_ASSERT_LE(file.CountCache(), 0);
375
376 file.Resize(33333333);
377 file.PrefetchCache(11111111, 11111111);
378 UNIT_ASSERT_GE(file.CountCache(), 11111111);
379
380 UNIT_ASSERT_LE(file.CountCache(0, 11111111), 1111111);
381 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(11111111, 11111111), 11111111);
382 UNIT_ASSERT_LE(file.CountCache(22222222, 11111111), 1111111);
383
384 file.FlushCache(11111111, 11111111);
385 UNIT_ASSERT_GE(file.CountCache(), 11111111);
386
387 // first and last incomplete pages could stay in cache
388 file.EvictCache(11111111, 11111111);
389 UNIT_ASSERT_LT(file.CountCache(11111111, 11111111), 4096 * 2);
390
391 file.EvictCache();
392 UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
393 }
394#else
395 {

Callers

nothing calls this directly

Calls 7

MakeTempNameFunction · 0.85
GetHandleMethod · 0.45
CountCacheMethod · 0.45
ResizeMethod · 0.45
PrefetchCacheMethod · 0.45
FlushCacheMethod · 0.45
EvictCacheMethod · 0.45

Tested by

no test coverage detected