Fix report_basic test
[platform/core/system/crash-worker.git] / tests / test3.c
1 #include <glib.h>
2 #include <gio/gio.h>
3 #include <stdio.h>
4
5 intptr_t crash_other_thread = 0;
6 #define CRASHING_THREAD 19
7
8 gboolean crasher(gpointer data)
9 {
10         *(int*)data = 1;
11         return TRUE;
12 }
13
14 void *fun(void *arg)
15 {
16         intptr_t threadnum = (intptr_t)arg;
17         if (crash_other_thread && threadnum == CRASHING_THREAD)
18                 crasher(NULL);
19         else
20                 while (1);
21         return NULL;
22 }
23
24 int main(int argc)
25 {
26         GMainLoop *loop = g_main_loop_new(NULL, FALSE);
27
28         crash_other_thread = argc > 1;
29
30         if (!crash_other_thread)
31         {
32                 GSource *idle_source = g_idle_source_new();
33                 g_source_set_callback(idle_source, crasher, NULL, NULL);
34                 g_source_attach(idle_source, g_main_context_ref_thread_default());
35         }
36
37         pthread_t t;
38         intptr_t i;
39
40         for (i = 0; i <= CRASHING_THREAD; i++)
41                 pthread_create(&t, NULL, fun, (void *)i);
42
43         g_main_loop_run(loop);
44
45         return 0;
46 }