diff options
author | kimkim <kimkim@yandex-team.ru> | 2022-02-10 16:49:28 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:28 +0300 |
commit | 10807864acf73d00f425a23b442aac2cf34403a8 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/system | |
parent | 13f84424ed9975f6827d9786087c6fe6ea265cda (diff) | |
download | ydb-10807864acf73d00f425a23b442aac2cf34403a8.tar.gz |
Restoring authorship annotation for <kimkim@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/atexit.cpp | 2 | ||||
-rw-r--r-- | util/system/atexit_ut.cpp | 134 | ||||
-rw-r--r-- | util/system/backtrace_ut.cpp | 60 | ||||
-rw-r--r-- | util/system/condvar.h | 4 | ||||
-rw-r--r-- | util/system/condvar_ut.cpp | 92 | ||||
-rw-r--r-- | util/system/context.cpp | 8 | ||||
-rw-r--r-- | util/system/context.h | 2 | ||||
-rw-r--r-- | util/system/dynlib.cpp | 2 | ||||
-rw-r--r-- | util/system/dynlib.h | 2 | ||||
-rw-r--r-- | util/system/error_ut.cpp | 2 | ||||
-rw-r--r-- | util/system/event.h | 2 | ||||
-rw-r--r-- | util/system/event_ut.cpp | 42 | ||||
-rw-r--r-- | util/system/file.cpp | 2 | ||||
-rw-r--r-- | util/system/file.h | 2 | ||||
-rw-r--r-- | util/system/filemap.cpp | 4 | ||||
-rw-r--r-- | util/system/filemap.h | 4 | ||||
-rw-r--r-- | util/system/filemap_ut.cpp | 114 | ||||
-rw-r--r-- | util/system/guard.h | 2 | ||||
-rw-r--r-- | util/system/guard_ut.cpp | 68 | ||||
-rw-r--r-- | util/system/hostname.cpp | 2 | ||||
-rw-r--r-- | util/system/mutex.cpp | 2 | ||||
-rw-r--r-- | util/system/mutex.h | 4 | ||||
-rw-r--r-- | util/system/mutex_ut.cpp | 88 | ||||
-rw-r--r-- | util/system/rwlock_ut.cpp | 84 | ||||
-rw-r--r-- | util/system/thread.cpp | 4 | ||||
-rw-r--r-- | util/system/thread.h | 2 | ||||
-rw-r--r-- | util/system/tls.h | 4 |
27 files changed, 369 insertions, 369 deletions
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp index 328b0efa3b..74fb10b6b1 100644 --- a/util/system/atexit.cpp +++ b/util/system/atexit.cpp @@ -4,7 +4,7 @@ #include "spinlock.h" #include "thread.h" -#include <util/generic/ylimits.h> +#include <util/generic/ylimits.h> #include <util/generic/utility.h> #include <util/generic/deque.h> #include <util/generic/queue.h> diff --git a/util/system/atexit_ut.cpp b/util/system/atexit_ut.cpp index d577b27a2a..953f432811 100644 --- a/util/system/atexit_ut.cpp +++ b/util/system/atexit_ut.cpp @@ -1,85 +1,85 @@ #include <library/cpp/testing/unittest/registar.h> #include "atexit.h" - + #include <errno.h> -#ifdef _win_ +#ifdef _win_ // not implemented -#else +#else #include <sys/types.h> #include <sys/wait.h> -#endif //_win_ - -#include <stdio.h> - -#ifdef _win_ +#endif //_win_ + +#include <stdio.h> + +#ifdef _win_ // not implemented -#else -struct TAtExitParams { - TAtExitParams(int fd_, const char* str_) - : fd(fd_) - , str(str_) - { - } - - int fd; - const char* str; -}; - +#else +struct TAtExitParams { + TAtExitParams(int fd_, const char* str_) + : fd(fd_) + , str(str_) + { + } + + int fd; + const char* str; +}; + void MyAtExitFunc(void* ptr) { THolder<TAtExitParams> params{static_cast<TAtExitParams*>(ptr)}; if (write(params->fd, params->str, strlen(params->str)) < 0) { abort(); } -} -#endif - +} +#endif + class TAtExitTest: public TTestBase { UNIT_TEST_SUITE(TAtExitTest); UNIT_TEST(TestAtExit) - UNIT_TEST_SUITE_END(); - - void TestAtExit() { -#ifdef _win_ + UNIT_TEST_SUITE_END(); + + void TestAtExit() { +#ifdef _win_ // not implemented -#else - int ret; - int pipefd[2]; - - ret = pipe(pipefd); - UNIT_ASSERT(ret == 0); - - pid_t pid = fork(); - - if (pid < 0) { - UNIT_ASSERT(0); - } - - if (pid > 0) { - char data[1024]; - int last = 0; - - close(pipefd[1]); - - while (read(pipefd[0], data + last++, 1) > 0 && last < 1024) { - } - data[--last] = 0; - - UNIT_ASSERT(strcmp(data, "High prio\nMiddle prio\nLow-middle prio\nLow prio\nVery low prio\n") == 0); - } else { - close(pipefd[0]); - - AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Low prio\n"), 3); - AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Middle prio\n"), 5); - AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "High prio\n"), 7); - AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Very low prio\n"), 1); - AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Low-middle prio\n"), 4); - - exit(0); - } -#endif //_win_ - } -}; - -UNIT_TEST_SUITE_REGISTRATION(TAtExitTest); +#else + int ret; + int pipefd[2]; + + ret = pipe(pipefd); + UNIT_ASSERT(ret == 0); + + pid_t pid = fork(); + + if (pid < 0) { + UNIT_ASSERT(0); + } + + if (pid > 0) { + char data[1024]; + int last = 0; + + close(pipefd[1]); + + while (read(pipefd[0], data + last++, 1) > 0 && last < 1024) { + } + data[--last] = 0; + + UNIT_ASSERT(strcmp(data, "High prio\nMiddle prio\nLow-middle prio\nLow prio\nVery low prio\n") == 0); + } else { + close(pipefd[0]); + + AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Low prio\n"), 3); + AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Middle prio\n"), 5); + AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "High prio\n"), 7); + AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Very low prio\n"), 1); + AtExit(MyAtExitFunc, new TAtExitParams(pipefd[1], "Low-middle prio\n"), 4); + + exit(0); + } +#endif //_win_ + } +}; + +UNIT_TEST_SUITE_REGISTRATION(TAtExitTest); diff --git a/util/system/backtrace_ut.cpp b/util/system/backtrace_ut.cpp index 41e62bd188..9b5ead71bc 100644 --- a/util/system/backtrace_ut.cpp +++ b/util/system/backtrace_ut.cpp @@ -2,21 +2,21 @@ #include <util/generic/array_ref.h> #include <library/cpp/testing/unittest/registar.h> - + #include <util/stream/output.h> using PFunc = int (*)(void**, size_t); - -int Dbg1(void** buf, size_t len) { + +int Dbg1(void** buf, size_t len) { volatile int ret = (int)BackTrace(buf, len); - return ret; -} - -int Dbg2(void** buf, size_t len) { + return ret; +} + +int Dbg2(void** buf, size_t len) { volatile int ret = (int)BackTrace(buf, len); - return ret; -} - + return ret; +} + void FormatBackTraceReplacement(IOutputStream* out, void* const*, size_t) { *out << "WorksLikeACharm" << Endl; } @@ -35,13 +35,13 @@ void SomeMethod() { } class TBackTraceTest: public TTestBase { - UNIT_TEST_SUITE(TBackTraceTest); + UNIT_TEST_SUITE(TBackTraceTest); UNIT_TEST(TestBackTrace) UNIT_TEST(TestBackTraceView) UNIT_TEST(TestPrintBackTrace) UNIT_TEST(TestSetFormatBackTraceFn) - UNIT_TEST_SUITE_END(); - + UNIT_TEST_SUITE_END(); + void TestPrintBackTrace() { SomeMethod(); } @@ -55,21 +55,21 @@ class TBackTraceTest: public TTestBase { TestPrintBackTrace(); } - void TestBackTrace() { + void TestBackTrace() { //PrintBackTrace(); - void* buf1[100]; - size_t ret1; - - void* buf2[100]; - size_t ret2; - - volatile PFunc func = &Dbg1; - ret1 = (*func)(buf1, 100); - func = &Dbg2; - ret2 = (*func)(buf2, 100); - - UNIT_ASSERT_EQUAL(ret1, ret2); - } + void* buf1[100]; + size_t ret1; + + void* buf2[100]; + size_t ret2; + + volatile PFunc func = &Dbg1; + ret1 = (*func)(buf1, 100); + func = &Dbg2; + ret2 = (*func)(buf2, 100); + + UNIT_ASSERT_EQUAL(ret1, ret2); + } void TestBackTraceView() { try { @@ -80,6 +80,6 @@ class TBackTraceTest: public TTestBase { UNIT_ASSERT_VALUES_EQUAL(btView.size(), bt.size()); } } -}; - -UNIT_TEST_SUITE_REGISTRATION(TBackTraceTest); +}; + +UNIT_TEST_SUITE_REGISTRATION(TBackTraceTest); diff --git a/util/system/condvar.h b/util/system/condvar.h index 79fe7d98bd..569162717c 100644 --- a/util/system/condvar.h +++ b/util/system/condvar.h @@ -2,8 +2,8 @@ #include "mutex.h" -#include <util/generic/ptr.h> -#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> +#include <util/generic/noncopyable.h> #include <util/datetime/base.h> #include <utility> diff --git a/util/system/condvar_ut.cpp b/util/system/condvar_ut.cpp index 7c1c85a26a..5130a18d32 100644 --- a/util/system/condvar_ut.cpp +++ b/util/system/condvar_ut.cpp @@ -3,45 +3,45 @@ #include "condvar.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/system/atomic.h> #include <util/system/atomic_ops.h> #include <util/thread/pool.h> - + class TCondVarTest: public TTestBase { - UNIT_TEST_SUITE(TCondVarTest); + UNIT_TEST_SUITE(TCondVarTest); UNIT_TEST(TestBasics) UNIT_TEST(TestSyncronize) - UNIT_TEST_SUITE_END(); - - struct TSharedData { - TSharedData() - : stopWaiting(false) - , in(0) - , out(0) - , waited(0) - , failed(false) - { - } - - TMutex mutex; - TCondVar condVar1; - TCondVar condVar2; - + UNIT_TEST_SUITE_END(); + + struct TSharedData { + TSharedData() + : stopWaiting(false) + , in(0) + , out(0) + , waited(0) + , failed(false) + { + } + + TMutex mutex; + TCondVar condVar1; + TCondVar condVar2; + TAtomic stopWaiting; - + TAtomic in; TAtomic out; - + TAtomic waited; - - bool failed; - }; - + + bool failed; + }; + class TThreadTask: public IObjectInQueue { public: using PFunc = void (TThreadTask::*)(void); - + TThreadTask(PFunc func, size_t id, size_t totalIds, TSharedData& data) : Func_(func) , Id_(id) @@ -49,20 +49,20 @@ class TCondVarTest: public TTestBase { , Data_(data) { } - + void Process(void*) override { THolder<TThreadTask> This(this); (this->*Func_)(); } - + #define FAIL_ASSERT(cond) \ if (!(cond)) { \ Data_.failed = true; \ - } + } void RunBasics() { Y_ASSERT(TotalIds_ == 3); - + if (Id_ < 2) { TGuard<TMutex> guard(Data_.mutex); while (!AtomicGet(Data_.stopWaiting)) { @@ -109,10 +109,10 @@ class TCondVarTest: public TTestBase { AtomicIncrement(Data_.waited); while (AtomicGet(Data_.in) < TotalIds_) { bool res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1)); - FAIL_ASSERT(res == true); - } - } - + FAIL_ASSERT(res == true); + } + } + AtomicIncrement(Data_.out); if (AtomicGet(Data_.out) == TotalIds_) { AtomicSet(Data_.in, 0); @@ -121,10 +121,10 @@ class TCondVarTest: public TTestBase { while (AtomicGet(Data_.out) < TotalIds_) { bool res = Data_.condVar2.WaitT(Data_.mutex, TDuration::Seconds(1)); FAIL_ASSERT(res == true); - } - } + } + } } - + FAIL_ASSERT(AtomicGet(Data_.waited) == (TotalIds_ - 1) * 10); } @@ -157,15 +157,15 @@ class TCondVarTest: public TTestBase { FAIL_ASSERT(Data_.waited == (TotalIds_ - 1) * 10); } -#undef FAIL_ASSERT - +#undef FAIL_ASSERT + private: PFunc Func_; size_t Id_; TAtomicBase TotalIds_; TSharedData& Data_; - }; - + }; + private: #define RUN_CYCLE(what, count) \ Q_.Start(count); \ @@ -176,11 +176,11 @@ private: bool b = Data_.failed; \ Data_.failed = false; \ UNIT_ASSERT(!b); - + inline void TestBasics() { RUN_CYCLE(RunBasics, 3); } - + inline void TestBasicsWithPredicate() { RUN_CYCLE(RunBasicsWithPredicate, 3); } @@ -195,6 +195,6 @@ private: #undef RUN_CYCLE TSharedData Data_; TThreadPool Q_; -}; - -UNIT_TEST_SUITE_REGISTRATION(TCondVarTest); +}; + +UNIT_TEST_SUITE_REGISTRATION(TCondVarTest); diff --git a/util/system/context.cpp b/util/system/context.cpp index 82d113b09c..ad99309088 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -25,7 +25,7 @@ namespace __cxxabiv1 { #endif #include <util/stream/output.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #define FROM_CONTEXT_IMPL #include "context.h" @@ -220,10 +220,10 @@ void ContextTrampoLine(void* arg) { TContMachineContext::TContMachineContext() : Fiber_(ConvertThreadToFiber(this)) , MainFiber_(true) -{ +{ Y_ENSURE(Fiber_, TStringBuf("fiber error")); -} - +} + TContMachineContext::TContMachineContext(const TContClosure& c) : Fiber_(CreateFiber(c.Stack.size(), (LPFIBER_START_ROUTINE)ContextTrampoLine, (LPVOID)c.TrampoLine)) , MainFiber_(false) diff --git a/util/system/context.h b/util/system/context.h index 5db49a9583..d2a349bfc5 100644 --- a/util/system/context.h +++ b/util/system/context.h @@ -7,7 +7,7 @@ #include <util/generic/array_ref.h> #include <util/generic/utility.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #define STACK_ALIGN (8 * PLATFORM_DATA_ALIGN) diff --git a/util/system/dynlib.cpp b/util/system/dynlib.cpp index 35ebc4f7b8..9d2541c25f 100644 --- a/util/system/dynlib.cpp +++ b/util/system/dynlib.cpp @@ -123,7 +123,7 @@ void* TDynamicLibrary::SymOptional(const char* name) noexcept { void* TDynamicLibrary::Sym(const char* name) { if (!IsLoaded()) { - ythrow yexception() << "library not loaded"; + ythrow yexception() << "library not loaded"; } return Impl_->Sym(name); diff --git a/util/system/dynlib.h b/util/system/dynlib.h index de77cd86cf..66eaf4a5c1 100644 --- a/util/system/dynlib.h +++ b/util/system/dynlib.h @@ -2,7 +2,7 @@ #include "defaults.h" -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/string.h> #define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name)) diff --git a/util/system/error_ut.cpp b/util/system/error_ut.cpp index 57fbf40b5f..763b0dddb7 100644 --- a/util/system/error_ut.cpp +++ b/util/system/error_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/ylimits.h> +#include <util/generic/ylimits.h> #ifdef _win_ #include "winint.h" diff --git a/util/system/event.h b/util/system/event.h index 7e8dfe4d2b..cab2fc478a 100644 --- a/util/system/event.h +++ b/util/system/event.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/datetime/base.h> struct TEventResetType { diff --git a/util/system/event_ut.cpp b/util/system/event_ut.cpp index 685336e927..2506cb7a91 100644 --- a/util/system/event_ut.cpp +++ b/util/system/event_ut.cpp @@ -2,22 +2,22 @@ #include "atomic.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/thread/pool.h> - + namespace { - struct TSharedData { - TSharedData() - : Counter(0) - , failed(false) - { - } - + struct TSharedData { + TSharedData() + : Counter(0) + , failed(false) + { + } + TAtomic Counter; TManualEvent event; - bool failed; - }; - + bool failed; + }; + struct TThreadTask: public IObjectInQueue { public: TThreadTask(TSharedData& data, size_t id) @@ -25,7 +25,7 @@ namespace { , Id_(id) { } - + void Process(void*) override { THolder<TThreadTask> This(this); @@ -38,16 +38,16 @@ namespace { Data_.event.Signal(); } else { while (!Data_.event.WaitT(TDuration::Seconds(100))) { - } + } AtomicAdd(Data_.Counter, Id_); - } + } } - + private: TSharedData& Data_; size_t Id_; - }; - + }; + class TSignalTask: public IObjectInQueue { private: TManualEvent& Ev_; @@ -89,12 +89,12 @@ Y_UNIT_TEST_SUITE(EventTest) { queue.Start(5); for (size_t i = 0; i < 5; ++i) { UNIT_ASSERT(queue.Add(new TThreadTask(data, i))); - } + } queue.Stop(); UNIT_ASSERT(data.Counter == 10); UNIT_ASSERT(!data.failed); } - + Y_UNIT_TEST(ConcurrentSignalAndWaitTest) { // test for problem detected by thread-sanitizer (signal/wait race) SEARCH-2113 const size_t limit = 200; @@ -121,7 +121,7 @@ Y_UNIT_TEST_SUITE(EventTest) { tasks.emplace_back(MakeHolder<TSignalTask>(*owner->Ev)); tasks.emplace_back(std::move(owner)); } - + TThreadPool queue; queue.Start(4); for (auto& task : tasks) { diff --git a/util/system/file.cpp b/util/system/file.cpp index 3a684cd90a..4a261d020c 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -18,7 +18,7 @@ #include <util/generic/size_literals.h> #include <util/generic/string.h> -#include <util/generic/ylimits.h> +#include <util/generic/ylimits.h> #include <util/generic/yexception.h> #include <util/datetime/base.h> diff --git a/util/system/file.h b/util/system/file.h index 1d67a2ca7f..9502e159b6 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -4,7 +4,7 @@ #include "flock.h" #include <util/generic/flags.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/noncopyable.h> #include <cstdio> diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 50b94878ee..7454a4cb94 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -30,7 +30,7 @@ #error todo #endif -#include <util/generic/utility.h> +#include <util/generic/utility.h> #include <util/system/sanitizers.h> #include "filemap.h" @@ -512,7 +512,7 @@ void TFileMap::Unmap() { if (Map_.Unmap(Region_)) { Region_.Reset(); } else { - ythrow yexception() << "can't unmap file"; + ythrow yexception() << "can't unmap file"; } } diff --git a/util/system/filemap.h b/util/system/filemap.h index 5517231d34..11be64bff4 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -5,8 +5,8 @@ #include "yassert.h" #include <util/generic/noncopyable.h> -#include <util/generic/ptr.h> -#include <util/generic/utility.h> +#include <util/generic/ptr.h> +#include <util/generic/utility.h> #include <util/generic/yexception.h> #include <util/generic/flags.h> #include <util/generic/string.h> diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 96836304af..73f109dc88 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -3,9 +3,9 @@ #ifdef _unix_ #include <sys/resource.h> #endif - -#include "filemap.h" - + +#include "filemap.h" + #include <util/system/fs.h> #include <cstring> @@ -13,43 +13,43 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { static const char* FileName_("./mappped_file"); - + void BasicTest(TMemoryMapCommon::EOpenMode mode) { - char data[] = "abcdefgh"; - + char data[] = "abcdefgh"; + TFile file(FileName_, CreateAlways | WrOnly); file.Write(static_cast<void*>(data), sizeof(data)); - file.Close(); - - { + file.Close(); + + { TFileMap mappedFile(FileName_, mode); - mappedFile.Map(0, mappedFile.Length()); - UNIT_ASSERT(mappedFile.MappedSize() == sizeof(data) && mappedFile.Length() == sizeof(data)); - UNIT_ASSERT(mappedFile.IsOpen()); - for (size_t i = 0; i < sizeof(data); ++i) { - UNIT_ASSERT(static_cast<char*>(mappedFile.Ptr())[i] == data[i]); - static_cast<char*>(mappedFile.Ptr())[i] = data[i] + 1; - } - mappedFile.Flush(); + mappedFile.Map(0, mappedFile.Length()); + UNIT_ASSERT(mappedFile.MappedSize() == sizeof(data) && mappedFile.Length() == sizeof(data)); + UNIT_ASSERT(mappedFile.IsOpen()); + for (size_t i = 0; i < sizeof(data); ++i) { + UNIT_ASSERT(static_cast<char*>(mappedFile.Ptr())[i] == data[i]); + static_cast<char*>(mappedFile.Ptr())[i] = data[i] + 1; + } + mappedFile.Flush(); TFileMap::TMapResult mapResult = mappedFile.Map(2, 2); UNIT_ASSERT(mapResult.MappedSize() == 2); UNIT_ASSERT(mapResult.MappedData() == mappedFile.Ptr()); - UNIT_ASSERT(mappedFile.MappedSize() == 2); - UNIT_ASSERT(static_cast<char*>(mappedFile.Ptr())[0] == 'd' && static_cast<char*>(mappedFile.Ptr())[1] == 'e'); + UNIT_ASSERT(mappedFile.MappedSize() == 2); + UNIT_ASSERT(static_cast<char*>(mappedFile.Ptr())[0] == 'd' && static_cast<char*>(mappedFile.Ptr())[1] == 'e'); - mappedFile.Unmap(); + mappedFile.Unmap(); UNIT_ASSERT(mappedFile.MappedSize() == 0); FILE* f = fopen(FileName_, "rb"); TFileMap mappedFile2(f); - mappedFile2.Map(0, mappedFile2.Length()); - UNIT_ASSERT(mappedFile2.MappedSize() == sizeof(data)); - UNIT_ASSERT(static_cast<char*>(mappedFile2.Ptr())[0] == data[0] + 1); - fclose(f); - } + mappedFile2.Map(0, mappedFile2.Length()); + UNIT_ASSERT(mappedFile2.MappedSize() == sizeof(data)); + UNIT_ASSERT(static_cast<char*>(mappedFile2.Ptr())[0] == data[0] + 1); + fclose(f); + } NFs::Remove(FileName_); - } + } Y_UNIT_TEST(TestFileMap) { BasicTest(TMemoryMapCommon::oRdWr); @@ -170,7 +170,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { maps.emplace_back(MakeHolder<TFileMap>(FileName_, TMemoryMapCommon::oRdOnly | TMemoryMapCommon::oNotGreedy)); maps.back()->Map(i * sizeof(page), sizeof(page)); } - + // Oh, good, we're not dead yet for (int i = 0; i < 16; ++i) { TFileMap& map = *maps[i]; @@ -212,20 +212,20 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { #endif Y_UNIT_TEST(TestFileMappedArray) { - { + { TFileMappedArray<ui32> mappedArray; - ui32 data[] = {123, 456, 789, 10}; - size_t sz = sizeof(data) / sizeof(data[0]); + ui32 data[] = {123, 456, 789, 10}; + size_t sz = sizeof(data) / sizeof(data[0]); TFile file(FileName_, CreateAlways | WrOnly); file.Write(static_cast<void*>(data), sizeof(data)); - file.Close(); - + file.Close(); + mappedArray.Init(FileName_); // actual test begin UNIT_ASSERT(mappedArray.Size() == sz); for (size_t i = 0; i < sz; ++i) { - UNIT_ASSERT(mappedArray[i] == data[i]); + UNIT_ASSERT(mappedArray[i] == data[i]); } UNIT_ASSERT(mappedArray.GetAt(mappedArray.Size()) == 0); @@ -234,7 +234,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { UNIT_ASSERT(!mappedArray.Empty()); // actual test end mappedArray.Term(); - + // Init array via file mapping TFileMap fileMap(FileName_); fileMap.Map(0, fileMap.Length()); @@ -255,41 +255,41 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { file = TFile(FileName_, WrOnly); file.Seek(0, sEnd); file.Write("x", 1); - file.Close(); - + file.Close(); + bool caught = false; - try { + try { mappedArray.Init(FileName_); - } catch (const yexception&) { + } catch (const yexception&) { caught = true; - } + } UNIT_ASSERT(caught); - } + } NFs::Remove(FileName_); - } - + } + Y_UNIT_TEST(TestMappedArray) { - ui32 sz = 10; + ui32 sz = 10; TMappedArray<ui32> mappedArray; - ui32* ptr = mappedArray.Create(sz); + ui32* ptr = mappedArray.Create(sz); UNIT_ASSERT(ptr != nullptr); - UNIT_ASSERT(mappedArray.size() == sz); - UNIT_ASSERT(mappedArray.begin() + sz == mappedArray.end()); - - for (size_t i = 0; i < sz; ++i) { + UNIT_ASSERT(mappedArray.size() == sz); + UNIT_ASSERT(mappedArray.begin() + sz == mappedArray.end()); + + for (size_t i = 0; i < sz; ++i) { mappedArray[i] = (ui32)i; - } - for (size_t i = 0; i < sz; ++i) { - UNIT_ASSERT(mappedArray[i] == i); - } - + } + for (size_t i = 0; i < sz; ++i) { + UNIT_ASSERT(mappedArray[i] == i); + } + TMappedArray<ui32> mappedArray2(1000); - mappedArray.swap(mappedArray2); + mappedArray.swap(mappedArray2); UNIT_ASSERT(mappedArray.size() == 1000 && mappedArray2.size() == sz); - } - + } + Y_UNIT_TEST(TestMemoryMap) { TFile file(FileName_, CreateAlways | WrOnly); file.Close(); @@ -356,4 +356,4 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { } NFs::Remove(FileName_); } -}; +}; diff --git a/util/system/guard.h b/util/system/guard.h index e4e6b04853..efc091d5f8 100644 --- a/util/system/guard.h +++ b/util/system/guard.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/noncopyable.h> +#include <util/generic/noncopyable.h> template <class T> struct TCommonLockOps { diff --git a/util/system/guard_ut.cpp b/util/system/guard_ut.cpp index e5901d1c8e..404ede99ab 100644 --- a/util/system/guard_ut.cpp +++ b/util/system/guard_ut.cpp @@ -2,11 +2,11 @@ #include "rwlock.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/thread/pool.h> - + struct TTestGuard: public TTestBase { - UNIT_TEST_SUITE(TTestGuard); + UNIT_TEST_SUITE(TTestGuard); UNIT_TEST(TestGuard) UNIT_TEST(TestTryGuard) UNIT_TEST(TestMove) @@ -15,20 +15,20 @@ struct TTestGuard: public TTestBase { UNIT_TEST(TestTryReadGuard) UNIT_TEST(TestWithLock) UNIT_TEST(TestWithLockScope); - UNIT_TEST_SUITE_END(); - - struct TGuardChecker { - TGuardChecker() - : guarded(false) - { - } - - void Acquire() { - guarded = true; - } - void Release() { - guarded = false; - } + UNIT_TEST_SUITE_END(); + + struct TGuardChecker { + TGuardChecker() + : guarded(false) + { + } + + void Acquire() { + guarded = true; + } + void Release() { + guarded = false; + } bool TryAcquire() { if (guarded) { return false; @@ -37,10 +37,10 @@ struct TTestGuard: public TTestBase { return true; } } - - bool guarded; - }; - + + bool guarded; + }; + void TestUnguard() { TGuardChecker m; @@ -101,16 +101,16 @@ struct TTestGuard: public TTestBase { UNIT_ASSERT_VALUES_EQUAL(n, 1); } - void TestGuard() { - TGuardChecker checker; - - UNIT_ASSERT(!checker.guarded); - { - TGuard<TGuardChecker> guard(checker); - UNIT_ASSERT(checker.guarded); - } - UNIT_ASSERT(!checker.guarded); - } + void TestGuard() { + TGuardChecker checker; + + UNIT_ASSERT(!checker.guarded); + { + TGuard<TGuardChecker> guard(checker); + UNIT_ASSERT(checker.guarded); + } + UNIT_ASSERT(!checker.guarded); + } void TestTryGuard() { TGuardChecker checker; @@ -175,6 +175,6 @@ struct TTestGuard: public TTestBase { Y_UNUSED(Guard); } } -}; - -UNIT_TEST_SUITE_REGISTRATION(TTestGuard) +}; + +UNIT_TEST_SUITE_REGISTRATION(TTestGuard) diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 2fe1adb19c..386f646d6b 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -1,6 +1,6 @@ #include <util/memory/tempbuf.h> #include <util/generic/singleton.h> -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> #include <util/network/ip.h> #if defined(_unix_) diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 5710447400..4041402db9 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -85,7 +85,7 @@ public: return TryEnterCriticalSection(obj); #endif // _WIN32_WINNT < 0x0400 } -#endif // _win_ +#endif // _win_ inline bool TryAcquire() noexcept { #if defined(_win_) diff --git a/util/system/mutex.h b/util/system/mutex.h index 5973b169c6..032630d134 100644 --- a/util/system/mutex.h +++ b/util/system/mutex.h @@ -3,8 +3,8 @@ #include "guard.h" #include "defaults.h" -#include <util/generic/ptr.h> -#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> +#include <util/generic/noncopyable.h> class TFakeMutex: public TNonCopyable { public: diff --git a/util/system/mutex_ut.cpp b/util/system/mutex_ut.cpp index 0fc27c191d..c8d7caafa1 100644 --- a/util/system/mutex_ut.cpp +++ b/util/system/mutex_ut.cpp @@ -2,52 +2,52 @@ #include "atomic.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/thread/pool.h> -#include <util/random/random.h> - +#include <util/random/random.h> + class TMutexTest: public TTestBase { - UNIT_TEST_SUITE(TMutexTest); + UNIT_TEST_SUITE(TMutexTest); UNIT_TEST(TestBasics) UNIT_TEST(TestFake) UNIT_TEST(TestRecursive) - UNIT_TEST_SUITE_END(); - - struct TSharedData { - TSharedData() - : sharedCounter(0) - , failed(false) - { - } - - volatile ui32 sharedCounter; - TMutex mutex; - TFakeMutex fakeMutex; - - bool failed; - }; - + UNIT_TEST_SUITE_END(); + + struct TSharedData { + TSharedData() + : sharedCounter(0) + , failed(false) + { + } + + volatile ui32 sharedCounter; + TMutex mutex; + TFakeMutex fakeMutex; + + bool failed; + }; + class TThreadTask: public IObjectInQueue { public: using PFunc = void (TThreadTask::*)(void); - + TThreadTask(PFunc func, TSharedData& data, size_t id) : Func_(func) , Data_(data) , Id_(id) { } - + void Process(void*) override { THolder<TThreadTask> This(this); (this->*Func_)(); } - + #define FAIL_ASSERT(cond) \ if (!(cond)) { \ Data_.failed = true; \ - } + } void RunBasics() { Data_.mutex.Acquire(); @@ -55,10 +55,10 @@ class TMutexTest: public TTestBase { Data_.sharedCounter = oldCounter; usleep(10 + RandomNumber<ui32>() % 10); FAIL_ASSERT(Data_.sharedCounter == oldCounter); - + Data_.mutex.Release(); } - + void RunFakeMutex() { bool res = Data_.fakeMutex.TryAcquire(); FAIL_ASSERT(res); @@ -69,9 +69,9 @@ class TMutexTest: public TTestBase { Data_.mutex.Acquire(); ++Data_.sharedCounter; usleep(1); - } + } FAIL_ASSERT(Data_.sharedCounter == Id_ + 1); - + bool res = Data_.mutex.TryAcquire(); FAIL_ASSERT(res); Data_.mutex.Release(); @@ -79,20 +79,20 @@ class TMutexTest: public TTestBase { for (size_t i = 0; i < Id_; ++i) { --Data_.sharedCounter; Data_.mutex.Release(); - } + } FAIL_ASSERT(Data_.sharedCounter == 1); --Data_.sharedCounter; Data_.mutex.Release(); } - -#undef FAIL_ASSERT - + +#undef FAIL_ASSERT + private: PFunc Func_; TSharedData& Data_; size_t Id_; - }; - + }; + private: #define RUN_CYCLE(what, count) \ Q_.Start(count); \ @@ -103,27 +103,27 @@ private: bool b = Data_.failed; \ Data_.failed = false; \ UNIT_ASSERT(!b); - + void TestBasics() { RUN_CYCLE(RunBasics, 5); - + UNIT_ASSERT(Data_.sharedCounter == 10); Data_.sharedCounter = 0; } - + void TestFake() { RUN_CYCLE(RunFakeMutex, 3); } - + void TestRecursive() { RUN_CYCLE(RunRecursiveMutex, 4); } - -#undef RUN_CYCLE - + +#undef RUN_CYCLE + private: TSharedData Data_; TThreadPool Q_; -}; - -UNIT_TEST_SUITE_REGISTRATION(TMutexTest) +}; + +UNIT_TEST_SUITE_REGISTRATION(TMutexTest) diff --git a/util/system/rwlock_ut.cpp b/util/system/rwlock_ut.cpp index d050737c9c..2b384c05b3 100644 --- a/util/system/rwlock_ut.cpp +++ b/util/system/rwlock_ut.cpp @@ -2,36 +2,36 @@ #include "atomic.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/thread/pool.h> -#include <util/random/random.h> - +#include <util/random/random.h> + class TRWMutexTest: public TTestBase { - UNIT_TEST_SUITE(TRWMutexTest); + UNIT_TEST_SUITE(TRWMutexTest); UNIT_TEST(TestReaders) UNIT_TEST(TestReadersWriters) - UNIT_TEST_SUITE_END(); - - struct TSharedData { - TSharedData() - : writersIn(0) - , readersIn(0) - , failed(false) - { - } - + UNIT_TEST_SUITE_END(); + + struct TSharedData { + TSharedData() + : writersIn(0) + , readersIn(0) + , failed(false) + { + } + TAtomic writersIn; TAtomic readersIn; - - bool failed; - - TRWMutex mutex; - }; + + bool failed; + + TRWMutex mutex; + }; class TThreadTask: public IObjectInQueue { public: using PFunc = void (TThreadTask::*)(void); - + TThreadTask(PFunc func, TSharedData& data, size_t id, size_t total) : Func_(func) , Data_(data) @@ -39,62 +39,62 @@ class TRWMutexTest: public TTestBase { , Total_(total) { } - + void Process(void*) override { THolder<TThreadTask> This(this); (this->*Func_)(); } - + #define FAIL_ASSERT(cond) \ if (!(cond)) { \ Data_.failed = true; \ - } + } void RunReaders() { Data_.mutex.AcquireRead(); - + AtomicIncrement(Data_.readersIn); usleep(100); FAIL_ASSERT(Data_.readersIn == long(Total_)); usleep(100); AtomicDecrement(Data_.readersIn); - + Data_.mutex.ReleaseRead(); } - + void RunReadersWriters() { if (Id_ % 2 == 0) { for (size_t i = 0; i < 10; ++i) { Data_.mutex.AcquireRead(); - + AtomicIncrement(Data_.readersIn); FAIL_ASSERT(Data_.writersIn == 0); usleep(RandomNumber<ui32>() % 5); AtomicDecrement(Data_.readersIn); - + Data_.mutex.ReleaseRead(); } } else { for (size_t i = 0; i < 10; ++i) { Data_.mutex.AcquireWrite(); - + AtomicIncrement(Data_.writersIn); FAIL_ASSERT(Data_.readersIn == 0 && Data_.writersIn == 1); usleep(RandomNumber<ui32>() % 5); AtomicDecrement(Data_.writersIn); - + Data_.mutex.ReleaseWrite(); - } - } + } + } } -#undef FAIL_ASSERT - +#undef FAIL_ASSERT + private: PFunc Func_; TSharedData& Data_; size_t Id_; size_t Total_; - }; + }; private: #define RUN_CYCLE(what, count) \ @@ -106,19 +106,19 @@ private: bool b = Data_.failed; \ Data_.failed = false; \ UNIT_ASSERT(!b); - + void TestReaders() { RUN_CYCLE(RunReaders, 1); } - + void TestReadersWriters() { RUN_CYCLE(RunReadersWriters, 1); } - -#undef RUN_CYCLE + +#undef RUN_CYCLE private: TSharedData Data_; TThreadPool Q_; -}; - -UNIT_TEST_SUITE_REGISTRATION(TRWMutexTest) +}; + +UNIT_TEST_SUITE_REGISTRATION(TRWMutexTest) diff --git a/util/system/thread.cpp b/util/system/thread.cpp index 37e4a6b446..6236746c2d 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -2,8 +2,8 @@ #include "thread.h" #include "thread.i" -#include <util/generic/ptr.h> -#include <util/generic/ymath.h> +#include <util/generic/ptr.h> +#include <util/generic/ymath.h> #include <util/generic/ylimits.h> #include <util/generic/yexception.h> #include "yassert.h" diff --git a/util/system/thread.h b/util/system/thread.h index 9ba987f321..a6e8abdb5b 100644 --- a/util/system/thread.h +++ b/util/system/thread.h @@ -4,7 +4,7 @@ /// If you need threads, use thread pool functionality in <util/thread/factory.h> /// @see SystemThreadFactory() -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/string.h> #include "defaults.h" diff --git a/util/system/tls.h b/util/system/tls.h index c8047ebf9e..3c4f56dbeb 100644 --- a/util/system/tls.h +++ b/util/system/tls.h @@ -2,8 +2,8 @@ #include "defaults.h" -#include <util/generic/ptr.h> -#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> +#include <util/generic/noncopyable.h> #include <new> |