xref: /aosp_15_r20/external/cronet/third_party/abseil-cpp/absl/debugging/stacktrace_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/debugging/stacktrace.h"
16 
17 #include "gtest/gtest.h"
18 #include "absl/base/macros.h"
19 #include "absl/base/optimization.h"
20 
21 namespace {
22 
23 // This test is currently only known to pass on Linux x86_64/aarch64.
24 #if defined(__linux__) && (defined(__x86_64__) || defined(__aarch64__))
Unwind(void * p)25 ABSL_ATTRIBUTE_NOINLINE void Unwind(void* p) {
26   ABSL_ATTRIBUTE_UNUSED static void* volatile sink = p;
27   constexpr int kSize = 16;
28   void* stack[kSize];
29   int frames[kSize];
30   absl::GetStackTrace(stack, kSize, 0);
31   absl::GetStackFrames(stack, frames, kSize, 0);
32 }
33 
HugeFrame()34 ABSL_ATTRIBUTE_NOINLINE void HugeFrame() {
35   char buffer[1 << 20];
36   Unwind(buffer);
37   ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
38 }
39 
TEST(StackTrace,HugeFrame)40 TEST(StackTrace, HugeFrame) {
41   // Ensure that the unwinder is not confused by very large stack frames.
42   HugeFrame();
43   ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
44 }
45 #endif
46 
47 }  // namespace
48