aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/atexit_ut.cpp
diff options
context:
space:
mode:
authorkimkim <kimkim@yandex-team.ru>2022-02-10 16:49:27 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:27 +0300
commit13f84424ed9975f6827d9786087c6fe6ea265cda (patch)
treeb94acc282c49a5de96b9e3e19feead21736f3273 /util/system/atexit_ut.cpp
parent35f29a67a6b8e50e1826c837330086049114c5ba (diff)
downloadydb-13f84424ed9975f6827d9786087c6fe6ea265cda.tar.gz
Restoring authorship annotation for <kimkim@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/atexit_ut.cpp')
-rw-r--r--util/system/atexit_ut.cpp134
1 files changed, 67 insertions, 67 deletions
diff --git a/util/system/atexit_ut.cpp b/util/system/atexit_ut.cpp
index 953f432811..d577b27a2a 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);