2 * Copyright (c) 2017-2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 typedef struct __thread_test_table {
26 static GThread *my_thread = NULL;
27 static GMainLoop *main_loop = NULL;
28 static thread_test_node thread_test_table[1000] = { 0 };
29 static int thread_test_idx = 0;
30 static int loop = 100;
31 static int thread_sw = 1;
33 static void *thread_function(void *data)
36 int test_idx = GPOINTER_TO_INT(data);
42 thread_test_table[test_idx].t_func();
50 static GThread **unit_test_thread_start(int test_num)
53 GThread **thread_list = (GThread **)calloc(sizeof(GThread*), N_THREADS);
54 for (i = 0; i < N_THREADS; i++)
55 thread_list[i] = g_thread_new(NULL, thread_function, GINT_TO_POINTER(test_num));
60 static void unit_test_thread_stop(GThread **thread_list)
63 for (i = 0; i < N_THREADS; i++)
64 g_thread_join(thread_list[i]);
69 static void unit_thread_test()
72 GThread **thread_test[MAX_TEST_CASE];
74 printf("START!!!! thread test for system-settings %d tests\n", thread_test_idx);
77 for (i = 0; i < thread_test_idx; i++) {
78 thread_test[i] = unit_test_thread_start(i);
79 printf("%3d %s:start!\n", i, thread_test_table[i].test_name);
81 unit_test_thread_stop(thread_test[i]);
82 printf("%3d %s:OK\n", i, thread_test_table[i].test_name);
85 printf("END!!!! thread test for system-settings\n");
88 static gpointer loop_func(gpointer data)
90 g_main_loop_run(main_loop);
94 static void start_main_loop_thread()
96 my_thread = g_thread_new(NULL, loop_func, NULL);
99 static void stop_main_loop_thread()
101 g_main_loop_quit(main_loop);
102 g_thread_join(my_thread);
103 g_main_loop_unref(main_loop);
106 void add_test_func(char *test_name, GTestFunc func_pointer)
108 g_test_add_func(test_name, func_pointer);
110 thread_test_table[thread_test_idx].test_name = test_name;
111 thread_test_table[thread_test_idx].t_func = func_pointer;
116 int main(int argc, char **argv)
118 main_loop = g_main_loop_new(NULL, FALSE);
120 g_test_init(&argc, &argv, NULL);
121 g_test_set_nonfatal_assertions();
123 start_main_loop_thread();
130 stop_main_loop_thread();