proxygen
folly::symbolizer::test Namespace Reference

Classes

class  ElfCacheTest
 

Functions

void writeAll (int fd, const char *str)
 
void expect (LineReader &lr, const char *expected)
 
 TEST (LineReader, Simple)
 
 TEST (SignalHandler, Simple)
 
void failHard ()
 
void foo ()
 
 TEST (Symbolizer, Single)
 
int comparator (const void *ap, const void *bp)
 
FOLLY_NOINLINE void bar ()
 
void bar (FrameArray< 100 > &frames)
 
void runElfCacheTest (Symbolizer &symbolizer)
 
 TEST_F (ElfCacheTest, TinyElfCache)
 
 TEST_F (ElfCacheTest, SignalSafeElfCache)
 
 TEST (SymbolizerTest, SymbolCache)
 

Variables

FrameArray< 100 > * framesToFill {nullptr}
 
FrameArray< 100 > goldenFrames
 

Function Documentation

FOLLY_NOINLINE void folly::symbolizer::test::bar ( )

Definition at line 29 of file ExceptionCounterTest.cpp.

Referenced by baz(), comparator(), foo(), folly::symbolizer::test::ElfCacheTest::SetUp(), TEST(), and testExceptionPtr1().

29  {
30  throw std::runtime_error("hello");
31 }
void folly::symbolizer::test::bar ( FrameArray< 100 > &  frames)

Definition at line 69 of file SymbolizerTest.cpp.

References a, comparator(), and framesToFill.

69  {
70  framesToFill = &frames;
71  int a[2] = {1, 2};
72  // Use qsort, which is in a different library
73  qsort(a, 2, sizeof(int), comparator);
74  framesToFill = nullptr;
75 }
int comparator(const void *ap, const void *bp)
char a
FrameArray< 100 > * framesToFill
int folly::symbolizer::test::comparator ( const void *  ap,
const void *  bp 
)

Definition at line 58 of file SymbolizerTest.cpp.

References a, b, bar(), FOLLY_NOINLINE, framesToFill, and folly::symbolizer::getStackTrace().

Referenced by bar(), testing::internal::BoundSecondMatcher< Tuple2Matcher, Second >::Impl< T >::MatchAndExplain(), and testing::WhenSortedBy().

58  {
60 
61  int a = *static_cast<const int*>(ap);
62  int b = *static_cast<const int*>(bp);
63  return a < b ? -1 : a > b ? 1 : 0;
64 }
char b
ssize_t getStackTrace(uintptr_t *addresses, size_t maxAddresses)
Definition: StackTrace.cpp:25
char a
FrameArray< 100 > * framesToFill
void folly::symbolizer::test::expect ( LineReader lr,
const char *  expected 
)
void folly::symbolizer::test::failHard ( )
inline

Definition at line 23 of file SignalHandlerTest.h.

Referenced by TEST().

23  {
24  *(/* nolint */ volatile char*)42; // SIGSEGV
25 }
void folly::symbolizer::test::foo ( )

Definition at line 29 of file SymbolizerTest.cpp.

29 {}
void folly::symbolizer::test::runElfCacheTest ( Symbolizer symbolizer)

Definition at line 93 of file SymbolizerTest.cpp.

References ASSERT_LE, EXPECT_STREQ, folly::symbolizer::FrameArray< N >::frameCount, folly::symbolizer::FrameArray< N >::frames, goldenFrames, i, and folly::symbolizer::Symbolizer::symbolize().

Referenced by TEST_F().

93  {
94  FrameArray<100> frames = goldenFrames;
95  for (size_t i = 0; i < frames.frameCount; ++i) {
96  frames.frames[i].clear();
97  }
98  symbolizer.symbolize(frames);
99  ASSERT_LE(4, frames.frameCount);
100  for (size_t i = 1; i < 4; ++i) {
101  EXPECT_STREQ(goldenFrames.frames[i].name, frames.frames[i].name);
102  }
103 }
#define ASSERT_LE(val1, val2)
Definition: gtest.h:1964
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
FrameArray< 100 > goldenFrames
folly::symbolizer::test::TEST ( Symbolizer  ,
Single   
)

