Files
systemd/src/test/test-coredump-stacktrace.c
Frantisek Sumsal 937f609b41 test: build the crashing test binary outside of the test
So we don't have to pull in gcc and other stuff into it.

Also, make the test itself a bit more robust and debug-able.
2025-10-11 22:37:33 +02:00

30 lines
492 B
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/* This is a test program that intentionally segfaults so we can generate a
* predictable-ish stack trace in tests. */
#include <stdlib.h>
__attribute__((noinline))
static void baz(int *x) {
*x = rand();
}
__attribute__((noinline))
static void bar(void) {
int * volatile x = NULL;
baz(x);
}
__attribute__((noinline))
static void foo(void) {
bar();
}
int main(void) {
foo();
return 0;
}