[UTC][system-settings-native-utc][Non-ACR][Added thread safety test code about font...
authorjinwang.an <jinwang.an@samsung.com>
Thu, 27 Oct 2016 11:13:19 +0000 (20:13 +0900)
committerJaeKyung Lee <jk79.lee@samsung.com>
Thu, 17 Nov 2016 01:01:35 +0000 (17:01 -0800)
Change-Id: I38e93ad758e347f8ff9403e83a7637f19a2f5629
Signed-off-by: jinwang.an <jinwang.an@samsung.com>
scripts/tcbuild.sh [changed mode: 0644->0755]
src/utc/system-settings/CMakeLists.txt
src/utc/system-settings/utc-system-settings.c

old mode 100644 (file)
new mode 100755 (executable)
index d410296..8a1e5d6 100755 (executable)
@@ -31,7 +31,7 @@ INSTALL(PROGRAMS ${EXEC_NAME}
 )
 
 IF( DEFINED ASAN )
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -pie -g -fsanitize=address -fsanitize-recover=address -U_FORTIFY_SOURCE -fno-omit-frame-pointer")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -pie -g -fsanitize=address -fsanitize-recover=address -U_FORTIFY_SOURCE -fno-omit-frame-pointer -lpthread")
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib -Wl,-fsanitize=address")
 ELSE()
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fPIE -Wall")
index ac4445e..d59a1fa 100755 (executable)
 #include <glib.h>
 #include <storage.h>
 
+
+
+
+/*********************************************************************************/
+/* thread safety checking start                                                  */
+/*********************************************************************************/
+#include <pthread.h>
+
+/* initialize thread */
+/* int number : thread number (max 10)*/
+#define MY_MAX_THREAD_CHECK_NUM 10
+
+typedef void *(*thr_func)(void *arg);
+typedef struct _my_thread_data {
+       int thread_number;
+       thr_func thr_func_list[MY_MAX_THREAD_CHECK_NUM];
+       pthread_t thr_list[MY_MAX_THREAD_CHECK_NUM];
+       void *thr_data[MY_MAX_THREAD_CHECK_NUM];
+       int error;
+} my_thread_data;
+
+void* init_thr_safety_check(int number)
+{
+       my_thread_data* handle = malloc(sizeof(my_thread_data));
+       handle->thread_number = number;
+       handle->error = 0;
+       return (void*)handle;
+}
+
+int do_thr_safety_check(void* handle)
+{
+       my_thread_data* thd = (my_thread_data*)handle;
+
+       int i;
+       for( i = 0 ; i < thd->thread_number ; i++)
+       {
+               if ((pthread_create(&thd->thr_list[i], NULL, thd->thr_func_list[i], thd) )) {
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+void deinit_thr_safety_check(void* handle)
+{
+       my_thread_data* thd = (my_thread_data*)handle;
+       int i;
+       for( i = 0 ; i < thd->thread_number ; i++)
+       {
+               pthread_join(thd->thr_list[i], NULL);
+       }
+
+       free(handle);
+
+}
+
+#define LOOP_COUNT 1000
+#define FONT_SIZE_1 10
+#define FONT_SIZE_2 30
+#define FONT_SIZE_3 30
+
+
+void* test_thread_1(void *arg)
+{
+       my_thread_data* thd = (my_thread_data*)arg;
+
+       int i;
+       int font_size = 0;
+       for(i = 0; i< LOOP_COUNT; i++) {
+                system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, FONT_SIZE_1);
+               system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &font_size);
+
+               if(font_size != FONT_SIZE_1)
+                       thd->error ++;
+               usleep(1000);
+       }
+
+       return NULL;
+}
+
+void* test_thread_2(void *arg)
+{
+       my_thread_data* thd = (my_thread_data*)arg;
+
+       int i;
+       int font_size = 0;
+       for(i = 0; i< LOOP_COUNT; i++) {
+               system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, FONT_SIZE_2);
+               system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &font_size);
+
+               if(font_size != FONT_SIZE_2)
+                       thd->error ++;
+               usleep(1000);
+       }
+       return NULL;
+}
+
+void* test_thread_3(void *arg)
+{
+       my_thread_data* thd = (my_thread_data*)arg;
+
+       int i;
+       int font_size = 0;
+       for(i = 0; i< LOOP_COUNT; i++) {
+               system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, FONT_SIZE_3);
+               system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &font_size);
+
+               if(font_size != FONT_SIZE_3)
+                       thd->error ++;
+               usleep(1000);
+       }
+       return NULL;
+}
+
+void thread_safety_checking()
+{
+       my_thread_data* handle = init_thr_safety_check(3);
+
+       handle->thr_func_list[0] = test_thread_1;
+       handle->thr_func_list[1] = test_thread_2;
+       handle->thr_func_list[2] = test_thread_3;
+
+       do_thr_safety_check(handle);
+
+       printf("\\n[%s][Line : %d]Thread Check!!! >>>>>>>>>>>>>> %d\\n", __FILE__, __LINE__, handle->error);
+
+       deinit_thr_safety_check(handle);
+}
+
+/*********************************************************************************/
+/* thread safety checking end                                                    */
+/*********************************************************************************/
+
 static int my_assert_ret(int retcode)
 {
        if (retcode == SYSTEM_SETTINGS_ERROR_NOT_SUPPORTED) {
@@ -481,6 +615,7 @@ int utc_system_settings_get_value_int_p2(void)
        int retcode = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &font_size);
        my_assert_ret(retcode);
 
+       thread_safety_checking();
        return 0;
 }
 
@@ -1352,3 +1487,4 @@ int utc_system_settings_unset_changed_cb_p24(void)
 
        return 0;
 }
+