--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ *
+ * 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);
+}