aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/thread_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/system/thread_ut.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system/thread_ut.cpp')
-rw-r--r--util/system/thread_ut.cpp166
1 files changed, 83 insertions, 83 deletions
diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp
index be610bc0ea..d820898fd5 100644
--- a/util/system/thread_ut.cpp
+++ b/util/system/thread_ut.cpp
@@ -1,60 +1,60 @@
-#include "thread.h"
-
+#include "thread.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <atomic>
Y_UNIT_TEST_SUITE(TSysThreadTest) {
- struct TIdTester {
- inline TIdTester()
+ struct TIdTester {
+ inline TIdTester()
: Thr(nullptr)
- , Cur(0)
- , Real(0)
- {
- }
-
- static inline void* DoRun(void* ptr) {
- ((TIdTester*)ptr)->Run();
-
+ , Cur(0)
+ , Real(0)
+ {
+ }
+
+ static inline void* DoRun(void* ptr) {
+ ((TIdTester*)ptr)->Run();
+
return nullptr;
- }
-
- inline void Run() {
- Cur = TThread::CurrentThreadId();
- Real = Thr->Id();
+ }
+
+ inline void Run() {
+ Cur = TThread::CurrentThreadId();
+ Real = Thr->Id();
Numeric = TThread::CurrentThreadNumericId();
- }
-
- TThread* Thr;
- TThread::TId Cur;
- TThread::TId Real;
+ }
+
+ TThread* Thr;
+ TThread::TId Cur;
+ TThread::TId Real;
TThread::TId Numeric;
- };
-
+ };
+
Y_UNIT_TEST(TestThreadId) {
- TIdTester tst;
- TThread thr(tst.DoRun, &tst);
-
- tst.Thr = &thr;
-
- thr.Start();
- thr.Join();
-
- UNIT_ASSERT_EQUAL(tst.Cur, tst.Real);
- UNIT_ASSERT(tst.Cur != 0);
+ TIdTester tst;
+ TThread thr(tst.DoRun, &tst);
+
+ tst.Thr = &thr;
+
+ thr.Start();
+ thr.Join();
+
+ UNIT_ASSERT_EQUAL(tst.Cur, tst.Real);
+ UNIT_ASSERT(tst.Cur != 0);
UNIT_ASSERT(tst.Numeric != 0);
UNIT_ASSERT(tst.Numeric != tst.Real);
- }
-
- void* ThreadProc(void*) {
+ }
+
+ void* ThreadProc(void*) {
TThread::SetCurrentThreadName("CurrentThreadSetNameTest");
return nullptr;
- }
-
- void* ThreadProc2(void*) {
+ }
+
+ void* ThreadProc2(void*) {
return nullptr;
- }
-
+ }
+
void* ThreadProc3(void*) {
const auto name = TThread::CurrentThreadName();
Y_FAKE_READ(name);
@@ -107,18 +107,18 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
Y_UNIT_TEST(TestSetThreadName) {
TThread thread(&ThreadProc, nullptr);
- // just check it doesn't crash
- thread.Start();
- thread.Join();
- }
-
+ // just check it doesn't crash
+ thread.Start();
+ thread.Join();
+ }
+
Y_UNIT_TEST(TestSetThreadName2) {
TThread thread(TThread::TParams(&ThreadProc, nullptr, 0).SetName("XXX"));
-
- thread.Start();
- thread.Join();
- }
-
+
+ thread.Start();
+ thread.Join();
+ }
+
Y_UNIT_TEST(TestGetThreadName) {
TThread thread(&ThreadProc3, nullptr);
thread.Start();
@@ -139,45 +139,45 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
Y_UNIT_TEST(TestDoubleJoin) {
TThread thread(&ThreadProc, nullptr);
-
- thread.Start();
- thread.Join();
-
+
+ thread.Start();
+ thread.Join();
+
UNIT_ASSERT_EQUAL(thread.Join(), nullptr);
- }
-
+ }
+
Y_UNIT_TEST(TestDoubleStart) {
TThread thread(&ThreadProc, nullptr);
-
- thread.Start();
- UNIT_ASSERT_EXCEPTION(thread.Start(), yexception);
- thread.Join();
- }
-
+
+ thread.Start();
+ UNIT_ASSERT_EXCEPTION(thread.Start(), yexception);
+ thread.Join();
+ }
+
Y_UNIT_TEST(TestNoStart) {
TThread thread(&ThreadProc, nullptr);
- }
-
+ }
+
Y_UNIT_TEST(TestNoStartJoin) {
TThread thread(&ThreadProc, nullptr);
-
+
UNIT_ASSERT_EQUAL(thread.Join(), nullptr);
- }
-
+ }
+
Y_UNIT_TEST(TestStackPointer) {
- TArrayHolder<char> buf(new char[64000]);
+ TArrayHolder<char> buf(new char[64000]);
TThread thr(TThread::TParams(ThreadProc2, nullptr).SetStackPointer(buf.Get()).SetStackSize(64000));
-
- thr.Start();
- UNIT_ASSERT_VALUES_EQUAL(thr.Join(), nullptr);
- }
-
+
+ thr.Start();
+ UNIT_ASSERT_VALUES_EQUAL(thr.Join(), nullptr);
+ }
+
Y_UNIT_TEST(TestStackLimits) {
- TCurrentThreadLimits sl;
-
- UNIT_ASSERT(sl.StackBegin);
- UNIT_ASSERT(sl.StackLength > 0);
- }
+ TCurrentThreadLimits sl;
+
+ UNIT_ASSERT(sl.StackBegin);
+ UNIT_ASSERT(sl.StackLength > 0);
+ }
Y_UNIT_TEST(TestFunc) {
std::atomic_bool flag = {false};
@@ -206,7 +206,7 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
Y_UNIT_TEST(TestCallable) {
std::atomic_bool flag = {false};
- struct TCallable: TMoveOnly {
+ struct TCallable: TMoveOnly {
std::atomic_bool* Flag_;
TCallable(std::atomic_bool* flag)
@@ -226,4 +226,4 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
UNIT_ASSERT_VALUES_EQUAL(thread.Join(), nullptr);
UNIT_ASSERT(flag);
}
-};
+};