proxygen
ThreadNameTest.cpp File Reference
#include <thread>
#include <folly/ScopeGuard.h>
#include <folly/portability/GTest.h>
#include <folly/synchronization/Baton.h>
#include <folly/system/ThreadName.h>

Go to the source code of this file.

Functions

 TEST (ThreadName, getCurrentThreadName)
 
 TEST (ThreadName, setThreadName_other_id)
 

Function Documentation

TEST ( ThreadName  ,
getCurrentThreadName   
)

Definition at line 35 of file ThreadNameTest.cpp.

References EXPECT_EQ, folly::getCurrentThreadName(), folly::Baton< MayBlock, Atom >::post(), SCOPE_EXIT, folly::setThreadName(), and folly::Baton< MayBlock, Atom >::wait().

35  {
36  thread th([] {
37  EXPECT_EQ(expectedSetSelfThreadNameResult, setThreadName(kThreadName));
38  if (expectedSetSelfThreadNameResult) {
39  EXPECT_EQ(kThreadName.toString(), *getCurrentThreadName());
40  }
41  });
42  SCOPE_EXIT {
43  th.join();
44  };
45 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
bool setThreadName(std::thread::id tid, StringPiece name)
Definition: ThreadName.cpp:109
Optional< std::string > getCurrentThreadName()
Definition: ThreadName.cpp:105
TEST ( ThreadName  ,
setThreadName_other_id   
)

Definition at line 69 of file ThreadNameTest.cpp.

References EXPECT_EQ, folly::getThreadName(), folly::Baton< MayBlock, Atom >::post(), SCOPE_EXIT, folly::setThreadName(), and folly::Baton< MayBlock, Atom >::wait().

69  {
70  Baton<> let_thread_end;
71  thread th([&] { let_thread_end.wait(); });
72  SCOPE_EXIT {
73  th.join();
74  };
75  SCOPE_EXIT {
76  let_thread_end.post();
77  };
78  EXPECT_EQ(
79  expectedSetOtherThreadNameResult,
80  setThreadName(th.get_id(), kThreadName));
81  if (expectedSetOtherThreadNameResult) {
82  EXPECT_EQ(*getThreadName(th.get_id()), kThreadName);
83  }
84 }
Optional< std::string > getThreadName(std::thread::id id)
Definition: ThreadName.cpp:90
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
FOLLY_ALWAYS_INLINE void wait(const WaitOptions &opt=wait_options()) noexcept
Definition: Baton.h:170
void post() noexcept
Definition: Baton.h:123
bool setThreadName(std::thread::id tid, StringPiece name)
Definition: ThreadName.cpp:109