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.
This commit is contained in:
@@ -275,6 +275,17 @@ executables += [
|
||||
'sources' : files('test-compress.c'),
|
||||
'link_with' : [libshared],
|
||||
},
|
||||
test_template + {
|
||||
'sources' : files('test-coredump-stacktrace.c'),
|
||||
'type' : 'manual',
|
||||
# This test intentionally crashes with SIGSEGV by dereferencing a NULL pointer
|
||||
# to generate a coredump with a predictable stack trace. To prevent sanitizers
|
||||
# from catching the error first let's disable them explicitly, and also always
|
||||
# build with minimal optimizations to make the stack trace predictable no matter
|
||||
# what we build the rest of systemd with
|
||||
'override_options' : ['b_sanitize=none', 'strip=false', 'debug=true'],
|
||||
'c_args' : ['-fno-sanitize=all', '-fno-optimize-sibling-calls', '-O1'],
|
||||
},
|
||||
test_template + {
|
||||
'sources' : files('test-cryptolib.c'),
|
||||
'dependencies' : libopenssl,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user