aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/file_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/system/file_ut.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/file_ut.cpp')
-rw-r--r--util/system/file_ut.cpp278
1 files changed, 139 insertions, 139 deletions
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 941e6a50f3..799da739f8 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -1,22 +1,22 @@
-#include "file.h"
+#include "file.h"
#include "fs.h"
#include "tempfile.h"
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/stream/file.h>
-#include <util/generic/yexception.h>
+
+#include <util/stream/file.h>
+#include <util/generic/yexception.h>
class TFileTest: public TTestBase {
- UNIT_TEST_SUITE(TFileTest);
- UNIT_TEST(TestOpen);
+ UNIT_TEST_SUITE(TFileTest);
+ UNIT_TEST(TestOpen);
UNIT_TEST(TestOpenSync);
- UNIT_TEST(TestRW);
- UNIT_TEST(TestReWrite);
- UNIT_TEST(TestAppend);
- UNIT_TEST(TestLinkTo);
- UNIT_TEST(TestResize);
- UNIT_TEST(TestLocale);
+ UNIT_TEST(TestRW);
+ UNIT_TEST(TestReWrite);
+ UNIT_TEST(TestAppend);
+ UNIT_TEST(TestLinkTo);
+ UNIT_TEST(TestResize);
+ UNIT_TEST(TestLocale);
UNIT_TEST(TestFlush);
UNIT_TEST(TestFlushSpecialFile);
UNIT_TEST(TestRawRead);
@@ -24,13 +24,13 @@ class TFileTest: public TTestBase {
UNIT_TEST(TestRawPread);
UNIT_TEST(TestPread);
UNIT_TEST(TestCache);
- UNIT_TEST_SUITE_END();
-
-public:
- void TestOpen();
+ UNIT_TEST_SUITE_END();
+
+public:
+ void TestOpen();
void TestOpenSync();
- void TestRW();
- void TestLocale();
+ void TestRW();
+ void TestLocale();
void TestFlush();
void TestFlushSpecialFile();
void TestRawRead();
@@ -38,83 +38,83 @@ public:
void TestRawPread();
void TestPread();
void TestCache();
-
- inline void TestLinkTo() {
- TTempFile tmp1("tmp1");
- TTempFile tmp2("tmp2");
-
- {
- TFile f1(tmp1.Name(), OpenAlways | WrOnly);
- TFile f2(tmp2.Name(), OpenAlways | WrOnly);
-
- f1.LinkTo(f2);
-
- f1.Write("12345", 5);
- f2.Write("67890", 5);
- }
-
+
+ inline void TestLinkTo() {
+ TTempFile tmp1("tmp1");
+ TTempFile tmp2("tmp2");
+
+ {
+ TFile f1(tmp1.Name(), OpenAlways | WrOnly);
+ TFile f2(tmp2.Name(), OpenAlways | WrOnly);
+
+ f1.LinkTo(f2);
+
+ f1.Write("12345", 5);
+ f2.Write("67890", 5);
+ }
+
UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp2.Name()).ReadAll(), "1234567890");
- }
-
- inline void TestAppend() {
- TTempFile tmp("tmp");
-
- {
- TFile f(tmp.Name(), OpenAlways | WrOnly);
-
- f.Write("12345678", 8);
- }
-
- {
- TFile f(tmp.Name(), OpenAlways | WrOnly | ForAppend);
-
- f.Write("67", 2);
- f.Write("89", 2);
- }
-
+ }
+
+ inline void TestAppend() {
+ TTempFile tmp("tmp");
+
+ {
+ TFile f(tmp.Name(), OpenAlways | WrOnly);
+
+ f.Write("12345678", 8);
+ }
+
+ {
+ TFile f(tmp.Name(), OpenAlways | WrOnly | ForAppend);
+
+ f.Write("67", 2);
+ f.Write("89", 2);
+ }
+
UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "123456786789");
- }
-
- inline void TestReWrite() {
- TTempFile tmp("tmp");
-
- {
- TFile f(tmp.Name(), OpenAlways | WrOnly);
-
- f.Write("12345678", 8);
- }
-
- {
- TFile f(tmp.Name(), OpenAlways | WrOnly);
-
- f.Write("6789", 4);
- }
-
+ }
+
+ inline void TestReWrite() {
+ TTempFile tmp("tmp");
+
+ {
+ TFile f(tmp.Name(), OpenAlways | WrOnly);
+
+ f.Write("12345678", 8);
+ }
+
+ {
+ TFile f(tmp.Name(), OpenAlways | WrOnly);
+
+ f.Write("6789", 4);
+ }
+
UNIT_ASSERT_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "67895678");
- }
+ }
- inline void TestResize() {
- TTempFile tmp("tmp");
+ inline void TestResize() {
+ TTempFile tmp("tmp");
- {
- TFile file(tmp.Name(), OpenAlways | WrOnly);
+ {
+ TFile file(tmp.Name(), OpenAlways | WrOnly);
- file.Write("1234567", 7);
- file.Seek(3, sSet);
+ file.Write("1234567", 7);
+ file.Seek(3, sSet);
- file.Resize(5);
- UNIT_ASSERT_EQUAL(file.GetLength(), 5);
- UNIT_ASSERT_EQUAL(file.GetPosition(), 3);
+ file.Resize(5);
+ UNIT_ASSERT_EQUAL(file.GetLength(), 5);
+ UNIT_ASSERT_EQUAL(file.GetPosition(), 3);
- file.Resize(12);
- UNIT_ASSERT_EQUAL(file.GetLength(), 12);
- UNIT_ASSERT_EQUAL(file.GetPosition(), 3);
+ file.Resize(12);
+ UNIT_ASSERT_EQUAL(file.GetLength(), 12);
+ UNIT_ASSERT_EQUAL(file.GetPosition(), 3);
}
-
+
const TString data = TUnbufferedFileInput(tmp.Name()).ReadAll();
- UNIT_ASSERT_EQUAL(data.length(), 12);
+ UNIT_ASSERT_EQUAL(data.length(), 12);
UNIT_ASSERT(data.StartsWith("12345"));
- }
+ }
};
UNIT_TEST_SUITE_REGISTRATION(TFileTest);
@@ -168,7 +168,7 @@ void TFileTest::TestRW() {
UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt");
UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0);
ui32 d[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- f1.Write(&d, sizeof(ui32) * 10);
+ f1.Write(&d, sizeof(ui32) * 10);
UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 40);
UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 40);
UNIT_ASSERT_VALUES_EQUAL(f1.Seek(12, sSet), 12);
@@ -197,7 +197,7 @@ void TFileTest::TestRW() {
}
#ifdef _unix_
- #include <locale.h>
+ #include <locale.h>
#endif
void TFileTest::TestLocale() {
@@ -328,86 +328,86 @@ void TFileTest::TestPread() {
}
#ifdef _linux_
- #include <sys/statfs.h>
+ #include <sys/statfs.h>
#endif
#ifndef TMPFS_MAGIC
- #define TMPFS_MAGIC 0x01021994
+ #define TMPFS_MAGIC 0x01021994
#endif
-void TFileTest::TestCache(){
+void TFileTest::TestCache(){
#ifdef _linux_
- {// create file in /tmp, current dir could be tmpfs which does not support fadvise
- TFile file(MakeTempName("/tmp"), OpenAlways | Transient | RdWr | NoReadAhead);
+ {// create file in /tmp, current dir could be tmpfs which does not support fadvise
+ TFile file(MakeTempName("/tmp"), OpenAlways | Transient | RdWr | NoReadAhead);
-struct statfs fs;
-if (!fstatfs(file.GetHandle(), &fs) && fs.f_type == TMPFS_MAGIC) {
- return;
-}
+struct statfs fs;
+if (!fstatfs(file.GetHandle(), &fs) && fs.f_type == TMPFS_MAGIC) {
+ return;
+}
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 0), 0);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 0), 0);
-file.Resize(7);
-file.PrefetchCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(3, 2), 2);
+file.Resize(7);
+file.PrefetchCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(3, 2), 2);
-file.FlushCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
+file.FlushCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
-file.EvictCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
+file.EvictCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
-file.PrefetchCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
+file.PrefetchCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 7);
-file.Resize(12345);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 4096);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(4096, 0), 0);
+file.Resize(12345);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 4096);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(4096, 0), 0);
-file.PrefetchCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 12345);
+file.PrefetchCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 12345);
-file.FlushCache();
-file.EvictCache();
-UNIT_ASSERT_LE(file.CountCache(), 0);
+file.FlushCache();
+file.EvictCache();
+UNIT_ASSERT_LE(file.CountCache(), 0);
-file.Resize(33333333);
-file.PrefetchCache(11111111, 11111111);
-UNIT_ASSERT_GE(file.CountCache(), 11111111);
+file.Resize(33333333);
+file.PrefetchCache(11111111, 11111111);
+UNIT_ASSERT_GE(file.CountCache(), 11111111);
-UNIT_ASSERT_LE(file.CountCache(0, 11111111), 1111111);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(11111111, 11111111), 11111111);
-UNIT_ASSERT_LE(file.CountCache(22222222, 11111111), 1111111);
+UNIT_ASSERT_LE(file.CountCache(0, 11111111), 1111111);
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(11111111, 11111111), 11111111);
+UNIT_ASSERT_LE(file.CountCache(22222222, 11111111), 1111111);
-file.FlushCache(11111111, 11111111);
-UNIT_ASSERT_GE(file.CountCache(), 11111111);
+file.FlushCache(11111111, 11111111);
+UNIT_ASSERT_GE(file.CountCache(), 11111111);
-// first and last incomplete pages could stay in cache
-file.EvictCache(11111111, 11111111);
-UNIT_ASSERT_LT(file.CountCache(11111111, 11111111), 4096 * 2);
+// first and last incomplete pages could stay in cache
+file.EvictCache(11111111, 11111111);
+UNIT_ASSERT_LT(file.CountCache(11111111, 11111111), 4096 * 2);
-file.EvictCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
-}
+file.EvictCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), 0);
+}
#else
- {TFile file(MakeTempName(), OpenAlways | Transient | RdWr);
+ {TFile file(MakeTempName(), OpenAlways | Transient | RdWr);
-file.Resize(12345);
+file.Resize(12345);
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), -1);
-file.PrefetchCache();
-file.FlushCache();
-file.EvictCache();
-UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 12345), -1);
-}
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(), -1);
+file.PrefetchCache();
+file.FlushCache();
+file.EvictCache();
+UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 12345), -1);
+}
#endif
}
Y_UNIT_TEST_SUITE(TTestDecodeOpenMode) {
Y_UNIT_TEST(It) {
- UNIT_ASSERT_VALUES_EQUAL("0", DecodeOpenMode(0));
+ UNIT_ASSERT_VALUES_EQUAL("0", DecodeOpenMode(0));
UNIT_ASSERT_VALUES_EQUAL("RdOnly", DecodeOpenMode(RdOnly));
UNIT_ASSERT_VALUES_EQUAL("RdWr", DecodeOpenMode(RdWr));
UNIT_ASSERT_VALUES_EQUAL("WrOnly|ForAppend", DecodeOpenMode(WrOnly | ForAppend));