diff options
author | f0b0s <f0b0s@yandex-team.ru> | 2022-02-10 16:46:51 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:51 +0300 |
commit | cdae02d225fb5b3afbb28990e79a7ac6c9125327 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library | |
parent | deabc5260ac2e17b8f5152ee060bec1740613540 (diff) | |
download | ydb-cdae02d225fb5b3afbb28990e79a7ac6c9125327.tar.gz |
Restoring authorship annotation for <f0b0s@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/binsaver/bin_saver.h | 2 | ||||
-rw-r--r-- | library/cpp/sighandler/async_signals_handler.cpp | 82 | ||||
-rw-r--r-- | library/cpp/testing/unittest/registar.h | 28 | ||||
-rw-r--r-- | library/cpp/testing/unittest/utmain.cpp | 74 |
4 files changed, 93 insertions, 93 deletions
diff --git a/library/cpp/binsaver/bin_saver.h b/library/cpp/binsaver/bin_saver.h index ac16355709..412424889f 100644 --- a/library/cpp/binsaver/bin_saver.h +++ b/library/cpp/binsaver/bin_saver.h @@ -78,7 +78,7 @@ private: #if (!defined(_MSC_VER)) // In MSVC __has_trivial_copy returns false to enums, primitive types and arrays. static_assert(__has_trivial_copy(T), "Class is nontrivial copyable, you must define operator&, see"); -#endif +#endif DataChunk(p, sizeof(T)); } diff --git a/library/cpp/sighandler/async_signals_handler.cpp b/library/cpp/sighandler/async_signals_handler.cpp index 2f9338df33..00ce1c18fb 100644 --- a/library/cpp/sighandler/async_signals_handler.cpp +++ b/library/cpp/sighandler/async_signals_handler.cpp @@ -2,31 +2,31 @@ #include <util/system/platform.h> -#if !defined(_win_) +#if !defined(_win_) #include <errno.h> -#include <fcntl.h> +#include <fcntl.h> #include <signal.h> -#include <string.h> +#include <string.h> -#include <unistd.h> +#include <unistd.h> #if defined(_linux_) #include <dlfcn.h> #endif -#include <util/system/atomic.h> -#include <util/system/defaults.h> -#include <util/system/event.h> -#include <util/system/rwlock.h> -#include <util/system/spinlock.h> -#include <util/system/thread.h> -#include <util/system/yassert.h> +#include <util/system/atomic.h> +#include <util/system/defaults.h> +#include <util/system/event.h> +#include <util/system/rwlock.h> +#include <util/system/spinlock.h> +#include <util/system/thread.h> +#include <util/system/yassert.h> #include <util/generic/hash.h> - + namespace { volatile int SIGNAL_PIPE_WRITE_FD = 0; // will be initialized in ctor - + void WriteAllOrDie(const int fd, const void* buf, size_t bufsize) { size_t totalBytesWritten = 0; @@ -36,14 +36,14 @@ namespace { Y_VERIFY(result >= 0 || (result == -1 && errno == EINTR), "write failed: %s (errno = %d)", strerror(errno), errno); totalBytesWritten += static_cast<size_t>(result); } - } - + } + void PipeWriterSignalHandler(int, siginfo_t* info, void*) { const ui8 signum = static_cast<ui8>(info->si_signo); WriteAllOrDie(SIGNAL_PIPE_WRITE_FD, &signum, 1); } - + // Handler for the "asynchronous" unix signals (those which can occur // at arbitrary point of execution and have no need to be reacted on instantly // and/or to preserve execution context at the point of interrupt). @@ -60,7 +60,7 @@ namespace { TAtomic ShouldDie; TSystemEvent DieEvent; - + static void* ThreadFunc(void* data) { reinterpret_cast<TAsyncSignalsHandler*>(data)->RealThreadFunc(); @@ -85,7 +85,7 @@ namespace { } else if (bytesRead == -1) { continue; } - + { TReadGuard dnd(HandlersLock); @@ -104,7 +104,7 @@ namespace { { int filedes[2] = {-1}; -#ifdef _linux_ +#ifdef _linux_ int result; { @@ -126,22 +126,22 @@ namespace { } if (result != 0 && errno == ENOSYS) { // linux older than 2.6.27 returns "not implemented" -#endif +#endif Y_VERIFY(pipe(filedes) == 0, "pipe failed: %s (errno = %d)", strerror(errno), errno); - + SignalPipeReadFd = filedes[0]; SIGNAL_PIPE_WRITE_FD = filedes[1]; Y_VERIFY(fcntl(SignalPipeReadFd, F_SETFD, FD_CLOEXEC) == 0, "fcntl failed: %s (errno = %d)", strerror(errno), errno); Y_VERIFY(fcntl(SIGNAL_PIPE_WRITE_FD, F_SETFD, FD_CLOEXEC) == 0, "fcntl failed: %s (errno = %d)", strerror(errno), errno); -#ifdef _linux_ +#ifdef _linux_ } else { Y_VERIFY(result == 0, "pipe2 failed: %s (errno = %d)", strerror(errno), errno); SignalPipeReadFd = filedes[0]; SIGNAL_PIPE_WRITE_FD = filedes[1]; } -#endif - +#endif + Thread.Start(); Thread.Detach(); } @@ -154,9 +154,9 @@ namespace { DieEvent.WaitT(TDuration::Seconds(15)); /* may cause VERIFY failure in signal handler, propably we should leave it to process clean procedure - close(SIGNAL_PIPE_WRITE_FD); - close(SignalPipeReadFd); -*/ + close(SIGNAL_PIPE_WRITE_FD); + close(SignalPipeReadFd); +*/ } bool DoInstall(int signum, TAutoPtr<TEventHandler> handler) { @@ -179,7 +179,7 @@ namespace { Y_VERIFY(!sigaction(signum, &a, nullptr), "sigaction failed: %s (errno = %d)", strerror(errno), errno); } - } + } }; // This pointer is never deleted - yeah, it's intended memory leak. @@ -190,27 +190,27 @@ namespace { // - destruct variable, ignoring thread - which will cause data corruption. TAsyncSignalsHandler* SIGNALS_HANDLER = nullptr; } - + void SetAsyncSignalHandler(int signum, TAutoPtr<TEventHandler> handler) { - static TAtomic lock; + static TAtomic lock; if (Y_UNLIKELY(SIGNALS_HANDLER == nullptr)) { - TGuard<TAtomic> dnd(lock); + TGuard<TAtomic> dnd(lock); if (SIGNALS_HANDLER == nullptr) { - // NEVERS GETS DESTROYED - SIGNALS_HANDLER = new TAsyncSignalsHandler(); - } - } + // NEVERS GETS DESTROYED + SIGNALS_HANDLER = new TAsyncSignalsHandler(); + } + } - SIGNALS_HANDLER->Install(signum, handler); + SIGNALS_HANDLER->Install(signum, handler); } -#else //_win_ +#else //_win_ -void SetAsyncSignalHandler(int, TAutoPtr<TEventHandler>) { - // TODO: it's really easy to port using _pipe, _read and _write, but it must be tested properly. -} +void SetAsyncSignalHandler(int, TAutoPtr<TEventHandler>) { + // TODO: it's really easy to port using _pipe, _read and _write, but it must be tested properly. +} #endif @@ -224,7 +224,7 @@ namespace { if (func) Func = func; } - + int Handle(int signum) override { if (Func) { Func(signum); diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index e6f96c5dc2..44517a0092 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -136,13 +136,13 @@ namespace NUnitTest { virtual bool CheckAccessTest(TString /*suite*/, const char* /*name*/); virtual void Run(std::function<void()> f, const TString& /*suite*/, const char* /*name*/, bool /*forceFork*/); - - // This process is forked for current test + + // This process is forked for current test virtual bool GetIsForked() const; - // --fork-tests is set (warning: this may be false, but never the less test will be forked if called inside UNIT_FORKED_TEST) + // --fork-tests is set (warning: this may be false, but never the less test will be forked if called inside UNIT_FORKED_TEST) virtual bool GetForkTests() const; - + private: virtual void OnStart(); @@ -236,7 +236,7 @@ namespace NUnitTest { void AfterTest(); bool GetIsForked() const; - + bool GetForkTests() const; ITestSuiteProcessor* Processor() const noexcept; @@ -290,11 +290,11 @@ private: \ #endif #define UNIT_TEST_CHECK_TEST_IS_DECLARED_ONLY_ONCE(F) \ - /* If you see this message - delete multiple UNIT_TEST(TestName) with same TestName. */ \ + /* If you see this message - delete multiple UNIT_TEST(TestName) with same TestName. */ \ /* It's forbidden to declare same test twice because it breaks --fork-tests logic. */ \ int You_have_declared_test_##F##_multiple_times_This_is_forbidden; \ Y_UNUSED(You_have_declared_test_##F##_multiple_times_This_is_forbidden); - + #define UNIT_TEST_RUN(F, FF, context) \ this->BeforeTest((#F)); \ { \ @@ -306,7 +306,7 @@ private: \ }; \ this->TTestBase::Run(std::bind(&T##F##Caller::X, this, context), StaticName(), (#F), FF); \ } - + #define UNIT_TEST_IMPL(F, FF) \ UNIT_TEST_CHECK_TEST_IS_DECLARED_ONLY_ONCE(F) { \ NUnitTest::TTestContext context(this->TTestBase::Processor()); \ @@ -325,10 +325,10 @@ private: \ } \ } -#define UNIT_TEST(F) UNIT_TEST_IMPL(F, false) +#define UNIT_TEST(F) UNIT_TEST_IMPL(F, false) + +#define UNIT_FORKED_TEST(F) UNIT_TEST_IMPL(F, true) -#define UNIT_FORKED_TEST(F) UNIT_TEST_IMPL(F, true) - #define UNIT_TEST_EXCEPTION(F, E) \ /* main process with "--fork-tests" flag treats exceptions as errors - it's result of forked test run */ \ if (this->GetForkTests() && !this->GetIsForked()) { \ @@ -811,7 +811,7 @@ public: \ , ForceFork_(forceFork) { } - + virtual ~TBaseTestCase() = default; // Each test case is executed in 3 steps: @@ -837,7 +837,7 @@ public: \ std::function<void(TTestContext&)> Body_; bool ForceFork_; }; - + using TBaseFixture = TBaseTestCase; // Class for checking that code raises unittest failure @@ -1014,7 +1014,7 @@ public: \ #define Y_UNIT_TEST(N) Y_UNIT_TEST_IMPL(N, false, TCurrentTestCase) #define Y_UNIT_TEST_F(N, F) Y_UNIT_TEST_IMPL(N, false, F) #define SIMPLE_UNIT_FORKED_TEST(N) Y_UNIT_TEST_IMPL(N, true, TCurrentTestCase) - + #define Y_UNIT_TEST_SUITE_IMPLEMENTATION(N) \ namespace NTestSuite##N diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 122ff6d9ea..305bc6b40f 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -269,20 +269,20 @@ public: inline void SetForkTests(bool val) { ForkTests = val; } - + inline bool GetForkTests() const override { return ForkTests; } - + inline void SetIsForked(bool val) { IsForked = val; SetIsTTY(IsForked || CalcIsTTY(stderr)); } - + inline bool GetIsForked() const override { return IsForked; } - + inline void SetLoop(bool loop) { Loop = loop; } @@ -469,47 +469,47 @@ private: TList<TString> args(1, "--is-forked-internal"); args.push_back(Sprintf("+%s::%s", suite.data(), name)); - + // stdin is ignored - unittest should not need them... TShellCommand cmd(AppName, args, TShellCommandOptions().SetUseShell(false).SetCloseAllFdsOnExec(true).SetAsync(false).SetLatency(1)); cmd.Run(); - + const TString& err = cmd.GetError(); const size_t msgIndex = err.find(ForkCorrectExitMsg); - + // everything is printed by parent process except test's result output ("good" or "fail") // which is printed by child. If there was no output - parent process prints default message. ForkExitedCorrectly = msgIndex != TString::npos; - + // TODO: stderr output is always printed after stdout Cout.Write(cmd.GetOutput()); Cerr.Write(err.c_str(), Min(msgIndex, err.size())); - + // do not use default case, so gcc will warn if new element in enum will be added switch (cmd.GetStatus()) { - case TShellCommand::SHELL_FINISHED: { - // test could fail with zero status if it calls exit(0) in the middle. - if (ForkExitedCorrectly) - break; + case TShellCommand::SHELL_FINISHED: { + // test could fail with zero status if it calls exit(0) in the middle. + if (ForkExitedCorrectly) + break; [[fallthrough]]; - } - case TShellCommand::SHELL_ERROR: { - ythrow yexception() << "Forked test failed"; - } - - case TShellCommand::SHELL_NONE: { - ythrow yexception() << "Forked test finished with unknown status"; - } - case TShellCommand::SHELL_RUNNING: { + } + case TShellCommand::SHELL_ERROR: { + ythrow yexception() << "Forked test failed"; + } + + case TShellCommand::SHELL_NONE: { + ythrow yexception() << "Forked test finished with unknown status"; + } + case TShellCommand::SHELL_RUNNING: { Y_VERIFY(false, "This can't happen, we used sync mode, it's a bug!"); - } - case TShellCommand::SHELL_INTERNAL_ERROR: { - ythrow yexception() << "Forked test failed with internal error: " << cmd.GetInternalError(); - } - } + } + case TShellCommand::SHELL_INTERNAL_ERROR: { + ythrow yexception() << "Forked test failed with internal error: " << cmd.GetInternalError(); + } + } } - + private: bool PrintBeforeSuite_; bool PrintBeforeTest_; @@ -618,7 +618,7 @@ static int DoUsage(const char* progname) { << " --show-fails print a list of all failed tests at the end\n" << " --dont-show-fails do not print a list of all failed tests at the end\n" << " --continue-on-fail print a message and continue running test suite instead of break\n" - << " --print-times print wall clock duration of each test\n" + << " --print-times print wall clock duration of each test\n" << " --fork-tests run each test in a separate process\n" << " --trace-path path to the trace file to be generated\n" << " --trace-path-append path to the trace file to be appended\n"; @@ -664,7 +664,7 @@ int NUnitTest::RunMain(int argc, char** argv) { NPlugin::OnStartMain(argc, argv); Y_DEFER { NPlugin::OnStopMain(argc, argv); }; - TColoredProcessor processor(GetExecPath()); + TColoredProcessor processor(GetExecPath()); IOutputStream* listStream = &Cout; THolder<IOutputStream> listFile; @@ -689,10 +689,10 @@ int NUnitTest::RunMain(int argc, char** argv) { processor.SetPrintBeforeSuite(false); } else if (strcmp(name, "--print-before-test=false") == 0) { processor.SetPrintBeforeTest(false); - } else if (strcmp(name, "--print-before-suite") == 0) { - processor.SetPrintBeforeSuite(true); - } else if (strcmp(name, "--print-before-test") == 0) { - processor.SetPrintBeforeTest(true); + } else if (strcmp(name, "--print-before-suite") == 0) { + processor.SetPrintBeforeSuite(true); + } else if (strcmp(name, "--print-before-test") == 0) { + processor.SetPrintBeforeTest(true); } else if (strcmp(name, "--show-fails") == 0) { processor.SetShowFails(true); } else if (strcmp(name, "--dont-show-fails") == 0) { @@ -707,10 +707,10 @@ int NUnitTest::RunMain(int argc, char** argv) { } else if (strcmp(name, "--to") == 0) { ++i; processor.SetEnd(FromString<size_t>(argv[i])); - } else if (strcmp(name, "--fork-tests") == 0) { - processor.SetForkTests(true); + } else if (strcmp(name, "--fork-tests") == 0) { + processor.SetForkTests(true); } else if (strcmp(name, "--is-forked-internal") == 0) { - processor.SetIsForked(true); + processor.SetIsForked(true); } else if (strcmp(name, "--loop") == 0) { processor.SetLoop(true); } else if (strcmp(name, "--trace-path") == 0) { |