Skip to content

Commit 1aff3af

Browse files
committed
tests/glibc: add backtrace test
1 parent b9a6900 commit 1aff3af

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/glibc/backtrace.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
#include <execinfo.h>
3+
#include <stdio.h>
4+
#include <unistd.h>
5+
6+
void func() {
7+
void *callstack[128];
8+
int frames = backtrace(callstack, 128);
9+
fprintf(stderr, "backtrace returns %d frames:\n", frames);
10+
// we expect at least 3 frames: _start, main and func
11+
assert(frames >= 3);
12+
13+
backtrace_symbols_fd(callstack, frames, STDERR_FILENO);
14+
return;
15+
}
16+
17+
int main(int argc, char **argv) {
18+
(void) argc;
19+
(void) argv;
20+
21+
func();
22+
23+
return 0;
24+
}

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ all_test_cases = [
114114
'glibc/error_at_line',
115115
'glibc/getgrouplist',
116116
'glibc/rpmatch',
117+
'glibc/backtrace',
117118
'linux/xattr',
118119
'linux/pthread_setname_np',
119120
'linux/pthread_attr',

0 commit comments

Comments
 (0)