1 #include <unit_test_fw.h>
3 typedef struct __thread_test_table {
9 static GThread *my_thread = NULL;
10 static GMainLoop *main_loop = NULL;
11 static thread_test_node thread_test_table[1000] = {0};
12 static int thread_test_idx = 0;
13 static int loop = 100;
14 static int thread_sw = 1;
17 void *thread_function(void *data)
20 int test_idx = (int)data;
26 thread_test_table[test_idx].t_func();
34 static GThread **unit_test_thread_start(int test_num)
37 GThread **thread_list = (GThread **)calloc(sizeof(GThread*), N_THREADS);
38 for (i = 0; i < N_THREADS; i++) {
39 thread_list[i] = g_thread_new(NULL, thread_function, (void*)test_num);
44 static void unit_test_thread_stop(GThread **thread_list)
47 for (i = 0; i < N_THREADS; i++) {
48 g_thread_join(thread_list[i]);
54 static void unit_thread_test()
57 GThread **thread_test[MAX_TEST_CASE];
59 printf("START!!!! thread test for system-settings %d tests\n", thread_test_idx);
62 for (i = 0; i < thread_test_idx; i++) {
63 thread_test[i] = unit_test_thread_start(i);
64 printf("%3d %s:start!\n", i, thread_test_table[i].test_name);
66 unit_test_thread_stop(thread_test[i]);
67 printf("%3d %s:OK\n", i, thread_test_table[i].test_name);
70 printf("END!!!! thread test for system-settings\n");
73 static gpointer loop_func(gpointer data)
75 g_main_loop_run(main_loop);
79 static void start_main_loop_thread()
81 my_thread = g_thread_new(NULL, loop_func, NULL);
84 static void stop_main_loop_thread()
86 g_main_loop_quit(main_loop);
87 g_thread_join(my_thread);
88 g_main_loop_unref(main_loop);
91 int main(int argc, char* argv[])
95 main_loop = g_main_loop_new(NULL, FALSE);
97 g_test_init(&argc, &argv, NULL);
98 g_test_set_nonfatal_assertions();
100 start_main_loop_thread();
107 stop_main_loop_thread();
111 void add_test_func(char * test_name, GTestFunc func_pointer)
113 g_test_add_func(test_name, func_pointer);
115 thread_test_table[thread_test_idx].test_name = test_name;
116 thread_test_table[thread_test_idx].t_func = func_pointer;