Definition at line 31 of file SymbolizerTest.cpp.

References a, folly::Range< Iter >::advance(), ASSERT_TRUE, folly::symbolizer::SymbolizedFrame::demangledName(), EXPECT_EQ, folly::symbolizer::Dwarf::LocationInfo::file, folly::symbolizer::SymbolizedFrame::location, folly::Range< const char * >::npos, folly::Range< Iter >::rfind(), folly::Range< Iter >::str(), folly::symbolizer::Symbolizer::symbolize(), and folly::symbolizer::Dwarf::Path::toString().

31  {
32  Symbolizer symbolizer;
33  SymbolizedFrame a;
34  ASSERT_TRUE(symbolizer.symbolize(reinterpret_cast<uintptr_t>(foo), a));
35  EXPECT_EQ("folly::symbolizer::test::foo()", a.demangledName());
36 
37  // The version of clang we use doesn't generate a `.debug_aranges` section,
38  // which the symbolizer needs to lookup the filename.
39  constexpr bool built_with_clang =
40 #ifdef __clang__
41  true;
42 #else
43  false;
44 #endif
45  if (!built_with_clang) {
46  auto path = a.location.file.toString();
47  folly::StringPiece basename(path);
48  auto pos = basename.rfind('/');
49  if (pos != folly::StringPiece::npos) {
50  basename.advance(pos + 1);
51  }
52  EXPECT_EQ("SymbolizerTest.cpp", basename.str());
53  }
54 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char a
static const size_type npos
Definition: Range.h:197
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
folly::symbolizer::test::TEST ( SignalHandler  ,
Simple   
)

Definition at line 45 of file SignalHandlerTest.cpp.

References folly::symbolizer::addFatalSignalCallback(), failHard(), folly::symbolizer::installFatalSignalCallbacks(), and folly::symbolizer::installFatalSignalHandler().

45  {
46  addFatalSignalCallback(callback1);
47  addFatalSignalCallback(callback2);
50 
51  EXPECT_DEATH(
52  failHard(),
53  "^\\*\\*\\* Aborted at [0-9]+ \\(Unix time, try 'date -d @[0-9]+'\\) "
54  "\\*\\*\\*\n"
55  "\\*\\*\\* Signal 11 \\(SIGSEGV\\) \\(0x2a\\) received by PID [0-9]+ "
56  "\\(pthread TID 0x[0-9a-f]+\\) \\(linux TID [0-9]+\\) "
57  "\\(maybe from PID [0-9]+, UID [0-9]+\\) "
58  "\\(code: address not mapped to object\\), "
59  "stack trace: \\*\\*\\*\n"
60  ".*\n"
61  ".* @ [0-9a-f]+.* folly::symbolizer::test::SignalHandler_Simple_Test"
62  "::TestBody\\(\\).*\n"
63  ".*\n"
64  ".* @ [0-9a-f]+.* main.*\n"
65  ".*\n"
66  "Callback1\n"
67  "Callback2\n"
68  ".*");
69 }
void addFatalSignalCallback(SignalCallback cb)
void installFatalSignalCallbacks()
void installFatalSignalHandler()
folly::symbolizer::test::TEST ( LineReader  ,
Simple   
)

Definition at line 46 of file LineReaderTest.cpp.

References expect(), folly::test::TemporaryFile::fd(), and writeAll().

46  {
47  TemporaryFile file;
48  int fd = file.fd();
49  writeAll(
50  fd,
51  "Meow\n"
52  "Hello world\n"
53  "This is a long line. It is longer than the other lines.\n"
54  "\n"
55  "Incomplete last line");
56 
57  {
58  CHECK_ERR(lseek(fd, 0, SEEK_SET));
59  char buf[10];
60  LineReader lr(fd, buf, sizeof(buf));
61  expect(lr, "Meow\n");
62  expect(lr, "Hello worl");
63  expect(lr, "d\n");
64  expect(lr, "This is a ");
65  expect(lr, "long line.");
66  expect(lr, " It is lon");
67  expect(lr, "ger than t");
68  expect(lr, "he other l");
69  expect(lr, "ines.\n");
70  expect(lr, "\n");
71  expect(lr, "Incomplete");
72  expect(lr, " last line");
73  expect(lr, "");
74  }
75 
76  {
77  CHECK_ERR(lseek(fd, 0, SEEK_SET));
78  char buf[80];
79  LineReader lr(fd, buf, sizeof(buf));
80  expect(lr, "Meow\n");
81  expect(lr, "Hello world\n");
82  expect(lr, "This is a long line. It is longer than the other lines.\n");
83  expect(lr, "\n");
84  expect(lr, "Incomplete last line");
85  expect(lr, "");
86  }
87 }
void writeAll(int fd, const char *str)
void expect(LineReader &lr, const char *expected)
folly::symbolizer::test::TEST ( SymbolizerTest  ,
SymbolCache   
)

Definition at line 122 of file SymbolizerTest.cpp.

References bar(), EXPECT_STREQ, folly::symbolizer::FrameArray< N >::frameCount, folly::symbolizer::FrameArray< N >::frames, folly::symbolizer::Dwarf::FULL, i, and folly::symbolizer::Symbolizer::symbolize().

122  {
123  Symbolizer symbolizer(nullptr, Dwarf::LocationInfoMode::FULL, 100);
124 
125  FrameArray<100> frames;
126  bar(frames);
127  symbolizer.symbolize(frames);
128 
129  FrameArray<100> frames2;
130  bar(frames2);
131  symbolizer.symbolize(frames2);
132  for (size_t i = 0; i < frames.frameCount; i++) {
133  EXPECT_STREQ(frames.frames[i].name, frames2.frames[i].name);
134  }
135 }
void bar(FrameArray< 100 > &frames)
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
folly::symbolizer::test::TEST_F ( ElfCacheTest  ,
TinyElfCache   
)

Definition at line 105 of file SymbolizerTest.cpp.

References i, and runElfCacheTest().

105  {
106  ElfCache cache(1);
107  Symbolizer symbolizer(&cache);
108  // Run twice, in case the wrong stuff gets evicted?
109  for (size_t i = 0; i < 2; ++i) {
110  runElfCacheTest(symbolizer);
111  }
112 }
void runElfCacheTest(Symbolizer &symbolizer)
folly::symbolizer::test::TEST_F ( ElfCacheTest  ,
SignalSafeElfCache   
)

Definition at line 114 of file SymbolizerTest.cpp.

References i, and runElfCacheTest().

114  {
115  SignalSafeElfCache cache(100);
116  Symbolizer symbolizer(&cache);
117  for (size_t i = 0; i < 2; ++i) {
118  runElfCacheTest(symbolizer);
119  }
120 }
void runElfCacheTest(Symbolizer &symbolizer)
void folly::symbolizer::test::writeAll ( int  fd,
const char *  str 
)

Definition at line 31 of file LineReaderTest.cpp.

References folly::writeFull().

Referenced by TEST().

31  {
32  ssize_t n = strlen(str);
33  CHECK_EQ(n, writeFull(fd, str, n));
34 }
ssize_t writeFull(int fd, const void *buf, size_t count)
Definition: FileUtil.cpp:134

Variable Documentation

FrameArray<100>* folly::symbolizer::test::framesToFill {nullptr}

Definition at line 56 of file SymbolizerTest.cpp.

Referenced by bar(), and comparator().

FrameArray<100> folly::symbolizer::test::goldenFrames

Definition at line 83 of file SymbolizerTest.cpp.

Referenced by runElfCacheTest().