From: Konstantin Drabeniuk Date: Tue, 6 Dec 2016 12:41:19 +0000 (+0200) Subject: ut: write unit tests for tdm_vblank.c file X-Git-Tag: accepted/tizen/unified/20171102.061517~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51a1f6f344c40d482c365e2a4ced92835cc0478c;p=platform%2Fcore%2Fuifw%2Flibtdm.git ut: write unit tests for tdm_vblank.c file Change-Id: I5638c538aeb4749857164fa9ae25942f13909856 Signed-off-by: Konstantin Drabeniuk Signed-off-by: SooChan Lim --- diff --git a/ut/Makefile.am b/ut/Makefile.am index f580d2c..b8e002f 100644 --- a/ut/Makefile.am +++ b/ut/Makefile.am @@ -11,10 +11,10 @@ tdm_utests_SOURCES = \ src/ut_tdm_helper.cpp \ src/ut_tdm_pp.cpp \ src/ut_tdm_thread.cpp \ + src/ut_tdm_vblank.cpp \ stubs/tbm_stubs.cpp \ stubs/tdm_log.cpp \ stubs/tdm_server.cpp \ - stubs/tdm_vblank.cpp \ stubs/stub_pthread.cpp \ stubs/stub_stdlib.cpp \ stubs/tdm_backend_module_subs.cpp \ diff --git a/ut/src/ut_tdm_thread.cpp b/ut/src/ut_tdm_thread.cpp index e6b062b..76f69d0 100644 --- a/ut/src/ut_tdm_thread.cpp +++ b/ut/src/ut_tdm_thread.cpp @@ -50,6 +50,7 @@ static void _init_test() stub_unistd_init(); stub_tdm_display_init(); stub_tdm_pp_init(); + tdm_debug_module = TDM_DEBUG_THREAD; } /* UNIT TESTS */ @@ -269,7 +270,8 @@ TEST(tdm_thread_init, success_init) ASSERT_TRUE(keep_private_thread != NULL); ASSERT_TRUE(keep_private_thread->private_loop == &private_loop); ASSERT_TRUE(private_loop.private_thread != NULL); - ASSERT_EQ(private_loop.private_thread->display_tid, stub_syscall_return_value); + ASSERT_EQ(private_loop.private_thread->display_tid, + stub_syscall_return_value); free(private_loop.private_thread); } diff --git a/ut/src/ut_tdm_vblank.cpp b/ut/src/ut_tdm_vblank.cpp new file mode 100644 index 0000000..a808ea8 --- /dev/null +++ b/ut/src/ut_tdm_vblank.cpp @@ -0,0 +1,881 @@ +/************************************************************************** + * + * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Konstantin Drabeniuk + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * +**************************************************************************/ + +#include "gtest/gtest.h" + +#include "stub_pthread.h" +#include "stub_tdm_display.h" +#include "stub_stdlib.h" +#include "stub_unistd.h" +#include "stub_tdm_event_loop.h" +#include "stub_tdm_thread.h" +#include "stub_tdm.h" +#include "stub_tdm_event_loop.h" +#include "stub_tdm_helper.h" + +#include "tdm_vblank.c" + +static void _init_test() +{ + stub_tdm_helper_init(); + stub_tdm_event_loop_init(); + stub_tdm_init(); + stub_tdm_thread_init(); + stub_tdm_event_loop_init(); + stub_stdlib_init(); + stub_stdlib_init(); + stub_tdm_display_init(); + stub_pthread_init(); + vblank_list_inited = 0; + tdm_debug_module = TDM_DEBUG_VBLANK; +} + +/* UNIT TESTS */ + +/* tdm_vblank_create() */ + +TEST(tdm_vblank_create, error_dpy_is_null) +{ + tdm_vblank *vblank; + tdm_private_output output; + tdm_error error; + + _init_test(); + + vblank = tdm_vblank_create(NULL, &output, &error); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); + ASSERT_TRUE(vblank == NULL); +} + +TEST(tdm_vblank_create, error_output_is_null) +{ + tdm_vblank *vblank; + tdm_private_display display; + tdm_error error; + + _init_test(); + + vblank = tdm_vblank_create(&display, NULL, &error); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); + ASSERT_TRUE(vblank == NULL); +} + +TEST(tdm_vblank_create, error_list_inited_mutex_init) +{ + tdm_vblank *vblank; + tdm_private_display display; + tdm_private_output output; + tdm_error error; + + _init_test(); + + PTHREAD_MUTEX_INIT_ERROR = -1; + + vblank = tdm_vblank_create(&display, &output, &error); + + ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); + ASSERT_TRUE(vblank == NULL); +} + +TEST(tdm_vblank_create, error_mode_is_null) +{ + tdm_vblank *vblank; + tdm_private_display display; + tdm_private_output output; + tdm_error error; + + _init_test(); + + stub_tdm_output_get_mode_error = 1; + + vblank = tdm_vblank_create(&display, &output, &error); + + ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); + ASSERT_TRUE(vblank == NULL); +} + +TEST(tdm_vblank_create, error_calloc_error) +{ + tdm_vblank *vblank; + tdm_private_display display; + tdm_private_output output; + tdm_error error; + + _init_test(); + + CALLOC_ERROR = 1; + + vblank = tdm_vblank_create(&display, &output, &error); + + ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); + ASSERT_TRUE(vblank == NULL); +} + +TEST(tdm_vblank_create, success_vblank_create) +{ + tdm_private_vblank *vblank; + tdm_private_display display; + tdm_private_output output; + tdm_error error; + tdm_private_vblank *find_item; + tdm_private_vblank *tmp; + + _init_test(); + + vblank = + (tdm_private_vblank *) tdm_vblank_create(&display, &output, &error); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_TRUE(vblank != NULL); + ASSERT_TRUE(stub_tdm_output_change_handler == _tdm_vblank_cb_output_change); + ASSERT_EQ(vblank->stamp, stamp); + ASSERT_EQ(vblank->owner_tid, stub_syscall_return_value); + ASSERT_TRUE(vblank->dpy == &display); + ASSERT_TRUE(vblank->output == &output); + ASSERT_EQ(vblank->dpms, stub_tdm_dpms_returned_value); + ASSERT_EQ(vblank->vrefresh, stub_tdm_mode.vrefresh); + ASSERT_EQ(vblank->HW_vblank_gap, 1.0 / vblank->vrefresh); + ASSERT_EQ(vblank->check_HW_or_SW, 1); + ASSERT_EQ(vblank->fps, stub_tdm_mode.vrefresh); + ASSERT_TRUE(LIST_IS_EMPTY(&vblank->HW_wait_list)); + ASSERT_TRUE(LIST_IS_EMPTY(&vblank->SW_wait_list)); + LIST_FOR_EACH_ENTRY_SAFE(find_item, tmp, &vblank_list, link) { + if (find_item == vblank) + break; + find_item = NULL; + } + ASSERT_TRUE(find_item != NULL); + ASSERT_TRUE(LIST_IS_EMPTY(&valid_wait_list)); + free(vblank); +} + +/* tdm_vblank_destroy() */ + +TEST(tdm_vblank_destroy, success_vblank_destroy) +{ + tdm_private_vblank *vblank; + int SW_timer = 10; + tdm_vblank_wait_info *hw_vblank_wait_info; + tdm_vblank_wait_info *sw_vblank_wait_info; + + _init_test(); + + vblank = (tdm_private_vblank *) calloc(1, sizeof *vblank); + hw_vblank_wait_info = + (tdm_vblank_wait_info *) calloc(1, sizeof *hw_vblank_wait_info); + sw_vblank_wait_info = + (tdm_vblank_wait_info *) calloc(1, sizeof *sw_vblank_wait_info); + + LIST_INITHEAD(&vblank_list); + LIST_ADD(&vblank->link, &vblank_list); + + vblank->SW_timer = &SW_timer; + + LIST_INITHEAD(&hw_vblank_wait_info->valid_link); + LIST_INITHEAD(&vblank->HW_wait_list); + LIST_ADD(&hw_vblank_wait_info->link, &vblank->HW_wait_list); + + LIST_INITHEAD(&sw_vblank_wait_info->valid_link); + LIST_INITHEAD(&vblank->SW_wait_list); + LIST_ADD(&sw_vblank_wait_info->link, &vblank->SW_wait_list); + + tdm_vblank_destroy(vblank); + + ASSERT_TRUE(LIST_IS_EMPTY(&vblank_list)); + ASSERT_TRUE(stub_tdm_event_loop_removed_source == &SW_timer); + ASSERT_TRUE(stub_tdm_output_change_handler == _tdm_vblank_cb_output_change); + ASSERT_TRUE(LIST_IS_EMPTY(&vblank->HW_wait_list)); + ASSERT_TRUE(LIST_IS_EMPTY(&vblank->SW_wait_list)); + ASSERT_EQ(FREE_CALLED, 1); +} + +/* tdm_vblank_set_fps() */ + +TEST(tdm_vblank_set_fps, error_vblank_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_set_fps(NULL, 5); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_set_fps, error_fps_is_0) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + error = tdm_vblank_set_fps(&vblank, 0); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_set_fps, success_fps_is_already_set) +{ + tdm_error error; + tdm_private_vblank vblank; + unsigned int fps = 60; + + _init_test(); + + vblank.fps = fps; + + error = tdm_vblank_set_fps(&vblank, fps); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.fps, fps); +} + +TEST(tdm_vblank_set_fps, success_set_fps) +{ + tdm_error error; + tdm_private_vblank vblank; + unsigned int fps = 60; + + _init_test(); + + vblank.fps = fps - 10; + + error = tdm_vblank_set_fps(&vblank, fps); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.fps, fps); + ASSERT_EQ(vblank.check_HW_or_SW, 1); +} + +/* tdm_vblank_set_offset() */ + +TEST(tdm_vblank_set_offset, error_vblank_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_set_offset(NULL, 1); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_set_offset, success_offset_is_already_set) +{ + tdm_error error; + tdm_private_vblank vblank; + int offset = 256; + + _init_test(); + + vblank.offset = offset; + + error = tdm_vblank_set_offset(&vblank, offset); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.offset, offset); +} + +TEST(tdm_vblank_set_offset, success_vblank_set_offset) +{ + tdm_error error; + tdm_private_vblank vblank; + int offset = 256; + + _init_test(); + + vblank.offset = offset - 64; + + error = tdm_vblank_set_offset(&vblank, offset); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.offset, offset); + ASSERT_EQ(vblank.check_HW_or_SW, 1); +} + +/* tdm_vblank_set_enable_fake() */ + +TEST(tdm_vblank_set_enable_fake, error_vblank_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_set_enable_fake(NULL, 1); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_set_enable_fake, success_enable_fake_is_already_set) +{ + tdm_error error; + tdm_private_vblank vblank; + int enable_fake = 256; + + _init_test(); + + vblank.enable_fake = enable_fake; + + error = tdm_vblank_set_enable_fake(&vblank, enable_fake); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.enable_fake, enable_fake); +} + +TEST(tdm_vblank_set_enable_fake, success_vblank_set_enable_fake) +{ + tdm_error error; + tdm_private_vblank vblank; + int enable_fake = 256; + + _init_test(); + + vblank.enable_fake = enable_fake - 64; + + error = tdm_vblank_set_enable_fake(&vblank, enable_fake); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank.enable_fake, enable_fake); +} + +/* tdm_vblank_get_enable_fake() */ + +TEST(tdm_vblank_get_enable_fake, error_vblank_is_null) +{ + unsigned int enable_fake; + + _init_test(); + + enable_fake = tdm_vblank_get_enable_fake(NULL); + + ASSERT_EQ(enable_fake, 0); +} + +TEST(tdm_vblank_get_enable_fake, success_vblank_get_enable_fake) +{ + tdm_private_vblank vblank; + unsigned int enable_fake; + + _init_test(); + + vblank.enable_fake = 15; + + enable_fake = tdm_vblank_get_enable_fake(&vblank); + + ASSERT_EQ(enable_fake, vblank.enable_fake); +} + +/* tdm_vblank_cb_vblank_SW() */ + +TEST(tdm_vblank_cb_vblank_SW, error_vblank_is_null_and_vblank_stamp_less_0) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_cb_vblank_SW(NULL, -1); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_cb_vblank_SW, success_vblank_is_null_and_not_on_vblank_list) +{ + tdm_error error; + + _init_test(); + + LIST_INITHEAD(&vblank_list); + + error = tdm_vblank_cb_vblank_SW(NULL, 5); + + ASSERT_EQ(error, TDM_ERROR_NONE); +} + +TEST(tdm_vblank_cb_vblank_SW, success_not_in_display_thread) +{ + tdm_error error; + tdm_private_vblank vblank; + tdm_thread_cb_vblank_sw *vblank_sw; + tdm_private_display display; + + _init_test(); + + vblank.owner_tid = 10; + vblank.stamp = 15.0; + vblank.dpy = &display; + + stub_syscall_return_value = vblank.owner_tid - 1; + + error = tdm_vblank_cb_vblank_SW(&vblank, 5); + + vblank_sw = (tdm_thread_cb_vblank_sw *) stub_tdm_thread_send_cb_buff; + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(vblank_sw->base.length, sizeof(tdm_thread_cb_vblank_sw)); + ASSERT_EQ(vblank_sw->base.type, TDM_THREAD_CB_VBLANK_SW); + ASSERT_DOUBLE_EQ(vblank_sw->vblank_stamp, vblank.stamp); +} + +TEST(tdm_vblank_cb_vblank_SW, success_SW_wait_list_is_empty) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.owner_tid = 10; + + stub_syscall_return_value = vblank.owner_tid; + + LIST_INITHEAD(&vblank.SW_wait_list); + + error = tdm_vblank_cb_vblank_SW(&vblank, 5); + + ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); +} + +TEST(tdm_vblank_cb_vblank_SW, success_vblank_cb_vblank_SW) +{ + tdm_error error; + tdm_private_vblank vblank; + tdm_vblank_wait_info *first_wait_info; + tdm_vblank_wait_info *wait_info; + + _init_test(); + + first_wait_info = + (tdm_vblank_wait_info *) calloc(1, sizeof *first_wait_info); + wait_info = (tdm_vblank_wait_info *) calloc(1, sizeof *wait_info); + + vblank.owner_tid = 10; + + stub_syscall_return_value = vblank.owner_tid; + + LIST_INITHEAD(&vblank.SW_wait_list); + LIST_INITHEAD(&first_wait_info->valid_link); + LIST_INITHEAD(&wait_info->valid_link); + + LIST_ADD(&wait_info->link, &vblank.SW_wait_list); + LIST_ADD(&first_wait_info->link, &vblank.SW_wait_list); + + vblank.last_seq = 20; + first_wait_info->target_seq = 19; + wait_info->target_seq = 21; + + first_wait_info->target_time = 5; + wait_info->target_time = 5; + + first_wait_info->func = stub_tdm_vblank_handler; + wait_info->func = stub_tdm_vblank_handler; + + error = tdm_vblank_cb_vblank_SW(&vblank, 5); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(FREE_CALLED, 1); + ASSERT_EQ(stub_tdm_vblank_handler_call_count, 2); +} + +TEST(tdm_vblank_cb_vblank_SW, success_vblank_cb_vblank_SW_2) +{ + tdm_error error; + tdm_private_vblank vblank; + tdm_vblank_wait_info *first_wait_info; + tdm_vblank_wait_info *wait_info; + + _init_test(); + + first_wait_info = + (tdm_vblank_wait_info *) calloc(1, sizeof *first_wait_info); + wait_info = (tdm_vblank_wait_info *) calloc(1, sizeof *wait_info); + + vblank.owner_tid = 10; + + stub_syscall_return_value = vblank.owner_tid; + + LIST_INITHEAD(&vblank.SW_wait_list); + LIST_INITHEAD(&first_wait_info->valid_link); + LIST_INITHEAD(&wait_info->valid_link); + + LIST_ADD(&wait_info->link, &vblank.SW_wait_list); + LIST_ADD(&first_wait_info->link, &vblank.SW_wait_list); + + vblank.last_seq = 20; + first_wait_info->target_seq = 19; + wait_info->target_seq = 21; + + first_wait_info->target_time = 5; + wait_info->target_time = 10; + + first_wait_info->func = stub_tdm_vblank_handler; + wait_info->func = stub_tdm_vblank_handler; + + error = tdm_vblank_cb_vblank_SW(&vblank, 5); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(FREE_CALLED, 1); + ASSERT_EQ(stub_tdm_vblank_handler_call_count, 1); +} + +/* tdm_vblank_wait() */ + +TEST(tdm_vblank_wait, error_vblank_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_wait(NULL, 1, 1, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_wait, error_func_is_null) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + error = tdm_vblank_wait(&vblank, 1, 1, 1, NULL, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_wait, error_not_in_display_thread) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.owner_tid = 10; + + stub_syscall_return_value = vblank.owner_tid - 1; + + error = tdm_vblank_wait(&vblank, 1, 1, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_BAD_REQUEST); +} + +TEST(tdm_vblank_wait, error_dpms_is_off_and_enable_fake_is_0) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_OFF; + vblank.enable_fake = 0; + + stub_syscall_return_value = vblank.owner_tid; + + error = tdm_vblank_wait(&vblank, 1, 1, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_DPMS_OFF); +} + +TEST(tdm_vblank_wait, error_calloc) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + + stub_syscall_return_value = vblank.owner_tid; + + CALLOC_ERROR = 1; + + error = tdm_vblank_wait(&vblank, 1, 1, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); +} + +TEST(tdm_vblank_wait, error_vblank_wait_HW_and_vblank_wait_SW) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 60; + vblank.offset = 1; + vblank.last_time = 0; + vblank.SW_timer = &SW_timer; + + stub_syscall_return_value = vblank.owner_tid; + stub_tdm_output_wait_vblank_error = 1; + stub_tdm_event_loop_source_timer_update_error = 1; + + error = tdm_vblank_wait(&vblank, 0, 0, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); +} + +TEST(tdm_vblank_wait, error_vblank_wait_SW) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 24; + vblank.offset = 1; + vblank.last_time = 0; + vblank.SW_timer = &SW_timer; + + stub_syscall_return_value = vblank.owner_tid; + stub_tdm_event_loop_source_timer_update_error = 1; + + error = tdm_vblank_wait(&vblank, 0, 0, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); +} + +TEST(tdm_vblank_wait, success_vblank_wait_SW) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.owner_tid = 10; + vblank.enable_fake = 1; + vblank.dpms = TDM_OUTPUT_DPMS_OFF; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 60; + vblank.offset = 1; + vblank.last_time = 0; + vblank.SW_timer = &SW_timer; + + stub_syscall_return_value = vblank.owner_tid; + + error = tdm_vblank_wait(&vblank, 0, 0, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); +} + +TEST(tdm_vblank_wait, success_vblank_wait_HW) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 60; + vblank.offset = 0; + vblank.last_time = 0; + vblank.SW_timer = &SW_timer; + + stub_syscall_return_value = vblank.owner_tid; + + error = tdm_vblank_wait(&vblank, 0, 0, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); +} + +/* tdm_vblank_wait_seq() */ + +TEST(tdm_vblank_wait_seq, error_vblank_is_null) +{ + tdm_error error; + + _init_test(); + + error = tdm_vblank_wait_seq(NULL, 1, 1, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_wait_seq, error_func_is_null) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + error = tdm_vblank_wait_seq(&vblank, 1, 1, 1, NULL, NULL); + + ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); +} + +TEST(tdm_vblank_wait_seq, success_last_seq_is_0) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.last_seq = 0; + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 60; + vblank.offset = 0; + vblank.last_time = 0; + vblank.SW_timer = &SW_timer; + + stub_syscall_return_value = vblank.owner_tid; + + error = + tdm_vblank_wait_seq(&vblank, 0, 0, 1, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); +} + +TEST(tdm_vblank_wait_seq, + success_sequence_greater_last_seq_and_seq_target_less_curr) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.last_seq = 1; + vblank.vblank_gap = 0; + + stub_tdm_helper_get_time_ret_val = 100; + + error = + tdm_vblank_wait_seq(&vblank, 0, 0, 5, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(stub_tdm_vblank_handler_call_count, 1); +} + +TEST(tdm_vblank_wait_seq, success_target_is_too_close_to_current) +{ + tdm_error error; + tdm_private_vblank vblank; + + _init_test(); + + vblank.last_seq = 1; + vblank.vblank_gap = 0; + + stub_tdm_helper_get_time_ret_val = vblank.last_time - 0.0001; + + error = + tdm_vblank_wait_seq(&vblank, 0, 0, 5, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(stub_tdm_vblank_handler_call_count, 1); +} + +TEST(tdm_vblank_wait_seq, success_sequence_greater_last_seq) +{ + tdm_error error; + tdm_private_vblank vblank; + int SW_timer = 10; + + _init_test(); + + LIST_INITHEAD(&vblank.HW_wait_list); + LIST_INITHEAD(&vblank.SW_wait_list); + + vblank.last_seq = 1; + vblank.owner_tid = 10; + vblank.dpms = TDM_OUTPUT_DPMS_ON; + vblank.check_HW_or_SW = 1; + vblank.vrefresh = 60; + vblank.fps = 60; + vblank.offset = 0; + vblank.last_time = 1; + vblank.SW_timer = &SW_timer; + vblank.vblank_gap = 0; + + stub_syscall_return_value = vblank.owner_tid; + + stub_tdm_helper_get_time_ret_val = vblank.last_time - 0.5; + + error = + tdm_vblank_wait_seq(&vblank, 0, 0, 5, stub_tdm_vblank_handler, NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); +} + +TEST(tdm_vblank_wait_seq, + success_last_seq_is_not_0_and_no_sequence_greater_last_seq) +{ + tdm_error error; + tdm_private_vblank vblank; + unsigned int sequence = TDM_VBLANK_UINT_1Q + 100; + + _init_test(); + + vblank.last_seq = sequence + 100; + vblank.vblank_gap = 0; + + stub_tdm_helper_get_time_ret_val = vblank.last_time - 0.0001; + + error = + tdm_vblank_wait_seq(&vblank, 0, 0, sequence, stub_tdm_vblank_handler, + NULL); + + ASSERT_EQ(error, TDM_ERROR_NONE); + ASSERT_EQ(stub_tdm_vblank_handler_call_count, 1); +} diff --git a/ut/stubs/stub_tdm.h b/ut/stubs/stub_tdm.h index 7530855..64a8125 100644 --- a/ut/stubs/stub_tdm.h +++ b/ut/stubs/stub_tdm.h @@ -3,9 +3,16 @@ #include -tdm_private_output stub_private_output; +static tdm_private_output stub_private_output; +static int stub_tdm_vblank_handler_call_count; -tdm_private_output* +static void +stub_tdm_init() +{ + stub_tdm_vblank_handler_call_count = 0; +} + +static tdm_private_output* stub_tdm_display_find_output_stamp(tdm_private_display *private_display, double stamp) { (void)private_display; @@ -14,6 +21,13 @@ stub_tdm_display_find_output_stamp(tdm_private_display *private_display, double return &stub_private_output; } +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) +{ + stub_tdm_vblank_handler_call_count++; +} + #define tdm_display_find_output_stamp stub_tdm_display_find_output_stamp #endif // STUB_TDM_H diff --git a/ut/stubs/stub_tdm_display.h b/ut/stubs/stub_tdm_display.h index a73dc90..00a1ec0 100644 --- a/ut/stubs/stub_tdm_display.h +++ b/ut/stubs/stub_tdm_display.h @@ -3,10 +3,19 @@ #include "tdm.h" +#ifdef __cplusplus +extern "C" { +#endif + static int stub_tdm_output_cb_commit_called; static int stub_tdm_output_cb_vblank_called; static int stub_tdm_output_cb_status_called; -static int stub_tdm_output_cb_dpms_called; +static int stub_tdm_output_cb_dpms_called; +static int stub_tdm_output_get_mode_error; +static tdm_output_mode stub_tdm_mode; +static tdm_output_change_handler stub_tdm_output_change_handler; +static tdm_output_dpms stub_tdm_dpms_returned_value; +static int stub_tdm_output_wait_vblank_error; static void stub_tdm_display_init() @@ -14,6 +23,11 @@ stub_tdm_display_init() stub_tdm_output_cb_commit_called = 0; stub_tdm_output_cb_vblank_called = 0; stub_tdm_output_cb_dpms_called = 0; + stub_tdm_output_get_mode_error = 0; + stub_tdm_output_change_handler = NULL; + stub_tdm_dpms_returned_value = TDM_OUTPUT_DPMS_ON; + stub_tdm_mode.vrefresh = 24; + stub_tdm_output_wait_vblank_error = 0; } static void @@ -63,9 +77,74 @@ stub_tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void * stub_tdm_output_cb_dpms_called = 1; } +static tdm_error +stub_tdm_output_get_mode(tdm_output *output, const tdm_output_mode **mode) +{ + if (stub_tdm_output_get_mode_error) { + *mode = NULL; + return TDM_ERROR_OPERATION_FAILED; + } + + *mode = &stub_tdm_mode; + + return TDM_ERROR_NONE; +} + +static tdm_error +stub_tdm_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value) +{ + (void)output; + + *dpms_value = stub_tdm_dpms_returned_value; + return TDM_ERROR_NONE; +} + +static tdm_error +stub_tdm_output_add_change_handler(tdm_output *output, + tdm_output_change_handler func, + void *user_data) +{ + (void)output; + (void)user_data; + + stub_tdm_output_change_handler = func; + + return TDM_ERROR_NONE; +} + +static void +stub_tdm_output_remove_change_handler(tdm_output *output, + tdm_output_change_handler func, + void *user_data) +{ + (void)output; + (void)user_data; + + stub_tdm_output_change_handler = func; +} + +static tdm_error +stub_tdm_output_wait_vblank(tdm_output *output, int interval, int sync, + tdm_output_vblank_handler func, void *user_data) +{ + if (stub_tdm_output_wait_vblank_error) + return TDM_ERROR_DPMS_OFF; + + return TDM_ERROR_NONE; +} + +#ifdef __cplusplus +} +#endif + #define tdm_output_cb_commit stub_tdm_output_cb_commit #define tdm_output_cb_vblank stub_tdm_output_cb_vblank #define tdm_output_cb_status stub_tdm_output_cb_status #define tdm_output_cb_dpms stub_tdm_output_cb_dpms +#define tdm_output_get_mode stub_tdm_output_get_mode +#define tdm_output_get_dpms stub_tdm_output_get_dpms +#define tdm_output_add_change_handler stub_tdm_output_add_change_handler +#define tdm_output_remove_change_handler stub_tdm_output_remove_change_handler +#define tdm_output_wait_vblank stub_tdm_output_wait_vblank #endif // STUB_TDM_DISPLAY_H diff --git a/ut/stubs/stub_tdm_event_loop.h b/ut/stubs/stub_tdm_event_loop.h index 9d12527..e978acd 100644 --- a/ut/stubs/stub_tdm_event_loop.h +++ b/ut/stubs/stub_tdm_event_loop.h @@ -1,11 +1,17 @@ #ifndef STUB_TDM_EVENT_LOOP_H #define STUB_TDM_EVENT_LOOP_H +#include "tdm_backend.h" + static int TDM_EVENT_LOOP_DISPATCH_ERROR; +static tdm_event_loop_source *stub_tdm_event_loop_removed_source; +static int stub_tdm_event_loop_source_timer_update_error; static void stub_tdm_event_loop_init() { + stub_tdm_event_loop_removed_source = NULL; TDM_EVENT_LOOP_DISPATCH_ERROR = 0; + stub_tdm_event_loop_source_timer_update_error = 0; } static int stub_tdm_event_loop_get_fd(tdm_private_display *private_display) @@ -26,7 +32,28 @@ static tdm_error stub_tdm_event_loop_dispatch(tdm_private_display *private_displ return TDM_ERROR_NONE; } +static void stub_tdm_event_loop_source_remove(tdm_event_loop_source *source) +{ + (void)source; + + stub_tdm_event_loop_removed_source = source; +} + +static tdm_error +stub_tdm_event_loop_source_timer_update(tdm_event_loop_source *source, unsigned int ms_delay) +{ + (void)source; + (void)ms_delay; + + if (stub_tdm_event_loop_source_timer_update_error) + return TDM_ERROR_OPERATION_FAILED; + + return TDM_ERROR_NONE; +} + #define tdm_event_loop_get_fd stub_tdm_event_loop_get_fd #define tdm_event_loop_dispatch stub_tdm_event_loop_dispatch +#define tdm_event_loop_source_remove stub_tdm_event_loop_source_remove +#define tdm_event_loop_source_timer_update stub_tdm_event_loop_source_timer_update #endif // STUB_TDM_EVENT_LOOP_H diff --git a/ut/stubs/stub_tdm_helper.h b/ut/stubs/stub_tdm_helper.h new file mode 100644 index 0000000..d1f6044 --- /dev/null +++ b/ut/stubs/stub_tdm_helper.h @@ -0,0 +1,26 @@ +#ifndef STUB_TDM_HELPER_H +#define STUB_TDM_HELPER_H + +static double stub_tdm_helper_get_time_ret_val; + +static void +stub_tdm_helper_init() +{ + struct timespec tp; + + if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) + stub_tdm_helper_get_time_ret_val = (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0; + else + stub_tdm_helper_get_time_ret_val = 0; +} + +static double +stub_tdm_helper_get_time(void) +{ + return stub_tdm_helper_get_time_ret_val; +} + +#define tdm_helper_get_time_ret_val stub_tdm_helper_get_time_ret_val +#define tdm_helper_get_time stub_tdm_helper_get_time + +#endif // STUB_TDM_HELPER_H diff --git a/ut/stubs/stub_tdm_thread.h b/ut/stubs/stub_tdm_thread.h index 38af02b..0fc110a 100644 --- a/ut/stubs/stub_tdm_thread.h +++ b/ut/stubs/stub_tdm_thread.h @@ -1,11 +1,18 @@ #ifndef STUB_TDM_THREAD_H #define STUB_TDM_THREAD_H +#include "tdm_private.h" +#include + static int TDM_THREAD_HANDLE_ERROR; +static int stub_tdm_thread_send_cb_error; +static char stub_tdm_thread_send_cb_buff[1024]; -void stub_tdm_thread_init() +static void stub_tdm_thread_init() { TDM_THREAD_HANDLE_ERROR = 0; + stub_tdm_thread_send_cb_error = 0; + memset(stub_tdm_thread_send_cb_buff, 0, 1024); } static int stub_tdm_thread_get_fd(tdm_private_loop *private_loop) @@ -26,7 +33,19 @@ static tdm_error stub_tdm_thread_handle_cb(tdm_private_loop *private_loop) return TDM_ERROR_NONE; } +static tdm_error +stub_tdm_thread_send_cb(tdm_private_loop *private_loop, tdm_thread_cb_base *base) +{ + if (stub_tdm_thread_send_cb_error) + return TDM_ERROR_OPERATION_FAILED; + + memcpy(stub_tdm_thread_send_cb_buff, base, base->length); + + return TDM_ERROR_NONE; +} + #define tdm_thread_get_fd stub_tdm_thread_get_fd #define tdm_thread_handle_cb stub_tdm_thread_handle_cb +#define tdm_thread_send_cb stub_tdm_thread_send_cb #endif // STUB_TDM_THREAD_H diff --git a/ut/stubs/tbm_stubs.cpp b/ut/stubs/tbm_stubs.cpp index 520e2d3..ce98c5f 100644 --- a/ut/stubs/tbm_stubs.cpp +++ b/ut/stubs/tbm_stubs.cpp @@ -206,6 +206,21 @@ int tbm_surface_internal_get_num_bos(tbm_surface_h surface) return 0; } +int tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info) +{ + +} + +tbm_format tbm_surface_get_format(tbm_surface_h surface) +{ + +} + +int tbm_surface_get_height(tbm_surface_h surface) +{ + +} + void stub_tbm_init() { TBM_BUFMGR_DEINIT_CALLED = 0; diff --git a/ut/stubs/tdm_vblank.cpp b/ut/stubs/tdm_vblank.cpp deleted file mode 100644 index fd83fc6..0000000 --- a/ut/stubs/tdm_vblank.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "tdm.h" -#include "tdm_private.h" - -#define TDM_VBLANK_UINT_MAX 4294967295U -#define TDM_VBLANK_UINT_1Q 1073741823U /* UINT_MAX / 4 */ -#define TDM_VBLANK_UINT_3Q 3221225471U /* UINT_MAX / 4 * 3 */ - -#define TDM_VBLANK_SEQ_REACHED_MAX(seq, last_seq) \ - ((seq) < TDM_VBLANK_UINT_1Q && TDM_VBLANK_UINT_3Q < (last_seq)) - -#define VER(fmt, arg...) TDM_ERR("[%p] "fmt, private_vblank, ##arg) -#define VWR(fmt, arg...) TDM_WRN("[%p] "fmt, private_vblank, ##arg) -#define VIN(fmt, arg...) TDM_INFO("[%p] "fmt, private_vblank, ##arg) -#define VDB(fmt, arg...) TDM_DBG("[%p] "fmt, private_vblank, ##arg) - -typedef enum { - VBLANK_TYPE_SW, - VBLANK_TYPE_SW_FAKE, - VBLANK_TYPE_HW, - VBLANK_TYPE_HW_SW, -} tdm_vblank_wait_type; - -typedef struct _tdm_vblank_wait_info tdm_vblank_wait_info; - -typedef struct _tdm_private_vblank { - struct list_head link; - - tdm_display *dpy; - tdm_output *output; - tdm_output_dpms dpms; - unsigned int vrefresh; - - unsigned int check_HW_or_SW; - unsigned int fps; - int offset; - unsigned int enable_fake; - - double vblank_gap; - unsigned int quotient; - - unsigned int last_seq; - unsigned int last_tv_sec; - unsigned int last_tv_usec; - - /* for HW */ - double HW_vblank_gap; - struct list_head HW_wait_list; - - /* for SW */ - tdm_event_loop_source *SW_timer; - struct list_head SW_wait_list; -} tdm_private_vblank; - -struct _tdm_vblank_wait_info { - struct list_head link; - struct list_head valid_link; - - unsigned int stamp; - - unsigned int req_sec; - unsigned int req_usec; - unsigned int interval; - - tdm_vblank_handler func; - void *user_data; - tdm_private_vblank *private_vblank; - - tdm_vblank_wait_type type; - - unsigned int target_sec; - unsigned int target_usec; - unsigned int target_seq; -}; - -tdm_vblank* -tdm_vblank_create(tdm_display *dpy, tdm_output *output, tdm_error *error) -{ - (void)dpy; - (void)output; - (void)error; - - return NULL; -} - -void -tdm_vblank_destroy(tdm_vblank *vblank) -{ - (void)vblank; -} - -tdm_error -tdm_vblank_set_fps(tdm_vblank *vblank, unsigned int fps) -{ - (void)vblank; - (void)fps; - - return TDM_ERROR_NONE; -} - -tdm_error -tdm_vblank_set_offset(tdm_vblank *vblank, int offset) -{ - (void)vblank; - (void)offset; - - return TDM_ERROR_NONE; -} - -tdm_error -tdm_vblank_set_enable_fake(tdm_vblank *vblank, unsigned int enable_fake) -{ - (void)vblank; - (void)enable_fake; - - return TDM_ERROR_NONE; -} - -unsigned int -tdm_vblank_get_enable_fake(tdm_vblank *vblank) -{ - (void)vblank; - - return 0; -} - -tdm_error -tdm_vblank_wait(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_usec, - unsigned int interval, tdm_vblank_handler func, void *user_data) -{ - (void)vblank; - (void)req_sec; - (void)req_usec; - (void)interval; - (void)func; - (void)user_data; - - return TDM_ERROR_NONE; -} - -tdm_error -tdm_vblank_wait_seq(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_usec, - unsigned int sequence, tdm_vblank_handler func, void *user_data) -{ - (void)vblank; - (void)req_sec; - (void)req_usec; - (void)sequence; - (void)func; - (void)user_data; - - return TDM_ERROR_NONE; -} - -tdm_error -tdm_vblank_cb_vblank_SW(tdm_vblank *vblank, double vblank_stamp) -{ - (void)vblank; - (void)vblank_stamp; - - return TDM_ERROR_NONE; -}