From: Konstantin Drabeniuk Date: Wed, 14 Dec 2016 14:30:15 +0000 (+0200) Subject: ut: improve code coverage of tdm_buffer.c X-Git-Tag: submit/tizen/20171101.104829~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a05eb9094fa96b6f511c0000c086edca7b39981d;p=platform%2Fcore%2Fuifw%2Flibtdm.git ut: improve code coverage of tdm_buffer.c Change-Id: Ie003d457b800029c280952303c8a0d4b1a97edd6 Signed-off-by: Konstantin Drabeniuk Signed-off-by: SooChan Lim --- diff --git a/ut/src/ut_tdm_buffer.cpp b/ut/src/ut_tdm_buffer.cpp index 2eab3d96..4ebac107 100644 --- a/ut/src/ut_tdm_buffer.cpp +++ b/ut/src/ut_tdm_buffer.cpp @@ -30,8 +30,8 @@ #include "tbm_stubs.h" #include "stub_pthread.h" -#include "tdm_list_stubs.h" #include "stub_stdlib.h" +#include "stub_tdm.h" #include "tdm_buffer.c" @@ -43,9 +43,11 @@ void tdm_buffer_release_handler_f(tbm_surface_h buffer, void *user_data) static void _init_test() { + stub_tdm_init(); stub_pthread_init(); stub_tbm_init(); stub_stdlib_init(); + tdm_debug_module = TDM_DEBUG_BUFFER; } /* tdm_buffer_list_get_first_entry */ @@ -62,6 +64,39 @@ TEST(tdm_buffer_list_get_first_entry, null_ptr_fail_1) ASSERT_TRUE(actual == expected); } +TEST(tdm_buffer_list_get_first_entry, success_list_is_empty) +{ + tbm_surface_h actual; + struct list_head buff_list; + + _init_test(); + + LIST_INITHEAD(&buff_list); + + actual = tdm_buffer_list_get_first_entry(&buff_list); + + ASSERT_TRUE(actual == NULL); +} + +TEST(tdm_buffer_list_get_first_entry, success) +{ + tbm_surface_h actual; + struct list_head buff_list; + tdm_buffer_info buf_info; + struct _tbm_surface buffer; + + _init_test(); + + buf_info.buffer = &buffer; + + LIST_INITHEAD(&buff_list); + LIST_ADD(&buf_info.link, &buff_list); + + actual = tdm_buffer_list_get_first_entry(&buff_list); + + ASSERT_TRUE(actual == &buffer); +} + /* tdm_buffer_ref_backend */ TEST(tdm_buffer_ref_backend, work_flow_success_2) @@ -216,6 +251,36 @@ TEST(tdm_buffer_add_release_handler, null_ptr_fail_1) /* tdm_buffer_get_info */ +TEST(tdm_buffer_get_info, work_flow_success_5) +{ + struct _tbm_surface buffer; + tdm_buffer_info *actual; + + _init_test(); + + TBM_BO_GET_USER_DATA_NULL = 1; + tbm_surface_internal_set_user_data_error = 1; + + actual = tdm_buffer_get_info(&buffer); + + ASSERT_TRUE(actual == NULL); +} + +TEST(tdm_buffer_get_info, work_flow_success_4) +{ + struct _tbm_surface buffer; + tdm_buffer_info *actual; + + _init_test(); + + TBM_BO_GET_USER_DATA_NULL = 1; + tbm_surface_internal_add_user_data_error = 1; + + actual = tdm_buffer_get_info(&buffer); + + ASSERT_TRUE(actual == NULL); +} + TEST(tdm_buffer_get_info, work_flow_success_3) { struct _tbm_surface buffer; @@ -259,3 +324,232 @@ TEST(tdm_buffer_get_info, work_flow_success_1) ASSERT_TRUE(actual != not_expected); } + +/* tdm_buffer_remove_release_handler() */ + +TEST(tdm_buffer_remove_release_handler, success) +{ + struct _tbm_surface buffer; + int user_data; + tdm_buffer_func_info *func_info_1; + tdm_buffer_func_info *func_info_2; + tdm_buffer_info buf_info; + tdm_buffer_func_info *func_info = NULL, *next = NULL; + + _init_test(); + + func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1); + func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2); + + func_info_1->release_func = stub_tdm_buffer_release_handler; + func_info_1->user_data = &user_data; + + func_info_2->release_func = NULL; + func_info_2->user_data = NULL; + + tbm_surface_internal_get_user_data_ret = &buf_info; + + LIST_INITHEAD(&buf_info.release_funcs); + LIST_ADD(&func_info_1->link, &buf_info.release_funcs); + LIST_ADD(&func_info_2->link, &buf_info.release_funcs); + + tdm_buffer_remove_release_handler(&buffer, stub_tdm_buffer_release_handler, &user_data); + + ASSERT_EQ(FREE_CALLED, 1); + LIST_FOR_EACH_ENTRY_SAFE(func_info, next, &buf_info.release_funcs, link) { + if (func_info->release_func != stub_tdm_buffer_release_handler || func_info->user_data != &user_data) + continue; + + ASSERT_TRUE(0); + } + free(func_info_2); +} + +/* tdm_buffer_remove_release_handler_internal() */ + +TEST(tdm_buffer_remove_release_handler_internal, success) +{ + struct _tbm_surface buffer; + tdm_buffer_func_info *func_info_1; + tdm_buffer_func_info *func_info_2; + tdm_buffer_info buf_info; + + _init_test(); + + func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1); + func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2); + + tbm_surface_internal_get_user_data_ret = &buf_info; + + LIST_INITHEAD(&buf_info.release_funcs); + LIST_ADD(&func_info_1->link, &buf_info.release_funcs); + LIST_ADD(&func_info_2->link, &buf_info.release_funcs); + + tdm_buffer_remove_release_handler_internal(&buffer); + + ASSERT_EQ(FREE_CALLED, 1); + free(func_info_1); +} + +/* tdm_buffer_unref_backend() */ + +TEST(tdm_buffer_unref_backend, success_ref_count_is_3) +{ + struct _tbm_surface buffer; + tdm_buffer_info buf_info; + + _init_test(); + + tbm_surface_internal_get_user_data_ret = &buf_info; + buf_info.backend_ref_count = 3; + + tdm_buffer_unref_backend(&buffer); + + ASSERT_EQ(buf_info.backend_ref_count, 2); +} + +TEST(tdm_buffer_unref_backend, success) +{ + struct _tbm_surface buffer; + tdm_buffer_info buf_info; + tdm_buffer_func_info func_info; + + _init_test(); + + tbm_surface_internal_get_user_data_ret = &buf_info; + buf_info.backend_ref_count = 1; + func_info.release_func = stub_tdm_buffer_release_handler; + + LIST_INITHEAD(&buf_info.release_funcs); + LIST_ADD(&func_info.link, &buf_info.release_funcs); + + tdm_buffer_unref_backend(&buffer); + + ASSERT_EQ(stub_tdm_buffer_release_handler_count, 1); + ASSERT_EQ(tbm_surface_internal_ref_count, 1); + ASSERT_EQ(tbm_surface_internal_unref_count, 2); +} + +/* tdm_buffer_add_destroy_handler() */ + +TEST(tdm_buffer_add_destroy_handler, error_buffer_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_buffer_add_destroy_handler(NULL, stub_tdm_buffer_destroy_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_buffer_add_destroy_handler, error_func_is_null) +{ + tdm_error error; + struct _tbm_surface buffer; + + _init_test(); + + error = tdm_buffer_add_destroy_handler(&buffer, NULL, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_buffer_add_destroy_handler, error_buffer_get_info) +{ + tdm_error error; + struct _tbm_surface buffer; + + _init_test(); + + tbm_surface_internal_get_user_data_ret = NULL; + tbm_surface_internal_add_user_data_error = 1; + + error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); +} + +TEST(tdm_buffer_add_destroy_handler, error_calloc) +{ + tdm_error error; + struct _tbm_surface buffer; + tdm_buffer_info buf_info; + + _init_test(); + + tbm_surface_internal_get_user_data_ret = &buf_info; + + CALLOC_ERROR = 1; + + error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); +} + +TEST(tdm_buffer_add_destroy_handler, success) +{ + tdm_error error; + struct _tbm_surface buffer; + tdm_buffer_info buf_info; + int user_data; + tdm_buffer_func_info *func_info = NULL, *f = NULL; + + _init_test(); + + tbm_surface_internal_get_user_data_ret = &buf_info; + + LIST_INITHEAD(&buf_info.destroy_funcs); + + error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, &user_data); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_TRUE(!LIST_IS_EMPTY(&buf_info.destroy_funcs)); + LIST_FOR_EACH_ENTRY(f, &buf_info.destroy_funcs, link) { + if (f->destroy_func != stub_tdm_buffer_destroy_handler || f->user_data != &user_data) + continue; + func_info = f; + } + ASSERT_TRUE(func_info); + free(func_info); +} + +/* tdm_buffer_remove_release_handler() */ + +TEST(tdm_buffer_remove_destroy_handler, success) +{ + struct _tbm_surface buffer; + int user_data; + tdm_buffer_func_info *func_info_1; + tdm_buffer_func_info *func_info_2; + tdm_buffer_info buf_info; + tdm_buffer_func_info *func_info = NULL, *next = NULL; + + _init_test(); + + func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1); + func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2); + + func_info_1->destroy_func = stub_tdm_buffer_destroy_handler; + func_info_1->user_data = &user_data; + + func_info_2->release_func = NULL; + func_info_2->user_data = NULL; + + tbm_surface_internal_get_user_data_ret = &buf_info; + + LIST_INITHEAD(&buf_info.destroy_funcs); + LIST_ADD(&func_info_1->link, &buf_info.destroy_funcs); + LIST_ADD(&func_info_2->link, &buf_info.destroy_funcs); + + tdm_buffer_remove_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, &user_data); + + ASSERT_EQ(FREE_CALLED, 1); + LIST_FOR_EACH_ENTRY_SAFE(func_info, next, &buf_info.destroy_funcs, link) { + if (func_info->release_func != stub_tdm_buffer_destroy_handler || func_info->user_data != &user_data) + continue; + + ASSERT_TRUE(0); + } + free(func_info_2); +} diff --git a/ut/stubs/stub_tdm.h b/ut/stubs/stub_tdm.h index b8c05279..d30fd303 100644 --- a/ut/stubs/stub_tdm.h +++ b/ut/stubs/stub_tdm.h @@ -7,6 +7,7 @@ static tdm_private_output stub_private_output; static int stub_tdm_vblank_handler_call_count; static int stub_tdm_output_change_handler_count; static int stub_tdm_output_commit_handler_count; +static int stub_tdm_buffer_release_handler_count; static void stub_tdm_init() @@ -14,6 +15,7 @@ stub_tdm_init() stub_tdm_vblank_handler_call_count = 0; stub_tdm_output_change_handler_count = 0; stub_tdm_output_commit_handler_count = 0; + stub_tdm_buffer_release_handler_count = 0; } static tdm_private_output* @@ -29,6 +31,13 @@ static void stub_tdm_vblank_handler(tdm_vblank *vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data) { + (void)vblank; + (void)error; + (void)sequence; + (void)tv_sec; + (void)tv_usec; + (void)user_data; + stub_tdm_vblank_handler_call_count++; } @@ -36,6 +45,10 @@ static tdm_error stub_tdm_display_update_output(tdm_private_display *private_display, tdm_output *output_backend, int pipe) { + (void)private_display; + (void)output_backend; + (void)pipe; + return TDM_ERROR_NONE; } @@ -45,6 +58,11 @@ stub_tdm_output_change_handler_cb(tdm_output *output, tdm_value value, void *user_data) { + (void)output; + (void)type; + (void)value; + (void)user_data; + stub_tdm_output_change_handler_count++; } @@ -53,9 +71,33 @@ stub_tdm_output_commit_handler(tdm_output *output, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data) { + (void)output; + (void)sequence; + (void)tv_sec; + (void)tv_usec; + (void)tv_usec; + (void)user_data; + stub_tdm_output_commit_handler_count++; } +static void +stub_tdm_buffer_release_handler(tbm_surface_h buffer, void *user_data) +{ + (void)buffer; + (void)user_data; + + stub_tdm_buffer_release_handler_count++; +} + +static void +stub_tdm_buffer_destroy_handler(tbm_surface_h buffer, + void *user_data) +{ + (void)buffer; + (void)user_data; +} + #define tdm_display_find_output_stamp stub_tdm_display_find_output_stamp #define tdm_display_update_output stub_tdm_display_update_output diff --git a/ut/stubs/tbm_stubs.cpp b/ut/stubs/tbm_stubs.cpp index bc5d19bd..c86fabc6 100644 --- a/ut/stubs/tbm_stubs.cpp +++ b/ut/stubs/tbm_stubs.cpp @@ -5,6 +5,11 @@ int TBM_BUFMGR_DEINIT_CALLED = 0; int TBM_BO_GET_USER_DATA_NULL = 0; int tbm_surface_queue_release_count; +int tbm_surface_internal_add_user_data_error; +int tbm_surface_internal_set_user_data_error; +void *tbm_surface_internal_get_user_data_ret; +int tbm_surface_internal_ref_count; +int tbm_surface_internal_unref_count; tbm_bufmgr tbm_bufmgr_init(int fd) { @@ -70,11 +75,15 @@ int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data) void tbm_surface_internal_ref(tbm_surface_h surface) { (void)surface; + + tbm_surface_internal_ref_count++; } void tbm_surface_internal_unref(tbm_surface_h surface) { (void)surface; + + tbm_surface_internal_unref_count++; } tbm_surface_queue_error_e tbm_surface_queue_acquire( @@ -146,7 +155,13 @@ int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, { (void)surface; (void)key; - (void)data; + + if (tbm_surface_internal_get_user_data_ret) { + *data = tbm_surface_internal_get_user_data_ret; + return 1; + } + + *data = NULL; return 0; } @@ -158,6 +173,9 @@ int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, (void)key; (void)data_free_func; + if (tbm_surface_internal_add_user_data_error) + return 0; + return 1; } @@ -168,6 +186,9 @@ int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, (void)key; (void)data; + if (tbm_surface_internal_set_user_data_error) + return 0; + return 1; } @@ -241,4 +262,9 @@ void stub_tbm_init() TBM_BUFMGR_DEINIT_CALLED = 0; TBM_BO_GET_USER_DATA_NULL = 0; tbm_surface_queue_release_count = 0; + tbm_surface_internal_add_user_data_error = 0; + tbm_surface_internal_set_user_data_error = 0; + tbm_surface_internal_get_user_data_ret = NULL; + tbm_surface_internal_ref_count = 0; + tbm_surface_internal_unref_count = 0; } diff --git a/ut/stubs/tbm_stubs.h b/ut/stubs/tbm_stubs.h index 42219416..e8e1f13f 100644 --- a/ut/stubs/tbm_stubs.h +++ b/ut/stubs/tbm_stubs.h @@ -8,6 +8,11 @@ extern int TBM_BUFMGR_DEINIT_CALLED; extern int TBM_BO_GET_USER_DATA_NULL; extern int tbm_surface_queue_release_count; +extern int tbm_surface_internal_add_user_data_error; +extern int tbm_surface_internal_set_user_data_error; +extern void *tbm_surface_internal_get_user_data_ret; +extern int tbm_surface_internal_ref_count; +extern int tbm_surface_internal_unref_count; struct _tbm_surface { int temp;