From 8619f8934a2762fa35d80b792ad349cd1128c1e9 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 11 Jul 2023 21:17:10 +0200 Subject: test: add test for segfaulting CI script The C code leaked out of src/, so I moved .clang-format and some compile options to the root directory. Also, I'm starting to hit test execution limits; I'm going to limit the repositories used for stress testing. --- test/sigsegv/CMakeLists.txt | 11 +++++++++++ test/sigsegv/lib.c | 5 +++++ test/sigsegv/lib.h | 10 ++++++++++ test/sigsegv/main.c | 16 ++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 test/sigsegv/CMakeLists.txt create mode 100644 test/sigsegv/lib.c create mode 100644 test/sigsegv/lib.h create mode 100644 test/sigsegv/main.c (limited to 'test/sigsegv') diff --git a/test/sigsegv/CMakeLists.txt b/test/sigsegv/CMakeLists.txt new file mode 100644 index 0000000..b92147d --- /dev/null +++ b/test/sigsegv/CMakeLists.txt @@ -0,0 +1,11 @@ +# Hopefully putting the NULL reference to a separate library should force the +# sigsegv binary to crash. If I put it in main.c, surprisingly, Clang (with +# -O2) produces a binary that doesn't crash: https://godbolt.org/z/joeqEEs3Y. +# To force it to crash, the -fno-delete-null-pointer-checks flag is required: +# https://godbolt.org/z/o3xEoeG3z. This is a bit hacky though; putting the +# reference in a separate library should also do the trick. + +add_library(null lib.c) + +add_executable(sigsegv main.c) +target_link_libraries(sigsegv PRIVATE null) diff --git a/test/sigsegv/lib.c b/test/sigsegv/lib.c new file mode 100644 index 0000000..1e136cc --- /dev/null +++ b/test/sigsegv/lib.c @@ -0,0 +1,5 @@ +#include "lib.h" + +#include + +struct data *data = NULL; diff --git a/test/sigsegv/lib.h b/test/sigsegv/lib.h new file mode 100644 index 0000000..1f162d5 --- /dev/null +++ b/test/sigsegv/lib.h @@ -0,0 +1,10 @@ +#ifndef __LIB_H__ +#define __LIB_H__ + +struct data { + int x; +}; + +extern struct data *data; + +#endif diff --git a/test/sigsegv/main.c b/test/sigsegv/main.c new file mode 100644 index 0000000..428d168 --- /dev/null +++ b/test/sigsegv/main.c @@ -0,0 +1,16 @@ +#include "lib.h" + +#include + +int main(void) +{ + puts("Started the test program."); + fflush(stdout); + + printf("This will crash: %d.\n", data->x); + + puts("You shouldn't see this."); + fflush(stdout); + + return 0; +} -- cgit v1.2.3