• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "quiche/common/platform/api/quiche_stack_trace.h"
2 
3 #include <cstdint>
4 
5 #include "absl/base/attributes.h"
6 #include "absl/base/optimization.h"
7 #include "absl/strings/str_cat.h"
8 #include "quiche/common/platform/api/quiche_test.h"
9 
10 namespace quiche {
11 namespace test {
12 namespace {
13 
ShouldRunTest()14 bool ShouldRunTest() {
15 #if defined(ABSL_HAVE_ATTRIBUTE_NOINLINE)
16   return QuicheShouldRunStackTraceTest();
17 #else
18   // If QuicheDesignatedStackTraceTestFunction gets inlined, the test will
19   // inevitably fail, since the function won't be on the stack trace.  Disable
20   // the test in that scenario.
21   return false;
22 #endif
23 }
24 
QuicheDesignatedStackTraceTestFunction()25 ABSL_ATTRIBUTE_NOINLINE std::string QuicheDesignatedStackTraceTestFunction() {
26   std::string result = QuicheStackTrace();
27   ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
28   return result;
29 }
30 
TEST(QuicheStackTraceTest,GetStackTrace)31 TEST(QuicheStackTraceTest, GetStackTrace) {
32   if (!ShouldRunTest()) {
33     return;
34   }
35 
36   std::string stacktrace = QuicheDesignatedStackTraceTestFunction();
37   EXPECT_THAT(stacktrace,
38               testing::HasSubstr("QuicheDesignatedStackTraceTestFunction"));
39 }
40 
41 }  // namespace
42 }  // namespace test
43 }  // namespace quiche
44