test program for crashing with threads sandbox/adrian.s/test
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 13 Dec 2016 12:19:55 +0000 (13:19 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Tue, 13 Dec 2016 12:19:55 +0000 (13:19 +0100)
tests/test3.c [new file with mode: 0644]

diff --git a/tests/test3.c b/tests/test3.c
new file mode 100644 (file)
index 0000000..ca6ae03
--- /dev/null
@@ -0,0 +1,46 @@
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdio.h>
+
+int crash_other_thread = 0;
+#define CRASHING_THREAD 19
+
+gboolean crasher(gpointer data)
+{
+       *(int*)data = 1;
+       return TRUE;
+}
+
+void *fun(void *arg)
+{
+       int threadnum = (int)arg;
+       if (crash_other_thread && threadnum == CRASHING_THREAD)
+               crasher(NULL);
+       else
+               while (1);
+       return NULL;
+}
+
+int main(int argc)
+{
+       GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+
+       crash_other_thread = argc > 1;
+
+       if (!crash_other_thread)
+       {
+               GSource *idle_source = g_idle_source_new();
+               g_source_set_callback(idle_source, crasher, NULL, NULL);
+               g_source_attach(idle_source, g_main_context_ref_thread_default());
+       }
+
+       pthread_t t;
+       int i;
+
+       for (i = 0; i <= CRASHING_THREAD; i++)
+               pthread_create(&t, NULL, fun, (void *)i);
+
+       g_main_loop_run(loop);
+
+       return 0;
+}