aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/sigsegv
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-07-11 21:17:10 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-07-11 23:14:52 +0200
commit8619f8934a2762fa35d80b792ad349cd1128c1e9 (patch)
tree0078ea6f8f14c25a8ddbcf573d4e67dfa3dc3d32 /test/sigsegv
parentsqlite: make some identifiers more readable (diff)
downloadcimple-8619f8934a2762fa35d80b792ad349cd1128c1e9.tar.gz
cimple-8619f8934a2762fa35d80b792ad349cd1128c1e9.zip
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.
Diffstat (limited to '')
-rw-r--r--test/sigsegv/CMakeLists.txt11
-rw-r--r--test/sigsegv/lib.c5
-rw-r--r--test/sigsegv/lib.h10
-rw-r--r--test/sigsegv/main.c16
4 files changed, 42 insertions, 0 deletions
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 <stddef.h>
+
+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 <stdio.h>
+
+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;
+}