[NFC][Py Reformat] Reformat python files in llvm
[llvm-project.git] / libunwind / test / libunwind_02.pass.cpp
blobfc034378781a2fa0c93fdf9d2d547b517c47b5d7
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 // TODO: Figure out why this fails with Memory Sanitizer.
11 // XFAIL: msan
13 #undef NDEBUG
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <unwind.h>
18 #define EXPECTED_NUM_FRAMES 50
19 #define NUM_FRAMES_UPPER_BOUND 100
21 _Unwind_Reason_Code callback(_Unwind_Context *context, void *cnt) {
22 (void)context;
23 int *i = (int *)cnt;
24 ++*i;
25 if (*i > NUM_FRAMES_UPPER_BOUND) {
26 abort();
28 return _URC_NO_REASON;
31 void test_backtrace() {
32 int n = 0;
33 _Unwind_Backtrace(&callback, &n);
34 if (n < EXPECTED_NUM_FRAMES) {
35 abort();
39 int test(int i) {
40 if (i == 0) {
41 test_backtrace();
42 return 0;
43 } else {
44 return i + test(i - 1);
48 int main(int, char**) {
49 int total = test(50);
50 assert(total == 1275);
51 return 0;