1 #include <unit_test_fw.h>
3 typedef struct __thread_test_table {
8 static GThread *my_thread = NULL;
9 static GMainLoop *main_loop = NULL;
10 static thread_test_node thread_test_table[1000] = {0};
11 static int thread_test_idx = 0;
12 static int loop = 100;
13 static int thread_sw = 1;
15 void *thread_function(void *data)
18 int test_idx = (int)data;
24 thread_test_table[test_idx].t_func();
32 static GThread **unit_test_thread_start(int test_num)
35 GThread **thread_list = (GThread **)calloc(sizeof(GThread*), N_THREADS);
36 for (i = 0; i < N_THREADS; i++) {
37 thread_list[i] = g_thread_new(NULL, thread_function, (void*)test_num);
42 static void unit_test_thread_stop(GThread **thread_list)
45 for (i = 0; i < N_THREADS; i++) {
46 g_thread_join(thread_list[i]);
52 static void unit_thread_test()
55 GThread **thread_test[MAX_TEST_CASE];
57 printf("START!!!! thread test for system-settings %d tests\n", thread_test_idx);
60 for (i = 0; i < thread_test_idx; i++) {
61 thread_test[i] = unit_test_thread_start(i);
62 printf("%3d %s:start!\n", i, thread_test_table[i].test_name);
64 unit_test_thread_stop(thread_test[i]);
65 printf("%3d %s:OK\n", i, thread_test_table[i].test_name);
68 printf("END!!!! thread test for system-settings\n");
71 static gpointer loop_func(gpointer data)
73 g_main_loop_run(main_loop);
77 static void start_main_loop_thread()
79 my_thread = g_thread_new(NULL, loop_func, NULL);
82 static void stop_main_loop_thread()
84 g_main_loop_quit(main_loop);
85 g_thread_join(my_thread);
86 g_main_loop_unref(main_loop);
90 int main(int argc, char* argv[])
92 main_loop = g_main_loop_new(NULL, FALSE);
94 g_test_init(&argc, &argv, NULL);
95 g_test_set_nonfatal_assertions();
97 start_main_loop_thread();
104 stop_main_loop_thread();
108 void add_test_func(char * test_name, GTestFunc func_pointer)
110 g_test_add_func(test_name, func_pointer);
112 thread_test_table[thread_test_idx].test_name = test_name;
113 thread_test_table[thread_test_idx].t_func = func_pointer;