From 44724ab5201823cfc9d241f6b76ba7808d075dbc Mon Sep 17 00:00:00 2001 From: Andrii Sokolenko Date: Mon, 6 Nov 2017 18:44:55 +0200 Subject: [PATCH 01/16] [utest] Rework unit-test based on blackbox method. Removed stubs, wrappers. Added 35 tests Change-Id: Id5b1e9f90a47ec55f985416057acc1e338971714 Signed-off-by: Andrii Sokolenko --- utests/Makefile.am | 30 +- utests/src/ut_common.h | 10 + utests/src/{main_tests.cpp => ut_main.cpp} | 3 + utests/src/ut_tdm.cpp | 434 +- utests/src/ut_tdm_backend.cpp | 263 -- utests/src/ut_tdm_buffer.cpp | 555 --- utests/src/ut_tdm_capture.cpp | 927 +--- utests/src/ut_tdm_display.cpp | 4710 -------------------- utests/src/ut_tdm_event_loop.cpp | 630 --- utests/src/ut_tdm_helper.cpp | 766 ---- utests/src/ut_tdm_layer.cpp | 81 + utests/src/ut_tdm_output.cpp | 71 + utests/src/ut_tdm_pp.cpp | 784 +--- utests/src/ut_tdm_thread.cpp | 824 ---- utests/src/ut_tdm_vblank.cpp | 890 ---- utests/stubs/stub_backend.cpp | 377 -- utests/stubs/stub_backend.h | 97 - utests/stubs/stub_dlfcn.cpp | 26 - utests/stubs/stub_dlfcn.h | 25 - utests/stubs/stub_fcntl.h | 26 - utests/stubs/stub_pthread.cpp | 61 - utests/stubs/stub_pthread.h | 32 - utests/stubs/stub_stdio.h | 105 - utests/stubs/stub_stdlib.cpp | 83 - utests/stubs/stub_stdlib.h | 36 - utests/stubs/stub_tdm.h | 104 - utests/stubs/stub_tdm_buffer.h | 37 - utests/stubs/stub_tdm_capture.h | 76 - utests/stubs/stub_tdm_display.h | 150 - utests/stubs/stub_tdm_event_loop.h | 72 - utests/stubs/stub_tdm_helper.h | 41 - utests/stubs/stub_tdm_pp.h | 62 - utests/stubs/stub_tdm_server.h | 40 - utests/stubs/stub_tdm_thread.h | 102 - utests/stubs/stub_tdm_vblank.h | 86 - utests/stubs/stub_unistd.cpp | 126 - utests/stubs/stub_unistd.h | 46 - utests/stubs/tbm_bufmgr.h | 1025 ----- utests/stubs/tbm_stubs.cpp | 270 -- utests/stubs/tbm_stubs.h | 45 - utests/stubs/tbm_surface.h | 742 --- utests/stubs/tbm_surface_internal.h | 367 -- utests/stubs/tbm_surface_queue.h | 125 - utests/stubs/tbm_type.h | 26 - utests/stubs/tdm_backend_module_subs.cpp | 387 -- utests/stubs/tdm_event_loop_stubs.h | 95 - utests/stubs/tdm_log.cpp | 32 - utests/stubs/tdm_server.cpp | 16 - utests/stubs/wayland-server-core.h | 168 - .../stubs/wayland-tbm-drm-auth-client-protocol.h | 62 - 50 files changed, 456 insertions(+), 15692 deletions(-) create mode 100644 utests/src/ut_common.h rename utests/src/{main_tests.cpp => ut_main.cpp} (90%) delete mode 100644 utests/src/ut_tdm_backend.cpp delete mode 100644 utests/src/ut_tdm_buffer.cpp delete mode 100644 utests/src/ut_tdm_display.cpp delete mode 100644 utests/src/ut_tdm_event_loop.cpp delete mode 100644 utests/src/ut_tdm_helper.cpp create mode 100644 utests/src/ut_tdm_layer.cpp create mode 100644 utests/src/ut_tdm_output.cpp delete mode 100644 utests/src/ut_tdm_thread.cpp delete mode 100644 utests/src/ut_tdm_vblank.cpp delete mode 100644 utests/stubs/stub_backend.cpp delete mode 100644 utests/stubs/stub_backend.h delete mode 100644 utests/stubs/stub_dlfcn.cpp delete mode 100644 utests/stubs/stub_dlfcn.h delete mode 100644 utests/stubs/stub_fcntl.h delete mode 100644 utests/stubs/stub_pthread.cpp delete mode 100644 utests/stubs/stub_pthread.h delete mode 100644 utests/stubs/stub_stdio.h delete mode 100644 utests/stubs/stub_stdlib.cpp delete mode 100644 utests/stubs/stub_stdlib.h delete mode 100644 utests/stubs/stub_tdm.h delete mode 100644 utests/stubs/stub_tdm_buffer.h delete mode 100644 utests/stubs/stub_tdm_capture.h delete mode 100644 utests/stubs/stub_tdm_display.h delete mode 100644 utests/stubs/stub_tdm_event_loop.h delete mode 100644 utests/stubs/stub_tdm_helper.h delete mode 100644 utests/stubs/stub_tdm_pp.h delete mode 100644 utests/stubs/stub_tdm_server.h delete mode 100644 utests/stubs/stub_tdm_thread.h delete mode 100644 utests/stubs/stub_tdm_vblank.h delete mode 100644 utests/stubs/stub_unistd.cpp delete mode 100644 utests/stubs/stub_unistd.h delete mode 100644 utests/stubs/tbm_bufmgr.h delete mode 100644 utests/stubs/tbm_stubs.cpp delete mode 100644 utests/stubs/tbm_stubs.h delete mode 100644 utests/stubs/tbm_surface.h delete mode 100644 utests/stubs/tbm_surface_internal.h delete mode 100644 utests/stubs/tbm_surface_queue.h delete mode 100644 utests/stubs/tbm_type.h delete mode 100644 utests/stubs/tdm_backend_module_subs.cpp delete mode 100644 utests/stubs/tdm_event_loop_stubs.h delete mode 100644 utests/stubs/tdm_log.cpp delete mode 100644 utests/stubs/tdm_server.cpp delete mode 100644 utests/stubs/wayland-server-core.h delete mode 100644 utests/stubs/wayland-tbm-drm-auth-client-protocol.h diff --git a/utests/Makefile.am b/utests/Makefile.am index 2588801..3357e0c 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -1,26 +1,12 @@ bin_PROGRAMS = tdm-utests tdm_utests_SOURCES = \ - src/main_tests.cpp \ + src/ut_main.cpp \ src/ut_tdm.cpp \ - src/ut_tdm_backend.cpp \ - src/ut_tdm_buffer.cpp \ - src/ut_tdm_capture.cpp \ - src/ut_tdm_display.cpp \ - src/ut_tdm_event_loop.cpp \ - 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/stub_pthread.cpp \ - stubs/stub_dlfcn.cpp \ - stubs/stub_stdlib.cpp \ - stubs/tdm_backend_module_subs.cpp \ - stubs/stub_unistd.cpp \ - stubs/stub_backend.cpp + src/ut_tdm_capture.cpp \ + src/ut_tdm_output.cpp \ + src/ut_tdm_layer.cpp tdm_utests_CXXFLAGS = \ $(CXXFLAGS) \ @@ -28,9 +14,10 @@ tdm_utests_CXXFLAGS = \ -I../src \ -I../include \ -I./src \ - -I./stubs \ -I$(includedir)/gtest \ -fpermissive \ + -rdynamic \ + -UFAIL_ON_UNSUPPORTED \ -w # The flag -w is used, because there are many warnings in libtdm's sources. # Warnings occur because we build project with g++. @@ -39,9 +26,8 @@ tdm_utests_CXXFLAGS = \ tdm_utests_LDFLAGS = \ ${LDFLAGS} \ $(TDM_LIBS) \ - -lgtest \ - -ldl \ - -pthread + $(top_builddir)/src/libtdm.la \ + -lgtest check: ./tdm-utests diff --git a/utests/src/ut_common.h b/utests/src/ut_common.h new file mode 100644 index 0000000..c30269d --- /dev/null +++ b/utests/src/ut_common.h @@ -0,0 +1,10 @@ +#ifndef UT_COMMON_H +#define UT_COMMON_H +#define CHECK_FLAG(FLAG) \ +do {\ + if(!FLAG) {\ + std::cout << "[ SKIPPED ]" << " not supported" << std::endl;\ + return;\ + }\ +} while(0) +#endif // UT_COMMON_H diff --git a/utests/src/main_tests.cpp b/utests/src/ut_main.cpp similarity index 90% rename from utests/src/main_tests.cpp rename to utests/src/ut_main.cpp index 50d2725..b6aeb4a 100644 --- a/utests/src/main_tests.cpp +++ b/utests/src/ut_main.cpp @@ -3,6 +3,8 @@ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. * * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -31,5 +33,6 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; return RUN_ALL_TESTS(); } diff --git a/utests/src/ut_tdm.cpp b/utests/src/ut_tdm.cpp index 9110ca6..6a6ead6 100644 --- a/utests/src/ut_tdm.cpp +++ b/utests/src/ut_tdm.cpp @@ -3,6 +3,8 @@ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. * * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -26,294 +28,266 @@ * **************************************************************************/ -#include "../stubs/stub_dlfcn.h" #include "gtest/gtest.h" - -/*------ stubs -----------------*/ -#include "tdm_event_loop_stubs.h" -#include "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_tdm_vblank.h" -#include "stub_stdlib.h" -#include "stub_stdio.h" -#include "stub_unistd.h" -#include "tdm_event_loop_stubs.h" -#include "tdm.c" -/*------ tested file -----------*/ - -static void _init_test() +#include "tdm.h" + +class TDMInit : public ::testing::Test { +protected: + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + } + void TearDown(void) + { + } +}; + +class TDMDefault : public ::testing::Test { +protected: + tdm_display *dpy = NULL; + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + } + void TearDown(void) + { + tdm_display_deinit(dpy); + dpy = NULL; + } +}; + + +TEST_F(TDMInit, DisplayInitDeinitSuccessful) { - stub_pthread_init(); - stub_tbm_init(); - stub_stdlib_init(); - - stub_dlfcn_init(); - stub_stdio_init(); - stub_tdm_vblank_init(); - g_private_display = NULL; + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display_deinit(dpy); + dpy = NULL; } -extern tdm_backend_module tdm_backend_module_stub; - - -/* tdm_display_update */ - -TEST(tdm_display_update, work_flow_success_1) +TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullError) { tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_update(NULL); - - ASSERT_EQ(error, expected_error); + tdm_display *dpy = tdm_display_init(NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display_deinit(dpy); + dpy = NULL; } -/* tdm_display_init() */ -TEST(tdm_display_init, work_flow_success_1___first_call) +TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimes) { - tdm_error error = TDM_ERROR_BAD_REQUEST; - tdm_display *disp; - - _init_test(); - - //to download tdm_backend_module; - stub_dlfcn_ctrl.dlopen_returned_val = (void*)1; - stub_dlfcn_ctrl.dlsym_returned_val = &tdm_backend_module_stub; - - setenv("TDM_DEBUG_MODULE", "all", 1); - setenv("TDM_DEBUG_DUMP", "capture,pp,layer,all", 1); - setenv("TDM_DEBUG_PATH", "log.txt", 1); - stub_getenv_return_real_value = 1; - - disp = tdm_display_init(&error); - - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_TRUE(g_private_display != NULL); - ASSERT_TRUE(g_private_display == disp); - ASSERT_EQ(1, g_private_display->init_count); + for (int i = 0; i < 20; ++i) { + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display_deinit(dpy); + dpy = NULL; + } } -TEST(tdm_display_init, work_flow_success_2___second_call) +TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy) { - tdm_error error = TDM_ERROR_BAD_REQUEST; - tdm_display *disp; - tdm_private_display display; - - _init_test(); - memset(&display, 0, sizeof(display)); - g_private_display = &display; - g_private_display->init_count = 1; - - disp = tdm_display_init(&error); - - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_TRUE(g_private_display != NULL); - ASSERT_TRUE(g_private_display == disp); - ASSERT_EQ(2, g_private_display->init_count); + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display_deinit(NULL); + tdm_display_deinit(dpy); + dpy = NULL; } - -TEST(tdm_display_init, work_flow_error_1___calloc_error) +TEST_F(TDMInit, DisplayDeinitDeathWrongDpy) { - tdm_error error = TDM_ERROR_BAD_REQUEST; - tdm_display *disp; - - _init_test(); - CALLOC_ERROR = 1; - - disp = tdm_display_init(&error); - - ASSERT_EQ(TDM_ERROR_OUT_OF_MEMORY, error); - ASSERT_TRUE(disp == NULL); - ASSERT_TRUE(g_private_display == NULL); + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display *wrong_dpy = 0xBEAF; + EXPECT_DEATH(tdm_display_deinit(wrong_dpy), ""); + tdm_display_deinit(dpy); + dpy = NULL; } -TEST(tdm_display_init, work_flow_error_2___mutex_init_error) +TEST_F(TDMDefault, DisplayUpdateSuccessful) { - tdm_error error = TDM_ERROR_BAD_REQUEST; - tdm_display *disp; - - _init_test(); - PTHREAD_MUTEX_INIT_ERROR = 1; - - disp = tdm_display_init(&error); - - ASSERT_NE(TDM_ERROR_NONE, error); - ASSERT_TRUE(disp == NULL); - ASSERT_TRUE(g_private_display == NULL); + ASSERT_TRUE(tdm_display_update(dpy) == TDM_ERROR_NONE); } -/* tdm_display_deinit */ - -TEST(tdm_display_deinit, work_flow_success_1___init_count_more_then_one) +TEST_F(TDMDefault, DisplayUpdateFailNullDpy) { - tdm_private_display *dpy; - unsigned int expected = 2; - unsigned int actual; - - _init_test(); - - dpy = (tdm_private_display *)calloc(1, sizeof(tdm_private_display)); - g_private_display = dpy; - dpy->init_count = 3; - - tdm_display_deinit(dpy); - - actual = dpy->init_count; - - free(dpy); - - ASSERT_NE(g_private_display, NULL); - ASSERT_EQ(actual, expected); + ASSERT_FALSE(tdm_display_update(NULL) == TDM_ERROR_NONE); } -//TEST(tdm_display_deinit, work_flow_success_2___init_count_is_one) -//{ -// unsigned int expected = 2; -// unsigned int actual; -// -// tdm_error error = TDM_ERROR_BAD_REQUEST; -// tdm_display *disp; -// -// _init_test(); -// -// //to download tdm_backend_module; -// stub_dlfcn_ctrl.dlopen_returned_val = (void*)1; -// stub_dlfcn_ctrl.dlsym_returned_val = &tdm_backend_module_stub; -// -// disp = tdm_display_init(&error); -// -// ASSERT_EQ(TDM_ERROR_NONE, error); -// -// //call tested function -// tdm_display_deinit(disp); -// -// ASSERT_EQ(NULL, g_private_display); -// ASSERT_TRUE(FREE_CALLED); -//} - - -/* tdm_display_check_module_abi */ -TEST(tdm_display_check_module_abi, work_flow_success_1) +TEST_F(TDMDefault, DisplayGetFDSuccesful) { - int res; - tdm_private_display private_display; - tdm_backend_module module; - private_display.module_data = &module; - module.abi_version = 0x00010001; - - res = tdm_display_check_module_abi(&private_display, 1, 1); - - ASSERT_EQ(1, res); + int fd = -42; + ASSERT_TRUE(tdm_display_get_fd(dpy, &fd) == TDM_ERROR_NONE); + ASSERT_FALSE(fd == -42); } -TEST(tdm_display_check_module_abi, work_flow_error_1___wrong_version) +TEST_F(TDMDefault, DisplayGetFDFailNullAll) { - int res; - tdm_private_display private_display; - tdm_backend_module module; - private_display.module_data = &module; - module.abi_version = 0x00010001; - - /*minor*/ - res = tdm_display_check_module_abi(&private_display, 1, 2); - ASSERT_EQ(0, res); + ASSERT_FALSE(tdm_display_get_fd(NULL, NULL) == TDM_ERROR_NONE); +} - /*major*/ - res = tdm_display_check_module_abi(&private_display, 2, 1); - ASSERT_EQ(0, res); +TEST_F(TDMDefault, DisplayGetFDFailNullFD) +{ + ASSERT_FALSE(tdm_display_get_fd(dpy, NULL) == TDM_ERROR_NONE); } -/* tdm_display_check_module_abi */ -TEST(tdm_display_enable_debug_module, work_flow_success_1) +TEST_F(TDMDefault, DisplayGetFDFailNullDpy) { - tdm_error error; + int fd = -42; + ASSERT_FALSE(tdm_display_get_fd(NULL, &fd) == TDM_ERROR_NONE); +} - //check all - error = tdm_display_enable_debug_module("all"); - ASSERT_EQ(0xFFFFFFFF, tdm_debug_module); - ASSERT_EQ(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DISABLED_DisplayHandleEventsSuccessful) +{ + /* TODO Generate events*/ + ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE); +} - //check none - error = tdm_display_enable_debug_module("none"); - ASSERT_EQ(0, tdm_debug_module); - ASSERT_EQ(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessful) +{ + const char *name = NULL; + const char *vendor = NULL; + int major = -42, minor = -42; + ASSERT_TRUE(tdm_display_get_backend_info(dpy, &name, &vendor, &major, &minor) == TDM_ERROR_NONE); + ASSERT_FALSE(name == NULL); + ASSERT_FALSE(vendor == NULL); + ASSERT_FALSE(major == -42); + ASSERT_FALSE(minor == -42); +} - //check buffer,thread,mutex,vblank - error = tdm_display_enable_debug_module("buffer,thread,mutex,vblank"); - ASSERT_EQ((TDM_DEBUG_BUFFER | TDM_DEBUG_THREAD | TDM_DEBUG_MUTEX | TDM_DEBUG_VBLANK) , - tdm_debug_module); - ASSERT_EQ(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetBackendInfoFailNullAll) +{ + ASSERT_FALSE(tdm_display_get_backend_info(NULL, NULL, NULL, NULL, NULL) == TDM_ERROR_NONE); +} +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyDpy) +{ + ASSERT_TRUE(tdm_display_get_backend_info(dpy, NULL, NULL, NULL, NULL) == TDM_ERROR_NONE); } -TEST(tdm_display_enable_debug_module, work_flow_error_1___bad_module) +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyName) { - tdm_error error; + const char *name = NULL; + ASSERT_TRUE(tdm_display_get_backend_info(dpy, &name, NULL, NULL, NULL) == TDM_ERROR_NONE); + ASSERT_FALSE(name == NULL); +} - //check bufer - error = tdm_display_enable_debug_module("bufer"); - ASSERT_EQ(0 , tdm_debug_module); - ASSERT_NE(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyVendor) +{ + const char *vendor = NULL; + ASSERT_TRUE(tdm_display_get_backend_info(dpy, NULL, &vendor, NULL, NULL) == TDM_ERROR_NONE); + ASSERT_FALSE(vendor == NULL); } -/* tdm_display_enable_ttrace_vblank */ -TEST(tdm_display_enable_ttrace_vblank, work_flow_success_1) +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyMajor) { - tdm_error error; - tdm_private_display private_display; - tdm_private_output output; - tdm_output_mode current_mode; - int vblank = 1; + int major = -42; + ASSERT_TRUE(tdm_display_get_backend_info(dpy, NULL, NULL, &major, NULL) == TDM_ERROR_NONE); + ASSERT_FALSE(major == -42); +} - _init_test(); - stub_tdm_vblank_create_returned = &vblank; +TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyMinor) +{ + int minor = -42; + ASSERT_TRUE(tdm_display_get_backend_info(dpy, NULL, NULL, NULL, &minor) == TDM_ERROR_NONE); + ASSERT_FALSE(minor == -1); +} - output.current_mode = ¤t_mode; - output.private_display = &private_display; +TEST_F(TDMDefault, DisplayGetCapabilitiesSuccessful) +{ + tdm_display_capability capabilities = -42; + ASSERT_TRUE(tdm_display_get_capabilities(dpy, &capabilities) == TDM_ERROR_NONE); + ASSERT_FALSE(capabilities == -1); +} - error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1); - ASSERT_EQ(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetCapabilitiesFailNullAll) +{ + ASSERT_FALSE(tdm_display_get_capabilities(NULL, NULL) == TDM_ERROR_NONE); +} - error = tdm_display_enable_ttrace_vblank(&private_display, &output, 0); +TEST_F(TDMDefault, DisplayGetCapabilitiesFailSetOnlyDpy) +{ + ASSERT_FALSE(tdm_display_get_capabilities(dpy, NULL) == TDM_ERROR_NONE); } -TEST(tdm_display_enable_ttrace_vblank, work_flow_error_1___vblank_wait_fail) +TEST_F(TDMDefault, DisplayGetPPCapabilitiesSuccessful) { - tdm_error error; - tdm_private_display private_display; - tdm_private_output output; - tdm_output_mode current_mode; - int vblank = 1; + tdm_pp_capability capabilities = -42; + tdm_error error = TDM_ERROR_NONE; + error = tdm_display_get_pp_capabilities(dpy, &capabilities); + ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY); + if (error == TDM_ERROR_NONE) { + ASSERT_FALSE(capabilities == -42); + } +} - _init_test(); +TEST_F(TDMDefault, DisplayGetPPCapabilitiesFailNullAll) +{ + ASSERT_FALSE(tdm_display_get_pp_capabilities(NULL, NULL) == TDM_ERROR_NONE); +} - output.current_mode = ¤t_mode; - output.private_display = &private_display; - stub_tdm_vblank_create_returned = &vblank; +TEST_F(TDMDefault, DisplayGetCaptureCapabilitiesSuccessful) +{ + tdm_capture_capability capabilities = -42; + tdm_error error = TDM_ERROR_NONE; + error = tdm_display_get_capture_capabilities(dpy, &capabilities); + ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY); + if (error == TDM_ERROR_NONE) { + ASSERT_FALSE(capabilities == -42); + } +} - stub_tdm_vblank_wait_error = 1; +TEST_F(TDMDefault, DisplayGetCaptureCapabilitiesFailNullAll) +{ + ASSERT_FALSE(tdm_display_get_capture_capabilities(NULL, NULL) == TDM_ERROR_NONE); +} - error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1); - ASSERT_NE(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetMaxLayerCountSuccessful) +{ + int max_count = -42; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_max_layer_count(dpy, &max_count)); + ASSERT_FALSE(-42 == max_count); } -TEST(tdm_display_enable_ttrace_vblank, work_flow_error_2___vblank_create_fail) +TEST_F(TDMDefault, DisplayGetMaxLayerCountFailNullAll) { - tdm_error error; - tdm_private_display private_display; - tdm_private_output output; - tdm_output_mode current_mode; + ASSERT_FALSE(TDM_ERROR_NONE == tdm_display_get_max_layer_count(NULL, NULL)); +} - _init_test(); - stub_tdm_vblank_create_returned = NULL; +TEST_F(TDMDefault, DisplayGetMaxLayerCountFailSetOnlyDpy) +{ + ASSERT_FALSE(TDM_ERROR_NONE == tdm_display_get_max_layer_count(dpy, NULL)); +} - output.current_mode = ¤t_mode; - output.private_display = &private_display; +TEST_F(TDMDefault, DisplayGetOutputCountSuccessful) +{ + int count = -42; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_output_count(dpy, &count)); + ASSERT_FALSE(-42 == count); +} - error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1); - ASSERT_EQ(TDM_ERROR_NONE, error); +TEST_F(TDMDefault, DisplayGetOutputCountFailNullALl) +{ + ASSERT_FALSE(TDM_ERROR_NONE == tdm_display_get_output_count(NULL, NULL)); } +TEST_F(TDMDefault, DisplayGetOutputCountFailSetOnlyDpy) +{ + ASSERT_FALSE(TDM_ERROR_NONE == tdm_display_get_output_count(dpy, NULL)); +} diff --git a/utests/src/ut_tdm_backend.cpp b/utests/src/ut_tdm_backend.cpp deleted file mode 100644 index 6366f69..0000000 --- a/utests/src/ut_tdm_backend.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/************************************************************************** - * - * 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 "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" - -#include "tdm_backend.c" - -static void _init_test() -{ - stub_pthread_init(); - stub_tbm_init(); - stub_stdlib_init(); -} - -/* tdm_backend_register_func_capture */ - -TEST(tdm_backend_register_func_capture, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_display dpy; - tdm_func_capture func_capture; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - error = tdm_backend_register_func_capture(&dpy, &func_capture); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_capture, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_BAD_MODULE; - tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - error = tdm_backend_register_func_capture(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_capture, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_func_capture func_capture; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_capture(NULL, &func_capture); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_backend_register_func_pp */ - -TEST(tdm_backend_register_func_pp, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_display dpy; - tdm_func_pp func_pp; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - error = tdm_backend_register_func_pp(&dpy, &func_pp); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_pp, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_BAD_MODULE; - tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - error = tdm_backend_register_func_pp(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_pp, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_func_pp func_pp; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_pp(NULL, &func_pp); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_backend_register_func_layer */ - -TEST(tdm_backend_register_func_layer, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_display dpy; - tdm_func_layer func_layer; - tdm_backend_module module; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.module_data = &module; - module.abi_version = 0x00010005; - - error = tdm_backend_register_func_layer(&dpy, &func_layer); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_layer, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_layer(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_layer, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_func_layer func_layer; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_layer(NULL, &func_layer); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_backend_register_func_output */ - -TEST(tdm_backend_register_func_output, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_display dpy; - tdm_func_output func_output; - tdm_backend_module module; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.module_data = &module; - - error = tdm_backend_register_func_output(&dpy, &func_output); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_output, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_output(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_output, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_func_output func_output; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_output(NULL, &func_output); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_backend_register_func_display */ - -TEST(tdm_backend_register_func_display, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_display dpy; - tdm_func_display func_display; - tdm_backend_module module; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.module_data = &module; - module.abi_version = 0x00020000; - - error = tdm_backend_register_func_display(&dpy, &func_display); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_display, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_display(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_backend_register_func_display, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_func_display func_display; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_backend_register_func_display(NULL, &func_display); - - ASSERT_EQ(error, expected_error); -} diff --git a/utests/src/ut_tdm_buffer.cpp b/utests/src/ut_tdm_buffer.cpp deleted file mode 100644 index 4ebac10..0000000 --- a/utests/src/ut_tdm_buffer.cpp +++ /dev/null @@ -1,555 +0,0 @@ -/************************************************************************** - * - * 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 "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_tdm.h" - -#include "tdm_buffer.c" - -void tdm_buffer_release_handler_f(tbm_surface_h buffer, void *user_data) -{ - (void)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 */ - -TEST(tdm_buffer_list_get_first_entry, null_ptr_fail_1) -{ - tbm_surface_h expected = NULL; - tbm_surface_h actual; - - _init_test(); - - actual = tdm_buffer_list_get_first_entry(NULL); - - 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) -{ - struct _tbm_surface buffer; - tbm_surface_h not_expected = NULL; - tbm_surface_h actual; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - CALLOC_RETURN_BUFFER = 1; - actual = tdm_buffer_ref_backend(&buffer); - - ASSERT_TRUE(actual != not_expected); -} - -TEST(tdm_buffer_ref_backend, work_flow_success_1) -{ - struct _tbm_surface buffer; - tbm_surface_h actual; - tbm_surface_h expected = NULL; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - CALLOC_ERROR = 1; - - actual = tdm_buffer_ref_backend(&buffer); - - ASSERT_TRUE(actual == expected); -} - - -TEST(tdm_buffer_ref_backend, null_ptr_fail_1) -{ - tbm_surface_h expected = NULL; - tbm_surface_h actual; - - _init_test(); - - actual = tdm_buffer_ref_backend(NULL); - - ASSERT_TRUE(actual == expected); -} - -/* tdm_buffer_add_release_handler */ - -TEST(tdm_buffer_add_release_handler, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_BUSY; - struct _tbm_surface buffer; - int data = 1; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - error = - tdm_buffer_add_release_handler(&buffer, tdm_buffer_release_handler_f, - &data); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_buffer_add_release_handler, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - int data = 1; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - - _init_test(); - - CALLOC_ERROR = 1; - error = - tdm_buffer_add_release_handler(&buffer, tdm_buffer_release_handler_f, - &data); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_buffer_add_release_handler, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - int data = 1; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - CALLOC_ERROR = 1; - error = - tdm_buffer_add_release_handler(&buffer, tdm_buffer_release_handler_f, - &data); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_buffer_add_release_handler, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - int data = 1; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - CALLOC_ERROR = 1; - error = - tdm_buffer_add_release_handler(&buffer, tdm_buffer_release_handler_f, - &data); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_buffer_add_release_handler, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - int data = 1; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_buffer_add_release_handler(&buffer, NULL, &data); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_buffer_add_release_handler, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - int data = 1; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = - tdm_buffer_add_release_handler(NULL, tdm_buffer_release_handler_f, - &data); - - ASSERT_EQ(error, expected_error); - -} - -/* 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; - tdm_buffer_info *actual; - tdm_buffer_info *not_expected = NULL; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - - actual = tdm_buffer_get_info(&buffer); - - ASSERT_TRUE(actual != not_expected); - free(actual); -} - -TEST(tdm_buffer_get_info, work_flow_success_2) -{ - struct _tbm_surface buffer; - tdm_buffer_info *actual; - tdm_buffer_info *expected = NULL; - - _init_test(); - - TBM_BO_GET_USER_DATA_NULL = 1; - CALLOC_ERROR = 1; - actual = tdm_buffer_get_info(&buffer); - - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_buffer_get_info, work_flow_success_1) -{ - struct _tbm_surface buffer; - tdm_buffer_info *not_expected = NULL; - tdm_buffer_info *actual; - - _init_test(); - - actual = tdm_buffer_get_info(&buffer); - - 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/utests/src/ut_tdm_capture.cpp b/utests/src/ut_tdm_capture.cpp index 2bab7bf..9715d1a 100644 --- a/utests/src/ut_tdm_capture.cpp +++ b/utests/src/ut_tdm_capture.cpp @@ -3,6 +3,8 @@ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. * * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -27,890 +29,43 @@ **************************************************************************/ #include "gtest/gtest.h" - -#include "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_backend.h" -#include "stub_unistd.h" -#include "stub_tdm_thread.h" -#include "stub_tdm_buffer.h" -#include "stub_tdm_helper.h" - -#include "tdm_capture.c" - -//local stubs for callbeck functions -static int stub_tdm_capture_done_handler_called; -static void stub_tdm_capture_done_handler(tdm_capture *capture, - tbm_surface_h buffer, void *user_data) -{ - stub_tdm_capture_done_handler_called = 1; -} - -/* UNIT TESTS */ - -static void _init_test() -{ - stub_tdm_helper_init(); - stub_tdm_buffer_init(); - stub_tdm_thread_init(); - stub_unistd_init(); - stub_pthread_init(); - stub_backend_init(); - stub_tbm_init(); - stub_stdlib_init(); - tdm_debug_dump = TDM_DUMP_FLAG_CAPTURE; - tdm_debug_module = TDM_DEBUG_BUFFER; - stub_tdm_capture_done_handler_called = 0; -} - -/* tdm_capture_commit */ - -TEST(tdm_capture_commit, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - tdm_private_output private_output; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_pp_private_buffer b_1, b_2; - - _init_test(); - - LIST_INITHEAD(&capture.pending_buffer_list); - LIST_INITHEAD(&capture.buffer_list); - - LIST_ADD(&b_1.link, &capture.pending_buffer_list); - LIST_ADD(&b_2.link, &capture.pending_buffer_list); - - capture.private_display = &private_display; - private_display.func_capture.capture_commit = capture_commit; - CALLOC_RETURN_BUFFER = 1; - capture.private_output = &private_output; - private_output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_capture_commit(&capture); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(LIST_LENGTH(&capture.buffer_list), 2); -} - -//TEST(tdm_capture_commit, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_NONE; -// struct _tdm_private_capture capture; -// struct _tdm_private_display private_display; -// tdm_private_output private_output; -// tdm_pp_private_buffer b_1, b_2; -// -// _init_test(); -// -// LIST_INITHEAD(&capture.pending_buffer_list); -// LIST_INITHEAD(&capture.buffer_list); -// -// LIST_ADD(&b_1.link, &capture.pending_buffer_list); -// LIST_ADD(&b_2.link, &capture.pending_buffer_list); -// -// capture.private_display = &private_display; -// private_display.func_capture.capture_commit = capture_commit; -// CAPTURE_COMMIT_ERROR = 1; -// capture.private_output = &private_output; -// private_output.current_dpms_value = TDM_OUTPUT_DPMS_ON; -// -// error = tdm_capture_commit(&capture); -// -// ASSERT_NE(error, TDM_ERROR_NONE); -// ASSERT_EQ(LIST_LENGTH(&capture.buffer_list), 0); -// ASSERT_EQ(stub_tdm_buffer_remove_release_handler_internal_count, 2); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -//} - -TEST(tdm_capture_commit, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - tdm_private_output private_output; - - _init_test(); - - LIST_INITHEAD(&capture.pending_buffer_list); - - capture.private_display = &private_display; - private_display.func_capture.capture_commit = NULL; - capture.private_output = &private_output; - private_output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_capture_commit(&capture); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_capture_commit, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_BAD_REQUEST; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - tdm_private_output private_output; - - _init_test(); - - LIST_INITHEAD(&capture.pending_buffer_list); - - capture.private_display = &private_display; - private_display.func_capture.capture_commit = NULL; - capture.private_output = &private_output; - private_output.current_dpms_value = TDM_OUTPUT_DPMS_OFF; - - error = tdm_capture_commit(&capture); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_capture_commit, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_capture_commit(NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_capture_set_info */ - -TEST(tdm_capture_set_info, error_capture_set_info_is_null) -{ - tdm_info_capture info; - tdm_error error; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - - _init_test(); - - capture.private_display = &private_display; - private_display.func_capture.capture_set_info = NULL; - - error = tdm_capture_set_info(&capture, &info); - - ASSERT_EQ(error, TDM_ERROR_NOT_IMPLEMENTED); -} - -TEST(tdm_capture_set_info, work_flow_success_2) -{ - tdm_info_capture info; - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output private_output; - tdm_output_mode current_mode; - - _init_test(); - - capture.private_output = &private_output; - private_output.current_mode = ¤t_mode; - current_mode.vrefresh = 24; - info.type = TDM_CAPTURE_TYPE_STREAM; - info.frequency = 0; - - capture.private_display = &private_display; - private_display.func_capture.capture_set_info = capture_set_info; - - error = tdm_capture_set_info(&capture, &info); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(info.frequency, current_mode.vrefresh); -} - -TEST(tdm_capture_set_info, work_flow_success_1) -{ - tdm_info_capture info; - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tdm_private_display private_display; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - - _init_test(); - - capture.private_display = &private_display; - private_display.func_capture.capture_set_info = capture_set_info; - CAPTURE_SET_INFO_ERROR = 1; - - error = tdm_capture_set_info(&capture, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_capture_set_info, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_capture_set_info(&capture, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_capture_set_info, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_info_capture info; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_capture_set_info(NULL, &info); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_capture_create_layer_internal */ - -TEST(tdm_capture_create_layer_internal, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_layer private_layer; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *not_expected = NULL; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - LIST_INITHEAD(&private_layer.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_create_capture = layer_create_capture; - private_display.func_capture.capture_destroy = capture_destroy; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER; - - actual = tdm_capture_create_layer_internal(&private_layer, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual != not_expected); - free(actual); -} - -TEST(tdm_capture_create_layer_internal, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_layer private_layer; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - - _init_test(); - - LIST_INITHEAD(&private_layer.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_create_capture = layer_create_capture; - private_display.func_capture.capture_destroy = capture_destroy; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER; - - CALLOC_ERROR = 1; - - actual = tdm_capture_create_layer_internal(&private_layer, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_layer_internal, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_layer private_layer; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - - _init_test(); - - LIST_INITHEAD(&private_layer.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_create_capture = layer_create_capture; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - LAYER_CREATE_CAPTURE_ERROR = 1; - - actual = tdm_capture_create_layer_internal(&private_layer, &error); - - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_layer_internal, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_layer private_layer; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - LIST_INITHEAD(&private_layer.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - - actual = tdm_capture_create_layer_internal(&private_layer, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -/* tc_tdm_capture_create_output_internal */ - -TEST(tdm_capture_create_output_internal, work_flow_success_5) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *not_expected = NULL; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_capture private_capture; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.func_output.output_create_capture = output_create_capture; - private_display.func_capture.capture_destroy = capture_destroy; - private_display.func_capture.capture_set_done_handler = - capture_set_done_handler; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT; - - private_capture.stamp = stub_tdm_helper_get_time_ret_val; - - LIST_ADD(&private_capture.display_link, &private_display.capture_list); - - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual != not_expected); - free(actual); -} - -TEST(tdm_capture_create_output_internal, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.func_output.output_create_capture = output_create_capture; - private_display.func_capture.capture_destroy = capture_destroy; - private_display.func_capture.capture_set_done_handler = capture_set_done_handler; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT; - CAPTURE_SET_DONE_HANDLER_ERROR = 1; - - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_output_internal, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.func_output.output_create_capture = output_create_capture; - private_display.func_capture.capture_destroy = capture_destroy; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - CALLOC_ERROR = 1; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT; - - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_output_internal, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.func_output.output_create_capture = output_create_capture; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT; - OUTPUT_CREATE_CAPTURE_ERROR = 1; - - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_output_internal, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -TEST(tdm_capture_create_output_internal, TDM_CAPTURE_CAPABILITY_OUTPUT_is_not_set) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_output private_output; - struct _tdm_private_display private_display; - tdm_private_capture *actual; - tdm_private_capture *expected = NULL; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - LIST_INITHEAD(&private_output.capture_list); - LIST_INITHEAD(&private_display.capture_list); - - private_output.private_display = &private_display; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER; - - actual = tdm_capture_create_output_internal(&private_output, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(actual == expected); -} - -/* tdm_capture_cb_done() */ - -TEST(tdm_capture_cb_done, success_not_in_display_thread) -{ - tdm_private_capture private_capture; - struct _tbm_surface buffer; - tdm_thread_cb_capture_done *capture_done; - tdm_private_display private_display; - - _init_test(); - - private_capture.private_display = &private_display; - stub_syscall_return_value = 50; - private_capture.owner_tid = stub_syscall_return_value + 1; - private_capture.stamp = 10.15; - - tdm_capture_cb_done(&private_capture, &buffer, &private_capture); - - capture_done = (tdm_thread_cb_capture_done *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(capture_done->base.type, TDM_THREAD_CB_CAPTURE_DONE); - ASSERT_EQ(capture_done->base.length, sizeof * capture_done); - ASSERT_DOUBLE_EQ(capture_done->capture_stamp, private_capture.stamp); - ASSERT_TRUE(capture_done->buffer == &buffer); - ASSERT_TRUE(capture_done->user_data == &private_capture); -} - -//TEST(tdm_capture_cb_done, success_in_display_thread) -//{ -// tdm_private_capture private_capture; -// struct _tbm_surface buffer; -// tdm_thread_cb_capture_done *capture_done; -// tdm_private_display private_display; -// tdm_capture_private_buffer *capture_buffer_1; -// tdm_capture_private_buffer *capture_buffer_2; -// -// _init_test(); -// -// capture_buffer_1 = (tdm_capture_private_buffer *) -// calloc(1, sizeof * capture_buffer_1); -// capture_buffer_2 = (tdm_capture_private_buffer *) -// calloc(1, sizeof * capture_buffer_2); -// -// LIST_INITHEAD(&private_capture.buffer_list); -// LIST_ADD(&capture_buffer_1->link, &private_capture.buffer_list); -// LIST_ADD(&capture_buffer_2->link, &private_capture.buffer_list); -// -// capture_buffer_1->buffer = &buffer; -// -// private_capture.private_display = &private_display; -// stub_syscall_return_value = 50; -// stub_syscall_reset = 1; -// private_capture.owner_tid = stub_syscall_return_value; -// private_capture.done_func = stub_tdm_capture_done_handler; -// -// tdm_capture_cb_done(&private_capture, &buffer, &private_capture); -// -// ASSERT_EQ(FREE_CALLED, 1); -// ASSERT_EQ(stub_tdm_capture_done_handler_called, 1); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 1); -// ASSERT_TRUE(!_tdm_capture_find_tbm_buffer(&private_capture.buffer_list, &buffer)); -//} - -/* tdm_capture_find_stamp() */ - -TEST(tdm_capture_find_stamp, success_capture_list_is_empty) -{ - tdm_private_capture *capture_ret; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&private_display.capture_list); - - capture_ret = tdm_capture_find_stamp(&private_display, 0.5); - - ASSERT_EQ(capture_ret, NULL); -} - -TEST(tdm_capture_find_stamp, success) -{ - tdm_private_capture *capture_ret; - tdm_private_display private_display; - double stamp = 54.54; - tdm_private_capture capture; - - _init_test(); - - capture.stamp = stamp; - - LIST_INITHEAD(&private_display.capture_list); - LIST_ADD(&capture.display_link, &private_display.capture_list); - - capture_ret = tdm_capture_find_stamp(&private_display, stamp); - - ASSERT_EQ(capture_ret, &capture); -} - -/* tdm_capture_destroy_internal() */ - -//TEST(tdm_capture_destroy_internal, success) -//{ -// tdm_private_capture *capture; -// tdm_private_display private_display; -// struct list_head list; -// struct list_head dsp_list; -// tdm_buffer_info *b1, *b2; -// -// _init_test(); -// -// b1 = (tdm_buffer_info *)calloc(1, sizeof * b1); -// b2 = (tdm_buffer_info *)calloc(1, sizeof * b2); -// -// capture = (tdm_private_capture *)calloc(1, sizeof * capture); -// capture->private_display = &private_display; -// -// private_display.func_capture.capture_destroy = capture_destroy; -// -// LIST_INITHEAD(&list); -// LIST_INITHEAD(&dsp_list); -// LIST_INITHEAD(&capture->pending_buffer_list); -// LIST_INITHEAD(&capture->buffer_list); -// -// LIST_ADD(&capture->link, &list); -// LIST_ADD(&capture->display_link, &dsp_list); -// LIST_ADD(&b1->link, &capture->pending_buffer_list); -// LIST_ADD(&b2->link, &capture->buffer_list); -// -// tdm_capture_destroy_internal(capture); -// -// ASSERT_TRUE(LIST_IS_EMPTY(&list)); -// ASSERT_TRUE(LIST_IS_EMPTY(&dsp_list)); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -// ASSERT_EQ(FREE_CALLED, 1); -// ASSERT_EQ(capture_destroy_is_called, 1); -//} - -/* tdm_capture_destroy() */ - -//TEST(tdm_capture_destroy, success) -//{ -// tdm_private_capture *capture; -// tdm_private_display private_display; -// struct list_head list; -// struct list_head dsp_list; -// tdm_buffer_info *b1, *b2; -// -// _init_test(); -// -// b1 = (tdm_buffer_info *)calloc(1, sizeof * b1); -// b2 = (tdm_buffer_info *)calloc(1, sizeof * b2); -// -// capture = (tdm_private_capture *)calloc(1, sizeof * capture); -// capture->private_display = &private_display; -// -// private_display.func_capture.capture_destroy = capture_destroy; -// -// LIST_INITHEAD(&list); -// LIST_INITHEAD(&dsp_list); -// LIST_INITHEAD(&capture->pending_buffer_list); -// LIST_INITHEAD(&capture->buffer_list); -// -// LIST_ADD(&capture->link, &list); -// LIST_ADD(&capture->display_link, &dsp_list); -// LIST_ADD(&b1->link, &capture->pending_buffer_list); -// LIST_ADD(&b2->link, &capture->buffer_list); -// -// tdm_capture_destroy(capture); -// -// ASSERT_TRUE(LIST_IS_EMPTY(&list)); -// ASSERT_TRUE(LIST_IS_EMPTY(&dsp_list)); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -// ASSERT_EQ(FREE_CALLED, 1); -// ASSERT_EQ(capture_destroy_is_called, 1); -//} - -/* tdm_capture_set_done_handler() */ - -TEST(tdm_capture_set_done_handler, error_capture_is_null) -{ - tdm_error error; - - error = tdm_capture_set_done_handler(NULL, stub_tdm_capture_done_handler, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_capture_set_done_handler, error_func_is_null) -{ - tdm_error error; - tdm_private_capture capture; - - error = tdm_capture_set_done_handler(&capture, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_capture_set_done_handler, success) -{ - tdm_error error; - tdm_private_capture capture; - int user_data; - - error = tdm_capture_set_done_handler(&capture, stub_tdm_capture_done_handler, &user_data); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_TRUE(capture.done_func == stub_tdm_capture_done_handler); - ASSERT_TRUE(capture.done_user_data == &user_data); -} - -/* tdm_capture_attach() */ - -TEST(tdm_capture_attach, error_buffer_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_capture_attach(&capture, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_capture_attach, error_capture_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - - _init_test(); - - error = tdm_capture_attach(NULL, &buffer); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_capture_attach, error_func_capture_attach_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tbm_surface buffer; - tdm_private_display dsp; - - _init_test(); - - capture.private_display = &dsp; - dsp.func_capture.capture_attach = NULL; - - error = tdm_capture_attach(&capture, &buffer); - - ASSERT_EQ(error, TDM_ERROR_NOT_IMPLEMENTED); -} - -TEST(tdm_capture_attach, error_length_of_pending_buffer_list_ge_max_attach_count) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tbm_surface buffer; - tdm_private_display dsp; - tdm_backend_module module; - tdm_capture_private_buffer b1, b2; - - _init_test(); - - capture.private_display = &dsp; - dsp.func_capture.capture_attach = capture_attach; - - dsp.module_data = &module; - module.abi_version = 0x000100002; - - LIST_INITHEAD(&capture.pending_buffer_list); - LIST_INITHEAD(&capture.buffer_list); - LIST_ADD(&b1.link, &capture.pending_buffer_list); - LIST_ADD(&b2.link, &capture.pending_buffer_list); - - dsp.caps_capture.max_attach_count = 1; - - error = tdm_capture_attach(&capture, &buffer); - - ASSERT_EQ(error, TDM_ERROR_BAD_REQUEST); -} - -TEST(tdm_capture_attach, error_calloc) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tbm_surface buffer; - tdm_private_display dsp; - tdm_backend_module module; - - _init_test(); - - capture.private_display = &dsp; - dsp.func_capture.capture_attach = capture_attach; - - dsp.module_data = &module; - module.abi_version = 0x000100002; - - LIST_INITHEAD(&capture.pending_buffer_list); - LIST_INITHEAD(&capture.buffer_list); - - dsp.caps_capture.max_attach_count = 3; - - CALLOC_ERROR = 1; - - error = tdm_capture_attach(&capture, &buffer); - - ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); -} - -TEST(tdm_capture_attach, error_capture_attach) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tbm_surface buffer; - tdm_private_display dsp; - tdm_backend_module module; - - _init_test(); - - capture.private_display = &dsp; - dsp.func_capture.capture_attach = capture_attach; - - dsp.module_data = &module; - module.abi_version = 0x000100002; - - LIST_INITHEAD(&capture.pending_buffer_list); - LIST_INITHEAD(&capture.buffer_list); - - dsp.caps_capture.max_attach_count = 3; - - CAPTURE_ATTACH_ERROR = 1; - - error = tdm_capture_attach(&capture, &buffer); - - ASSERT_NE(error, TDM_ERROR_NONE); -} - -TEST(tdm_capture_attach, success) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_capture capture; - struct _tbm_surface buffer; - tdm_private_display dsp; - tdm_backend_module module; - tdm_capture_private_buffer *capture_buffer; - - _init_test(); - - capture.private_display = &dsp; - dsp.func_capture.capture_attach = capture_attach; - - dsp.module_data = &module; - module.abi_version = 0x000100002; - - LIST_INITHEAD(&capture.pending_buffer_list); - LIST_INITHEAD(&capture.buffer_list); - - dsp.caps_capture.max_attach_count = 3; - - error = tdm_capture_attach(&capture, &buffer); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_TRUE(!LIST_IS_EMPTY(&capture.pending_buffer_list)); - free(container_of(capture.pending_buffer_list.next, capture_buffer, link)); +#include "tdm.h" +#include "ut_common.h" + +class TDMCapture : public ::testing::Test { +protected: + tdm_display *dpy = NULL; + tdm_capture_capability capture_capabilities = -42; + bool has_capture = false; + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + error = tdm_display_get_capture_capabilities(dpy, &capture_capabilities); +#ifdef FAIL_ON_UNSUPPORTED + ASSERT_GT(capture_capabilities, 0); +#endif + if (capture_capabilities > 0) + has_capture = true; + } + void TearDown(void) + { + tdm_display_deinit(dpy); + dpy = NULL; + } +}; + +TEST_F(TDMCapture, DisplayGetCaptureAvailableFormatsSuccessful) +{ + CHECK_FLAG(has_capture); + const tbm_format * formats = NULL; + int count = -42; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_catpure_available_formats(dpy, &formats, &count)); + ASSERT_FALSE(-42 == count); + ASSERT_FALSE(NULL == formats); } diff --git a/utests/src/ut_tdm_display.cpp b/utests/src/ut_tdm_display.cpp deleted file mode 100644 index a35ea56..0000000 --- a/utests/src/ut_tdm_display.cpp +++ /dev/null @@ -1,4710 +0,0 @@ -/************************************************************************** - * - * 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 "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_backend.h" -#include "stub_tdm_pp.h" -#include "stub_tdm_capture.h" -#include "stub_tdm_thread.h" -#include "stub_tdm_event_loop.h" -#include "stub_tdm_buffer.h" -#include "stub_unistd.h" -#include "stub_tdm_thread.h" -#include "stub_tdm.h" -#include "stub_tdm_buffer.h" -#include "stub_tdm_helper.h" -#include "tdm_list.h" - -#include "tdm_display.c" -#include "tdm_layer.c" -#include "tdm_output.c" - -static void _init_test() -{ - stub_tdm_helper_init(); - stub_tdm_buffer_init(); - stub_tdm_init(); - stub_unistd_init(); - stub_tdm_thread_init(); - stub_pthread_init(); - stub_tdm_event_loop_init(); - stub_tdm_thread_init(); - stub_tdm_capture_init(); - stub_tdm_pp_init(); - stub_backend_init(); - stub_tbm_init(); - stub_stdlib_init(); - tdm_debug_module = TDM_DEBUG_THREAD | TDM_DEBUG_BUFFER; - tdm_debug_dump = TDM_DUMP_FLAG_LAYER; - tdm_dump_enable = 1; -} - -static void ut_tdm_output_vblank_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)user_data; -} - -/* UNIT TESTS */ - -/* tdm_layer_create_capture() */ - -TEST(tdm_layer_create_capture, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - tdm_layer_create_capture(&layer, &error); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_create_capture, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - CAPTURE_CREATE_LAYER_INTERNAL_ERROR = 1; - - tdm_layer_create_capture(&layer, &error); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_create_capture, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - tdm_layer_create_capture(NULL, &error); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_set_video_pos() */ - -TEST(tdm_layer_set_video_pos, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_video_pos = layer_set_video_pos; - layer.caps.capabilities = TDM_LAYER_CAPABILITY_VIDEO; - - error = tdm_layer_set_video_pos(&layer, 5); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_video_pos, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_video_pos = layer_set_video_pos; - layer.caps.capabilities = TDM_LAYER_CAPABILITY_VIDEO; - LAYER_SET_VIDEO_POS_ERROR = 1; - - error = tdm_layer_set_video_pos(&layer, 5); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_set_video_pos, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_video_pos = NULL; - layer.caps.capabilities = TDM_LAYER_CAPABILITY_VIDEO; - - error = tdm_layer_set_video_pos(&layer, 5); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_video_pos, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - layer.caps.capabilities = TDM_LAYER_CAPABILITY_GRAPHIC; - - error = tdm_layer_set_video_pos(&layer, 5); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_video_pos, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_layer_set_video_pos(NULL, 5); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_is_usable() */ - -TEST(tdm_layer_is_usable, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - unsigned int usable = rand(); - unsigned int expected_usable = rand(); - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - layer.usable = expected_usable; - - error = tdm_layer_is_usable(&layer, &usable); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(usable, expected_usable); -} - -TEST(tdm_layer_is_usable, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_is_usable(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_is_usable, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - unsigned int usable = rand(); - - _init_test(); - - error = tdm_layer_is_usable(NULL, &usable); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_unset_buffer_queue() */ - -//TEST(tdm_layer_unset_buffer_queue, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_INVALID_PARAMETER; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// struct _tbm_surface waiting_buffer; -// struct _tbm_surface showing_buffer; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = &waiting_buffer; -// layer.showing_buffer = &showing_buffer; -// private_display.func_layer.layer_unset_buffer = layer_unset_buffer; -// -// error = tdm_layer_unset_buffer_queue(&layer); -// -// ASSERT_EQ(error, expected_error); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -// ASSERT_EQ(tbm_surface_queue_release_count, 2); -// ASSERT_TRUE(layer.waiting_buffer == NULL); -// ASSERT_TRUE(layer.showing_buffer == NULL); -//} - -//TEST(tdm_layer_unset_buffer_queue, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error not_expected_error = TDM_ERROR_NONE; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = NULL; -// layer.showing_buffer = NULL; -// private_display.func_layer.layer_unset_buffer = layer_unset_buffer; -// LAYER_UNSET_BUFFER_ERROR = 1; -// -// error = tdm_layer_unset_buffer_queue(&layer); -// -// ASSERT_NE(error, not_expected_error); -//} - -//TEST(tdm_layer_unset_buffer_queue, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = NULL; -// layer.showing_buffer = NULL; -// private_display.func_layer.layer_unset_buffer = NULL; -// -// error = tdm_layer_unset_buffer_queue(&layer); -// -// ASSERT_EQ(error, expected_error); -//} - -TEST(tdm_layer_unset_buffer_queue, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_layer_unset_buffer_queue(NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_set_buffer_queue() */ - -TEST(tdm_layer_set_buffer_queue, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - struct _tbm_surface_queue buffer_queue; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - struct _tbm_surface waiting_buffer; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_buffer = layer_set_buffer; - layer.buffer_queue = NULL; -// layer.waiting_buffer = &waiting_buffer; - - error = tdm_layer_set_buffer_queue(&layer, &buffer_queue); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 1); - ASSERT_EQ(tbm_surface_queue_release_count, 1); - ASSERT_TRUE(layer.waiting_buffer == NULL); -} - -TEST(tdm_layer_set_buffer_queue, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - struct _tbm_surface_queue buffer_queue; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_buffer = layer_set_buffer; - layer.buffer_queue = &buffer_queue; - - error = tdm_layer_set_buffer_queue(&layer, &buffer_queue); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_buffer_queue, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - struct _tbm_surface_queue buffer_queue; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_buffer = NULL; - - error = tdm_layer_set_buffer_queue(&layer, &buffer_queue); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_buffer_queue, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_set_buffer_queue(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_buffer_queue, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - struct _tbm_surface_queue buffer_queue; - - _init_test(); - - error = tdm_layer_set_buffer_queue(NULL, &buffer_queue); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_unset_buffer() */ - -//TEST(tdm_layer_unset_buffer, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_OPERATION_FAILED; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// struct _tbm_surface waiting_buffer; -// struct _tbm_surface showing_buffer; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = &waiting_buffer; -// layer.showing_buffer = &showing_buffer; -// private_display.func_layer.layer_unset_buffer = layer_unset_buffer; -// -// error = tdm_layer_unset_buffer(&layer); -// -// ASSERT_EQ(error, expected_error); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -//} - -//TEST(tdm_layer_unset_buffer, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error not_expected_error = TDM_ERROR_NONE; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = NULL; -// layer.showing_buffer = NULL; -// private_display.func_layer.layer_unset_buffer = layer_unset_buffer; -// LAYER_UNSET_BUFFER_ERROR = 1; -// -// error = tdm_layer_unset_buffer(&layer); -// -// ASSERT_NE(error, not_expected_error); -//} - -//TEST(tdm_layer_unset_buffer, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// -// _init_test(); -// -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = NULL; -// layer.showing_buffer = NULL; -// private_display.func_layer.layer_unset_buffer = NULL; -// -// error = tdm_layer_unset_buffer(&layer); -// -// ASSERT_EQ(error, expected_error); -//} - -TEST(tdm_layer_unset_buffer, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_layer_unset_buffer(NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_set_buffer() */ -// -//TEST(tdm_layer_set_buffer, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_OPERATION_FAILED; -// tdm_error expected_error = TDM_ERROR_NONE; -// struct _tbm_surface buffer; -// tdm_private_layer layer; -// tdm_private_output private_output; -// tdm_private_display private_display; -// struct _tbm_surface waiting_buffer; -// -// _init_test(); -// -// layer.caps.capabilities = TDM_LAYER_CAPABILITY_GRAPHIC; -// layer.private_output = &private_output; -// private_output.private_display = &private_display; -// layer.waiting_buffer = &waiting_buffer; -// private_display.func_layer.layer_set_buffer = layer_set_buffer; -// -// error = tdm_layer_set_buffer(&layer, &buffer); -// -// ASSERT_EQ(error, expected_error); -//} - -TEST(tdm_layer_set_buffer, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - struct _tbm_surface buffer; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_buffer = layer_set_buffer; - LAYER_SET_BUFFER_ERROR = 1; - - error = tdm_layer_set_buffer(&layer, &buffer); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_set_buffer, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - struct _tbm_surface buffer; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_buffer = NULL; - - error = tdm_layer_set_buffer(&layer, &buffer); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_buffer, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_set_buffer(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_buffer, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - struct _tbm_surface buffer; - - _init_test(); - - error = tdm_layer_set_buffer(NULL, &buffer); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_info() */ - -TEST(tdm_layer_get_info, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_info = layer_set_info; - - error = tdm_layer_get_info(&layer, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_info, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_info = layer_set_info; - LAYER_SET_INFO_ERROR = 1; - - error = tdm_layer_get_info(&layer, &info); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_get_info, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_info = NULL; - - error = tdm_layer_get_info(&layer, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_info, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_info(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_info, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_info_layer info; - - _init_test(); - - error = tdm_layer_get_info(NULL, &info); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_set_info() */ - -TEST(tdm_layer_set_info, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.usable = 1; - info.src_config.format = 0; - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_info = layer_set_info; - - error = tdm_layer_set_info(&layer, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_info, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - info.src_config.format = 1; - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_info = layer_set_info; - LAYER_SET_INFO_ERROR = 1; - - error = tdm_layer_set_info(&layer, &info); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_set_info, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_info_layer info; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_info = NULL; - - error = tdm_layer_set_info(&layer, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_info, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_set_info(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_info, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_info_layer info; - - _init_test(); - - error = tdm_layer_set_info(NULL, &info); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_property() */ - -TEST(tdm_layer_get_property, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_property = layer_get_property; - - error = tdm_layer_get_property(&layer, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_property, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_property = layer_get_property; - LAYER_GET_PROPERTY_ERROR = 1; - - error = tdm_layer_get_property(&layer, 1, &value); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_get_property, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_get_property = NULL; - - error = tdm_layer_get_property(&layer, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_property, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_property(&layer, 1, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_property, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_value value; - - _init_test(); - - error = tdm_layer_get_property(NULL, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_set_property() */ - -TEST(tdm_layer_set_property, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_property = layer_set_property; - - error = tdm_layer_set_property(&layer, 1, value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_property, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_property = layer_set_property; - LAYER_SET_PROPERTY_ERROR = 1; - - error = tdm_layer_set_property(&layer, 1, value); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_layer_set_property, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_value value; - tdm_private_layer layer; - tdm_private_output private_output; - tdm_private_display private_display; - - _init_test(); - - layer.private_output = &private_output; - private_output.private_display = &private_display; - private_display.func_layer.layer_set_property = NULL; - - error = tdm_layer_set_property(&layer, 1, value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_set_property, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_value value; - - _init_test(); - - error = tdm_layer_set_property(NULL, 1, value); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_zpos() */ - -TEST(tdm_layer_get_zpos, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - layer.private_output = &private_output; - int zpos; - int expected_zpos = 547; - - _init_test(); - - layer.caps.zpos = expected_zpos; - - error = tdm_layer_get_zpos(&layer, &zpos); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(zpos, expected_zpos); -} - -TEST(tdm_layer_get_zpos, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_zpos(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_zpos, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - int zpos; - - _init_test(); - - error = tdm_layer_get_zpos(NULL, &zpos); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_available_properties() */ - -TEST(tdm_layer_get_available_properties, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - const tdm_prop *props; - tdm_prop p; - int count; - tdm_prop *expected_props = &p; - int expected_count = 468; - - _init_test(); - - layer.private_output = &private_output; - layer.caps.props = expected_props; - layer.caps.prop_count = expected_count; - - error = tdm_layer_get_available_properties(&layer, &props, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(props == expected_props); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_layer_get_available_properties, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - const tdm_prop *props; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_available_properties(&layer, &props, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_available_properties, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - int count; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_available_properties(&layer, NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_available_properties, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - const tdm_prop *props; - int count; - - _init_test(); - - error = tdm_layer_get_available_properties(NULL, &props, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_available_formats() */ - -TEST(tdm_layer_get_available_formats, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_layer layer; - tdm_private_output private_output; - const tbm_format *formats; - tbm_format f; - int count; - tbm_format *expected_formats = &f; - int expected_count = 468; - - _init_test(); - - layer.private_output = &private_output; - layer.caps.formats = expected_formats; - layer.caps.format_count = expected_count; - - error = tdm_layer_get_available_formats(&layer, &formats, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(formats == expected_formats); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_layer_get_available_formats, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - const tbm_format *formats; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_available_formats(&layer, &formats, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_available_formats, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - int count; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_available_formats(&layer, NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_available_formats, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - const tbm_format *formats; - int count; - - _init_test(); - - error = tdm_layer_get_available_formats(NULL, &formats, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_layer_get_capabilities() */ - -TEST(tdm_layer_get_capabilities, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_layer_capability capabilities = TDM_LAYER_CAPABILITY_SCALE; - tdm_layer_capability expected_capabilities = TDM_LAYER_CAPABILITY_GRAPHIC; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - layer.caps.capabilities = expected_capabilities; - - error = tdm_layer_get_capabilities(&layer, &capabilities); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(capabilities, expected_capabilities); -} - -TEST(tdm_layer_get_capabilities, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_layer layer; - tdm_private_output private_output; - - _init_test(); - - layer.private_output = &private_output; - - error = tdm_layer_get_capabilities(&layer, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_layer_get_capabilities, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_layer_capability capabilities = TDM_LAYER_CAPABILITY_SCALE; - - _init_test(); - - error = tdm_layer_get_capabilities(NULL, &capabilities); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_create_capture() */ - -TEST(tdm_output_create_capture, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - - _init_test(); - - tdm_output_create_capture(&output, &error); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_create_capture, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_output output; - - _init_test(); - - TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR = 1; - - tdm_output_create_capture(&output, &error); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_create_capture, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - tdm_output_create_capture(NULL, &error); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_dpms() */ - -TEST(tdm_output_get_dpms, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_output_dpms dpms_value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_dpms = output_get_dpms; - - error = tdm_output_get_dpms(&output, &dpms_value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_dpms, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_output_dpms dpms_value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_dpms = output_get_dpms; - OUTPUT_GET_DPMS_ERROR = 1; - - error = tdm_output_get_dpms(&output, &dpms_value); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_get_dpms, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_output_dpms dpms_value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_dpms = NULL; - - error = tdm_output_get_dpms(&output, &dpms_value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_dpms, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_output_dpms dpms_value; - - _init_test(); - - error = tdm_output_get_dpms(NULL, &dpms_value); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_set_dpms() */ - -TEST(tdm_output_set_dpms, error_output_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - - _init_test(); - - error = tdm_output_set_dpms(NULL, dpms_value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_dpms, success_dpms_is_already_set) -{ - tdm_error error; - tdm_output_dpms dpms_value = (tdm_output_dpms)10; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.current_dpms_value = TDM_OUTPUT_DPMS_OFF; - - output.private_display = &private_display; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -TEST(tdm_output_set_dpms, error_event_loop_add_timer_handler_error) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_sub); - - stub_tdm_event_loop_add_timer_handler_error = 1; - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); -} - -TEST(tdm_output_set_dpms, success_output_set_dpms_is_null) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - tdm_func_output func_output; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_sub); - - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - - func_output.output_set_dpms = NULL; - - private_display.func_output = func_output; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -TEST(tdm_output_set_dpms, error_output_set_dpms) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - tdm_func_output func_output; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_sub); - - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - - func_output.output_set_dpms = output_set_dpms; - func_output.output_set_dpms_handler = NULL; - - private_display.func_output = func_output; - - OUTPUT_SET_DPMS_ERROR = 1; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); -} - -TEST(tdm_output_set_dpms, error_output_set_dpms_handler_is_null) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - tdm_func_output func_output; - tdm_private_change_handler change_handler; - - _init_test(); - - stub_tdm_event_loop_source_timer_update_error = 1; - - LIST_INITHEAD(&output.change_handler_list_sub); - LIST_INITHEAD(&output.change_handler_list_main); - LIST_ADD(&change_handler.link, &output.change_handler_list_sub); - - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - - func_output.output_set_dpms = output_set_dpms; - func_output.output_set_dpms_handler = NULL; - - private_display.func_output = func_output; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); -} - -TEST(tdm_output_set_dpms, success_output_set_dpms_handler_is_null) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - tdm_func_output func_output; - tdm_private_change_handler change_handler; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_sub); - LIST_INITHEAD(&output.change_handler_list_main); - LIST_ADD(&change_handler.link, &output.change_handler_list_sub); - - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - - func_output.output_set_dpms = output_set_dpms; - func_output.output_set_dpms_handler = NULL; - - private_display.func_output = func_output; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -TEST(tdm_output_set_dpms, success_output_set_dpms_handler_is_not_null) -{ - tdm_error error; - tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - tdm_func_output func_output; - - _init_test(); - - stub_tdm_event_loop_source_timer_update_error = 1; - - LIST_INITHEAD(&output.change_handler_list_sub); - LIST_INITHEAD(&output.change_handler_list_main); - - output.dpms_changed_timer = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - output.private_display = &private_display; - output.regist_dpms_cb = 0; - - func_output.output_set_dpms = output_set_dpms; - func_output.output_set_dpms_handler = output_set_dpms_handler; - - private_display.func_output = func_output; - - error = tdm_output_set_dpms(&output, dpms_value); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -/* tdm_output_get_mode() */ - -TEST(tdm_output_get_mode, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NONE; - const tdm_output_mode *mode; - tdm_private_output output; - tdm_output_mode expected_mode; - output.current_mode = &expected_mode; - - _init_test(); - - error = tdm_output_get_mode(&output, &mode); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(mode == &expected_mode); -} - -TEST(tdm_output_get_mode, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_mode(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_mode, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - const tdm_output_mode *mode; - - _init_test(); - - error = tdm_output_get_mode(NULL, &mode); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_set_mode() */ - -TEST(tdm_output_set_mode, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_output_mode mode; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_mode = output_set_mode; - - error = tdm_output_set_mode(&output, &mode); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_mode, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_output_mode mode; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_mode = output_set_mode; - OUTPUT_SET_MODE_ERROR = 1; - - error = tdm_output_set_mode(&output, &mode); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_set_mode, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_output_mode mode; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_mode = NULL; - - error = tdm_output_set_mode(&output, &mode); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_mode, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_set_mode(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_mode, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_output_mode mode; - - _init_test(); - - error = tdm_output_set_mode(NULL, &mode); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_commit() */ - -TEST(tdm_output_commit, work_flow_success_7) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_OFF; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_commit, work_flow_success_6) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = output_commit; - private_display.func_output.output_set_commit_handler = - output_set_commit_handler; - output.regist_commit_cb = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_commit, work_flow_success_5) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = output_commit; - private_display.func_output.output_set_commit_handler = - output_set_commit_handler; - output.regist_commit_cb = 0; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_commit, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = output_commit; - private_display.func_output.output_set_commit_handler = - output_set_commit_handler; - output.regist_commit_cb = 0; - OUTPUT_COMMIT_ERROR = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_commit, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = output_commit; - OUTPUT_COMMIT_ERROR = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - private_display.func_output.output_set_commit_handler = - output_set_commit_handler; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_commit, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = output_commit; - CALLOC_ERROR = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_commit, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - -// LIST_INITHEAD(&output.commit_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_commit = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_commit(&output, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_commit, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_output_commit(NULL, 0, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - - -/* tdm_output_wait_vblank() */ - -TEST(tdm_output_wait_vblank, work_flow_success_7) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_DPMS_OFF; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_STANDBY; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_wait_vblank, work_flow_success_6) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = output_wait_vblank; - private_display.func_output.output_set_vblank_handler = - output_set_vblank_handler; - output.regist_vblank_cb = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_wait_vblank, work_flow_success_5) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = output_wait_vblank; - private_display.func_output.output_set_vblank_handler = - output_set_vblank_handler; - output.regist_vblank_cb = 0; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_wait_vblank, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = output_wait_vblank; - private_display.func_output.output_set_vblank_handler = - output_set_vblank_handler; - OUTPUT_SET_VBLANK_HANDLER = 1; - output.regist_vblank_cb = 0; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_NE(error, not_expected_error); -} - -//TEST(tdm_output_wait_vblank, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error not_expected_error = TDM_ERROR_NONE; -// tdm_private_output output; -// tdm_private_display private_display; -// -// _init_test(); -// -// LIST_INITHEAD(&output.vblank_handler_list); -// -// output.private_display = &private_display; -// private_display.func_output.output_wait_vblank = output_wait_vblank; -// OUTPUT_WAIT_VBLANK_ERROR = 1; -// output.current_dpms_value = TDM_OUTPUT_DPMS_ON; -// -// error = tdm_output_wait_vblank(&output, 1, 1, -// ut_tdm_output_vblank_handler, NULL); -// -// ASSERT_NE(error, not_expected_error); -//} - -TEST(tdm_output_wait_vblank, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = output_wait_vblank; - CALLOC_ERROR = 1; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_wait_vblank, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&output.vblank_handler_list); - - output.private_display = &private_display; - private_display.func_output.output_wait_vblank = NULL; - output.current_dpms_value = TDM_OUTPUT_DPMS_ON; - - error = tdm_output_wait_vblank(&output, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_wait_vblank, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_output_wait_vblank(NULL, 1, 1, - ut_tdm_output_vblank_handler, NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_property() */ - -TEST(tdm_output_get_property, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_property = output_get_property; - - error = tdm_output_get_property(&output, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_property, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_property = output_get_property; - OUTPUT_GET_PROPERTY_ERROR = 1; - - error = tdm_output_get_property(&output, 1, &value); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_get_property, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_get_property = NULL; - - error = tdm_output_get_property(&output, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_property, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_property(&output, 1, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_property, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_value value; - - _init_test(); - - error = tdm_output_get_property(NULL, 1, &value); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_set_property() */ - -TEST(tdm_output_set_property, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_property = output_set_property; - - error = tdm_output_set_property(&output, 1, value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_property, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_property = output_set_property; - OUTPUT_SET_PROPERTY_ERROR = 1; - - error = tdm_output_set_property(&output, 1, value); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_output_set_property, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_value value; - tdm_private_output output; - tdm_private_display private_display; - - _init_test(); - - output.private_display = &private_display; - private_display.func_output.output_set_property = NULL; - - error = tdm_output_set_property(&output, 1, value); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_set_property, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_value value; - - _init_test(); - - error = tdm_output_set_property(NULL, 1, value); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_pipe() */ - -TEST(tdm_output_get_pipe, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - unsigned int pipe; - unsigned int expected_pipe = 4869; - - _init_test(); - - output.pipe = expected_pipe; - - error = tdm_output_get_pipe(&output, &pipe); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(pipe, expected_pipe); -} - -TEST(tdm_output_get_pipe, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_pipe(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_pipe, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - unsigned int pipe; - - _init_test(); - - error = tdm_output_get_pipe(NULL, &pipe); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_subpixel() */ - -TEST(tdm_output_get_subpixel, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - unsigned int subpixel; - unsigned int expected_subpixel = 4869; - - _init_test(); - - output.caps.subpixel = expected_subpixel; - - error = tdm_output_get_subpixel(&output, &subpixel); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(subpixel, expected_subpixel); -} - -TEST(tdm_output_get_subpixel, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_subpixel(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_subpixel, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - unsigned int subpixel; - - _init_test(); - - error = tdm_output_get_subpixel(NULL, &subpixel); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_physical_size() */ - -TEST(tdm_output_get_physical_size, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - unsigned int mmWidth; - unsigned int expected_mmWidth = 445; - unsigned int mmHeight; - unsigned int expected_mmHeight = 4547; - - _init_test(); - - output.caps.mmWidth = expected_mmWidth; - output.caps.mmHeight = expected_mmHeight; - - error = tdm_output_get_physical_size(&output, &mmWidth, &mmHeight); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(mmWidth, expected_mmWidth); - ASSERT_EQ(mmHeight, expected_mmHeight); -} - -TEST(tdm_output_get_physical_size, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - unsigned int mmHeight; - unsigned int expected_mmHeight = 4547; - - _init_test(); - - output.caps.mmHeight = expected_mmHeight; - - error = tdm_output_get_physical_size(&output, NULL, &mmHeight); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(mmHeight, expected_mmHeight); -} - -TEST(tdm_output_get_physical_size, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - unsigned int mmWidth; - unsigned int expected_mmWidth = 445; - - _init_test(); - - output.caps.mmWidth = expected_mmWidth; - - error = tdm_output_get_physical_size(&output, &mmWidth, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(mmWidth, expected_mmWidth); -} - -TEST(tdm_output_get_physical_size, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_output_get_physical_size(NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_available_size() */ - -TEST(tdm_output_get_available_size, work_flow_6) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int min_w; - int expected_min_w = 200; - int min_h; - int expected_min_h = 100; - int max_w; - int expected_max_w = 2000; - int max_h; - int expected_max_h = 1000; - int preferred_align; - int expected_preferred_align = 456; - - _init_test(); - - output.caps.min_w = expected_min_w; - output.caps.min_h = expected_min_h; - output.caps.max_w = expected_max_w; - output.caps.max_h = expected_max_h; - output.caps.preferred_align = expected_preferred_align; - - error = tdm_output_get_available_size(&output, &min_w, &min_h, &max_w, - &max_h, &preferred_align); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(preferred_align, expected_preferred_align); - ASSERT_EQ(min_w, expected_min_w); - ASSERT_EQ(min_h, expected_min_h); - ASSERT_EQ(max_w, expected_max_w); - ASSERT_EQ(max_h, expected_max_h); - ASSERT_EQ(preferred_align, expected_preferred_align); -} - -TEST(tdm_output_get_available_size, work_flow_5) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int preferred_align; - int expected_preferred_align = 456; - - _init_test(); - - output.caps.preferred_align = expected_preferred_align; - - error = tdm_output_get_available_size(&output, NULL, NULL, NULL, - NULL, &preferred_align); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(preferred_align, expected_preferred_align); -} - -TEST(tdm_output_get_available_size, work_flow_4) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int max_h; - int expected_max_h = 1000; - - _init_test(); - - output.caps.max_h = expected_max_h; - - error = tdm_output_get_available_size(&output, NULL, NULL, NULL, - &max_h, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(max_h, expected_max_h); -} - -TEST(tdm_output_get_available_size, work_flow_3) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int max_w; - int expected_max_w = 2000; - - _init_test(); - - output.caps.max_w = expected_max_w; - - error = tdm_output_get_available_size(&output, NULL, NULL, - &max_w, NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(max_w, expected_max_w); -} - -TEST(tdm_output_get_available_size, work_flow_2) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int min_h; - int expected_min_h = 100; - - _init_test(); - - output.caps.min_h = expected_min_h; - - error = tdm_output_get_available_size(&output, NULL, &min_h, - NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(min_h, expected_min_h); -} - -TEST(tdm_output_get_available_size, work_flow_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - int min_w; - int expected_min_w = 200; - - _init_test(); - - output.caps.min_w = expected_min_w; - - error = tdm_output_get_available_size(&output, &min_w, NULL, - NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(min_w, expected_min_w); -} - -TEST(tdm_output_get_available_size, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_output_get_available_size(NULL, NULL, NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_available_modes() */ - -TEST(tdm_output_get_available_modes, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - const tdm_output_mode *modes; - int count; - tdm_output_mode m; - const tdm_output_mode *expected_modes = &m; - int expected_count = 14; - - _init_test(); - - output.caps.modes = &m; - output.caps.mode_count = expected_count; - - error = tdm_output_get_available_modes(&output, &modes, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(modes == expected_modes); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_output_get_available_modes, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - const tdm_output_mode *modes; - - _init_test(); - - error = tdm_output_get_available_modes(&output, &modes, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_available_modes, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - int count; - - _init_test(); - - error = tdm_output_get_available_modes(&output, NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_available_modes, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - const tdm_output_mode *modes; - int count; - - _init_test(); - - error = tdm_output_get_available_modes(NULL, &modes, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_available_properties() */ - -TEST(tdm_output_get_available_properties, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - const tdm_prop *props; - int count; - tdm_prop p; - const tdm_prop *expected_props = &p; - int expected_count = 14; - - _init_test(); - - output.caps.props = &p; - output.caps.prop_count = expected_count; - - error = tdm_output_get_available_properties(&output, &props, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(props == expected_props); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_output_get_available_properties, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - const tdm_prop *props; - - _init_test(); - - error = tdm_output_get_available_properties(&output, &props, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_available_properties, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - int count; - - _init_test(); - - error = tdm_output_get_available_properties(&output, NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_available_properties, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - const tdm_prop *props; - int count; - - _init_test(); - - error = tdm_output_get_available_properties(NULL, &props, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_layer() */ - -TEST(tdm_output_get_layer, success_get_layer) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_private_layer private_layer; - tdm_layer *layer; - - _init_test(); - - private_layer.index = 15; - - LIST_INITHEAD(&output.layer_list); - LIST_ADD(&private_layer.link, &output.layer_list); - - layer = tdm_output_get_layer(&output, 15, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(layer == &private_layer); -} - -TEST(tdm_output_get_layer, success_list_is_empty) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_layer *layer; - - _init_test(); - - LIST_INITHEAD(&output.layer_list); - - layer = tdm_output_get_layer(&output, 1, &error); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(layer == NULL); -} - -TEST(tdm_output_get_layer, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - tdm_output_get_layer(NULL, 1, &error); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_layer_count() */ - -TEST(tdm_output_get_layer_count, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - int count; - tdm_private_output output; - tdm_private_layer private_layer_1; - tdm_private_layer private_layer_2; - - _init_test(); - - LIST_INITHEAD(&output.layer_list); - LIST_ADD(&private_layer_1.link, &output.layer_list); - LIST_ADD(&private_layer_2.link, &output.layer_list); - - error = tdm_output_get_layer_count(&output, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(count, 2); -} - -TEST(tdm_output_get_layer_count, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - int count; - tdm_private_output output; - - _init_test(); - - LIST_INITHEAD(&output.layer_list); - - error = tdm_output_get_layer_count(&output, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(count, 0); -} - -TEST(tdm_output_get_layer_count, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_layer_count(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_layer_count, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - int count; - - _init_test(); - - error = tdm_output_get_layer_count(NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_output_type() */ - -TEST(tdm_output_get_output_type, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - tdm_output_type type = TDM_OUTPUT_TYPE_DVID; - tdm_output_type expected_type = TDM_OUTPUT_TYPE_VGA; - - _init_test(); - - output.caps.type = expected_type; - - error = tdm_output_get_output_type(&output, &type); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(type, expected_type); -} - -TEST(tdm_output_get_output_type, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_output_type(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_output_type, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_output_type type = TDM_OUTPUT_TYPE_DVID; - - _init_test(); - - error = tdm_output_get_output_type(NULL, &type); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_conn_status() */ - -TEST(tdm_output_get_conn_status, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; - tdm_output_conn_status expected_status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - tdm_private_output output; - - _init_test(); - - output.caps.status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - - error = tdm_output_get_conn_status(&output, &status); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(status, expected_status); -} - -TEST(tdm_output_get_conn_status, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_conn_status(&output, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_conn_status, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_output_conn_status status; - - _init_test(); - - error = tdm_output_get_conn_status(NULL, &status); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_output_get_model_info() */ - -TEST(tdm_output_get_model_info, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - const char *maker; - const char *model; - const char *name; - char *expected_maker = output.caps.maker; - char *expected_model = output.caps.model; - char *expected_name = output.caps.name; - - _init_test(); - - error = tdm_output_get_model_info(&output, &maker, &model, &name); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(maker == expected_maker); - ASSERT_TRUE(model == expected_model); - ASSERT_TRUE(name == expected_name); -} - -TEST(tdm_output_get_model_info, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_INVALID_PARAMETER; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_model_info(&output, NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_output_get_model_info, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_output_get_model_info(NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_create_pp() */ - -TEST(tdm_display_create_pp, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - - _init_test(); - - tdm_display_create_pp(&dpy, &error); - - ASSERT_EQ(error, expected_error); - -} - -TEST(tdm_display_create_pp, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - - _init_test(); - - TDM_PP_CREATE_INTERNAL_ERROR = 1; - - tdm_display_create_pp(&dpy, &error); - - ASSERT_NE(error, not_expected_error); - -} - -TEST(tdm_display_create_pp, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - tdm_display_create_pp(NULL, &error); - - ASSERT_EQ(error, expected_error); - -} - -/* tdm_display_handle_events() */ - -TEST(tdm_display_handle_events, success_thread_handle_cb) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - - _init_test(); - - stub_tdm_thread_is_run = 1; - - error = tdm_display_handle_events(&dpy); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -TEST(tdm_display_handle_events, error_thread_handle_cb) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - - _init_test(); - - stub_tdm_thread_is_run = 1; - TDM_THREAD_HANDLE_ERROR = 1; - - error = tdm_display_handle_events(&dpy); - - ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); -} - -TEST(tdm_display_handle_events, error_poll) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - - _init_test(); - - stub_poll_error = 1; - - error = tdm_display_handle_events(&dpy); - - ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); -} - -TEST(tdm_display_handle_events, success_poll_eagain) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - - _init_test(); - - stub_poll_eagain = 1; - - error = tdm_display_handle_events(&dpy); - - ASSERT_EQ(error, TDM_ERROR_NONE); -} - -TEST(tdm_display_handle_events, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - tdm_private_loop private_loop; - - _init_test(); - - error = tdm_display_handle_events(&dpy); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_handle_events, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - - _init_test(); - - TDM_EVENT_LOOP_DISPATCH_ERROR = 1; - - error = tdm_display_handle_events(&dpy); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_display_handle_events, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_handle_events(NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_fd() */ - -TEST(tdm_display_get_fd, success_thread_is_running) -{ - tdm_error error; - int fd; - struct _tdm_private_display dpy; - - _init_test(); - - stub_tdm_thread_is_run = 1; - stub_tdm_thread_ret_fd = 5; - - error = tdm_display_get_fd(&dpy, &fd); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(fd, stub_tdm_thread_ret_fd); -} - -TEST(tdm_display_get_fd, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - int fd; - struct _tdm_private_display dpy; - - _init_test(); - - error = tdm_display_get_fd(&dpy, &fd); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_fd, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - struct _tdm_private_display dpy; - - _init_test(); - - error = tdm_display_get_fd(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_fd, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - int fd; - - _init_test(); - - error = tdm_display_get_fd(NULL, &fd); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_output() */ - -TEST(tdm_display_get_output, success_get_output) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error; - struct _tdm_private_display dpy; - tdm_output *ret_output; - tdm_private_output output; - - _init_test(); - - output.index = 20; - - LIST_INITHEAD(&dpy.output_list); - LIST_ADD(&output.link, &dpy.output_list); - - ret_output = tdm_display_get_output(&dpy, output.index, &error); - - expected_error = TDM_ERROR_NONE; - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(ret_output, &output); -} - -TEST(tdm_display_get_output, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error; - struct _tdm_private_display dpy; - - _init_test(); - - LIST_INITHEAD(&dpy.output_list); - - tdm_display_get_output(&dpy, 1, &error); - - expected_error = TDM_ERROR_NONE; - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_output, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error; - expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - tdm_display_get_output(NULL, 1, &error); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_output_count() */ - -TEST(tdm_display_get_output_count, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error; - struct _tdm_private_display dpy; - int count; - tdm_private_output output_1; - tdm_private_output output_2; - - _init_test(); - - LIST_INITHEAD(&dpy.output_list); - LIST_ADD(&output_1.link, &dpy.output_list); - LIST_ADD(&output_2.link, &dpy.output_list); - - error = tdm_display_get_output_count(&dpy, &count); - - expected_error = TDM_ERROR_NONE; - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(count, 2); -} - -TEST(tdm_display_get_output_count, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error; - struct _tdm_private_display dpy; - int count; - - _init_test(); - - LIST_INITHEAD(&dpy.output_list); - - error = tdm_display_get_output_count(&dpy, &count); - - expected_error = TDM_ERROR_NONE; - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(count, 0); -} - -TEST(tdm_display_get_output_count, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error; - struct _tdm_private_display dpy; - - _init_test(); - - error = tdm_display_get_output_count(&dpy, NULL); - - expected_error = TDM_ERROR_INVALID_PARAMETER; - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_output_count, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - int count; - - _init_test(); - - error = tdm_display_get_output_count(NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_catpure_available_formats() */ - -TEST(tdm_display_get_catpure_available_formats, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - const tbm_format *format; - int count; - tbm_format expected_format = 2; - int expected_count = 3; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - dpy.caps_capture.format_count = expected_count; - dpy.caps_capture.formats = &expected_format; - - error = tdm_display_get_catpure_available_formats(&dpy, &format, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(format == &expected_format); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_display_get_catpure_available_formats, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - const tbm_format *format; - int count; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - - error = tdm_display_get_catpure_available_formats(&dpy, &format, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_catpure_available_formats, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - const tbm_format *format; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_catpure_available_formats(&dpy, &format, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_catpure_available_formats, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - int count; - - _init_test(); - - error = tdm_display_get_catpure_available_formats(&dpy, NULL, &count); - - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_catpure_available_formats, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - const tbm_format *format; - int count; - - _init_test(); - - error = tdm_display_get_catpure_available_formats(NULL, &format, &count); - - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_capture_capabilities() */ - -TEST(tdm_display_get_capture_capabilities, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_capture_capability capability = TDM_CAPTURE_CAPABILITY_STREAM; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_capture_capability expected_capability = TDM_CAPTURE_CAPABILITY_LAYER; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - dpy.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER; - - error = tdm_display_get_capture_capabilities(&dpy, &capability); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(capability, expected_capability); -} - -TEST(tdm_display_get_capture_capabilities, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_capture_capability capability = TDM_CAPTURE_CAPABILITY_STREAM; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - - error = tdm_display_get_capture_capabilities(&dpy, &capability); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_capture_capabilities, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_capture_capabilities(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_capture_capabilities, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_capture_capability capability = TDM_CAPTURE_CAPABILITY_STREAM; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_capture_capabilities(NULL, &capability); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_pp_available_size() */ - -TEST(tdm_display_get_pp_available_size, work_flow_success_7) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int min_w = 0; - int expected_min_w = 200; - int min_h = 0; - int expected_min_h = 100; - int max_w = 0; - int expected_max_w = 2000; - int max_h = 0; - int expected_max_h = 1000; - int preferred_align = 0; - int expected_preferred_align = 500; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.min_w = expected_min_w; - dpy.caps_pp.min_h = expected_min_h; - dpy.caps_pp.max_w = expected_max_w; - dpy.caps_pp.max_h = expected_max_h; - dpy.caps_pp.preferred_align = expected_preferred_align; - - error = tdm_display_get_pp_available_size(&dpy, &min_w, &min_h, &max_w, - &max_h, &preferred_align); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(min_w, expected_min_w); - ASSERT_EQ(min_h, expected_min_h); - ASSERT_EQ(max_w, expected_max_w); - ASSERT_EQ(max_h, expected_max_h); - ASSERT_EQ(preferred_align, expected_preferred_align); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_6) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int preferred_align = 0; - int expected_preferred_align = 500; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.preferred_align = expected_preferred_align; - - error = tdm_display_get_pp_available_size(&dpy, NULL, NULL, NULL, NULL, - &preferred_align); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(preferred_align, expected_preferred_align); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_5) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int max_h = 0; - int expected_max_h = 1000; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.max_h = expected_max_h; - - error = tdm_display_get_pp_available_size(&dpy, NULL, NULL, NULL, - &max_h, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(max_h, expected_max_h); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_4) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int max_w = 0; - int expected_max_w = 2000; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.max_w = expected_max_w; - - error = tdm_display_get_pp_available_size(&dpy, NULL, NULL, &max_w, - NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(max_w, expected_max_w); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int min_h = 0; - int expected_min_h = 100; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.min_h = expected_min_h; - - error = tdm_display_get_pp_available_size(&dpy, NULL, &min_h, NULL, - NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(min_h, expected_min_h); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - int min_w = 0; - int expected_min_w = 200; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.min_w = expected_min_w; - - error = tdm_display_get_pp_available_size(&dpy, &min_w, NULL, NULL, - NULL, NULL); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(min_w, expected_min_w); -} - -TEST(tdm_display_get_pp_available_size, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - error = tdm_display_get_pp_available_size(&dpy, NULL, NULL, NULL, - NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_available_size, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_available_size(NULL, NULL, NULL, NULL, - NULL, NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_pp_available_formats() */ - -TEST(tdm_display_get_pp_available_formats, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - struct _tdm_private_display dpy; - const tbm_format *format; - int count; - tbm_format expected_format = 2; - int expected_count = 3; - tdm_error expected_error = TDM_ERROR_NONE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.format_count = expected_count; - dpy.caps_pp.formats = &expected_format; - - error = tdm_display_get_pp_available_formats(&dpy, &format, &count); - - ASSERT_EQ(error, expected_error); - ASSERT_TRUE(format == &expected_format); - ASSERT_EQ(count, expected_count); -} - -TEST(tdm_display_get_pp_available_formats, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - const tbm_format *format; - int count; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - error = tdm_display_get_pp_available_formats(&dpy, &format, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_available_formats, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - const tbm_format *format; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_available_formats(&dpy, &format, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_available_formats, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - int count; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_available_formats(&dpy, NULL, &count); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_available_formats, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - const tbm_format *format; - int count; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_available_formats(NULL, &format, &count); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_pp_capabilities() */ - -TEST(tdm_display_get_pp_capabilities, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_pp_capability capability = TDM_PP_CAPABILITY_SCALE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_pp_capability expected_capability = TDM_PP_CAPABILITY_TRANSFORM; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_PP; - dpy.caps_pp.capabilities = TDM_PP_CAPABILITY_TRANSFORM; - - error = tdm_display_get_pp_capabilities(&dpy, &capability); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(capability, expected_capability); -} - -TEST(tdm_display_get_pp_capabilities, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_pp_capability capability = TDM_PP_CAPABILITY_SCALE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NO_CAPABILITY; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - error = tdm_display_get_pp_capabilities(&dpy, &capability); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_capabilities, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_capabilities(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_pp_capabilities, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_pp_capability capability = TDM_PP_CAPABILITY_SCALE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_pp_capabilities(NULL, &capability); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_capabilities() */ - -TEST(tdm_display_get_capabilities, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_display_capability capability = TDM_DISPLAY_CAPABILITY_PP; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_display_capability expected_capability = TDM_DISPLAY_CAPABILITY_CAPTURE; - - _init_test(); - - dpy.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - error = tdm_display_get_capabilities(&dpy, &capability); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(capability, expected_capability); -} - -TEST(tdm_display_get_capabilities, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - struct _tdm_private_display dpy; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_capabilities(&dpy, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_display_get_capabilities, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_display_capability capability = TDM_DISPLAY_CAPABILITY_CAPTURE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_display_get_capabilities(NULL, &capability); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_display_get_capture_available_size() */ - -TEST(tdm_display_get_capture_available_size, error_dpy_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - - _init_test(); - - error = tdm_display_get_capture_available_size(NULL, NULL, NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_display_get_capture_available_size, error_no_capability) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display display; - - _init_test(); - - display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - - error = tdm_display_get_capture_available_size(&display, NULL, NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_NO_CAPABILITY); -} - -TEST(tdm_display_get_capture_available_size, success_get_capture_available_size) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display display; - int min_w, min_h, max_w, max_h, preferred_align; - - _init_test(); - - display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE; - - display.caps_capture.min_w = 200; - display.caps_capture.min_h = 300; - display.caps_capture.max_w = 1080; - display.caps_capture.max_h = 1920; - display.caps_capture.preferred_align = 100; - - error = tdm_display_get_capture_available_size(&display, &min_w, - &min_h, &max_w, &max_h, - &preferred_align); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(display.caps_capture.min_w, min_w); - ASSERT_EQ(display.caps_capture.min_h, min_h); - ASSERT_EQ(display.caps_capture.max_w, max_w); - ASSERT_EQ(display.caps_capture.max_h, max_h); - ASSERT_EQ(display.caps_capture.preferred_align, preferred_align); -} - -/* tdm_display_get_capture_available_size() */ - -TEST(tdm_display_get_max_layer_count, error_dpy_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - int max_count; - - _init_test(); - - error = tdm_display_get_max_layer_count(NULL, &max_count); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_display_get_max_layer_count, error_max_count_is_null) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display display; - - _init_test(); - - error = tdm_display_get_max_layer_count(&display, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_display_get_max_layer_count, success_get_max_layer_count) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_display display; - int max_count; - - _init_test(); - - display.caps_display.max_layer_count = 100; - - error = tdm_display_get_max_layer_count(&display, &max_count); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(display.caps_display.max_layer_count, max_count); -} - -/* tdm_display_get_backend_info() */ - -TEST(tdm_display_get_backend_info, error_dpy_is_null) -{ - tdm_error error; - - _init_test(); - - error = tdm_display_get_backend_info(NULL, NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_display_get_backend_info, success_get_backend_info) -{ - tdm_error error; - tdm_private_display display; - tdm_backend_module module_data; - const char *name; - const char *vendor; - int major; - int minor; - - _init_test(); - - display.module_data = &module_data; - - module_data.name = "name"; - module_data.vendor = "vendor"; - module_data.abi_version = 0xFFFFFFFF; - - error = tdm_display_get_backend_info(&display, &name, &vendor, &major, &minor); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_TRUE(name == module_data.name); - ASSERT_TRUE(vendor == module_data.vendor); - ASSERT_EQ(major, TDM_BACKEND_GET_ABI_MAJOR(module_data.abi_version)); - ASSERT_EQ(minor, TDM_BACKEND_GET_ABI_MINOR(module_data.abi_version)); -} - -/* tdm_output_get_capabilities() */ - -TEST(tdm_output_get_capabilities, error_output_is_null) -{ - tdm_error error; - tdm_output_capability capabilities; - - _init_test(); - - error = tdm_output_get_capabilities(NULL, &capabilities); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_get_capabilities, error_capabilities_is_null) -{ - tdm_error error; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_capabilities(&output, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_get_capabilities, success_get_capabilities) -{ - tdm_error error; - tdm_private_output output; - tdm_output_capability capabilities; - - _init_test(); - - output.caps.capabilities = TDM_OUTPUT_CAPABILITY_ASYNC_DPMS; - - error = tdm_output_get_capabilities(&output, &capabilities); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(capabilities, output.caps.capabilities); -} - -/* tdm_output_cb_status() */ - -TEST(tdm_output_cb_status, success_no_in_display_thread) -{ - tdm_private_output private_output; - tdm_private_display private_display; - tdm_thread_cb_output_status *output_status; - tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - - _init_test(); - - private_output.private_display = &private_display; - private_output.stamp = 15.25; - - LIST_INITHEAD(&private_output.change_handler_list_sub); - - tdm_output_cb_status(&private_output, status, &private_output); - - output_status = (tdm_thread_cb_output_status *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(output_status->base.type, TDM_THREAD_CB_OUTPUT_STATUS); - ASSERT_EQ(output_status->base.length, sizeof * output_status); - ASSERT_EQ(output_status->output_stamp, private_output.stamp); - ASSERT_EQ(output_status->status, status); - ASSERT_TRUE(output_status->user_data == &private_output); -} - -TEST(tdm_output_cb_status, success_in_display_thread) -{ - tdm_private_output private_output; - tdm_private_display private_display; - tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - tdm_private_change_handler change_handler; - - _init_test(); - - stub_tdm_thread_display_thread = 1; - private_output.private_display = &private_display; - private_output.stamp = 15.25; - - change_handler.func = stub_tdm_output_change_handler_cb; - - LIST_INITHEAD(&private_output.change_handler_list_main); - LIST_ADD(&change_handler.link, &private_output.change_handler_list_main); - - tdm_output_cb_status(&private_output, status, &private_output); - - ASSERT_TRUE(stub_tdm_output_change_handler_count); -} - -/* tdm_output_add_change_handler() */ - -TEST(tdm_output_add_change_handler, error_output_is_null) -{ - tdm_error error; - - _init_test(); - - error = tdm_output_add_change_handler(NULL, stub_tdm_output_change_handler_cb, - NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_add_change_handler, error_func_is_null) -{ - tdm_error error; - tdm_private_output output; - - _init_test(); - - error = tdm_output_add_change_handler(&output, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_add_change_handler, error_calloc) -{ - tdm_error error; - tdm_private_output output; - - _init_test(); - - CALLOC_ERROR = 1; - - error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb, - NULL); - - ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY); -} - -TEST(tdm_output_add_change_handler, success_no_in_display_thread) -{ - tdm_error error; - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *h = NULL, *handler = NULL; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - stub_syscall_return_value = 21615; - - error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main)); - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) { - if (h->func == stub_tdm_output_change_handler_cb || h->user_data == &user_data) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - ASSERT_TRUE(handler->private_output == &output); - ASSERT_EQ(handler->owner_tid, stub_syscall_return_value); - free(handler); -} - -TEST(tdm_output_add_change_handler, success_in_display_thread) -{ - tdm_error error; - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *h = NULL, *handler = NULL; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - stub_tdm_thread_display_thread = 1; - stub_syscall_return_value = 21615; - - error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_main)); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_main, link) { - if (h->func == stub_tdm_output_change_handler_cb || h->user_data == &user_data) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - ASSERT_TRUE(handler->private_output == &output); - ASSERT_EQ(handler->owner_tid, stub_syscall_return_value); - free(handler); -} - -/* tdm_output_remove_change_handler */ - -TEST(tdm_output_remove_change_handler, success_list_main) -{ - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *change_handler; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler->func = stub_tdm_output_change_handler_cb; - change_handler->user_data = &user_data; - - LIST_ADD(&change_handler->link, &output.change_handler_list_main); - - tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main)); -} - -TEST(tdm_output_remove_change_handler, success_list_sub) -{ - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *change_handler; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler->func = stub_tdm_output_change_handler_cb; - change_handler->user_data = &user_data; - - LIST_ADD(&change_handler->link, &output.change_handler_list_sub); - - tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub)); -} - -TEST(tdm_output_remove_change_handler, success_list_main_2) -{ - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *change_handler; - tdm_private_change_handler *change_handler_2; - tdm_private_change_handler *h = NULL, *handler = NULL; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler->func = NULL; - change_handler->user_data = NULL; - - change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler_2->func = stub_tdm_output_change_handler_cb; - change_handler_2->user_data = &user_data; - - LIST_ADD(&change_handler_2->link, &output.change_handler_list_main); - LIST_ADD(&change_handler->link, &output.change_handler_list_main); - - tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_main)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_main, link) { - if (h->func == NULL || h->user_data == NULL) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - LIST_DEL(&handler->link); - free(handler); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main)); -} - -TEST(tdm_output_remove_change_handler, success_list_sub_2) -{ - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *change_handler; - tdm_private_change_handler *change_handler_2; - tdm_private_change_handler *h = NULL, *handler = NULL; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler->func = NULL; - change_handler->user_data = NULL; - - change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler_2->func = stub_tdm_output_change_handler_cb; - change_handler_2->user_data = &user_data; - - LIST_ADD(&change_handler_2->link, &output.change_handler_list_sub); - LIST_ADD(&change_handler->link, &output.change_handler_list_sub); - - tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) { - if (h->func == NULL || h->user_data == NULL) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - LIST_DEL(&handler->link); - free(handler); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub)); -} - -TEST(tdm_output_remove_change_handler, success_handler_is_not_exist) -{ - tdm_private_output output; - int user_data = 10; - tdm_private_change_handler *change_handler; - tdm_private_change_handler *change_handler_2; - tdm_private_change_handler *h = NULL, *handler = NULL; - - _init_test(); - - LIST_INITHEAD(&output.change_handler_list_main); - LIST_INITHEAD(&output.change_handler_list_sub); - - change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler->func = NULL; - change_handler->user_data = NULL; - - change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler)); - - change_handler_2->func = NULL; - change_handler_2->user_data = NULL; - - LIST_ADD(&change_handler->link, &output.change_handler_list_sub); - LIST_ADD(&change_handler_2->link, &output.change_handler_list_sub); - - tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb, - &user_data); - - ASSERT_EQ(FREE_CALLED, 0); - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) { - if (h->func == NULL || h->user_data == NULL) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - LIST_DEL(&handler->link); - free(handler); - handler = NULL; - ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub)); - LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) { - if (h->func == NULL || h->user_data == NULL) { - handler = h; - break; - } - } - ASSERT_TRUE(handler); - LIST_DEL(&handler->link); - free(handler); - ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub)); -} - -/* tdm_output_get_cursor_available_size() */ - -TEST(tdm_output_get_cursor_available_size, error_output_is_null) -{ - tdm_error error; - - _init_test(); - - error = tdm_output_get_cursor_available_size(NULL, NULL, NULL, NULL, NULL, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_get_cursor_available_size, error_abi_version_is_1_4) -{ - tdm_error error; - tdm_private_output output; - tdm_private_display display; - tdm_backend_module module; - int min_w, min_h, max_w, max_h, preferred_align; - - _init_test(); - - output.private_display = &display; - - display.module_data = &module; - module.abi_version = 0x00010004; - - output.caps.cursor_min_w = 200; - output.caps.cursor_min_h = 300; - output.caps.cursor_max_w = 1080; - output.caps.cursor_max_h = 1920; - output.caps.cursor_preferred_align = 256; - - error = tdm_output_get_cursor_available_size(&output, &min_w, &min_h, &max_w, - &max_h, &preferred_align); - - ASSERT_EQ(error, TDM_ERROR_BAD_MODULE); - ASSERT_EQ(min_w, -1); - ASSERT_EQ(min_h, -1); - ASSERT_EQ(max_w, -1); - ASSERT_EQ(max_h, -1); - ASSERT_EQ(preferred_align, -1); -} - -TEST(tdm_output_get_cursor_available_size, success_abi_version_is_1_5) -{ - tdm_error error; - tdm_private_output output; - tdm_private_display display; - tdm_backend_module module; - int min_w, min_h, max_w, max_h, preferred_align; - - _init_test(); - - output.private_display = &display; - - display.module_data = &module; - module.abi_version = 0x00010005; - - output.caps.cursor_min_w = 200; - output.caps.cursor_min_h = 300; - output.caps.cursor_max_w = 1080; - output.caps.cursor_max_h = 1920; - output.caps.cursor_preferred_align = 256; - - error = tdm_output_get_cursor_available_size(&output, &min_w, &min_h, &max_w, - &max_h, &preferred_align); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(min_w, output.caps.cursor_min_w); - ASSERT_EQ(min_h, output.caps.cursor_min_h); - ASSERT_EQ(max_w, output.caps.cursor_max_w); - ASSERT_EQ(max_h, output.caps.cursor_max_h); - ASSERT_EQ(preferred_align, output.caps.cursor_preferred_align); -} - -/* tdm_output_get_primary_index() */ - -TEST(tdm_output_get_primary_index, error_output_is_null) -{ - tdm_error error; - int index; - - _init_test(); - - error = tdm_output_get_primary_index(NULL, &index); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_get_primary_index, error_index_is_null) -{ - tdm_error error; - tdm_private_output output; - - _init_test(); - - error = tdm_output_get_primary_index(&output, NULL); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_output_get_primary_index, success_layer_list_is_empty) -{ - tdm_error error; - tdm_private_output output; - int index = 0; - - _init_test(); - - LIST_INITHEAD(&output.layer_list); - - error = tdm_output_get_primary_index(&output, &index); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(index, 0); -} - -TEST(tdm_output_get_primary_index, success_get_primary_index) -{ - tdm_error error; - tdm_private_output output; - tdm_private_layer private_layer_1; - tdm_private_layer private_layer_2; - int index; - - _init_test(); - - LIST_INITHEAD(&output.layer_list); - LIST_ADD(&private_layer_1.link, &output.layer_list); - LIST_ADD(&private_layer_2.link, &output.layer_list); - - private_layer_1.index = 25; - private_layer_2.index = 35; - - private_layer_1.caps.capabilities = (tdm_layer_capability)(TDM_LAYER_CAPABILITY_GRAPHIC | - TDM_LAYER_CAPABILITY_PRIMARY); - - private_layer_2.caps.capabilities = (tdm_layer_capability)(TDM_LAYER_CAPABILITY_GRAPHIC | - TDM_LAYER_CAPABILITY_OVERLAY); - - error = tdm_output_get_primary_index(&output, &index); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(index, private_layer_1.index); -} - -/* tdm_output_cb_vblank() */ - -TEST(tdm_output_cb_vblank, success_no_in_display_thread) -{ - tdm_private_vblank_handler vblank_handler; - tdm_private_output output; - tdm_private_display display; - unsigned int sequence = 17, tv_sec = 145, tv_usec = 874; - tdm_thread_cb_output_vblank *output_vblank; - - _init_test(); - - vblank_handler.private_output = &output; - output.private_display = &display; - output.stamp = 10.11; - stub_syscall_return_value = 115; - vblank_handler.owner_tid = stub_syscall_return_value - 1; - - tdm_output_cb_vblank(&output, sequence, tv_sec, tv_usec, &vblank_handler); - - output_vblank = (tdm_thread_cb_output_vblank *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(output_vblank->base.type, TDM_THREAD_CB_OUTPUT_VBLANK); - ASSERT_EQ(output_vblank->base.length, sizeof * output_vblank); - ASSERT_DOUBLE_EQ(output_vblank->output_stamp, output.stamp); - ASSERT_EQ(output_vblank->sequence, sequence); - ASSERT_EQ(output_vblank->tv_sec, tv_sec); - ASSERT_EQ(output_vblank->tv_usec, tv_usec); - ASSERT_TRUE(output_vblank->user_data == &vblank_handler); -} - -//TEST(tdm_output_cb_vblank, success_in_display_thread) -//{ -// tdm_private_vblank_handler *vblank_handler; -// tdm_private_output output; -// tdm_private_display display; -// unsigned int sequence = 17, tv_sec = 145, tv_usec = 874; -// struct list_head list; -// -// _init_test(); -// -// vblank_handler = (tdm_private_vblank_handler *)calloc(1, sizeof * vblank_handler); -// vblank_handler->private_output = &output; -// output.private_display = &display; -// -// stub_syscall_return_value = 115; -// stub_syscall_reset = 1; -// -// vblank_handler->owner_tid = stub_syscall_return_value; -// vblank_handler->func = stub_tdm_output_vblank_handler; -// -// LIST_INITHEAD(&list); -// LIST_ADD(&vblank_handler->link, &list); -// -// tdm_output_cb_vblank(&output, sequence, tv_sec, tv_usec, vblank_handler); -// -// ASSERT_EQ(stub_tdm_output_vblank_handler_count, 1); -// ASSERT_EQ(FREE_CALLED, 1); -// ASSERT_TRUE(LIST_IS_EMPTY(&list)); -//} - -/* tdm_output_cb_commit() */ - -TEST(tdm_output_cb_commit, success_no_in_display_thread) -{ - tdm_private_output_commit_handler commit_handler; - tdm_private_output output; - tdm_private_display display; - unsigned int sequence = 17, tv_sec = 145, tv_usec = 874; - tdm_thread_cb_output_commit *output_commit; - - _init_test(); - - commit_handler.private_output = &output; - output.private_display = &display; - output.stamp = 10.11; - stub_syscall_return_value = 115; - commit_handler.owner_tid = stub_syscall_return_value - 1; - - tdm_output_cb_commit(&output, sequence, tv_sec, tv_usec, &commit_handler); - - output_commit = (tdm_thread_cb_output_commit *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(output_commit->base.type, TDM_THREAD_CB_OUTPUT_COMMIT); - ASSERT_EQ(output_commit->base.length, sizeof * output_commit); - ASSERT_DOUBLE_EQ(output_commit->output_stamp, output.stamp); - ASSERT_EQ(output_commit->sequence, sequence); - ASSERT_EQ(output_commit->tv_sec, tv_sec); - ASSERT_EQ(output_commit->tv_usec, tv_usec); - ASSERT_TRUE(output_commit->user_data == &commit_handler); -} - -TEST(tdm_output_cb_commit, success_in_display_thread) -{ - tdm_private_output_commit_handler *commit_handler; - tdm_private_output output; - tdm_private_display display; - unsigned int sequence = 17, tv_sec = 145, tv_usec = 874; - tdm_private_layer private_layer_1; - tdm_private_layer private_layer_2; - tdm_private_layer private_layer_3; - struct _tbm_surface waiting_buffer; - struct _tbm_surface showing_buffer; - struct list_head list; - struct _tbm_surface_queue surface_queue; - - _init_test(); - - commit_handler = (tdm_private_output_commit_handler *)calloc(1, sizeof * commit_handler); - - private_layer_1.waiting_buffer = NULL; - private_layer_1.showing_buffer = NULL; - -// private_layer_2.waiting_buffer = &waiting_buffer; -// private_layer_2.showing_buffer = &showing_buffer; - private_layer_2.buffer_queue = &surface_queue; - -// private_layer_3.waiting_buffer = &waiting_buffer; -// private_layer_3.showing_buffer = NULL; - - commit_handler->private_output = &output; - output.private_display = &display; - stub_syscall_return_value = 115; - commit_handler->owner_tid = stub_syscall_return_value; - - LIST_INITHEAD(&output.layer_list); - LIST_ADD(&private_layer_1.link, &output.layer_list); - LIST_ADD(&private_layer_2.link, &output.layer_list); - LIST_ADD(&private_layer_3.link, &output.layer_list); - - commit_handler->func = stub_tdm_output_commit_handler; - - LIST_INITHEAD(&list); - LIST_ADD(&commit_handler->link, &list); - - tdm_output_cb_commit(&output, sequence, tv_sec, tv_usec, commit_handler); - - ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 1); - ASSERT_EQ(tbm_surface_queue_release_count, 1); - ASSERT_TRUE(private_layer_1.showing_buffer == NULL); -// ASSERT_TRUE(private_layer_2.showing_buffer == &waiting_buffer); -// ASSERT_TRUE(private_layer_3.showing_buffer == &waiting_buffer); - ASSERT_TRUE(private_layer_1.waiting_buffer == NULL); - ASSERT_TRUE(private_layer_2.waiting_buffer == NULL); - ASSERT_TRUE(private_layer_3.waiting_buffer == NULL); - ASSERT_EQ(stub_tdm_output_commit_handler_count, 1); - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_TRUE(LIST_IS_EMPTY(&list)); -} - -/* tdm_output_cb_dpms() */ - -TEST(tdm_output_cb_dpms, success_no_in_display_thread) -{ - tdm_private_output output; - tdm_private_display display; - tdm_thread_cb_output_dpms *output_dpms; - tdm_output_dpms dpms = TDM_OUTPUT_DPMS_STANDBY; - - _init_test(); - - output.private_display = &display; - output.stamp = 10.11; - - LIST_INITHEAD(&output.change_handler_list_sub); - LIST_INITHEAD(&output.change_handler_list_main); - - tdm_output_cb_dpms(&output, dpms, &output); - - output_dpms = (tdm_thread_cb_output_dpms *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(output_dpms->base.type, TDM_THREAD_CB_OUTPUT_DPMS); - ASSERT_EQ(output_dpms->base.length, sizeof * output_dpms); - ASSERT_DOUBLE_EQ(output_dpms->output_stamp, output.stamp); - ASSERT_EQ(output_dpms->dpms, TDM_OUTPUT_DPMS_STANDBY); - ASSERT_TRUE(output_dpms->user_data == &output); -} - -TEST(tdm_output_cb_dpms, success_in_display_thread) -{ - tdm_private_output output; - tdm_private_display display; - tdm_output_dpms dpms = TDM_OUTPUT_DPMS_STANDBY; - tdm_private_change_handler change_handler_1; - tdm_private_change_handler change_handler_2; - - _init_test(); - - stub_tdm_thread_display_thread = 1; - - output.private_display = &display; - - LIST_INITHEAD(&output.change_handler_list_sub); - LIST_INITHEAD(&output.change_handler_list_main); - LIST_ADD(&change_handler_1.link, &output.change_handler_list_main); - LIST_ADD(&change_handler_2.link, &output.change_handler_list_main); - - change_handler_1.func = stub_tdm_output_change_handler_cb; - change_handler_2.func = stub_tdm_output_change_handler_cb; - - tdm_output_cb_dpms(&output, dpms, &output); - - ASSERT_EQ(stub_tdm_output_change_handler_count, 2); - ASSERT_EQ(output.current_dpms_value, dpms); - -} - -/* tdm_layer_get_displaying_buffer() */ - -TEST(tdm_layer_get_displaying_buffer, error_layer_is_null) -{ - tdm_error error; - tbm_surface_h buffer; - - _init_test(); - - buffer = tdm_layer_get_displaying_buffer(NULL, &error); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); - ASSERT_EQ(buffer, NULL); -} - -TEST(tdm_layer_get_displaying_buffer, error_showing_buffer_is_null) -{ - tdm_error error; - tbm_surface_h buffer; - tdm_private_layer layer; - tdm_private_output output; - - _init_test(); - - layer.private_output = &output; - - layer.showing_buffer = NULL; - - buffer = tdm_layer_get_displaying_buffer(&layer, &error); - - ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED); - ASSERT_EQ(buffer, NULL); -} - -TEST(tdm_layer_get_displaying_buffer, success_get_displaying_buffer) -{ - tdm_error error; - tbm_surface_h buffer; - tdm_private_layer layer; - tdm_private_output output; - struct _tbm_surface showing_buffer; - - _init_test(); - - layer.private_output = &output; - -// layer.showing_buffer = &showing_buffer; - - buffer = tdm_layer_get_displaying_buffer(&layer, &error); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(buffer, &showing_buffer); -} - -/* tdm_layer_get_buffer_flags() */ - -TEST(tdm_layer_get_buffer_flags, error_layer_is_null) -{ - tdm_error error; - unsigned int flags; - - _init_test(); - - error = tdm_layer_get_buffer_flags(NULL, &flags); - - ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER); -} - -TEST(tdm_layer_get_buffer_flags, error_layer_get_buffer_flags_is_null) -{ - tdm_error error; - unsigned int flags; - tdm_private_layer layer; - tdm_private_output output; - tdm_private_display display; - tdm_func_layer func_layer; - - _init_test(); - - layer.private_output = &output; - output.private_display = &display; - - func_layer.layer_get_buffer_flags = NULL; - - display.func_layer = func_layer; - - error = tdm_layer_get_buffer_flags(&layer, &flags); - - ASSERT_EQ(error, TDM_ERROR_NOT_IMPLEMENTED); -} - -TEST(tdm_layer_get_buffer_flags, success_get_buffer_flags) -{ - tdm_error error; - unsigned int flags; - tdm_private_layer layer; - tdm_private_output output; - tdm_private_display display; - tdm_func_layer func_layer; - - _init_test(); - - layer.private_output = &output; - output.private_display = &display; - - func_layer.layer_get_buffer_flags = layer_get_buffer_flags; - - display.func_layer = func_layer; - - error = tdm_layer_get_buffer_flags(&layer, &flags); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(flags, layer_get_buffer_flags_ret); -} diff --git a/utests/src/ut_tdm_event_loop.cpp b/utests/src/ut_tdm_event_loop.cpp deleted file mode 100644 index 863b317..0000000 --- a/utests/src/ut_tdm_event_loop.cpp +++ /dev/null @@ -1,630 +0,0 @@ -///************************************************************************** -// * -// * 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 -// -//#include "gtest/gtest.h" -// -//#include "tbm_stubs.h" -//#include "stub_pthread.h" -//#include "stub_stdlib.h" -//#include "stub_tdm_server.h" -//#include "stub_tdm_thread.h" -// - -#include "tdm_event_loop.c" -// -//#define ZEROING_DATA(ptr, size_of_ptr) memset((void*)ptr, 0, size_of_ptr); -// -//static void _init_test() -//{ -// WL_EVENT_LOOP_ADD_FD_ERROR = 0; -// WL_EVENT_SOURCE_FD_UPDATE_ERROR = 0; -// WL_EVENT_LOOP_ADD_TIMER_ERROR = 0; -// WL_EVENT_SOURCE_TIMER_UPDATE_ERROR = 0; -// WL_DISPLAY_CREATE_ERROR = 0; -// -// -// stub_pthread_init(); -// stub_tbm_init(); -// stub_stdlib_init(); -// stub_tdm_server(); -// stub_tdm_thread_init(); -//} -// -///* HELPER FUNCTIONS */ -// -//tdm_error ut_tdm_event_loop_fd_handler(int fd, tdm_event_loop_mask mask, -// void *user_data) -//{ -// (void)fd; -// (void)mask; -// (void)user_data; -// -// return TDM_ERROR_NONE; -//} -// -//tdm_error ut_tdm_event_loop_timer_handler(void *user_data) -//{ -// (void)user_data; -// -// return TDM_ERROR_NONE; -//} -// -///* UNIT TESTS */ -// -///* tdm_event_loop_source_timer_update */ -// -//TEST(tdm_event_loop_source_timer_update, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_OPERATION_FAILED; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_event_loop_source_timer source; -// -// _init_test(); -// -// error = tdm_event_loop_source_timer_update(&source, 100); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_source_timer_update, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; -// tdm_event_loop_source_timer source; -// -// _init_test(); -// -// WL_EVENT_SOURCE_TIMER_UPDATE_ERROR = 1; -// -// error = tdm_event_loop_source_timer_update(&source, 100); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_source_timer_update, null_ptr_fail_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// -// _init_test(); -// -// error = tdm_event_loop_source_timer_update(NULL, 100); -// -// ASSERT_EQ(error, expected_error); -//} -// -///* tdm_event_loop_add_timer_handler */ -// -//TEST(tdm_event_loop_add_timer_handler, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// tdm_event_loop_source_timer *timer_source; -// struct wl_event_loop wl_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// -// timer_source = -// (tdm_event_loop_source_timer *)tdm_event_loop_add_timer_handler(&dpy, -// ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -// free(timer_source); -//} -// -//TEST(tdm_event_loop_add_timer_handler, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// struct wl_event_loop wl_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// WL_EVENT_LOOP_ADD_TIMER_ERROR = 1; -// -// tdm_event_loop_add_timer_handler(&dpy, ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_timer_handler, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// struct wl_event_loop wl_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// CALLOC_ERROR = 1; -// -// tdm_event_loop_add_timer_handler(&dpy, ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_timer_handler, null_ptr_fail_4) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = NULL; -// -// tdm_event_loop_add_timer_handler(&dpy, ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_timer_handler, null_ptr_fail_3) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_private_display dpy; -// -// _init_test(); -// -// dpy.private_loop = NULL; -// -// tdm_event_loop_add_timer_handler(&dpy, ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_timer_handler, null_ptr_fail_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_private_display dpy; -// -// _init_test(); -// -// tdm_event_loop_add_timer_handler(&dpy, NULL, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_timer_handler, null_ptr_fail_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// -// _init_test(); -// -// tdm_event_loop_add_timer_handler(NULL, ut_tdm_event_loop_timer_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -///* tdm_event_loop_source_fd_update */ -// -//TEST(tdm_event_loop_source_fd_update, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_OPERATION_FAILED; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_event_loop_source_fd source; -// -// _init_test(); -// -// error = tdm_event_loop_source_fd_update(&source, mask); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_source_fd_update, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_event_loop_source_fd source; -// -// _init_test(); -// -// WL_EVENT_SOURCE_FD_UPDATE_ERROR = 1; -// -// error = tdm_event_loop_source_fd_update(&source, mask); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_source_fd_update, null_ptr_fail_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// -// _init_test(); -// -// error = tdm_event_loop_source_fd_update(NULL, mask); -// -// ASSERT_EQ(error, expected_error); -//} -// -///* tdm_event_loop_add_fd_handler */ -// -//TEST(tdm_event_loop_add_fd_handler, work_flow_success_3) -//{ -// tdm_error error = TDM_ERROR_INVALID_PARAMETER; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// struct wl_event_loop wl_loop; -// tdm_event_loop_source_fd *fd_source; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// -// fd_source = -// (tdm_event_loop_source_fd *)tdm_event_loop_add_fd_handler(&dpy, 5, mask, -// ut_tdm_event_loop_fd_handler, -// NULL, &error); -// free(fd_source); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// struct wl_event_loop wl_loop; -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// WL_EVENT_LOOP_ADD_FD_ERROR = 1; -// -// tdm_event_loop_add_fd_handler(&dpy, 5, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, work_flow_success_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// struct wl_event_loop wl_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = &wl_loop; -// CALLOC_ERROR = 1; -// -// tdm_event_loop_add_fd_handler(&dpy, 5, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, null_ptr_fail_5) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// tdm_private_loop private_loop; -// -// _init_test(); -// -// dpy.private_loop = &private_loop; -// private_loop.wl_loop = NULL; -// -// tdm_event_loop_add_fd_handler(&dpy, 5, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, null_ptr_fail_4) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// -// _init_test(); -// -// dpy.private_loop = NULL; -// -// tdm_event_loop_add_fd_handler(&dpy, 5, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, null_ptr_fail_3) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// -// _init_test(); -// -// tdm_event_loop_add_fd_handler(&dpy, 5, mask, NULL, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, null_ptr_fail_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// tdm_private_display dpy; -// -// _init_test(); -// -// tdm_event_loop_add_fd_handler(&dpy, -1, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_add_fd_handler, null_ptr_fail_1) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; -// tdm_event_loop_mask mask = TDM_EVENT_LOOP_READABLE; -// -// _init_test(); -// -// tdm_event_loop_add_fd_handler(NULL, 5, mask, ut_tdm_event_loop_fd_handler, -// NULL, &error); -// -// ASSERT_EQ(error, expected_error); -//} -// -///* tdm_event_loop_init */ -// -//TEST(tdm_event_loop_init, success_private_loop_was_allocated) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_private_display private_display; -// tdm_private_loop private_loop; -// -// private_display.private_loop = &private_loop; -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_init, error_could_not_allocate_private_loop) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_private_display private_display; -// -// _init_test(); -// -// private_display.private_loop = NULL; -// CALLOC_ERROR = 1; -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_init, error_could_not_create_display) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; -// tdm_private_display private_display; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// WL_DISPLAY_CREATE_ERROR = 1; -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_init, error_init_tdm_server) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; -// tdm_private_display private_display; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// stdub_tdm_server_init_error = 1; -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_init, error_init_thread) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; -// tdm_private_display private_display; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// stub_tdm_thread_init_init_error = 1; -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -//} -// -//TEST(tdm_event_loop_init, success_first_initialization_of_private_loop) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error expected_error = TDM_ERROR_NONE; -// tdm_private_display private_display; -// int expected_fd = -1; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// -// error = tdm_event_loop_init(&private_display); -// -// ASSERT_EQ(error, expected_error); -// ASSERT_TRUE(private_display.private_loop); -// ASSERT_EQ(private_display.private_loop->backend_fd, expected_fd); -// -// /* XXX: private_loop has been allocated within tdm_event_loop_init -// * so it's out duty to delete it */ -// free(private_display.private_loop); -//} -// -///* tdm_event_loop_deinit */ -// -//TEST(tdm_event_loop_deinit, success_private_loop_is_NULL) -//{ -// tdm_private_display private_display; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// -// tdm_event_loop_deinit(&private_display); -// -// ASSERT_FALSE(private_display.private_loop); -//} -// -//TEST(tdm_event_loop_deinit, success_private_loop_is_not_NULL) -//{ -// tdm_private_display private_display; -// tdm_event_loop_source_base *event_loop_source_base; -// struct wl_display wl_display; -// -// _init_test(); -// -// ZEROING_DATA(&private_display, sizeof(tdm_private_display)); -// -// private_display.private_loop = calloc(1, sizeof(tdm_private_loop)); -// private_display.private_loop->backend_source = NULL; -// private_display.private_loop->wl_display = &wl_display; -// -// tdm_event_loop_deinit(&private_display); -// -// ASSERT_FALSE(private_display.private_loop); -//} -// -///* tdm_event_loop_source_remove */ -// -//TEST(tdm_event_loop_source_remove, success_source_is_NULL) -//{ -// _init_test(); -// tdm_event_loop_source_remove(NULL); -//} -// -//TEST(tdm_event_loop_source_remove, success_source_is_not_NULL) -//{ -// tdm_event_loop_source_base *base; -// -// _init_test(); -// -// base = calloc(1, sizeof(tdm_event_loop_source_base)); -// ASSERT_TRUE(base); -// -// tdm_event_loop_source_remove(base); -//} -// -///* tdm_event_loop_flush */ -// -//TEST(tdm_event_loop_flush, success_wl_display_is_NULL) -//{ -// tdm_private_display private_display; -// tdm_private_loop private_loop; -// -// ZEROING_DATA(&private_display, sizeof(private_display)) -// ZEROING_DATA(&private_loop, sizeof(private_loop)) -// -// private_display.private_loop = &private_loop; -// -// tdm_event_loop_flush(&private_display); -//} -// -//TEST(tdm_event_loop_flush, success_wl_display_is_not_NULL) -//{ -// tdm_private_display private_display; -// tdm_private_loop private_loop; -// struct wl_display wl_display; -// -// ZEROING_DATA(&private_display, sizeof(private_display)) -// ZEROING_DATA(&private_loop, sizeof(private_loop)) -// -// private_display.private_loop = &private_loop; -// private_display.private_loop->wl_display = &wl_display; -// -// tdm_event_loop_flush(&private_display); -//} -// -// -// -// -// diff --git a/utests/src/ut_tdm_helper.cpp b/utests/src/ut_tdm_helper.cpp deleted file mode 100644 index 6787472..0000000 --- a/utests/src/ut_tdm_helper.cpp +++ /dev/null @@ -1,766 +0,0 @@ -/************************************************************************** - * - * 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 - -/*------ stubs -----------------*/ -#include "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_unistd.h" -#include "stub_fcntl.h" -#include "stub_dlfcn.h" -#include "stub_stdio.h" -#include "tdm_event_loop_stubs.h" - -#define png_write_info(p1, p2) -#define png_write_image(p1, p2) -#define png_write_end(p1, p2) -/*------ stubs ----------------*/ - -#pragma GCC optimize(0) - -extern "C" int -tbm_drm_helper_get_master_fd(void) -{ - return 20; -} - -#include "tdm_helper.c" - -static void _init_test() -{ - stub_stdio_init(); - stub_fcntl_init(); - stub_pthread_init(); - stub_unistd_init(); - stub_tbm_init(); - stub_stdlib_init(); -} - -/* UNIT TESTS */ - -/* tdm_helper_get_fd() */ - -TEST(tdm_helper_get_fd, work_flow_success_5) -{ - const char *env = "env"; - int fd; - - _init_test(); - - stub_getenv_name = env; - stub_getenv_return_value = "getenv"; - - fd = tdm_helper_get_fd(env); - - ASSERT_EQ(fd, 5); -} - -TEST(tdm_helper_get_fd, work_flow_success_4) -{ - const char *env = "env"; - int expected_fd = -1; - int fd; - - _init_test(); - - stub_dub_error = 1; - - stub_getenv_name = env; - stub_getenv_return_value = "getenv"; - - fd = tdm_helper_get_fd(env); - - ASSERT_EQ(fd, expected_fd); -} - -TEST(tdm_helper_get_fd, work_flow_success_3) -{ - const char *env = "env"; - int fd; - int expected_fd = -1; - - _init_test(); - - FCNTL_ERROR = 1; - - stub_getenv_name = env; - stub_getenv_return_value = "getenv"; - - fd = tdm_helper_get_fd(env); - - ASSERT_EQ(fd, expected_fd); -} - -TEST(tdm_helper_get_fd, work_flow_success_2) -{ - const char *env = "env"; - int expected_fd = -1; - int fd; - - _init_test(); - - SSCANF_ERROR = 1; - - stub_getenv_name = env; - stub_getenv_return_value = "getenv"; - - fd = tdm_helper_get_fd(env); - - ASSERT_EQ(fd, expected_fd); -} - -TEST(tdm_helper_get_fd, work_flow_success_1) -{ - const char *env = "env"; - int fd; - int expected_fd = -1; - - _init_test(); - - GETENV_ERROR = 1; - - fd = tdm_helper_get_fd(env); - - ASSERT_EQ(fd, expected_fd); -} - -/* tdm_helper_set_fd */ -TEST(tdm_helper_set_fd, work_flow_success_1) -{ - _init_test(); - tdm_helper_set_fd("TEST_ENV", 7); - - ASSERT_STREQ(stub_getenv_name, "TEST_ENV"); -} - -TEST(tdm_helper_set_fd, work_flow_error_1__setenv_error) -{ - _init_test(); - SETENV_ERROR = 1; - - tdm_helper_set_fd("TEST_ENV", 7); - - ASSERT_EQ(stub_getenv_name, 0); - ASSERT_EQ(stub_getenv_return_value, 0); -} - -/* tdm_helper_dump_start */ -TEST(tdm_helper_dump_start, work_flow_success_1) -{ - _init_test(); - int count = 0; - tdm_dump_enable = 0; - tdm_helper_dump_start("test_str1", &count); - ASSERT_EQ(tdm_dump_enable, 1); -} - -TEST(tdm_helper_dump_start, work_flow_error_1__NULL) -{ - _init_test(); - int count = 0; - tdm_dump_enable = 0; - tdm_helper_dump_start("test_str1", NULL); - ASSERT_EQ(tdm_dump_enable, 0); - tdm_helper_dump_start(NULL, &count); - ASSERT_EQ(tdm_dump_enable, 0); -} - -/* tdm_helper_dump_start */ -TEST(tdm_helper_dump_stop, work_flow_success_1) -{ - _init_test(); - tdm_dump_enable = 0; - tdm_helper_dump_stop(); - ASSERT_EQ(tdm_dump_enable, 0); -} - -tdm_error stub_output_get_mode(tdm_output *output, const tdm_output_mode **mode) -{ - static tdm_output_mode cmode; - *mode = &cmode; - return TDM_ERROR_NONE; -} - -tdm_error stub_output_get_property(tdm_output *output, unsigned int id, tdm_value *value) -{ - (tdm_output *)output; - (unsigned int)id; - value->s32 = 1; - return TDM_ERROR_NONE; -} - -tdm_error stub_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value) -{ - (tdm_layer *)layer; - (unsigned int)id; - value->s32 = 1; - return TDM_ERROR_NONE; -} - -tdm_error stub_layer_get_info(tdm_layer *layer, tdm_info_layer *info) -{ - (tdm_layer *)layer; - (tdm_info_layer *)info; - return TDM_ERROR_NONE; -} - - -/* tdm_helper_get_display_information */ -TEST(tdm_helper_get_display_information, work_flow_success_1) -{ - tdm_private_display disp; - tdm_backend_module module; - tdm_private_output output; - tdm_private_layer layer; - tdm_private_pp pp; - tdm_private_capture capture; - tdm_output_mode output_mode; - tdm_prop prop; - tdm_info_layer info; - tdm_private_display *private_display = &disp; - tbm_format formats[2] = {TBM_FORMAT_ABGR8888, 0}; - - memset(&disp, 0, sizeof(disp)); - memset(&module, 0, sizeof(module)); - memset(&output, 0, sizeof(output)); - memset(&layer, 0, sizeof(layer)); - memset(&pp, 0, sizeof(pp)); - memset(&capture, 0, sizeof(capture)); - memset(&output_mode, 0, sizeof(output_mode)); - memset(&prop, 0, sizeof(prop)); - memset(&info, 0, sizeof(info)); - - int len = 1024; - char rep[len]; - - _init_test(); - - //init disp - private_display->capabilities = TDM_DISPLAY_CAPABILITY_PP | TDM_DISPLAY_CAPABILITY_CAPTURE; - LIST_INITHEAD(&private_display->output_list); - LIST_INITHEAD(&private_display->pp_list); - LIST_INITHEAD(&private_display->capture_list); - - //init module - private_display->module_data = &module; - module.abi_version = 0x00010001; - module.name = "test"; - module.vendor = "test"; - - //init output - LIST_ADDTAIL(&output.link, &private_display->output_list); - LIST_INITHEAD(&output.capture_list); - LIST_INITHEAD(&output.layer_list); - output.caps.mode_count = 1; - output.caps.modes = &output_mode; - output.caps.prop_count = 1; - output.caps.props = ∝ - memset(&output_mode, 0, sizeof(output_mode)); - private_display->func_output.output_get_mode = stub_output_get_mode; - private_display->func_output.output_get_property = stub_output_get_property; - - //init layer - LIST_ADDTAIL(&layer.link, &output.layer_list); - layer.usable = 0; - layer.caps.format_count = 2; - layer.caps.formats = formats; - layer.caps.prop_count = 1; - layer.caps.props = ∝ - private_display->func_layer.layer_get_info = stub_layer_get_info; - private_display->func_layer.layer_get_property = stub_layer_get_property; - - //init pp - LIST_ADDTAIL(&pp.link, &private_display->pp_list); - private_display->caps_pp.format_count = 2; - private_display->caps_pp.formats = formats; - - //init capture - LIST_ADDTAIL(&capture.link, &private_display->capture_list); - private_display->caps_capture.format_count = 2; - private_display->caps_capture.formats = formats; - - tdm_helper_get_display_information(private_display, rep, &len); -} - -static int stub_tdm_helper_capture_handler_is_called = 0; -static void stub_tdm_helper_capture_handler(tbm_surface_h buffer, void *user_data) -{ - stub_tdm_helper_capture_handler_is_called = 1; -} - -/* tdm_helper_capture_output */ -TEST(tdm_helper_capture_output, work_flow_success_1) -{ - tdm_error error; - tdm_private_display display; - tdm_private_output output; - tdm_private_layer layer; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - memset(&output, 0, sizeof(output)); - memset(&layer, 0, sizeof(layer)); - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - //init output - LIST_INITHEAD(&output.layer_list); - LIST_ADDTAIL(&layer.link, &output.layer_list); - output.private_display = &display; -// layer.showing_buffer = (tbm_surface_h)&src_surface; - layer.private_output = &output; - layer.private_display = &display; - - - error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer); - - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_EQ(1, stub_tdm_helper_capture_handler_is_called); -} - -TEST(tdm_helper_capture_output, work_flow_error_1___no_layer) -{ - tdm_error error; - tdm_private_display display; - tdm_private_output output; - tdm_private_layer layer; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - memset(&output, 0, sizeof(output)); - memset(&layer, 0, sizeof(layer)); - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - //init output - LIST_INITHEAD(&output.layer_list); - output.private_display = &display; -// layer.showing_buffer = (tbm_surface_h)&src_surface; - layer.private_output = &output; - layer.private_display = &display; - - - error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer); - - ASSERT_NE(TDM_ERROR_NONE, error); -} - -TEST(tdm_helper_capture_output, work_flow_error_2___wrong_buffer_format) -{ - tdm_error error; - tdm_private_display display; - tdm_private_output output; - tdm_private_layer layer; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - memset(&output, 0, sizeof(output)); - memset(&layer, 0, sizeof(layer)); - - src_surface.info.format = TBM_FORMAT_XRGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - src_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - //init output - LIST_INITHEAD(&output.layer_list); - LIST_ADDTAIL(&layer.link, &output.layer_list); - output.private_display = &display; -// layer.showing_buffer = (tbm_surface_h)&src_surface; - layer.private_output = &output; - layer.private_display = &display; - - dst_surface.info.format = TBM_FORMAT_YUV410; - error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer); - ASSERT_EQ(TDM_ERROR_NONE, error); -} - -TEST(tdm_helper_capture_output, work_flow_error_2___tbm_surface_map) -{ - tdm_error error; - tdm_private_display display; - tdm_private_output output; - tdm_private_layer layer; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - memset(&output, 0, sizeof(output)); - memset(&layer, 0, sizeof(layer)); - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - //init output - LIST_INITHEAD(&output.layer_list); - LIST_ADDTAIL(&layer.link, &output.layer_list); - output.private_display = &display; -// layer.showing_buffer = (tbm_surface_h)&src_surface; - layer.private_output = &output; - layer.private_display = &display; - - - dst_surface.info.num_planes = 0; - error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer); - ASSERT_EQ(TDM_ERROR_NONE, error); - dst_surface.info.num_planes = 1; - - src_surface.info.num_planes = 0; - error = tdm_helper_capture_output(&output, (tbm_surface_h)&dst_surface, 0, 0, 10, 10, stub_tdm_helper_capture_handler, &layer); - ASSERT_EQ(TDM_ERROR_NONE, error); -} - -/* tdm_helper_convert_buffer */ -TEST(tdm_helper_convert_buffer, work_flow_success_1) -{ - tdm_error error; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - tdm_pos src_pos = {0, 0, 100, 100}; - tdm_pos dst_pos = {0, 0, 100, 100}; - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_EQ(TDM_ERROR_NONE, error); - - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_90, 0); - ASSERT_EQ(TDM_ERROR_NONE, error); - - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_180, 0); - ASSERT_EQ(TDM_ERROR_NONE, error); - - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED_270, 0); - ASSERT_EQ(TDM_ERROR_NONE, error); -} - - -TEST(tdm_helper_convert_buffer, work_flow_error_1__NULL) -{ - tdm_error error; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - tdm_pos src_pos = {0, 0, 100, 100}; - tdm_pos dst_pos = {0, 0, 100, 100}; - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - error = tdm_helper_convert_buffer(NULL, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); - error = tdm_helper_convert_buffer(&src_surface, NULL, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); -} - -TEST(tdm_helper_convert_buffer, work_flow_error_1___wrong_buffers) -{ - tdm_error error; - int src_mem[100][100]; - int dst_mem[100][100]; - struct _tbm_surface src_surface; - struct _tbm_surface dst_surface; - tdm_pos src_pos = {0, 0, 100, 100}; - tdm_pos dst_pos = {0, 0, 100, 100}; - - src_surface.info.format = TBM_FORMAT_ARGB8888; - src_surface.info.width = 100; - src_surface.info.height = 100; - src_surface.info.num_planes = 1; - src_surface.info.planes[0].ptr = (unsigned char*)src_mem; - src_surface.info.planes[0].stride = src_surface.info.width * 4; - - dst_surface.info.format = TBM_FORMAT_XRGB8888; - dst_surface.info.width = 100; - dst_surface.info.height = 100; - dst_surface.info.num_planes = 1; - dst_surface.info.planes[0].ptr = (unsigned char*)dst_mem; - dst_surface.info.planes[0].stride = dst_surface.info.width * 4; - - _init_test(); - - //fail map of src buffer - src_surface.info.num_planes = 0; - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); - src_surface.info.num_planes = 1; - - //fail map of dst buffer - dst_surface.info.num_planes = 0; - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); - dst_surface.info.num_planes = 1; - - //wrong format of src buffer - src_surface.info.format = TBM_FORMAT_YUV410; - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); - src_surface.info.format = TBM_FORMAT_ARGB8888; - - //wrong format of dst buffer - dst_surface.info.format = TBM_FORMAT_YUV410; - error = tdm_helper_convert_buffer(&src_surface, &dst_surface, &src_pos, &dst_pos, TDM_TRANSFORM_FLIPPED, 0); - ASSERT_NE(TDM_ERROR_NONE, error); - dst_surface.info.format = TBM_FORMAT_ARGB8888; -} - - -/* tdm_helper_clear_buffer_pos */ -TEST(tdm_helper_clear_buffer_pos, work_flow_success_1) -{ - int mem1[100*100*3]; - int mem2[100*100*3]; - int mem3[100*100*3]; - struct _tbm_surface surface; - tdm_pos pos = {1, 0, 9, 10}; - - surface.info.width = 10; - surface.info.height = 10; - surface.info.num_planes = 1; - surface.info.planes[0].ptr = (unsigned char*)mem1; - surface.info.planes[0].stride = surface.info.width * 4; - surface.info.planes[1].ptr = (unsigned char*)mem2; - surface.info.planes[1].stride = surface.info.width * 4; - surface.info.planes[2].ptr = (unsigned char*)mem3; - surface.info.planes[2].stride = surface.info.width * 4; - - _init_test(); - - surface.info.format = TBM_FORMAT_ARGB8888; - memset(mem1, 0x77, sizeof(mem1)); - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, &pos); - EXPECT_EQ(0, mem1[100+1]); - EXPECT_EQ(0x77777777, mem1[0]); - EXPECT_EQ(0x77777777, mem2[0]); - EXPECT_EQ(0x77777777, mem3[0]); - - - surface.info.format = TBM_FORMAT_YVU420; - memset(mem1, 0x77, sizeof(mem1)); - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, NULL); - EXPECT_EQ(0x10101010, mem1[0]); - EXPECT_EQ(0x80808080, mem2[0]); - EXPECT_EQ(0x80808080, mem3[0]); - - surface.info.format = TBM_FORMAT_NV12; - memset(mem1, 0x77, sizeof(mem1)); - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, NULL); - EXPECT_EQ(0x10101010, mem1[0]); - EXPECT_EQ(0x80808080, mem2[0]); - EXPECT_EQ(0x77777777, mem3[0]); - - surface.info.format = TBM_FORMAT_UYVY; - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, NULL); - EXPECT_EQ(0x80108010, mem1[0]); - EXPECT_EQ(0x77777777, mem2[0]); - EXPECT_EQ(0x77777777, mem3[0]); - - surface.info.format = TBM_FORMAT_YUYV; - memset(mem1, 0x77, sizeof(mem1)); - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, NULL); - EXPECT_EQ(0x10801080, mem1[0]); - EXPECT_EQ(0x77777777, mem2[0]); - EXPECT_EQ(0x77777777, mem3[0]); - - surface.info.format = TBM_FORMAT_YVU411; - memset(mem1, 0x77, sizeof(mem1)); - memset(mem2, 0x77, sizeof(mem2)); - memset(mem3, 0x77, sizeof(mem3)); - tdm_helper_clear_buffer_pos(&surface, NULL); - EXPECT_EQ(0x77777777, mem1[0]); - EXPECT_EQ(0x77777777, mem2[0]); - EXPECT_EQ(0x77777777, mem3[0]); -} - - -/* tdm_helper_clear_buffer */ -TEST(tdm_helper_clear_buffer, work_flow_success_1) -{ - int mem1[100*100*3]; - struct _tbm_surface surface; - - surface.info.width = 10; - surface.info.height = 10; - surface.info.num_planes = 1; - surface.info.planes[0].ptr = (unsigned char*)mem1; - surface.info.planes[0].stride = surface.info.width * 4; - - _init_test(); - - surface.info.format = TBM_FORMAT_ARGB8888; - memset(mem1, 0x77, sizeof(mem1)); - tdm_helper_clear_buffer(&surface); - EXPECT_EQ(0, mem1[0]); -} - -/* tdm_helper_dump_buffer */ -//TEST(tdm_helper_dump_buffer, work_flow_success_1) -//{ -// int mem1[10*10*3]; -// int mem2[10*10*3]; -// int mem3[10*10*3]; -// struct _tbm_surface surface; -// -// surface.info.width = 10; -// surface.info.height = 10; -// surface.info.num_planes = 1; -// surface.info.planes[0].ptr = (unsigned char*)mem1; -// surface.info.planes[0].stride = surface.info.width * 4; -// surface.info.planes[1].ptr = (unsigned char*)mem2; -// surface.info.planes[1].stride = surface.info.width * 4; -// surface.info.planes[2].ptr = (unsigned char*)mem3; -// surface.info.planes[2].stride = surface.info.width * 4; -// -// _init_test(); -// -// surface.info.format = TBM_FORMAT_ARGB8888; -// tdm_helper_dump_buffer(&surface, "tmp.png"); -// -// surface.info.format = TBM_FORMAT_YVU420; -// tdm_helper_dump_buffer(&surface, "tmp.yuv"); -// -// surface.info.format = TBM_FORMAT_NV12; -// tdm_helper_dump_buffer(&surface, "tmp.yuv"); -// -// surface.info.format = TBM_FORMAT_YUYV; -// tdm_helper_dump_buffer(&surface, "tmp.yuv"); -// -// surface.info.format = TBM_FORMAT_YVU411; -// tdm_helper_dump_buffer(&surface, "tmp.yuv"); -// -//} - -/* tdm_helper_dump_buffer */ -TEST(tdm_helper_dump_buffer, work_flow_error_1___NULL) -{ - struct _tbm_surface surface; - char str[1024] = {'t', 'm', 'p', 0}; - - _init_test(); - - tdm_helper_dump_buffer(&surface, "tmp.yuv"); - tdm_helper_dump_buffer(NULL, str); -} - diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp new file mode 100644 index 0000000..89064c0 --- /dev/null +++ b/utests/src/ut_tdm_layer.cpp @@ -0,0 +1,81 @@ +/************************************************************************** + * + * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko + * + * 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 "tdm.h" +#include "ut_common.h" + +class TDMLayer : public ::testing::Test { +protected: + tdm_display *dpy = NULL; + int output_count = -42; + int layer_count = -42; + bool has_layers = false; + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + error = tdm_display_get_output_count(dpy, &output_count); + error = tdm_display_get_max_layer_count(dpy, &layer_count); +#ifdef FAIL_ON_UNSUPPORTED + ASSERT_GT(output_count, 0); + ASSERT_GT(layer_count, 0); +#endif + if (layer_count > 0) + has_layers = true; + } + void TearDown(void) + { + tdm_display_deinit(dpy); + dpy = NULL; + } +}; + +TEST_F(TDMLayer, OutputGetLayerSuccessful) +{ + CHECK_FLAG(has_layers); + for (int i = 0; i < output_count; i++) { + tdm_error error_output = TDM_ERROR_NONE; + tdm_output * output = NULL; + output = tdm_display_get_output(dpy, i, &error_output); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error_output); + for (int k = 0; k < layer_count; k++) { + tdm_error error_layer = TDM_ERROR_NONE; + ASSERT_FALSE(NULL == tdm_output_get_layer(output, k, &error_layer)); + ASSERT_TRUE(TDM_ERROR_NONE == error_layer); + } + } +} diff --git a/utests/src/ut_tdm_output.cpp b/utests/src/ut_tdm_output.cpp new file mode 100644 index 0000000..6ea9f21 --- /dev/null +++ b/utests/src/ut_tdm_output.cpp @@ -0,0 +1,71 @@ +/************************************************************************** + * + * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko + * + * 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 "tdm.h" +#include "ut_common.h" + +class TDMOutput : public ::testing::Test { +protected: + tdm_display *dpy = NULL; + int output_count = -42; + bool has_output = false; + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + error = tdm_display_get_output_count(dpy, &output_count); +#ifdef FAIL_ON_UNSUPPORTED + ASSERT_GT(output_count, 0); +#endif + if (output_count > 0) + has_output = true; + } + void TearDown(void) + { + tdm_display_deinit(dpy); + dpy = NULL; + } +}; + +TEST_F(TDMOutput, DisplayGetOutputSuccessful) +{ + CHECK_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error)); + ASSERT_TRUE(TDM_ERROR_NONE == error); + } +} diff --git a/utests/src/ut_tdm_pp.cpp b/utests/src/ut_tdm_pp.cpp index d412e7f..18d9a96 100644 --- a/utests/src/ut_tdm_pp.cpp +++ b/utests/src/ut_tdm_pp.cpp @@ -3,6 +3,8 @@ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. * * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the @@ -27,753 +29,43 @@ **************************************************************************/ #include "gtest/gtest.h" - -#include "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_tdm_helper.h" -#include "stub_backend.h" -#include "stub_tdm_buffer.h" -#include "stub_unistd.h" -#include "stub_tdm_thread.h" -#include "stub_tdm_helper.h" -#include "stub_tdm_buffer.h" - -#include "tdm_pp.c" - -//local stubs for callbeck functions -static int stub_pp_destroy_is_called = 0; -static int stub_tdm_pp_done_handler_is_called; - -static void stub_pp_destroy(tdm_pp *pp) -{ - (void)pp; - - stub_pp_destroy_is_called = 1; -} - -static int stub_pp_set_done_handler_is_called = 0; -static int stub_pp_set_done_handler_error = 0; -static tdm_error stub_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, - void *user_data) -{ - (void)pp; - (void)func; - (void)user_data; - - if (stub_pp_set_done_handler_error) - return TDM_ERROR_OPERATION_FAILED; - - stub_pp_set_done_handler_is_called = 1; - return TDM_ERROR_NONE; -} - -static int stub_display_create_pp_is_called = 0; -static int stub_display_create_pp_error = 0; -static tdm_pp *stub_display_create_pp(tdm_backend_data *bdata, tdm_error *error) -{ - (void)bdata; - - if (stub_display_create_pp_error) { - if (error) - *error = TDM_ERROR_OPERATION_FAILED; - return NULL; +#include "tdm.h" +#include "ut_common.h" + +class TDMPP : public testing::Test { +protected: + tdm_display *dpy = NULL; + tdm_pp_capability pp_capabilities = -42; + bool has_pp = false; + void SetUp(void) + { + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + error = tdm_display_get_pp_capabilities(dpy, &pp_capabilities); +#ifdef FAIL_ON_UNSUPPORTED + ASSERT_GT(pp_capabilities, 0); +#endif + if (pp_capabilities > 0) + has_pp = true; } - stub_display_create_pp_is_called = 1; - static int backend_pp; - return &backend_pp; -} - -static int stub_pp_attach_is_called = 0; -static int stub_pp_attach_error = 0; -tdm_error stub_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst) -{ - (void)pp; - (void)src; - (void)dst; - - if (stub_pp_attach_error) - return TDM_ERROR_OPERATION_FAILED; - - stub_pp_attach_is_called = 1; - return TDM_ERROR_NONE; -} - -static void stub_tdm_pp_done_handler(tdm_pp *pp, tbm_surface_h src, - tbm_surface_h dst, void *user_data) -{ - (void)pp; - (void)src; - (void)dst; - (void)user_data; - - stub_tdm_pp_done_handler_is_called = 1; -} - -static void _init_test() -{ - stub_tdm_buffer_init(); - stub_tdm_helper_init(); - stub_tdm_buffer_init(); - stub_tdm_thread_init(); - stub_unistd_init(); - stub_pthread_init(); - stub_backend_init(); - stub_tbm_init(); - stub_stdlib_init(); - stub_pp_destroy_is_called = 0; - stub_pp_set_done_handler_is_called = 0; - stub_pp_set_done_handler_error = 0; - stub_display_create_pp_is_called = 0; - stub_pp_attach_is_called = 0; - stub_pp_attach_error = 0; - stub_tdm_pp_done_handler_is_called = 0; - stub_display_create_pp_error = 0; - tdm_debug_dump = TDM_DUMP_FLAG_PP; - tdm_debug_module = TDM_DEBUG_BUFFER; -} - -/* UNIT TESTS */ - -/* tdm_pp_commit */ - -TEST(tdm_pp_commit, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_private_pp pp; - tdm_private_display private_display; - tdm_pp_private_buffer b_1, b_2; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_commit = pp_commit; - - LIST_INITHEAD(&pp.pending_buffer_list); - LIST_INITHEAD(&pp.buffer_list); - - LIST_ADD(&b_1.link, &pp.pending_buffer_list); - LIST_ADD(&b_2.link, &pp.pending_buffer_list); - - - error = tdm_pp_commit(&pp); - - ASSERT_EQ(error, TDM_ERROR_NONE); - ASSERT_EQ(LIST_LENGTH(&pp.buffer_list), 2); -} - -//TEST(tdm_pp_commit, work_flow_success_2) -//{ -// tdm_error error = TDM_ERROR_NONE; -// tdm_error not_expected_error = TDM_ERROR_NONE; -// tdm_private_pp pp; -// tdm_private_display private_display; -// tdm_pp_private_buffer b_1, b_2; -// -// _init_test(); -// -// pp.private_display = &private_display; -// private_display.func_pp.pp_commit = pp_commit; -// PP_COMMIT_ERROR = 1; -// -// LIST_INITHEAD(&pp.pending_buffer_list); -// LIST_INITHEAD(&pp.buffer_list); -// -// LIST_ADD(&b_1.link, &pp.pending_buffer_list); -// LIST_ADD(&b_2.link, &pp.pending_buffer_list); -// -// error = tdm_pp_commit(&pp); -// -// ASSERT_NE(error, not_expected_error); -// ASSERT_EQ(LIST_LENGTH(&pp.buffer_list), 0); -// ASSERT_EQ(stub_tdm_buffer_remove_release_handler_internal_count, 4); -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 4); -//} - -TEST(tdm_pp_commit, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_commit = NULL; - - error = tdm_pp_commit(&pp); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_commit, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - _init_test(); - - error = tdm_pp_commit(NULL); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_pp_attach */ - -TEST(tdm_pp_attach, error_pp_attach) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_pp private_pp; - tdm_private_display private_display; - tdm_backend_module module; - struct _tbm_surface src; - struct _tbm_surface dst; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - LIST_ADDTAIL(&private_pp.link, &private_display.pp_list); - private_display.module_data = &module; - private_display.func_pp.pp_attach = stub_pp_attach; - private_display.caps_pp.max_attach_count = 3; - module.abi_version = 0x00010002; - - private_pp.private_display = &private_display; - LIST_INITHEAD(&private_pp.pending_buffer_list); - LIST_INITHEAD(&private_pp.buffer_list); - - stub_pp_attach_error = 1; - - error = tdm_pp_attach(&private_pp, &src, &dst); - - ASSERT_NE(TDM_ERROR_NONE, error); -} - -TEST(tdm_pp_attach, error_calloc_error) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_pp private_pp; - tdm_private_display private_display; - tdm_backend_module module; - struct _tbm_surface src; - struct _tbm_surface dst; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - LIST_ADDTAIL(&private_pp.link, &private_display.pp_list); - private_display.module_data = &module; - private_display.func_pp.pp_attach = stub_pp_attach; - private_display.caps_pp.max_attach_count = 3; - module.abi_version = 0x00010002; - - private_pp.private_display = &private_display; - LIST_INITHEAD(&private_pp.pending_buffer_list); - LIST_INITHEAD(&private_pp.buffer_list); - - CALLOC_ERROR = 1; - - error = tdm_pp_attach(&private_pp, &src, &dst); - - ASSERT_EQ(TDM_ERROR_OUT_OF_MEMORY, error); -} - -TEST(tdm_pp_attach, error_bad_request) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_pp private_pp; - tdm_private_display private_display; - tdm_backend_module module; - struct _tbm_surface src; - struct _tbm_surface dst; - tdm_pp_private_buffer pp_buffer_1; - tdm_pp_private_buffer pp_buffer_2; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - LIST_ADDTAIL(&private_pp.link, &private_display.pp_list); - private_display.module_data = &module; - private_display.func_pp.pp_attach = stub_pp_attach; - private_display.caps_pp.max_attach_count = 1; - module.abi_version = 0x00010002; - - private_pp.private_display = &private_display; - LIST_INITHEAD(&private_pp.pending_buffer_list); - LIST_INITHEAD(&private_pp.buffer_list); - - LIST_ADD(&pp_buffer_1.link, &private_pp.pending_buffer_list); - LIST_ADD(&pp_buffer_2.link, &private_pp.pending_buffer_list); - - error = tdm_pp_attach(&private_pp, &src, &dst); - - ASSERT_EQ(TDM_ERROR_BAD_REQUEST, error); -} - -TEST(tdm_pp_attach, error_pp_attach_is_not_implemented) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_pp private_pp; - tdm_private_display private_display; - struct _tbm_surface src; - struct _tbm_surface dst; - - _init_test(); - - private_display.func_pp.pp_attach = NULL; - - private_pp.private_display = &private_display; - - error = tdm_pp_attach(&private_pp, &src, &dst); - - ASSERT_EQ(TDM_ERROR_NOT_IMPLEMENTED, error); -} - -TEST(tdm_pp_attach, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_private_pp private_pp; - tdm_private_display private_display; - tdm_backend_module module; - struct _tbm_surface src; - struct _tbm_surface dst; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - LIST_ADDTAIL(&private_pp.link, &private_display.pp_list); - private_display.module_data = &module; - private_display.func_pp.pp_attach = stub_pp_attach; - private_display.caps_pp.max_attach_count = 3; - module.abi_version = 0x00010002; - - private_pp.private_display = &private_display; - LIST_INITHEAD(&private_pp.pending_buffer_list); - LIST_INITHEAD(&private_pp.buffer_list); - tdm_debug_dump = TDM_DUMP_FLAG_PP; - tdm_debug_module = TDM_DEBUG_BUFFER; - - error = tdm_pp_attach(&private_pp, &src, &dst); - - ASSERT_EQ(TDM_ERROR_NONE, error); - int num_of_pp_buff = LIST_LENGTH(&private_pp.pending_buffer_list); - ASSERT_EQ(1, num_of_pp_buff); -} - -TEST(tdm_pp_attach, null_ptr_fail_3) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_pp pp; - tdm_private_display private_display; - struct _tbm_surface src; - - _init_test(); - - pp.private_display = &private_display; - - error = tdm_pp_attach(&pp, &src, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_attach, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_pp pp; - tdm_private_display private_display; - struct _tbm_surface dst; - - _init_test(); - - pp.private_display = &private_display; - - error = tdm_pp_attach(&pp, NULL, &dst); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_attach, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - struct _tbm_surface src; - struct _tbm_surface dst; - - _init_test(); - - error = tdm_pp_attach(NULL, &src, &dst); - - ASSERT_EQ(error, expected_error); -} - -/* tdm_pp_set_info */ - -TEST(tdm_pp_set_info, work_flow_success_3) -{ - tdm_error error = TDM_ERROR_OPERATION_FAILED; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_info_pp info; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_set_info = pp_set_info; - - error = tdm_pp_set_info(&pp, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_set_info, work_flow_success_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error not_expected_error = TDM_ERROR_NONE; - tdm_info_pp info; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_set_info = pp_set_info; - PP_SET_INFO_ERROR = 1; - - error = tdm_pp_set_info(&pp, &info); - - ASSERT_NE(error, not_expected_error); -} - -TEST(tdm_pp_set_info, work_flow_success_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_NOT_IMPLEMENTED; - tdm_info_pp info; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_set_info = NULL; - - error = tdm_pp_set_info(&pp, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_set_info, null_ptr_fail_2) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - - error = tdm_pp_set_info(&pp, NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_set_info, null_ptr_fail_1) -{ - tdm_error error = TDM_ERROR_NONE; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_info_pp info; - - _init_test(); - - error = tdm_pp_set_info(NULL, &info); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_pp_set_done_handler, work_flow_success_1) -{ - tdm_error error; - tdm_private_pp pp; - tdm_private_display private_display; - int user_data = 0; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_set_info = NULL; - - error = tdm_pp_set_done_handler(&pp, stub_tdm_pp_done_handler, &user_data); - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_EQ(stub_tdm_pp_done_handler, pp.done_func); - ASSERT_EQ(&user_data, pp.done_user_data); - - error = tdm_pp_set_done_handler(&pp, stub_tdm_pp_done_handler, NULL); - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_EQ(stub_tdm_pp_done_handler, pp.done_func); - ASSERT_EQ(0, pp.done_user_data); -} - -TEST(tdm_pp_set_done_handler, work_flow_error_1___NULL) -{ - tdm_error error; - tdm_private_pp pp; - tdm_private_display private_display; - - _init_test(); - - pp.private_display = &private_display; - private_display.func_pp.pp_set_info = NULL; - - error = tdm_pp_set_done_handler(&pp, NULL, NULL); - ASSERT_NE(TDM_ERROR_NONE, error); - - error = tdm_pp_set_done_handler(NULL, stub_tdm_pp_done_handler, NULL); - ASSERT_NE(TDM_ERROR_NONE, error); -} - -TEST(tdm_pp_destroy, work_flow_success_1) -{ - tdm_private_pp *private_pp; - tdm_pp_private_buffer *pp_buffer1; - tdm_pp_private_buffer *pp_buffer2; - tdm_private_display private_display; - private_pp = (tdm_private_pp *)calloc(1, sizeof(tdm_private_pp)); - pp_buffer1 = (tdm_pp_private_buffer *)calloc(1, sizeof *pp_buffer1); - pp_buffer2 = (tdm_pp_private_buffer *)calloc(1, sizeof *pp_buffer2); - - private_display.func_pp.pp_destroy = stub_pp_destroy; - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - private_display.func_pp.pp_destroy = stub_pp_destroy; - LIST_ADDTAIL(&private_pp->link, &private_display.pp_list); - - - private_pp->private_display = &private_display; - LIST_INITHEAD(&private_pp->pending_buffer_list); - LIST_ADDTAIL(&pp_buffer1->link, &private_pp->pending_buffer_list); - - LIST_INITHEAD(&private_pp->buffer_list); - LIST_ADDTAIL(&pp_buffer2->link, &private_pp->buffer_list); - - tdm_pp_destroy(private_pp); - - ASSERT_EQ(4, stub_tdm_buffer_unref_backend_count); - ASSERT_EQ(3, stub_free_call_count); - ASSERT_TRUE(stub_pp_destroy_is_called); -} - -TEST(tdm_pp_destroy, work_flow_error_1___NULL) -{ - tdm_pp_destroy(NULL); -} - -/* tdm_pp_create_internal() */ - -TEST(tdm_pp_create_internal, work_flow_success_1) -{ - tdm_error error; - tdm_private_display private_display; - tdm_private_pp *private_pp_ret; - tdm_private_pp private_pp; - - _init_test(); - - stub_tdm_helper_get_time_ret_val = 1.1; - - private_display.func_pp.pp_destroy = stub_pp_destroy; - private_display.func_pp.pp_set_done_handler = stub_pp_set_done_handler; - private_display.func_display.display_create_pp = stub_display_create_pp; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - LIST_INITHEAD(&private_display.pp_list); - - private_pp.stamp = stub_tdm_helper_get_time_ret_val; - - LIST_ADD(&private_pp.link, &private_display.pp_list); - - private_pp_ret = tdm_pp_create_internal(&private_display, &error); - - ASSERT_EQ(TDM_ERROR_NONE, error); - ASSERT_TRUE(stub_pp_set_done_handler_is_called); - ASSERT_TRUE(stub_display_create_pp_is_called); - ASSERT_TRUE(private_pp_ret != NULL); -} - -TEST(tdm_pp_create_internal, work_flow_error_1___TDM_DISPLAY_CAPABILITY_PP_is_not_set) -{ - tdm_error error; - tdm_private_display private_display; - tdm_private_pp *private_pp; - - _init_test(); - - private_display.func_pp.pp_destroy = stub_pp_destroy; - private_display.func_pp.pp_set_done_handler = stub_pp_set_done_handler; - private_display.func_display.display_create_pp = stub_display_create_pp; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - LIST_INITHEAD(&private_display.pp_list); - - - private_display.capabilities = (tdm_display_capability)0; - - private_pp = tdm_pp_create_internal(&private_display, &error); - ASSERT_NE(TDM_ERROR_NONE, error); - ASSERT_TRUE(private_pp == NULL); -} - -TEST(tdm_pp_create_internal, work_flow_error_1___calloc_error) -{ - tdm_error error; - tdm_private_display private_display; - tdm_private_pp *private_pp; - - _init_test(); - - private_display.func_pp.pp_destroy = stub_pp_destroy; - private_display.func_pp.pp_set_done_handler = stub_pp_set_done_handler; - private_display.func_display.display_create_pp = stub_display_create_pp; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - LIST_INITHEAD(&private_display.pp_list); - - CALLOC_ERROR = 1; - - private_pp = tdm_pp_create_internal(&private_display, &error); - ASSERT_NE(TDM_ERROR_NONE, error); - ASSERT_TRUE(private_pp == NULL); -} - -TEST(tdm_pp_create_internal, work_flow_error_1___create_pp_error) -{ - tdm_error error; - tdm_private_display private_display; - tdm_private_pp *private_pp; - - _init_test(); - - stub_display_create_pp_error = 1; - private_display.func_display.display_create_pp = stub_display_create_pp; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - - private_pp = tdm_pp_create_internal(&private_display, &error); - ASSERT_NE(TDM_ERROR_NONE, error); - ASSERT_TRUE(private_pp == NULL); -} - -TEST(tdm_pp_create_internal, work_flow_error_1___set_done_handler_error) -{ - tdm_error error; - tdm_private_display private_display; - tdm_private_pp *private_pp; - - _init_test(); - - stub_pp_set_done_handler_error = 1; - - private_display.func_pp.pp_destroy = stub_pp_destroy; - private_display.func_pp.pp_set_done_handler = stub_pp_set_done_handler; - private_display.func_display.display_create_pp = stub_display_create_pp; - private_display.capabilities = TDM_DISPLAY_CAPABILITY_PP; - LIST_INITHEAD(&private_display.pp_list); - - private_pp = tdm_pp_create_internal(&private_display, &error); - ASSERT_NE(TDM_ERROR_NONE, error); - ASSERT_TRUE(private_pp == NULL); -} - -/* tdm_pp_cb_done() */ - -TEST(tdm_pp_cb_done, success_not_in_display_thread) -{ - tdm_private_pp private_pp; - struct _tbm_surface src, dst; - tdm_thread_cb_pp_done *pp_done; - - _init_test(); - - stub_syscall_return_value = 100; - private_pp.owner_tid = stub_syscall_return_value + 1; - private_pp.stamp = 200.05; - - tdm_pp_cb_done(&private_pp, &src, &dst, &private_pp); - - pp_done = (tdm_thread_cb_pp_done *)stub_tdm_thread_send_cb_buff; - - ASSERT_EQ(pp_done->base.type, TDM_THREAD_CB_PP_DONE); - ASSERT_EQ(pp_done->base.length, sizeof * pp_done); - ASSERT_DOUBLE_EQ(pp_done->pp_stamp, private_pp.stamp); - ASSERT_TRUE(pp_done->src == &src); - ASSERT_TRUE(pp_done->dst == &dst); - ASSERT_TRUE(pp_done->user_data == &private_pp); -} - -//TEST(tdm_pp_cb_done, success_in_display_thread) -//{ -// tdm_private_pp private_pp; -// struct _tbm_surface src, dst; -// tdm_pp_private_buffer *pp_buffer_1; -// tdm_pp_private_buffer *pp_buffer_2; -// -// _init_test(); -// -// stub_syscall_return_value = 100; -// stub_syscall_reset = 1; -// private_pp.owner_tid = stub_syscall_return_value; -// -// pp_buffer_1 = (tdm_pp_private_buffer *)calloc(1, sizeof (tdm_pp_private_buffer)); -// pp_buffer_2 = (tdm_pp_private_buffer *)calloc(1, sizeof (tdm_pp_private_buffer)); -// pp_buffer_1->src = &src; -// pp_buffer_1->dst = &dst; -// private_pp.done_func = stub_tdm_pp_done_handler; -// -// LIST_INITHEAD(&private_pp.buffer_list); -// LIST_ADD(&pp_buffer_1->link, &private_pp.buffer_list); -// LIST_ADD(&pp_buffer_2->link, &private_pp.buffer_list); -// -// tdm_pp_cb_done(&private_pp, &src, &dst, &private_pp); -// -// ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2); -// ASSERT_EQ(FREE_CALLED, 1); -// ASSERT_EQ(stub_tdm_pp_done_handler_is_called, 1); -// free(pp_buffer_2); -//} - -/* tdm_pp_find_stamp() */ - -TEST(tdm_pp_find_stamp, success_pp_list_is_empty) -{ - tdm_private_pp *private_pp_ret; - tdm_private_display private_display; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - - private_pp_ret = tdm_pp_find_stamp(&private_display, 0.5); - - ASSERT_TRUE(private_pp_ret == NULL); -} + void TearDown(void) + { + tdm_display_deinit(dpy); + dpy = NULL; + } +}; -TEST(tdm_pp_find_stamp, success_pp_find_stamp) +TEST_F(TDMPP, DisplayGetPPAvailableFormatsSuccessful) { - tdm_private_pp *private_pp_ret; - tdm_private_display private_display; - tdm_private_pp private_pp; - double stamp = 12.25; - - _init_test(); - - LIST_INITHEAD(&private_display.pp_list); - LIST_ADD(&private_pp.link, &private_display.pp_list); - - private_pp.stamp = stamp; - - private_pp_ret = tdm_pp_find_stamp(&private_display, stamp); - - ASSERT_TRUE(private_pp_ret == &private_pp); + CHECK_FLAG(has_pp); + const tbm_format * formats = NULL; + int count = -42; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count)); + ASSERT_FALSE(-42 == count); + ASSERT_FALSE(NULL == formats); } diff --git a/utests/src/ut_tdm_thread.cpp b/utests/src/ut_tdm_thread.cpp deleted file mode 100644 index 76f69d0..0000000 --- a/utests/src/ut_tdm_thread.cpp +++ /dev/null @@ -1,824 +0,0 @@ -/************************************************************************** - * - * 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 "tbm_stubs.h" -#include "stub_pthread.h" -#include "stub_stdlib.h" -#include "stub_unistd.h" -#include "stub_tdm.h" -#include "stub_tdm_display.h" -#include "stub_tdm_pp.h" -#include "stub_tdm_capture.h" -#include "stub_tdm_vblank.h" - -#include "tdm_thread.c" - -static void _init_test() -{ - keep_private_thread = NULL; - tdm_mutex_locked = 0; - - stub_pthread_init(); - stub_stdlib_init(); - stub_unistd_init(); - stub_tdm_display_init(); - stub_tdm_pp_init(); - tdm_debug_module = TDM_DEBUG_THREAD; -} - -/* UNIT TESTS */ - -/* tdm_thread_init */ - -TEST(tdm_thread_init, error_mutex_is_not_locked) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - - _init_test(); - - keep_private_thread = &private_thread; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, error_dpy_is_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - tdm_mutex_locked = 1; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, error_dpy_private_loop_is_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_private_display private_display; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, success_private_thread_is_not_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - tdm_private_thread private_thread; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - private_loop.private_thread = &private_thread; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, success_getenv_return_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - - stub_getenv_name = "TDM_THREAD"; - stub_getenv_return_value = NULL; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, success_getenv_return_0) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - - stub_getenv_name = "TDM_THREAD"; - stub_getenv_return_value = "0"; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, error_calloc_return_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - - stub_getenv_name = "TDM_THREAD"; - stub_getenv_return_value = "1"; - CALLOC_ERROR = 1; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, error_pipe_return_error) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - - stub_getenv_name = "TDM_THREAD"; - stub_getenv_return_value = "1"; - - stub_pipe_error = 1; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_init, success_init) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_display private_display; - tdm_private_loop dpy_private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - memset(&dpy_private_loop, 0, sizeof(tdm_private_loop)); - memset(&private_display, 0, sizeof(tdm_private_display)); - - tdm_mutex_locked = 1; - private_loop.dpy = &private_display; - private_display.private_loop = &dpy_private_loop; - - stub_getenv_name = "TDM_THREAD"; - stub_getenv_return_value = "1"; - stub_syscall_return_value = 10; - - error = tdm_thread_init(&private_loop); - - ASSERT_EQ(error, expected_error); - 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); - free(private_loop.private_thread); -} - -/* tdm_thread_deinit */ - -TEST(tdm_thread_deinit, error_mutex_is_not_locked) -{ - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - private_loop.private_thread = calloc(1, sizeof(tdm_private_thread)); - - keep_private_thread = private_loop.private_thread; - - tdm_thread_deinit(&private_loop); - - ASSERT_TRUE(keep_private_thread != NULL); -} - -TEST(tdm_thread_deinit, error_private_thread_is_null) -{ - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - keep_private_thread = calloc(1, sizeof(tdm_private_thread)); - - tdm_thread_deinit(&private_loop); - - ASSERT_TRUE(keep_private_thread != NULL); -} - -TEST(tdm_thread_deinit, success_deinit) -{ - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - tdm_mutex_locked = 1; - - private_loop.private_thread = calloc(1, sizeof(tdm_private_thread)); - - private_loop.private_thread->pipe[0] = 1; - private_loop.private_thread->pipe[1] = 2; - - keep_private_thread = private_loop.private_thread; - - tdm_thread_deinit(&private_loop); - - ASSERT_TRUE(keep_private_thread == NULL); - ASSERT_EQ(FREE_CALLED, 1); - ASSERT_EQ(stub_unistd_closed_fds[1], 1); - ASSERT_EQ(stub_unistd_closed_fds[2], 1); - ASSERT_TRUE(private_loop.private_thread == NULL); -} - -/* tdm_thread_get_fd */ - -TEST(tdm_thread_get_fd, error_mutex_is_not_locked) -{ - int ret; - int expected_ret = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - - _init_test(); - - keep_private_thread = &private_thread; - - ret = tdm_thread_get_fd(&private_loop); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_get_fd, error_private_loop_is_null) -{ - int ret; - int expected_ret = -1; - - _init_test(); - - tdm_mutex_locked = 1; - - ret = tdm_thread_get_fd(NULL); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_get_fd, error_private_thread_is_null) -{ - int ret; - int expected_ret = -1; - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - ret = tdm_thread_get_fd(&private_loop); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_get_fd, success_get_fd) -{ - int ret; - int expected_ret; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - private_thread.pipe[0] = 15; - - expected_ret = private_thread.pipe[0]; - - ret = tdm_thread_get_fd(&private_loop); - - ASSERT_EQ(ret, expected_ret); -} - -/* tdm_thread_send_cb */ - -TEST(tdm_thread_send_cb, error_mutex_is_not_locked) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_thread_cb_base base; - tdm_private_thread private_thread; - - _init_test(); - - keep_private_thread = &private_thread; - - ret = tdm_thread_send_cb(&private_loop, &base); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_send_cb, error_base_is_null) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER; - tdm_private_loop private_loop; - - _init_test(); - - ret = tdm_thread_send_cb(&private_loop, NULL); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_send_cb, error_private_loop_is_null) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER; - tdm_thread_cb_base base; - - _init_test(); - - ret = tdm_thread_send_cb(NULL, &base); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_send_cb, error_private_thread_is_null) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER; - tdm_private_loop private_loop; - tdm_thread_cb_base base; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - ret = tdm_thread_send_cb(&private_loop, &base); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_send_cb, error_write_error) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_thread_cb_base base; - tdm_private_thread private_thread; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - base.length = 256; - - stub_write_error = 1; - - ret = tdm_thread_send_cb(&private_loop, &base); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_send_cb, success_send_cb) -{ - tdm_error ret; - tdm_error expected_ret = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_thread_cb_base base; - tdm_private_thread private_thread; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - base.length = 256; - - ret = tdm_thread_send_cb(&private_loop, &base); - - ASSERT_EQ(ret, expected_ret); -} - -/* tdm_thread_handle_cb */ - -TEST(tdm_thread_handle_cb, error_private_loop_is_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - - error = tdm_thread_handle_cb(NULL); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_handle_cb, error_private_thread_is_null) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER; - tdm_private_loop private_loop; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_handle_cb, success_read_0_bytes) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_handle_cb, error_partial_reading) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_OPERATION_FAILED; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_base base; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&base; - base.length = sizeof(tdm_thread_cb_base); - - stub_read_returned_size = sizeof(tdm_thread_cb_base) - 1; - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_output_commit) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_output_commit cb_output_commit; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_output_commit; - cb_output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT; - cb_output_commit.base.length = sizeof(tdm_thread_cb_output_commit); - - stub_read_returned_size = sizeof(tdm_thread_cb_output_commit); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_output_cb_commit_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_output_vblank) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_output_vblank cb_output_vblank; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_output_vblank; - cb_output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK; - cb_output_vblank.base.length = sizeof(tdm_thread_cb_output_vblank); - - stub_read_returned_size = sizeof(tdm_thread_cb_output_vblank); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_output_cb_vblank_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_output_status) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_output_status cb_output_status; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_output_status; - cb_output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS; - cb_output_status.base.length = sizeof(tdm_thread_cb_output_status); - - stub_read_returned_size = sizeof(tdm_thread_cb_output_status); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_output_cb_status_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_output_dpms) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_output_dpms cb_output_dpms; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_output_dpms; - cb_output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS; - cb_output_dpms.base.length = sizeof(tdm_thread_cb_output_dpms); - - stub_read_returned_size = sizeof(tdm_thread_cb_output_dpms); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_output_cb_dpms_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_pp_done) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_pp_done cb_pp_done; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_pp_done; - cb_pp_done.base.type = TDM_THREAD_CB_PP_DONE; - cb_pp_done.base.length = sizeof(tdm_thread_cb_pp_done); - - stub_read_returned_size = sizeof(tdm_thread_cb_pp_done); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_pp_cb_done_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_capture_done) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_capture_done cb_capture_done; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_capture_done; - cb_capture_done.base.type = TDM_THREAD_CB_CAPTURE_DONE; - cb_capture_done.base.length = sizeof(tdm_thread_cb_capture_done); - - stub_read_returned_size = sizeof(tdm_thread_cb_capture_done); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_capture_cb_done_called, 1); -} - -TEST(tdm_thread_handle_cb, success_case_thread_cb_vblank_sw) -{ - tdm_error error; - tdm_error expected_error = TDM_ERROR_NONE; - tdm_private_loop private_loop; - tdm_private_thread private_thread; - tdm_thread_cb_vblank_sw cb_vblank_sw; - - _init_test(); - - memset(&private_loop, 0, sizeof(tdm_private_loop)); - private_loop.private_thread = &private_thread; - - stub_read_buf = (void *)&cb_vblank_sw; - cb_vblank_sw.base.type = TDM_THREAD_CB_VBLANK_SW; - cb_vblank_sw.base.length = sizeof(tdm_thread_cb_vblank_sw); - - stub_read_returned_size = sizeof(tdm_thread_cb_vblank_sw); - - error = tdm_thread_handle_cb(&private_loop); - - ASSERT_EQ(error, expected_error); - ASSERT_EQ(stub_tdm_vblank_cb_vblank_SW_called, 1); -} - -/* tdm_thread_in_display_thread */ - -TEST(tdm_thread_in_display_thread, success_keep_private_thread_is_null) -{ - int ret; - int expected_ret = 1; - pid_t tid; - - _init_test(); - - ret = tdm_thread_in_display_thread(tid); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_in_display_thread, success_in_display_thread) -{ - int ret; - int expected_ret = 1; - pid_t tid = 20; - static tdm_private_thread private_thread; - - _init_test(); - - private_thread.display_tid = tid; - keep_private_thread = &private_thread; - - ret = tdm_thread_in_display_thread(tid); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_in_display_thread, success_no_in_display_thread) -{ - int ret; - int expected_ret = 0; - pid_t tid = 20; - static tdm_private_thread private_thread; - - _init_test(); - - private_thread.display_tid = tid + 1; - keep_private_thread = &private_thread; - - ret = tdm_thread_in_display_thread(tid); - - ASSERT_EQ(ret, expected_ret); -} - -/* tdm_thread_is_running */ - -TEST(tdm_thread_is_running, success_no_is_running) -{ - int ret; - int expected_ret = 0; - - _init_test(); - - ret = tdm_thread_is_running(); - - ASSERT_EQ(ret, expected_ret); -} - -TEST(tdm_thread_is_running, success_is_running) -{ - int ret; - int expected_ret = 1; - static tdm_private_thread private_thread; - - _init_test(); - - keep_private_thread = &private_thread; - - ret = tdm_thread_is_running(); - - ASSERT_EQ(ret, expected_ret); -} diff --git a/utests/src/ut_tdm_vblank.cpp b/utests/src/ut_tdm_vblank.cpp deleted file mode 100644 index 9783ff1..0000000 --- a/utests/src/ut_tdm_vblank.cpp +++ /dev/null @@ -1,890 +0,0 @@ -/************************************************************************** - * - * 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 - -extern "C" const char* -tdm_server_get_client_name(pid_t pid) -{ - (void)pid; - return NULL; -} - -#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(); - - tdm_vblank_get_enable_fake(NULL, &enable_fake); - - 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; - - tdm_vblank_get_enable_fake(&vblank, &enable_fake); - - 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/utests/stubs/stub_backend.cpp b/utests/stubs/stub_backend.cpp deleted file mode 100644 index 5c78afa..0000000 --- a/utests/stubs/stub_backend.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include "stub_backend.h" -#include - -int OUTPUT_CREATE_CAPTURE_ERROR; -int CAPTURE_SET_DONE_HANDLER_ERROR; -int LAYER_CREATE_CAPTURE_ERROR; -int CAPTURE_SET_INFO_ERROR; -int CAPTURE_ATTACH_ERROR; -int CAPTURE_COMMIT_ERROR; -int OUTPUT_SET_PROPERTY_ERROR; -int OUTPUT_GET_PROPERTY_ERROR; -int OUTPUT_WAIT_VBLANK_ERROR; -int OUTPUT_SET_VBLANK_HANDLER; -int OUTPUT_COMMIT_ERROR; -int OUTPUT_SET_COMMIT_HANDLER; -int OUTPUT_SET_MODE_ERROR; -int OUTPUT_SET_DPMS_ERROR; -int OUTPUT_GET_DPMS_ERROR; -int LAYER_SET_PROPERTY_ERROR; -int LAYER_GET_PROPERTY_ERROR; -int LAYER_SET_INFO_ERROR; -int LAYER_SET_BUFFER_ERROR; -int LAYER_UNSET_BUFFER_ERROR; -int LAYER_SET_VIDEO_POS_ERROR; -int PP_SET_INFO_ERROR; -int PP_COMMIT_ERROR; -unsigned int layer_get_buffer_flags_ret; -int capture_destroy_is_called; - -void stub_backend_init() -{ - OUTPUT_CREATE_CAPTURE_ERROR = 0; - CAPTURE_SET_DONE_HANDLER_ERROR = 0; - LAYER_CREATE_CAPTURE_ERROR = 0; - CAPTURE_SET_INFO_ERROR = 0; - CAPTURE_ATTACH_ERROR = 0; - CAPTURE_COMMIT_ERROR = 0; - OUTPUT_SET_PROPERTY_ERROR = 0; - OUTPUT_GET_PROPERTY_ERROR = 0; - OUTPUT_WAIT_VBLANK_ERROR = 0; - OUTPUT_SET_VBLANK_HANDLER = 0; - OUTPUT_COMMIT_ERROR = 0; - OUTPUT_SET_COMMIT_HANDLER = 0; - OUTPUT_SET_MODE_ERROR = 0; - OUTPUT_SET_DPMS_ERROR = 0; - OUTPUT_GET_DPMS_ERROR = 0; - LAYER_SET_PROPERTY_ERROR = 0; - LAYER_GET_PROPERTY_ERROR = 0; - LAYER_SET_INFO_ERROR = 0; - LAYER_SET_BUFFER_ERROR = 0; - LAYER_UNSET_BUFFER_ERROR = 0; - LAYER_SET_VIDEO_POS_ERROR = 0; - PP_SET_INFO_ERROR = 0; - PP_COMMIT_ERROR = 0; - layer_get_buffer_flags_ret = 20; - capture_destroy_is_called = 0; -} - -tdm_capture *output_create_capture(tdm_output *output, tdm_error *error) -{ - (void)output; - (void)error; - - if (OUTPUT_CREATE_CAPTURE_ERROR) { - *error = TDM_ERROR_OPERATION_FAILED; - return NULL; - } - - *error = TDM_ERROR_NONE; - - return NULL; -} - -void capture_destroy(tdm_capture *capture) -{ - (void)capture; - - capture_destroy_is_called = 1; -} - -tdm_error capture_set_done_handler(tdm_capture *capture, - tdm_capture_done_handler func, void *user_data) -{ - (void)capture; - (void)func; - (void)user_data; - - if (CAPTURE_SET_DONE_HANDLER_ERROR) { - if (user_data) { - free(user_data); - } - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_capture *layer_create_capture(tdm_layer *layer, tdm_error *error) -{ - (void)layer; - (void)error; - - if (LAYER_CREATE_CAPTURE_ERROR) { - *error = TDM_ERROR_OPERATION_FAILED; - return NULL; - } - - *error = TDM_ERROR_NONE; - return NULL; -} - -tdm_error capture_set_info(tdm_capture *capture, tdm_info_capture *info) -{ - (void)capture; - (void)info; - - if (CAPTURE_SET_INFO_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error capture_commit(tdm_capture *capture) -{ - (void)capture; - - if (CAPTURE_COMMIT_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_property(tdm_output *output, unsigned int id, - tdm_value value) -{ - (void)output; - (void)id; - (void)value; - - if (OUTPUT_SET_PROPERTY_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_get_property(tdm_output *output, unsigned int id, - tdm_value *value) -{ - (void)output; - (void)id; - (void)value; - - if (OUTPUT_GET_PROPERTY_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_wait_vblank(tdm_output *output, int interval, int sync, - void *user_data) -{ - (void)output; - (void)interval; - (void)sync; - (void)user_data; - - free(user_data); - if (OUTPUT_WAIT_VBLANK_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_vblank_handler(tdm_output *output, - tdm_output_vblank_handler func) -{ - (void)output; - (void)func; - - if (OUTPUT_SET_VBLANK_HANDLER) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_commit(tdm_output *output, int sync, void *user_data) -{ - (void)output; - (void)sync; - - free(user_data); - if (OUTPUT_COMMIT_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_commit_handler(tdm_output *output, - tdm_output_commit_handler func) -{ - (void)output; - (void)func; - - if (OUTPUT_SET_COMMIT_HANDLER) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_mode(tdm_output *output, const tdm_output_mode *mode) -{ - (void)output; - (void)mode; - - if (OUTPUT_SET_MODE_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value) -{ - (void)output; - (void)dpms_value; - - if (OUTPUT_SET_DPMS_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value) -{ - (void)output; - (void)dpms_value; - - if (OUTPUT_GET_DPMS_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_set_property(tdm_layer *layer, unsigned int id, - tdm_value value) -{ - (void)layer; - (void)id; - (void)value; - - if (LAYER_SET_PROPERTY_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_get_property(tdm_layer *layer, unsigned int id, - tdm_value *value) -{ - (void)layer; - (void)id; - (void)value; - - if (LAYER_GET_PROPERTY_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_set_info(tdm_layer *layer, tdm_info_layer *info) -{ - (void)layer; - (void)info; - - if (LAYER_SET_INFO_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) -{ - (void)layer; - (void)buffer; - - if (LAYER_SET_BUFFER_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_unset_buffer(tdm_layer *layer) -{ - (void)layer; - - if (LAYER_UNSET_BUFFER_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error layer_set_video_pos(tdm_layer *layer, int zpos) -{ - (void)layer; - (void)zpos; - - if (LAYER_SET_VIDEO_POS_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info) -{ - (void)pp; - (void)info; - - if (PP_SET_INFO_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error pp_commit(tdm_pp *pp) -{ - (void)pp; - - if (PP_COMMIT_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - return TDM_ERROR_NONE; -} - -tdm_error output_set_dpms_handler(tdm_output *output, - tdm_output_dpms_handler func, - void *user_data) -{ - return TDM_ERROR_NONE; -} - -tdm_error layer_get_buffer_flags(tdm_layer *layer, unsigned int *flags) -{ - (void)layer; - - *flags = layer_get_buffer_flags_ret; - - return TDM_ERROR_NONE; -} - -tdm_error capture_attach(tdm_capture *capture, tbm_surface_h buffer) -{ - (void)capture; - (void)buffer; - - if (CAPTURE_ATTACH_ERROR) - return TDM_ERROR_OPERATION_FAILED; - - return TDM_ERROR_NONE; -} diff --git a/utests/stubs/stub_backend.h b/utests/stubs/stub_backend.h deleted file mode 100644 index a9c30d9..0000000 --- a/utests/stubs/stub_backend.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef _TDM_BACKEND_STUBS_H -#define _TDM_BACKEND_STUBS_H - -#include "tdm_types.h" - -#include "tdm_backend.h" - -extern int OUTPUT_CREATE_CAPTURE_ERROR; -extern int CAPTURE_SET_DONE_HANDLER_ERROR; -extern int LAYER_CREATE_CAPTURE_ERROR; -extern int CAPTURE_SET_INFO_ERROR; -extern int CAPTURE_ATTACH_ERROR; -extern int CAPTURE_COMMIT_ERROR; -extern int OUTPUT_SET_PROPERTY_ERROR; -extern int OUTPUT_GET_PROPERTY_ERROR; -extern int OUTPUT_WAIT_VBLANK_ERROR; -extern int OUTPUT_SET_VBLANK_HANDLER; -extern int OUTPUT_COMMIT_ERROR; -extern int OUTPUT_SET_COMMIT_HANDLER; -extern int OUTPUT_SET_MODE_ERROR; -extern int OUTPUT_SET_DPMS_ERROR; -extern int OUTPUT_GET_DPMS_ERROR; -extern int LAYER_SET_PROPERTY_ERROR; -extern int LAYER_GET_PROPERTY_ERROR; -extern int LAYER_SET_INFO_ERROR; -extern int LAYER_SET_BUFFER_ERROR; -extern int LAYER_UNSET_BUFFER_ERROR; -extern int LAYER_SET_VIDEO_POS_ERROR; -extern int PP_SET_INFO_ERROR; -extern int PP_COMMIT_ERROR; -extern unsigned int layer_get_buffer_flags_ret; -extern int capture_destroy_is_called; - -void stub_backend_init(); - -tdm_capture *output_create_capture(tdm_output *output, tdm_error *error); - -void capture_destroy(tdm_capture *capture); - -tdm_error capture_set_done_handler(tdm_capture *capture, - tdm_capture_done_handler func, void *user_data); - -tdm_capture *layer_create_capture(tdm_layer *layer, tdm_error *error); - -tdm_error capture_set_info(tdm_capture *capture, tdm_info_capture *info); -tdm_error capture_commit(tdm_capture *capture); - -tdm_error output_set_property(tdm_output *output, unsigned int id, - tdm_value value); - -tdm_error output_get_property(tdm_output *output, unsigned int id, - tdm_value *value); - -tdm_error output_wait_vblank(tdm_output *output, int interval, int sync, - void *user_data); - -tdm_error output_set_vblank_handler(tdm_output *output, - tdm_output_vblank_handler func); - -tdm_error output_commit(tdm_output *output, int sync, void *user_data); - -tdm_error output_set_commit_handler(tdm_output *output, - tdm_output_commit_handler func); - -tdm_error output_set_mode(tdm_output *output, const tdm_output_mode *mode); - -tdm_error output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value); - -tdm_error output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value); - -tdm_error layer_set_property(tdm_layer *layer, unsigned int id, - tdm_value value); - -tdm_error layer_get_property(tdm_layer *layer, unsigned int id, - tdm_value *value); - -tdm_error layer_set_info(tdm_layer *layer, tdm_info_layer *info); - -tdm_error layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer); - -tdm_error layer_unset_buffer(tdm_layer *layer); - -tdm_error layer_set_video_pos(tdm_layer *layer, int zpos); - -tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info); - -tdm_error pp_commit(tdm_pp *pp); - -tdm_error output_set_dpms_handler(tdm_output *output, - tdm_output_dpms_handler func, - void *user_data); - -tdm_error layer_get_buffer_flags(tdm_layer *layer, unsigned int *flags); - -tdm_error capture_attach(tdm_capture *capture, tbm_surface_h buffer); - -#endif /* _TDM_CAPTURE_STUBS_H */ diff --git a/utests/stubs/stub_dlfcn.cpp b/utests/stubs/stub_dlfcn.cpp deleted file mode 100644 index 7d7d964..0000000 --- a/utests/stubs/stub_dlfcn.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#define STUB_DLFCN_IMPL -#include "stub_dlfcn.h" - -struct _dlfcn_stub_ctrl stub_dlfcn_ctrl; - -void stub_dlfcn_init() -{ - stub_dlfcn_ctrl.dlsym_returned_val = 0; - stub_dlfcn_ctrl.dlopen_returned_val = 0; -} - -void *stub_dlopen(const char *file, int mode) -{ - return stub_dlfcn_ctrl.dlopen_returned_val; -} - -int stub_dlclose(void * handle) -{ - return 0; -} - -void *stub_dlsym(void *handle, const char *name) -{ - return stub_dlfcn_ctrl.dlsym_returned_val; -} - diff --git a/utests/stubs/stub_dlfcn.h b/utests/stubs/stub_dlfcn.h deleted file mode 100644 index ef7a473..0000000 --- a/utests/stubs/stub_dlfcn.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _DLFCN_STUBS_H_ -#define _DLFCN_STUBS_H_ - -#include - -struct _dlfcn_stub_ctrl { - void* dlsym_returned_val; - void* dlopen_returned_val; -}; - -extern struct _dlfcn_stub_ctrl stub_dlfcn_ctrl; - -void stub_dlfcn_init(); - -void *stub_dlopen (const char * file, int mode); -int stub_dlclose (void * handle); -void *stub_dlsym (void * handle, const char *name); - -#ifndef STUB_DLFCN_IMPL - #define dlopen stub_dlopen - #define dlclose stub_dlclose - #define dlsym stub_dlsym -#endif - -#endif /* _DLFCN_STUBS_H_ */ diff --git a/utests/stubs/stub_fcntl.h b/utests/stubs/stub_fcntl.h deleted file mode 100644 index 55a0fdc..0000000 --- a/utests/stubs/stub_fcntl.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef STUB_FCNTL_H -#define STUB_FCNTL_H - -static int FCNTL_ERROR; - -static void stub_fcntl_init() -{ - FCNTL_ERROR = 0; -} - -static int stub_fcntl(int fd, int cmd, ...) -{ - (void)fd; - (void)cmd; - - if (FCNTL_ERROR) { - FCNTL_ERROR = 0; - return -1; - } - - return 0; -} - -#define fcntl stub_fcntl - -#endif // STUB_FCNTL_H diff --git a/utests/stubs/stub_pthread.cpp b/utests/stubs/stub_pthread.cpp deleted file mode 100644 index becaf96..0000000 --- a/utests/stubs/stub_pthread.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include - -int PTHREAD_MUTEX_INIT_ERROR; - -void stub_pthread_init() -{ - PTHREAD_MUTEX_INIT_ERROR = 0; -} - -int stub_pthread_mutex_lock(pthread_mutex_t * __mutex) -{ - (void)__mutex; - - return 0; -} - -int stub_pthread_mutex_unlock(pthread_mutex_t * __mutex) -{ - (void)__mutex; - - return 0; -} - -int stub_pthread_mutex_init(pthread_mutex_t * __mutex, - const pthread_mutexattr_t * __mutexattr) -{ - (void)__mutex; - (void)__mutexattr; - - if (PTHREAD_MUTEX_INIT_ERROR) { - return PTHREAD_MUTEX_INIT_ERROR; - } - - return 0; -} - -int stub_pthread_create(pthread_t *newthread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) -{ - (void)newthread; - (void)attr; - (void)start_routine; - (void)arg; - - return 0; -} - -int stub_pthread_join(pthread_t th, void **thread_return) -{ - (void)th; - (void)thread_return; - - return 0; -} - -int stub_pthread_cancel(pthread_t th) -{ - (void)th; - - return 0; -} diff --git a/utests/stubs/stub_pthread.h b/utests/stubs/stub_pthread.h deleted file mode 100644 index c5a9351..0000000 --- a/utests/stubs/stub_pthread.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _PTHREAD_STUBS_H -#define _PTHREAD_STUBS_H - -#include -#include - -extern int PTHREAD_MUTEX_INIT_ERROR; - -void stub_pthread_init(); - -int stub_pthread_mutex_lock(pthread_mutex_t * __mutex); - -int stub_pthread_mutex_unlock(pthread_mutex_t * __mutex); - -int stub_pthread_mutex_init(pthread_mutex_t * __mutex, - const pthread_mutexattr_t * __mutexattr); - -int stub_pthread_create(pthread_t *newthread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg); - -int stub_pthread_join(pthread_t th, void **thread_return); - -int stub_pthread_cancel (pthread_t th); - -#define pthread_mutex_lock stub_pthread_mutex_lock -#define pthread_mutex_init stub_pthread_mutex_init -#define pthread_mutex_unlock stub_pthread_mutex_unlock -#define pthread_create stub_pthread_create -#define pthread_join stub_pthread_join -#define pthread_cancel stub_pthread_cancel - -#endif /* _PTHREAD_STUBS_H */ diff --git a/utests/stubs/stub_stdio.h b/utests/stubs/stub_stdio.h deleted file mode 100644 index 8f3144c..0000000 --- a/utests/stubs/stub_stdio.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef STUB_STDIO_H -#define STUB_STDIO_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -static struct _open_close_stub_ctrl { - int fopen_fd_returned; - int fclose_error; - int fclose_colled; - int close_error; - int close_colled; -} open_close_stub_ctrl; - -static int SSCANF_ERROR; - -static void stub_stdio_init() -{ - SSCANF_ERROR = 0; - open_close_stub_ctrl.fopen_fd_returned = 1; - open_close_stub_ctrl.fclose_error = 0; - open_close_stub_ctrl.fclose_colled = 0; - open_close_stub_ctrl.close_error = 0; - open_close_stub_ctrl.close_colled = 0; -} - -static int stub_sscanf(const char *buf, const char *format, ...) -{ - (void)buf; - (void)format; - - if (SSCANF_ERROR) { - return -1; - } - - return 0; -} - -#ifndef O_RDWR -#define O_RDWR 02 /* copy from */ -#endif -#ifndef O_ -#define O_CLOEXEC 02000000 /* copy from */ -#endif - -static FILE *stub_fopen (const char *filename, const char *modes) -{ - if (filename == NULL) - return NULL; - static FILE f; - return &f; -} - -static int stub_fclose (FILE *__stream) -{ - if (open_close_stub_ctrl.fclose_error) - return -1; - if (__stream == NULL) - return -1; - - open_close_stub_ctrl.fclose_colled = 1; - return 1; -} - -static int stub_fflush (FILE *__stream) -{ - return 1; -} - -static int stub_fileno (FILE *__stream) -{ - return 1; -} - -static int stub_setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n) -{ - return 1; -} - -static size_t stub_fwrite (const void * ptr, size_t size, - size_t n, FILE *s) -{ - return size; -} - -#ifdef open - #undef open -#endif -#define fopen stub_fopen -#define fclose stub_fclose -#define fflush stub_fflush -#define fileno stub_fileno -#define setvbuf stub_setvbuf -#define sscanf stub_sscanf -#define fwrite stub_fwrite - -#ifdef __cplusplus -} -#endif - - -#endif // STUB_STDIO_H diff --git a/utests/stubs/stub_stdlib.cpp b/utests/stubs/stub_stdlib.cpp deleted file mode 100644 index 55405a7..0000000 --- a/utests/stubs/stub_stdlib.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#define STUB_STDLIB_IMPL - -#include "stub_stdlib.h" - -int CALLOC_ERROR; -int CALLOC_RETURN_BUFFER; -int FREE_CALLED; -int GETENV_ERROR; -int SETENV_ERROR; - -char *stub_getenv_return_value; -int stub_getenv_return_real_value; -int stub_setenv_real; -char *stub_getenv_name; -int stub_free_call_count; - -tdm_buffer_info buffer; - -void *stub_calloc(size_t nmemb, size_t size) -{ - if (CALLOC_ERROR) { - return NULL; - } - - if (CALLOC_RETURN_BUFFER) { - return &buffer; - } - - return calloc(nmemb, size); -} - -void stub_free(void *ptr) -{ - FREE_CALLED = 1; - stub_free_call_count++; - free(ptr); -} - -char *stub_getenv(const char *name) -{ - if (stub_getenv_return_real_value) - return getenv(name); - - if (GETENV_ERROR) { - return NULL; - } - - if(!stub_getenv_name || !name) { - return NULL; - } - - if (!strcmp(stub_getenv_name, name)) { - return stub_getenv_return_value; - } - - return NULL; -} - -int stub_setenv(const char *name, const char *value, int replace) -{ - if (stub_setenv_real) - return setenv(name, value, replace); - - if (SETENV_ERROR) - return 1; - - stub_getenv_name = name; - stub_getenv_return_value = value; - - return 0; -} - -void stub_stdlib_init() -{ - CALLOC_ERROR = 0; - CALLOC_RETURN_BUFFER = 0; - FREE_CALLED = 0; - GETENV_ERROR = 0; - stub_getenv_return_value = NULL; - stub_getenv_name = NULL; - stub_getenv_return_real_value = 0; - stub_free_call_count = 0; -} diff --git a/utests/stubs/stub_stdlib.h b/utests/stubs/stub_stdlib.h deleted file mode 100644 index e923976..0000000 --- a/utests/stubs/stub_stdlib.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _STDLIB_STUBS_H -#define _STDLIB_STUBS_H - -#include -#include "tdm.h" -#include "tdm_private.h" - -extern int CALLOC_ERROR; -extern int CALLOC_RETURN_BUFFER; -extern int FREE_CALLED; -extern int GETENV_ERROR; -extern int SETENV_ERROR; - -extern tdm_buffer_info buffer; -extern char *stub_getenv_return_value; -extern char *stub_getenv_name; -extern int stub_getenv_return_real_value; -extern int stub_free_call_count; - -void *stub_calloc(size_t nmemb, size_t size); - -void stub_free(void *ptr); - -char *stub_getenv(const char *name); -int stub_setenv (const char *name, const char *value, int replace); - -void stub_stdlib_init(); - -#ifndef STUB_STDLIB_IMPL -#define calloc stub_calloc -#define free stub_free -#define getenv stub_getenv -#define setenv stub_setenv -#endif - -#endif /* _STDLIB_STUBS_H */ diff --git a/utests/stubs/stub_tdm.h b/utests/stubs/stub_tdm.h deleted file mode 100644 index d30fd30..0000000 --- a/utests/stubs/stub_tdm.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef STUB_TDM_H -#define STUB_TDM_H - -#include - -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() -{ - 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* -stub_tdm_display_find_output_stamp(tdm_private_display *private_display, double stamp) -{ - (void)private_display; - (void)stamp; - - 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) -{ - (void)vblank; - (void)error; - (void)sequence; - (void)tv_sec; - (void)tv_usec; - (void)user_data; - - stub_tdm_vblank_handler_call_count++; -} - -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; -} - -static void -stub_tdm_output_change_handler_cb(tdm_output *output, - tdm_output_change_type type, - tdm_value value, - void *user_data) -{ - (void)output; - (void)type; - (void)value; - (void)user_data; - - stub_tdm_output_change_handler_count++; -} - -static void -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 - -#endif // STUB_TDM_H diff --git a/utests/stubs/stub_tdm_buffer.h b/utests/stubs/stub_tdm_buffer.h deleted file mode 100644 index 81d76ef..0000000 --- a/utests/stubs/stub_tdm_buffer.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef STUB_TDM_BUFFER_H -#define STUB_TDM_BUFFER_H - -static int stub_tdm_buffer_unref_backend_count; -static int stub_tdm_buffer_remove_release_handler_internal_count; - -static void stub_tdm_buffer_init() -{ - stub_tdm_buffer_unref_backend_count = 0; - stub_tdm_buffer_remove_release_handler_internal_count = 0; -} - -static tbm_surface_h stub_tdm_buffer_ref_backend(tbm_surface_h buffer) -{ - (void)buffer; - - return NULL; -} - -static void stub_tdm_buffer_unref_backend(tbm_surface_h buffer) -{ - (void)buffer; - - stub_tdm_buffer_unref_backend_count++; -} - -static void -stub_tdm_buffer_remove_release_handler_internal(tbm_surface_h buffer) -{ - stub_tdm_buffer_remove_release_handler_internal_count++; -} - -#define tdm_buffer_ref_backend stub_tdm_buffer_ref_backend -#define tdm_buffer_unref_backend stub_tdm_buffer_unref_backend -#define tdm_buffer_remove_release_handler_internal stub_tdm_buffer_remove_release_handler_internal - -#endif // STUB_TDM_BUFFER_H diff --git a/utests/stubs/stub_tdm_capture.h b/utests/stubs/stub_tdm_capture.h deleted file mode 100644 index f7bf741..0000000 --- a/utests/stubs/stub_tdm_capture.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef STUB_TDM_CAPTURE_H -#define STUB_TDM_CAPTURE_H - -#include "tdm.h" -#include "tdm_private.h" - -static tdm_private_capture private_capture; -static int TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR; -static int CAPTURE_CREATE_LAYER_INTERNAL_ERROR; -static int stub_tdm_capture_cb_done_called; - -static void stub_tdm_capture_init() -{ - stub_tdm_capture_cb_done_called = 0; - TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR = 0; - CAPTURE_CREATE_LAYER_INTERNAL_ERROR = 0; -} - -static void -stub_tdm_capture_cb_done(tdm_capture *capture_backend, tbm_surface_h buffer, - void *user_data) -{ - (void)capture_backend; - (void)buffer; - (void)user_data; - - stub_tdm_capture_cb_done_called = 1; -} - -static tdm_private_capture * -stub_tdm_capture_find_stamp(tdm_private_display *private_display, double stamp) -{ - (void)private_display; - (void)stamp; - - return &private_capture; -} - -static tdm_private_capture * -stub_tdm_capture_create_output_internal(tdm_private_output*private_output, - tdm_error *error) -{ - (void)private_output; - (void)error; - - if (TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR) { - *error = TDM_ERROR_OPERATION_FAILED; - return NULL; - } - - *error = TDM_ERROR_NONE; - return NULL; -} - -static tdm_private_capture * -stub_tdm_capture_create_layer_internal(tdm_private_layer *private_layer, - tdm_error *error) -{ - (void)private_layer; - (void)error; - - if (CAPTURE_CREATE_LAYER_INTERNAL_ERROR) { - *error = TDM_ERROR_OPERATION_FAILED; - return NULL; - } - - *error = TDM_ERROR_NONE; - return NULL; -} - -#define tdm_capture_cb_done stub_tdm_capture_cb_done -#define tdm_capture_find_stamp stub_tdm_capture_find_stamp -#define tdm_capture_create_output_internal stub_tdm_capture_create_output_internal -#define tdm_capture_create_layer_internal stub_tdm_capture_create_layer_internal - -#endif // STUB_TDM_CAPTURE_H diff --git a/utests/stubs/stub_tdm_display.h b/utests/stubs/stub_tdm_display.h deleted file mode 100644 index 00a1ec0..0000000 --- a/utests/stubs/stub_tdm_display.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef STUB_TDM_DISPLAY_H -#define STUB_TDM_DISPLAY_H - -#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_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() -{ - 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 -stub_tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence, - unsigned int tv_sec, unsigned int tv_usec, void *user_data) -{ - (void)output_backend; - (void)sequence; - (void)tv_sec; - (void)tv_usec; - (void)user_data; - - stub_tdm_output_cb_commit_called = 1; -} - -static void -stub_tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence, - unsigned int tv_sec, unsigned int tv_usec, void *user_data) -{ - (void)output_backend; - (void)sequence; - (void)tv_sec; - (void)tv_usec; - (void)user_data; - - stub_tdm_output_cb_vblank_called = 1; -} - -static void -stub_tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status, - void *user_data) -{ - (void)output_backend; - (void)status; - (void)user_data; - - stub_tdm_output_cb_status_called = 1; -} - -static void -stub_tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data) -{ - (void)output_backend; - (void)dpms; - (void)user_data; - - 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/utests/stubs/stub_tdm_event_loop.h b/utests/stubs/stub_tdm_event_loop.h deleted file mode 100644 index cfbd9c3..0000000 --- a/utests/stubs/stub_tdm_event_loop.h +++ /dev/null @@ -1,72 +0,0 @@ -#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 int stub_tdm_event_loop_add_timer_handler_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; - stub_tdm_event_loop_add_timer_handler_error = 0; -} - -static int stub_tdm_event_loop_get_fd(tdm_private_display *private_display) -{ - (void)private_display; - - return 1; -} - -static tdm_error stub_tdm_event_loop_dispatch(tdm_private_display *private_display) -{ - (void)private_display; - - if (TDM_EVENT_LOOP_DISPATCH_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - 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; -} - -static tdm_event_loop_source * -stub_tdm_event_loop_add_timer_handler(tdm_display *dpy, tdm_event_loop_timer_handler func, - void *user_data, tdm_error *error) -{ - if (stub_tdm_event_loop_add_timer_handler_error) - return NULL; - - return (tdm_event_loop_source *)56544545; -} - -#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 -#define tdm_event_loop_add_timer_handler stub_tdm_event_loop_add_timer_handler - -#endif // STUB_TDM_EVENT_LOOP_H diff --git a/utests/stubs/stub_tdm_helper.h b/utests/stubs/stub_tdm_helper.h deleted file mode 100644 index 3754019..0000000 --- a/utests/stubs/stub_tdm_helper.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef STUB_TDM_HELPER_H -#define STUB_TDM_HELPER_H - -#ifdef __cplusplus -extern "C" { -#endif - -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; -} - -static void -stub_tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str) -{ - -} - -#ifdef __cplusplus -} -#endif - -#define tdm_helper_get_time_ret_val stub_tdm_helper_get_time_ret_val -#define tdm_helper_get_time stub_tdm_helper_get_time -#define tdm_helper_dump_buffer_str stub_tdm_helper_dump_buffer_str - -#endif // STUB_TDM_HELPER_H diff --git a/utests/stubs/stub_tdm_pp.h b/utests/stubs/stub_tdm_pp.h deleted file mode 100644 index ae43a4c..0000000 --- a/utests/stubs/stub_tdm_pp.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef STUB_TDM_PP_H -#define STUB_TDM_PP_H - -#include "tdm.h" -#include "tdm_private.h" - -static tdm_private_pp private_pp; - -static int TDM_PP_CREATE_INTERNAL_ERROR; -static int stub_tdm_pp_cb_done_called; - -static void stub_tdm_pp_init() -{ - stub_tdm_pp_cb_done_called = 0; - TDM_PP_CREATE_INTERNAL_ERROR = 0; -} - -static void -stub_tdm_pp_cb_done(tdm_pp *pp_backend, tbm_surface_h src, tbm_surface_h dst, - void *user_data) -{ - (void)pp_backend; - (void)src; - (void)dst; - (void)user_data; - - stub_tdm_pp_cb_done_called = 1; -} - -static tdm_private_pp * -stub_tdm_pp_find_stamp(tdm_private_display *private_display, double stamp) -{ - (void)private_display; - (void)stamp; - - return &private_pp; -} - -static tdm_private_pp * -stub_tdm_pp_create_internal(tdm_private_display *private_display, - tdm_error *error) -{ - (void)private_display; - - if (TDM_PP_CREATE_INTERNAL_ERROR) { - if (error) { - *error = TDM_ERROR_OPERATION_FAILED; - } - return NULL; - } - - if (error) { - *error = TDM_ERROR_NONE; - } - return NULL; -} - -#define tdm_pp_cb_done stub_tdm_pp_cb_done -#define tdm_pp_find_stamp stub_tdm_pp_find_stamp -#define tdm_pp_create_internal stub_tdm_pp_create_internal - -#endif // STUB_TDM_PP_H diff --git a/utests/stubs/stub_tdm_server.h b/utests/stubs/stub_tdm_server.h deleted file mode 100644 index a65da9e..0000000 --- a/utests/stubs/stub_tdm_server.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef STUB_TDM_SERVER_H -#define STUB_TDM_SERVER_H - -#include "tdm.h" -#include "tdm_private.h" - -#ifdef __cplusplus -extern "C" { -#endif - -static int stdub_tdm_server_init_error; - -static void -stub_tdm_server() -{ - stdub_tdm_server_init_error = 0; -} - -static tdm_error -stub_tdm_server_init(tdm_private_loop *private_loop) -{ - if (stdub_tdm_server_init_error) - return TDM_ERROR_OPERATION_FAILED; - return TDM_ERROR_NONE; -} - -static void -stub_tdm_server_deinit(tdm_private_loop *private_loop) -{ - -} - -#ifdef __cplusplus -} -#endif - -#define tdm_server_init stub_tdm_server_init -#define tdm_server_deinit stub_tdm_server_deinit - -#endif // STUB_TDM_SERVER_H diff --git a/utests/stubs/stub_tdm_thread.h b/utests/stubs/stub_tdm_thread.h deleted file mode 100644 index 1098320..0000000 --- a/utests/stubs/stub_tdm_thread.h +++ /dev/null @@ -1,102 +0,0 @@ -#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]; -static int stub_tdm_thread_is_run; -static int stub_tdm_thread_ret_fd; -static int stub_tdm_thread_display_thread; -static int stub_tdm_output_vblank_handler_count; -static int stub_tdm_thread_init_init_error; - -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); - stub_tdm_thread_is_run = 0; - stub_tdm_thread_ret_fd = 1; - stub_tdm_thread_display_thread = 0; - stub_tdm_output_vblank_handler_count = 0; - stub_tdm_thread_init_init_error = 0; -} - -static int stub_tdm_thread_get_fd(tdm_private_loop *private_loop) -{ - (void)private_loop; - - return stub_tdm_thread_ret_fd; -} - -static tdm_error stub_tdm_thread_handle_cb(tdm_private_loop *private_loop) -{ - (void)private_loop; - - if (TDM_THREAD_HANDLE_ERROR) { - return TDM_ERROR_OPERATION_FAILED; - } - - 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; -} - -static int -stub_tdm_thread_is_running(void) -{ - return (stub_tdm_thread_is_run) ? 1 : 0; -} - -static int -stub_tdm_thread_in_display_thread(pid_t tid) -{ - (void)tid; - - return (stub_tdm_thread_display_thread) ? 1 : 0; -} - -static void -stub_tdm_output_vblank_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)user_data; - - stub_tdm_output_vblank_handler_count++; -} - -/* XXX: named stub_tdm_thread_init_init since stub_tdm_thread_init has been - defined earlier */ -static tdm_error -stub_tdm_thread_init_init(tdm_private_loop *private_loop) -{ - if (stub_tdm_thread_init_init_error) - return TDM_ERROR_OPERATION_FAILED; - 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 -#define tdm_thread_is_running stub_tdm_thread_is_running -#define tdm_thread_in_display_thread stub_tdm_thread_in_display_thread -#define tdm_thread_init stub_tdm_thread_init_init - -#endif // STUB_TDM_THREAD_H diff --git a/utests/stubs/stub_tdm_vblank.h b/utests/stubs/stub_tdm_vblank.h deleted file mode 100644 index 7b73d6c..0000000 --- a/utests/stubs/stub_tdm_vblank.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef STUB_TDM_VBLANK_H -#define STUB_TDM_VBLANK_H - -#include "tdm.h" - -static int stub_tdm_vblank_cb_vblank_SW_called; -static int stub_tdm_vblank_wait_error; -static tdm_vblank* stub_tdm_vblank_create_returned = NULL; - -static void -stub_tdm_vblank_init() -{ - stub_tdm_vblank_cb_vblank_SW_called = 0; - stub_tdm_vblank_create_returned = NULL; - stub_tdm_vblank_wait_error = 0; -} - -static tdm_error -stub_tdm_vblank_cb_vblank_SW(tdm_vblank *vblank, double vblank_stamp) -{ - (void)vblank; - (void)vblank_stamp; - - stub_tdm_vblank_cb_vblank_SW_called = 1; - return TDM_ERROR_NONE; -} - -static tdm_vblank* -stub_tdm_vblank_create(tdm_display *dpy, tdm_output *output, tdm_error *error) -{ - (void)dpy; - (void)output; - (void)error; - - return stub_tdm_vblank_create_returned; -} - -static void -stub_tdm_vblank_destroy(tdm_vblank *vblank) -{ - (void)vblank; -} - -static tdm_error -stub_tdm_vblank_set_fps(tdm_vblank *vblank, unsigned int fps) -{ - (void)vblank; - (void)fps; - - return TDM_ERROR_NONE; -} - -static unsigned int -stub_tdm_vblank_get_enable_fake(tdm_vblank *vblank) -{ - (void)vblank; - - return 0; -} - -static tdm_error -stub_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; - - if(stub_tdm_vblank_wait_error) - return TDM_ERROR_BAD_REQUEST; - - return TDM_ERROR_NONE; -} - - -#define tdm_vblank_cb_vblank_SW stub_tdm_vblank_cb_vblank_SW -#define tdm_vblank_wait stub_tdm_vblank_wait -#define tdm_vblank_get_enable_fake stub_tdm_vblank_get_enable_fake -#define tdm_vblank_set_fps stub_tdm_vblank_set_fps -#define tdm_vblank_destroy stub_tdm_vblank_destroy -#define tdm_vblank_create stub_tdm_vblank_create - -#endif // STUB_TDM_VBLANK_H diff --git a/utests/stubs/stub_unistd.cpp b/utests/stubs/stub_unistd.cpp deleted file mode 100644 index 33fcf6e..0000000 --- a/utests/stubs/stub_unistd.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "stub_unistd.h" - -#include -#include - -int stub_pipe_error; -int stub_write_error; -int stub_syscall_return_value; -int stub_syscall_reset; -short stub_unistd_closed_fds[STUB_UNISTD_SIZE_FDS]; -void *stub_read_buf; -int stub_read_returned_size; -int stub_dub_error = 0; -int stub_poll_error; -int stub_poll_eagain; - -void stub_unistd_init() -{ - stub_pipe_error = 0; - stub_syscall_return_value = 1; - stub_syscall_reset = 0; - stub_write_error = 0; - stub_read_buf = NULL; - stub_read_returned_size = 0; - stub_dub_error = 0; - stub_poll_error = 0; - stub_poll_eagain = 0; - for(int i = 0; i < STUB_UNISTD_SIZE_FDS; ++i) { - stub_unistd_closed_fds[i] = 0; - } -} - -int stub_pipe(int pipedes[2]) -{ - if (stub_pipe_error) - return -1; - - return 0; -} - -long int stub_syscall(long int sysno, ...) -{ - (void)sysno; - long int ret = stub_syscall_return_value; - - if (stub_syscall_reset) - stub_syscall_return_value = 1; - - return ret; -} - -int stub_close(int fd) -{ - if (fd >= STUB_UNISTD_SIZE_FDS) { - return -1; - } - - stub_unistd_closed_fds[fd] = 1; - - return 0; -} - -ssize_t stub_write(int fd, const void *buf, size_t n) -{ - (void)fd; - (void)buf; - - if (stub_write_error) - return 0; - - return n; -} - -ssize_t stub_read(int fd, void *buf, size_t nbytes) -{ - if (!stub_read_buf) { - buf = NULL; - return 0; - } - - memcpy(buf, stub_read_buf, nbytes); - - return stub_read_returned_size; -} - -int stub_dup(int fd) -{ - (void)fd; - - if (stub_dub_error) { - return -1; - } - - return 5; -} - -int stub_dup2(int __fd, int __fd2) -{ - (void)__fd; - (void)__fd2; - - if (stub_dub_error) { - return -1; - } - - return 5; -} - -int stub_poll(struct pollfd *fds, nfds_t nfds, int timeout) -{ - (void)fds; - (void)nfds; - (void)timeout; - - if (stub_poll_eagain) { - stub_poll_eagain = 0; - errno = EAGAIN; - return -1; - } - if (stub_poll_error) { - errno = EPERM; - return -1; - } - - return 0; -} diff --git a/utests/stubs/stub_unistd.h b/utests/stubs/stub_unistd.h deleted file mode 100644 index e46afe9..0000000 --- a/utests/stubs/stub_unistd.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef STUB_UNISTD_H -#define STUB_UNISTD_H - -#include -#include - -#define STUB_UNISTD_SIZE_FDS 32 - -extern int stub_pipe_error; -extern int stub_syscall_return_value; -extern int stub_syscall_reset; -extern int stub_write_error; -extern short stub_unistd_closed_fds[STUB_UNISTD_SIZE_FDS]; -extern void *stub_read_buf; -extern int stub_read_returned_size; -extern int stub_dub_error; -extern int stub_poll_error; -extern int stub_poll_eagain; - -void stub_unistd_init(); - -int stub_pipe(int pipedes[2]); - -long int stub_syscall (long int sysno, ...); - -int stub_close(int fd); - -ssize_t stub_write(int fd, const void *buf, size_t n); - -ssize_t stub_read(int fd, void *buf, size_t nbytes); - -int stub_dup(int fd); -int stub_dup2(int __fd, int __fd2); - -int stub_poll(struct pollfd *fds, nfds_t nfds, int timeout); - -#define pipe(p) stub_pipe(p) -#define syscall(sysno, args...) stub_syscall(sysno, ##args) -#define close(fd) stub_close(fd) -#define write(fd, buf, n) stub_write(fd, buf, n) -#define read(fd, buf, nbytes) stub_read(fd, buf, nbytes) -#define dup(fd) stub_dup(fd) -#define dup2 stub_dup2 -#define poll(fds, nfds, timeout) stub_poll(fds, nfds, timeout) - -#endif // STUB_UNISTD_H diff --git a/utests/stubs/tbm_bufmgr.h b/utests/stubs/tbm_bufmgr.h deleted file mode 100644 index dc4fd59..0000000 --- a/utests/stubs/tbm_bufmgr.h +++ /dev/null @@ -1,1025 +0,0 @@ -#ifndef _TBM_BUFMGR_H_ -#define _TBM_BUFMGR_H_ - -#include -#include - -/* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */ -#ifndef TBM_ERROR_BASE -#define TBM_ERROR_BASE -0x02830000 -#endif - -/** - * \file tbm_bufmgr.h - * \brief Tizen Buffer Manager - */ - -/** - * @brief Definition for the tizen buffer manager - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef struct _tbm_bufmgr *tbm_bufmgr; - -/** - * @brief Definition for the tizen buffer object - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef struct _tbm_bo *tbm_bo; -/** - * @brief Definition for the key associated with the buffer object - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef uint32_t tbm_key; -/** - * @brief Definition for the file descripter of the system buffer manager - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef int32_t tbm_fd; - -/* TBM_DEVICE_TYPE */ - -/** - * @brief Definition for the device type to get the default handle - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_DEVICE_DEFAULT 0 -/** - * @brief Definition for the device type to get the virtual memory - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_DEVICE_CPU 1 -/** - * @brief Definition for the device type to get the 2D memory handle - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_DEVICE_2D 2 -/** - * @brief Definition for the device type to get the 3D memory handle - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_DEVICE_3D 3 -/** - * @brief Definition for the device type to get the multimedia handle - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_DEVICE_MM 4 - -/* TBM_OPTION */ - -/** - * @brief Definition for the access option to read - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_OPTION_READ (1 << 0) -/** - * @brief Definition for the access option to write - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_OPTION_WRITE (1 << 1) -/** - * @brief Definition for the vendor specific option that depends on the backend - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_OPTION_VENDOR (0xffff0000) - -/* unneeded version 2.0 */ -/** - * @brief Definition for the cache invalidate - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_CACHE_INV 0x01 -/** - * @brief Definition for the cache clean - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_CACHE_CLN 0x02 -/* unneeded version 2.0 */ - -/** - * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef union _tbm_bo_handle { - void *ptr; - int32_t s32; - uint32_t u32; - int64_t s64; - uint64_t u64; -} tbm_bo_handle; - -/** - * @brief Enumeration of bo memory type - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -enum TBM_BO_FLAGS { - TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */ - TBM_BO_SCANOUT = (1 << 0), /**< scanout memory */ - TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory */ - TBM_BO_WC = (1 << 2), /**< write-combine memory */ - TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */ -}; - -/** - * @brief Enumeration for tbm error type. - * @since_tizen 2.4 - */ -typedef enum { - TBM_ERROR_NONE = 0, /**< Successful */ - TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101, /**< failed to get fd failed */ - TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE | 0x0102, /**< failed to allocate the heap memory */ - TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,/**< failed to load module*/ - TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,/**< failed to initialize the pthread */ - TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE | 0x0105, /**< failed to allocate tbm_bo */ - TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of tbm_bo */ - TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107, /**< failed to import the handle of tbm_bo */ - TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108, /**< failed to import fd of tbm_bo */ - TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109, /**< failed to export the handle of the tbm_bo */ - TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x01010, /**< failed to export fd of tbm_bo */ - TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111, /**< failed to get the tbm_bo_handle */ - TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112, /**< failed to lock the tbm_bo */ - TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113, /**< failed to map the tbm_bo to get the tbm_bo_handle */ - TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114, /**< failed to unmap the tbm_bo */ - TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115, /**< failed to swap the tbm_bos */ - TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116, /**< failed to duplicate fd */ -} tbm_error_e; - -/** - * @brief Enumeration of tbm buffer manager capability. - * @since_tizen 2.4 - */ -enum TBM_BUFMGR_CAPABILITY { - TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/ - TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0), /**< Support sharing buffer by tbm key */ - TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1), /**< Support sharing buffer by tbm fd */ -}; - -#ifdef __cplusplus -extern "C" { -#endif - -/* Functions for buffer manager */ - -/** - * @brief Initializes the buffer manager. - * @details If fd is lower than zero, fd is get drm fd in tbm_bufmgr_init function\n - * The user can decide the lock type and cache flush type with the environment variables, which are BUFMGR_LOCK_TYPE and BUFMGR_MAP_CACHE.\n - * \n - * BUFMGR_LOCK default is once\n - * once : The previous bo which is locked is unlock when the new bo is trying to be locked\n - * always : The new bo is locked until the previous bo which is locked is unlocked\n - * never : Every bo is never locked.\n - * \n - * BUFMGR_MAP_CACHE default is true\n - * true : use map cache flushing\n - * false : to use map cache flushing - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] fd : file descripter of the system buffer manager - * @return a buffer manager - * @retval #tbm_bufmgr - * @see tbm_bufmgr_deinit(); - * @par Example - @code - #include - int bufmgr_fd; - - setenv("BUFMGR_LOCK_TYPE", "once", 1); - setenv("BUFMGR_MAP_CACHE", "true", 1); - - tbm_bufmgr bufmgr; - bufmgr = tbm_bufmgr_init (bufmgr_fd); - - .... - - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bufmgr tbm_bufmgr_init(int fd); - -/** - * @brief Deinitializes the buffer manager. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bufmgr : the buffer manager - * @see tbm_bufmgr_init() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_error_e error; - bufmgr = tbm_bufmgr_init (bufmgr_fd); - if (!bufmgr) - { - error = tbm_get_last_error (); - ... - } - - .... - - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -void tbm_bufmgr_deinit(tbm_bufmgr bufmgr); - -/* Functions for bo */ - -/** - * @brief Allocates the buffer object. - * @details This function create tbm_bo and set reference count to 1.\n - * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n - * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n - * #TBM_BO_SCANOUT indecates scanout memory\n - * #TBM_BO_NONCACHABLE indecates non-cachable memory\n - * #TBM_BO_WC indecates write-combine memory\n - * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bufmgr : the buffer manager - * @param[in] size : the size of buffer object - * @param[in] flags : the flags of memory type - * @return a buffer object - * @retval #tbm_bo - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - if (!bo) - { - error = tbm_get_last_error (); - ... - } - - .... - - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags); - -/** - * @brief Increases the reference count of bo. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @return a buffer object - * @retval #tbm_bo - * @see tbm_bo_unref() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - bo = tbm_bo_ref (bo); - - .... - - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo tbm_bo_ref(tbm_bo bo); - -/** - * @brief Decreases the reference count of bo - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @see tbm_bo_ref() - * @see tbm_bo_alloc() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -void tbm_bo_unref(tbm_bo bo); - -/** - * @brief Maps the buffer object according to the device type and the option. - * @details Cache flushing and Locking is executed, while tbm_bo is mapping in the proper condition according to the device type and the access option.\n - * If the cache flush type of bufmgr set true, the map cache flushing is executed - * If the lock type of bufmgr set once, the previous bo which is locked is unlock when the new bo is trying to be locked.\n - * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n - * If the lock type of bufmgr set never, Every bo is never locked.\n\n - * #TBM_DEVICE_DEFAULT indecates the default handle.\n - * #TBM_DEVICE_2D indecates the 2D memory handle.\n - * #TBM_DEVICE_3D indecates the 3D memory handle.\n - * #TBM_DEVICE_CPU indecates the virtual memory handle.\n - * #TBM_DEVICE_MM indecates the multimedia handle.\n\n - * #TBM_OPTION_READ indecates the accss option to read.\n - * #TBM_OPTION_WRITE indecates the access option to write.\n - * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] device : the device type to get a handle - * @param[in] opt : the option to access the buffer object - * @return the handle of the buffer object - * @exception #TBM_ERROR_NONE Success - * @exception #TBM_ERROR_BO_LOCK_FAILED tbm_bo lock failed - * @exception #TBM_ERROR_BO_MAP_FAILED tbm_bo map failed - * @retval #tbm_bo - * @see tbm_bo_unmap() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - tbm_bo_handle handle; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE); - if (handle.ptr == NULL) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unmap (bo); - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt); - -/** - * @brief Unmaps the buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @return 1 if this function succeeds, otherwise 0. - * @see tbm_bo_map() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo - tbm_bo_handle handle; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE); - - ... - - tbm_bo_unmap (bo); - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -int tbm_bo_unmap(tbm_bo bo); - -/** - * @brief Gets the tbm_bo_handle according to the device type. - * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n - * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n - * #TBM_DEVICE_DEFAULT indecates the default handle.\n - * #TBM_DEVICE_2D indecates the 2D memory handle.\n - * #TBM_DEVICE_3D indecates the 3D memory handle.\n - * #TBM_DEVICE_CPU indecates the virtual memory handle.\n - * #TBM_DEVICE_MM indecates the multimedia handle. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] device : the device type to get a handle - * @return the handle of the buffer object - * @retval #tbm_bo_handle - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - tbm_bo_handle handle; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D); - if (handle.ptr == NULL) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device); - -/** - * @brief Exports the buffer object by key. - * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @return key associated with the buffer object - * @retval #tbm_key - * @see tbm_bo_import() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo; - tbm_key key; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - key = tbm_bo_export (bo); - if (key == 0) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_key tbm_bo_export(tbm_bo bo); - -/** - * @brief Exports the buffer object by fd. - * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @remarks You must release the fd using close(). - * @param[in] bo : the buffer object - * @return fd associated with the buffer object - * @retval #tbm_fd - * @see tbm_bo_import_fd() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_fd bo_fd; - tbm_bufmgr bufmgr; - tbm_bo; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - bo_fd = tbm_bo_export (bo); - if (bo_fd == 0) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_fd tbm_bo_export_fd(tbm_bo bo); - -/** - * @brief Imports the buffer object associated with the key. - * @details The reference count of the tbm_bo is 1. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bufmgr : the buffer manager - * @param[in] key : the key associated with the buffer object - * @return a buffer object - * @retval #tbm_bo - * @see tbm_bo_export() - * @par Example - @code - #include - - int bufmgr_fd; - int bo_key; - tbm_bufmgr bufmgr; - tbm_bo; - tbm_error_e error; - - ... - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_import (bufmgr, key); - if (bo == NULL) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key); - -/** - * @brief Imports the buffer object associated with the fd. - * @details The reference count of the tbm_bo is 1. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @remarks You must release the fd using close(). - * @param[in] bufmgr : the buffer manager - * @param[in] fd : the fd associated with the buffer object - * @return a buffer object - * @retval #tbm_bo - * @see tbm_bo_export_fd() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_fd bo_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - tbm_error_e error; - - ... - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_import_fd (bo_fd); - if (bo == 0) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd); - -/** - * @brief Gets the size of a bo. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @return 1 if this function succeeds, otherwise 0. - * @see tbm_bo_alloc() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo; - int size; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - size = tbm_bo_size (bo); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -int tbm_bo_size(tbm_bo bo); - -/** - * @brief Gets the state where the buffer object is locked. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @return 1 if this bo is locked, otherwise 0. - * @see tbm_bo_map() - * @see tbm_bo_unmap() - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - ... - - if (tbm_bo_locked (bo)) - { - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode -*/ -int tbm_bo_locked(tbm_bo bo); - -/** - * @brief Swaps the buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo1 : the buffer object - * @param[in] bo2 : the buffer object - * @return 1 if this function succeeds, otherwise 0. - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo1; - tbm_bo bo2; - int ret; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT); - - ... - - ret = tbm_bo_swap (bo1, bo2); - if (ret == 0) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unref (bo1); - tbm_bo_unref (bo2); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2); - -/** - * @brief Called when the user data is deleted in buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] user_data User_data to be passed to callback function - * @pre The callback must be registered using tbm_bo_add_user_data().\n - * tbm_bo_delete_user_data() must be called to invoke this callback. - * @see tbm_bo_add_user_data() - * @see tbm_bo_delete_user_data() - */ -typedef void (*tbm_data_free) (void *user_data); - -/** - * @brief Adds a user_data to the buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] key : the key associated with the user_data - * @param[in] data_free_func : the function pointer to free the user_data - * @return 1 if this function succeeds, otherwise 0. - * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data(). - * @see tbm_data_free() - * @see tbm_bo_set_user_data() - * @see tbm_bo_get_user_data() - * @see tbm_bo_delete_user_data() - * @par Example - @code - #include - - void example_data_free (void *user_data) - { - char *data = (char*) user_data; - free(data); - } - - int main() - { - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - char *user_data; - char *get_data; - int ret; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - user_data = (char*) malloc (sizeof(char) * 128); - - ... - - tbm_bo_add_user_data (bo, 1, example_data_free); - tbm_bo_set_user_data (bo, 1, user_data); - - ... - - ret = tbm_bo_get_user_data (bo, 1, &get_data); - tbm_bo_delete_user_data (bo, 1); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - } - @endcode - */ - -int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, - tbm_data_free data_free_func); - -/** - * @brief Deletes the user_data in the buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] key : the key associated with the user_date - * @return 1 if this function succeeds, otherwise 0. - * @see tbm_bo_add_user_data() - * @see tbm_bo_get_user_data() - * @see tbm_bo_delete_user_data() - * @par Example - @code - #include - - void example_data_free (void *user_data) - { - char *data = (char*) user_data; - free(data); - } - - int main() - { - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - char *user_data; - char *get_data; - int ret; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - user_data = (char*) malloc (sizeof(char) * 128); - - ... - - tbm_bo_add_user_data (bo, 1, example_data_free); - tbm_bo_set_user_data (bo, 1, user_data); - - ... - - ret = tbm_bo_get_user_data (bo, 1, &get_data); - tbm_bo_delete_user_data (bo, 1); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - } - @endcode - */ -int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key); - -/** - * @brief Sets a user_date to the buffer object. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] key : the key associated with the user_date - * @param[in] data : a pointer of the user_data - * @return 1 if this function succeeds, otherwise 0. - * @see tbm_bo_add_user_data() - * @see tbm_bo_set_user_data() - * @see tbm_bo_delete_user_data() - * @par Example - @code - #include - - void example_data_free (void *user_data) - { - char *data = (char*) user_data; - free(data); - } - - int main() - { - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - char *user_data; - char *get_data; - int ret; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - user_data = (char*) malloc (sizeof(char) * 128); - - ... - - tbm_bo_add_user_data (bo, 1, example_data_free); - tbm_bo_set_user_data (bo, 1, user_data); - - ... - - ret = tbm_bo_get_user_data (bo, 1, &get_data); - tbm_bo_delete_user_data (bo, 1); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - } - @endcode - */ -int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data); - -/** - * @brief Gets a user_data from the buffer object with the key. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bo : the buffer object - * @param[in] key : the key associated with the user_date - * @param[out] data : to get the user data - * @return 1 if this function succeeds, otherwise 0. - * @see tbm_bo_add_user_data() - * @see tbm_bo_set_user_data() - * @see tbm_bo_get_user_data() - * @par Example - @code - #include - - void example_data_free (void *user_data) - { - char *data = (char*) user_data; - free(data); - } - - int main() - { - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - char *user_data; - char *get_data; - int ret; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - user_data = (char*) malloc (sizeof(char) * 128); - - ... - - tbm_bo_add_user_data (bo, 1, example_data_free); - tbm_bo_set_user_data (bo, 1, user_data); - - ... - - ret = tbm_bo_get_user_data (bo, 1, &get_data); - tbm_bo_delete_user_data (bo, 1); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - } - @endcode - */ -int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data); - -/** - * @brief Gets the latest tbm_error. - * @since_tizen 2.4 - * @return the latest tbm_error - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo bo; - tbm_bo_handle handle; - tbm_error_e error; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - if (!bo) - { - error = tbm_get_last_error (); - ... - } - - ... - - handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE); - if (handle.ptr == NULL) - { - error = tbm_get_last_error (); - ... - } - - ... - - tbm_bo_unmap (bo); - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_error_e tbm_get_last_error(void); - -/** - * @brief Gets the tbm buffer capability. - * @since_tizen 2.4 - * @param[in] bufmgr : the buffer manager - * @return the tbm bufmgr capability - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - unsigned int capability; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - - capability = tbm_bufmgr_get_capability (bufmgr); - - tbm_bufmgr_deinit (bufmgr); - @endcode - */ -unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr); - -/** - * @brief Gets the tbm bo flags. - * @since_tizen 2.4 - * @param[in] bo : the buffer object - * @return the tbm bo flags - * @see TBM_BO_FLAGS - * @par Example - @code - #include - - int bufmgr_fd; - tbm_bufmgr bufmgr; - tbm_bo; - int flags; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - flags = tbm_bo_get_flags (bo); - - ... - - tbm_bo_unref (bo); - tbm_bufmgr_deinit (bufmgr); - - @endcode - */ -int tbm_bo_get_flags(tbm_bo bo); - -/** - * @brief Print out the information of tbm_bos. - * @since_tizen 3.0 - * @param[in] bufmgr : the buffer manager - */ -void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr); - -/** - * @brief Print out the trace of tbm_bos. - * @since_tizen 3.0 - * @param[in] bufmgr : the buffer manager - * @param[in] onoff : 1 is on, and 0 is off - */ -void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff); - -int tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay); - -#ifdef __cplusplus -} -#endif -#endif /* _TBM_BUFMGR_H_ */ diff --git a/utests/stubs/tbm_stubs.cpp b/utests/stubs/tbm_stubs.cpp deleted file mode 100644 index c86fabc..0000000 --- a/utests/stubs/tbm_stubs.cpp +++ /dev/null @@ -1,270 +0,0 @@ -#include "tbm_stubs.h" - -#include - -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) -{ - (void)fd; - - return NULL; -} - -void tbm_bufmgr_deinit(tbm_bufmgr bufmgr) -{ - (void)bufmgr; - - TBM_BUFMGR_DEINIT_CALLED = 1; -} - -tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx) -{ - (void)surface; - (void)bo_idx; - - if (!surface) { - return NULL; - } - - return NULL; -} - -int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data) -{ - (void)bo; - (void)key; - (void)data; - - if (TBM_BO_GET_USER_DATA_NULL) { - *data = NULL; - return; - } - - *data = (void *)"data"; - - return 0; -} - -int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, - tbm_data_free data_free_func) -{ - (void)bo; - (void)key; - (void)data_free_func; - - return 0; -} - -int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data) -{ - (void)bo; - (void)key; - (void)data; - - return 0; -} - -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( - tbm_surface_queue_h surface_queue, tbm_surface_h *surface) -{ - (void)surface_queue; - (void)surface; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -tbm_surface_queue_error_e tbm_surface_queue_release( - tbm_surface_queue_h surface_queue, tbm_surface_h surface) -{ - (void)surface_queue; - (void)surface; - - tbm_surface_queue_release_count++; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -tbm_surface_queue_error_e tbm_surface_queue_add_acquirable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, - void *data) -{ - (void)surface_queue; - (void)acquirable_cb; - (void)data; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -tbm_surface_queue_error_e tbm_surface_queue_add_destroy_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, - void *data) -{ - (void)surface_queue; - (void)destroy_cb; - (void)data; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -tbm_surface_queue_error_e tbm_surface_queue_remove_acquirable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, - void *data) -{ - (void)surface_queue; - (void)acquirable_cb; - (void)data; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -tbm_surface_queue_error_e tbm_surface_queue_remove_destroy_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, - void *data) -{ - (void)surface_queue; - (void)destroy_cb; - (void)data; - - return TBM_SURFACE_QUEUE_ERROR_NONE; -} - -int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, - void **data) -{ - (void)surface; - (void)key; - - if (tbm_surface_internal_get_user_data_ret) { - *data = tbm_surface_internal_get_user_data_ret; - return 1; - } - - *data = NULL; - - return 0; -} - -int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, - tbm_data_free data_free_func) -{ - (void)surface; - (void)key; - (void)data_free_func; - - if (tbm_surface_internal_add_user_data_error) - return 0; - - return 1; -} - -int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, - void *data) -{ - (void)surface; - (void)key; - (void)data; - - if (tbm_surface_internal_set_user_data_error) - return 0; - - return 1; -} - -int tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info) -{ - (void)opt; - struct _tbm_surface *s = surface; - - if (s->info.num_planes > 0) - { - info->format = s->info.format; - info->width = s->info.width; - info->height = s->info.height; - info->num_planes = s->info.num_planes; - info->planes[0].ptr = s->info.planes[0].ptr; - info->planes[1].ptr = s->info.planes[1].ptr; - info->planes[2].ptr = s->info.planes[2].ptr; - info->planes[0].stride = s->info.planes[0].stride; - info->planes[1].stride = s->info.planes[1].stride; - info->planes[2].stride = s->info.planes[2].stride; - return 0; - } - return 1; -} - -int tbm_surface_unmap(tbm_surface_h surface) -{ - (void)surface; - - return 0; -} - -void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type) -{ - (void)surface; - (void)type; -} - -int tbm_surface_internal_delete_user_data(tbm_surface_h surface, - unsigned long key) -{ - (void)surface; - (void)key; - - return 0; -} - -int tbm_surface_internal_get_num_bos(tbm_surface_h surface) -{ - struct _tbm_surface *s = surface; - return s->info.num_planes; -} - -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; - 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/utests/stubs/tbm_stubs.h b/utests/stubs/tbm_stubs.h deleted file mode 100644 index e8e1f13..0000000 --- a/utests/stubs/tbm_stubs.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _TBM_STUBS_H -#define _TBM_STUBS_H - -#include -#include "tbm_bufmgr.h" -#include "tbm_surface_queue.h" - -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; - tbm_surface_info_s info; -}; - -struct _tbm_surface_queue { - int temp; -}; - -tbm_bufmgr tbm_bufmgr_init(int fd); - -void tbm_bufmgr_deinit(tbm_bufmgr bufmgr); - -tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx); - -int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data); - -int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, - tbm_data_free data_free_func); - -int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data); - -void tbm_surface_internal_ref(tbm_surface_h surface); - -void tbm_surface_internal_unref(tbm_surface_h surface); - -void stub_tbm_init(); - -#endif /* _TBM_STUBS_H */ diff --git a/utests/stubs/tbm_surface.h b/utests/stubs/tbm_surface.h deleted file mode 100644 index 445d421..0000000 --- a/utests/stubs/tbm_surface.h +++ /dev/null @@ -1,742 +0,0 @@ -#ifndef _TBM_SURFACE_H_ -#define _TBM_SURFACE_H_ - -/** - * @addtogroup CAPI_UI_TBM_SURFACE_MODULE - * @{ - */ - -#include -#include - -/** - * \file tbm_surface.h - * \brief TBM Surface - */ - -/** - * @brief Enumeration for tbm_surface error type. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef enum { - TBM_SURFACE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - TBM_SURFACE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - TBM_SURFACE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ -} tbm_surface_error_e; - -/** - * @brief Definition for the max number of TBM surface plane. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_SURF_PLANE_MAX 4 - -/* option to map the tbm_surface */ -/** - * @brief Definition for the access option to read. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_SURF_OPTION_READ (1 << 0) -/** - * @brief Definition for the access option to write. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_SURF_OPTION_WRITE (1 << 1) - -/** - * @brief Definition for the TBM plane struct. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef struct _tbm_surface_plane { - unsigned char *ptr; /**< Plane pointer */ - uint32_t size; /**< Plane size */ - uint32_t offset; /**< Plane offset */ - uint32_t stride; /**< Plane stride */ - - void *reserved1; /**< Reserved pointer1 */ - void *reserved2; /**< Reserved pointer2 */ - void *reserved3; /**< Reserved pointer3 */ -} tbm_surface_plane_s; - -/** - * @brief Definition for the TBM surface information struct. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef struct _tbm_surface_info { - uint32_t width; /**< TBM surface width */ - uint32_t height; /**< TBM surface height */ - tbm_format format; /**< TBM surface format*/ - uint32_t bpp; /**< TBM surface bbp */ - uint32_t size; /**< TBM surface size */ - - uint32_t num_planes; /**< The number of planes */ - tbm_surface_plane_s planes[TBM_SURF_PLANE_MAX]; /**< Array of planes */ - - void *reserved4; /**< Reserved pointer4 */ - void *reserved5; /**< Reserved pointer5 */ - void *reserved6; /**< Reserved pointer6 */ -} tbm_surface_info_s; - -#define __tbm_fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ - ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) - -/* color index */ -/** - * @brief Definition for the TBM surface format C8 ([7:0] C). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_C8 __tbm_fourcc_code('C', '8', ' ', ' ') - -/* 8 bpp RGB */ -/** - * @brief Definition for the TBM surface format RGB322 ([7:0] R:G:B 3:3:2). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGB332 __tbm_fourcc_code('R', 'G', 'B', '8') -/** - * @brief Definition for the TBM surface format RGB233 ([7:0] B:G:R 2:3:3). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGR233 __tbm_fourcc_code('B', 'G', 'R', '8') - -/* 16 bpp RGB */ -/** - * @brief Definition for the TBM surface format XRGB4444 ([15:0] x:R:G:B 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XRGB4444 __tbm_fourcc_code('X', 'R', '1', '2') -/** - * @brief Definition for the TBM surface format XBRG4444 ([15:0] x:B:G:R 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XBGR4444 __tbm_fourcc_code('X', 'B', '1', '2') -/** - * @brief Definition for the TBM surface format RGBX4444 ([15:0] R:G:B:x 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBX4444 __tbm_fourcc_code('R', 'X', '1', '2') -/** - * @brief Definition for the TBM surface format BGRX4444 ([15:0] B:G:R:x 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRX4444 __tbm_fourcc_code('B', 'X', '1', '2') - -/** - * @brief Definition for the TBM surface format ARGB4444 ([15:0] A:R:G:B 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ARGB4444 __tbm_fourcc_code('A', 'R', '1', '2') -/** - * @brief Definition for the TBM surface format ABGR4444 ([15:0] A:B:G:R 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ABGR4444 __tbm_fourcc_code('A', 'B', '1', '2') -/** - * @brief Definition for the TBM surface format RGBA4444 ([15:0] R:G:B:A 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBA4444 __tbm_fourcc_code('R', 'A', '1', '2') -/** - * @brief Definition for the TBM surface format BGRA4444 ([15:0] B:G:R:A 4:4:4:4 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRA4444 __tbm_fourcc_code('B', 'A', '1', '2') - -/** - * @brief Definition for the TBM surface format XRGB1555 ([15:0] x:R:G:B 1:5:5:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XRGB1555 __tbm_fourcc_code('X', 'R', '1', '5') -/** - * @brief Definition for the TBM surface format XBGR1555 ([15:0] x:B:G:R 1:5:5:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XBGR1555 __tbm_fourcc_code('X', 'B', '1', '5') -/** - * @brief Definition for the TBM surface format RGBX5551 ([15:0] R:G:B:x 5:5:5:1 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBX5551 __tbm_fourcc_code('R', 'X', '1', '5') -/** - * @brief Definition for the TBM surface format BGRX5551 ([15:0] B:G:R:x 5:5:5:1 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRX5551 __tbm_fourcc_code('B', 'X', '1', '5') - -/** - * @brief Definition for the TBM surface format ARGB1555 ([15:0] A:R:G:B 1:5:5:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ARGB1555 __tbm_fourcc_code('A', 'R', '1', '5') -/** - * @brief Definition for the TBM surface format ABGR1555 ([15:0] A:B:G:R 1:5:5:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ABGR1555 __tbm_fourcc_code('A', 'B', '1', '5') -/** - * @brief Definition for the TBM surface format RGBA5551 ([15:0] R:G:B:A 5:5:5:1 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBA5551 __tbm_fourcc_code('R', 'A', '1', '5') -/** - * @brief Definition for the TBM surface format BGRA5551 ([15:0] B:G:R:A 5:5:5:1 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRA5551 __tbm_fourcc_code('B', 'A', '1', '5') - -/** - * @brief Definition for the TBM surface format RGB565 ([15:0] R:G:B 5:6:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGB565 __tbm_fourcc_code('R', 'G', '1', '6') -/** - * @brief Definition for the TBM surface format BGR565 ([15:0] B:G:R 5:6:5 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGR565 __tbm_fourcc_code('B', 'G', '1', '6') - -/* 24 bpp RGB */ -/** - * @brief Definition for the TBM surface format RGB888 ([23:0] R:G:B little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGB888 __tbm_fourcc_code('R', 'G', '2', '4') -/** - * @brief Definition for the TBM surface format BGR888 ([23:0] B:G:R little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGR888 __tbm_fourcc_code('B', 'G', '2', '4') - -/* 32 bpp RGB */ -/** - * @brief Definition for the TBM surface format XRGB8888 ([31:0] x:R:G:B 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XRGB8888 __tbm_fourcc_code('X', 'R', '2', '4') -/** - * @brief Definition for the TBM surface format XBGR8888 ([31:0] x:B:G:R 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XBGR8888 __tbm_fourcc_code('X', 'B', '2', '4') -/** - * @brief Definition for the TBM surface format RGBX8888 ([31:0] R:G:B:x 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBX8888 __tbm_fourcc_code('R', 'X', '2', '4') -/** - * @brief Definition for the TBM surface format BGRX8888 ([31:0] B:G:R:x 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRX8888 __tbm_fourcc_code('B', 'X', '2', '4') - -/** - * @brief Definition for the TBM surface format ARGB8888 ([31:0] A:R:G:B 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ARGB8888 __tbm_fourcc_code('A', 'R', '2', '4') -/** - * @brief Definition for the TBM surface format ABGR8888 ([31:0] [31:0] A:B:G:R 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ABGR8888 __tbm_fourcc_code('A', 'B', '2', '4') -/** - * @brief Definition for the TBM surface format RGBA8888 ([31:0] R:G:B:A 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBA8888 __tbm_fourcc_code('R', 'A', '2', '4') -/** - * @brief Definition for the TBM surface format BGRA8888 ([31:0] B:G:R:A 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRA8888 __tbm_fourcc_code('B', 'A', '2', '4') - -/** - * @brief Definition for the TBM surface format XRGB2101010 ([31:0] x:R:G:B 2:10:10:10 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XRGB2101010 __tbm_fourcc_code('X', 'R', '3', '0') -/** - * @brief Definition for the TBM surface format XBGR2101010 ([31:0] x:B:G:R 2:10:10:10 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_XBGR2101010 __tbm_fourcc_code('X', 'B', '3', '0') -/** - * @brief Definition for the TBM surface format RGBX1010102 ([31:0] R:G:B:x 10:10:10:2 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBX1010102 __tbm_fourcc_code('R', 'X', '3', '0') -/** - * @brief Definition for the TBM surface format BGRX1010102 ([31:0] B:G:R:x 10:10:10:2 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRX1010102 __tbm_fourcc_code('B', 'X', '3', '0') - -/** - * @brief Definition for the TBM surface format ARGB2101010 ([31:0] A:R:G:B 2:10:10:10 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ARGB2101010 __tbm_fourcc_code('A', 'R', '3', '0') -/** - * @brief Definition for the TBM surface format ABGR2101010 ([31:0] A:B:G:R 2:10:10:10 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_ABGR2101010 __tbm_fourcc_code('A', 'B', '3', '0') -/** - * @brief Definition for the TBM surface format RGBA1010102 ([31:0] R:G:B:A 10:10:10:2 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_RGBA1010102 __tbm_fourcc_code('R', 'A', '3', '0') -/** - * @brief Definition for the TBM surface format BGRA1010102 ([31:0] B:G:R:A 10:10:10:2 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_BGRA1010102 __tbm_fourcc_code('B', 'A', '3', '0') /* */ - -/* packed YCbCr */ -/** - * @brief Definition for the TBM surface format YUYV ([31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YUYV __tbm_fourcc_code('Y', 'U', 'Y', 'V') -/** - * @brief Definition for the TBM surface format YVYU ([31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVYU __tbm_fourcc_code('Y', 'V', 'Y', 'U') /* */ -/** - * @brief Definition for the TBM surface format UYVY ([31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_UYVY __tbm_fourcc_code('U', 'Y', 'V', 'Y') -/** - * @brief Definition for the TBM surface format VYUY ([31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_VYUY __tbm_fourcc_code('V', 'Y', 'U', 'Y') - -/** - * @brief Definition for the TBM surface format AYUV ([31:0] A:Y:Cb:Cr 8:8:8:8 little endian). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_AYUV __tbm_fourcc_code('A', 'Y', 'U', 'V') - -/* - * 2 plane YCbCr - * index 0 = Y plane, [7:0] Y - * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian - * or - * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian - */ -/** - * @brief Definition for the TBM surface format NV12 (2x2 subsampled Cr:Cb plane). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_NV12 __tbm_fourcc_code('N', 'V', '1', '2') -/** - * @brief Definition for the TBM surface format NV21 (2x2 subsampled Cb:Cr plane). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_NV21 __tbm_fourcc_code('N', 'V', '2', '1') /* */ -/** - * @brief Definition for the TBM surface format NV16 (2x1 subsampled Cr:Cb plane). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_NV16 __tbm_fourcc_code('N', 'V', '1', '6') -/** - * @brief Definition for the TBM surface format NV61 (2x1 subsampled Cb:Cr plane). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_NV61 __tbm_fourcc_code('N', 'V', '6', '1') - -/* - * 3 plane YCbCr - * index 0: Y plane, [7:0] Y - * index 1: Cb plane, [7:0] Cb - * index 2: Cr plane, [7:0] Cr - * or - * index 1: Cr plane, [7:0] Cr - * index 2: Cb plane, [7:0] Cb - */ -/** - * @brief Definition for the TBM surface format YUV410 (4x4 subsampled Cb (1) and Cr (2) planes). - */ -#define TBM_FORMAT_YUV410 __tbm_fourcc_code('Y', 'U', 'V', '9') -/** - * @brief Definition for the TBM surface format YVU410 (4x4 subsampled Cr (1) and Cb (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVU410 __tbm_fourcc_code('Y', 'V', 'U', '9') -/** - * @brief Definition for the TBM surface format YUV411 (4x1 subsampled Cb (1) and Cr (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YUV411 __tbm_fourcc_code('Y', 'U', '1', '1') -/** - * @brief Definition for the TBM surface format YVU411 (4x1 subsampled Cr (1) and Cb (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVU411 __tbm_fourcc_code('Y', 'V', '1', '1') -/** - * @brief Definition for the TBM surface format YUV420 (2x2 subsampled Cb (1) and Cr (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YUV420 __tbm_fourcc_code('Y', 'U', '1', '2') -/** - * @brief Definition for the TBM surface format YVU420 (2x2 subsampled Cr (1) and Cb (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVU420 __tbm_fourcc_code('Y', 'V', '1', '2') -/** - * @brief Definition for the TBM surface format YUV422 (2x1 subsampled Cb (1) and Cr (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YUV422 __tbm_fourcc_code('Y', 'U', '1', '6') -/** - * @brief Definition for the TBM surface format YVU422 (2x1 subsampled Cr (1) and Cb (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVU422 __tbm_fourcc_code('Y', 'V', '1', '6') -/** - * @brief Definition for the TBM surface format YUV444 (non-subsampled Cb (1) and Cr (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YUV444 __tbm_fourcc_code('Y', 'U', '2', '4') -/** - * @brief Definition for the TBM surface format YVU444 (non-subsampled Cr (1) and Cb (2) planes). - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -#define TBM_FORMAT_YVU444 __tbm_fourcc_code('Y', 'V', '2', '4') - -/* 2 plane YCbCr */ -/** - * @brief Definition for the TBM surface format NV12MT (tiled '64x32' & multi-plane version of NV12). - * @since_tizen 3.0 @endif - */ -#define TBM_FORMAT_NV12MT __tbm_fourcc_code('T', 'M', '1', '2') - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Queries surface format list and number of format supported by the system. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @remarks You must release the formats using free(). - * - * @param[out] formats The format array which the system can support \n - * This pointer has to be freed by user. - * @param[out] num The number of formats - * - * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_NONE Success - * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION Invalid operation - * - * @par Example - @code - #include - - uint32_t *formats; - uint32_t format_num; - int ret, i; - - if (tbm_surface_query_formats (&formats, &format_num)) - { - for( i = 0 ; i < format_num ; i++) - { - if (formats[i] == TBM_FORMAT_RGB332) - { - - .... - - free (formats); - @endcode - */ -int tbm_surface_query_formats(uint32_t **formats, uint32_t *num); - -/** - * @brief Creates the tbm_surface. - * @details This function creates the tbm_surface with the given width, height, and format. - * - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. - * - * @param[in] width The width of surface - * @param[in] height The height of surface - * @param[in] format The format of surface - * - * @return #tbm_surface_h on success, - * otherwise @c NULL - * - * @retval #tbm_surface_h The TBM surface handle - * - * @exception #TBM_SURFACE_ERROR_NONE Success - * @exception #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * @exception #TBM_SURFACE_ERROR_INVALID_OPERATION Invalid operation - * - * @see tbm_surface_destroy() - * - * @par Example - @code - #include - - tbm_surface_h surface; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -tbm_surface_h tbm_surface_create(int width, int height, tbm_format format); - -/** - * @brief Destroys the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * - * @return #TBM_SURFACE_ERROR_NONE on success, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_NONE Success - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see tbm_surface_create() - * - * @par Example - @code - #include - - tbm_surface_h surface; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_destroy(tbm_surface_h surface); - -/** - * @brief Maps the tbm_surface according to the access option. - * @details After mapping tbm_surface, the information of tbm_surface is assigned in #tbm_surface_info_s struct. \n - * The information of tbm_surface has width, height, format, bpp, size, number of planes and information of planes. \n - * The information of planes has stride, offset, size and pointer of plane. \n - * #TBM_SURF_OPTION_READ indicates access option to read. \n - * #TBM_SURF_OPTION_WRITE indicates access option to write. - * - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * @param[in] opt The option to access the tbm_surface - * @param[out] info The information of the tbm_surface - * - * @return #TBM_SURFACE_ERROR_NONE on success, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_NONE Success - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION Invalid operation - * - * @see tbm_surface_unmap(); - * - * @par Example - @code - #include - - tbm_surface_h surface; - tbm_surface_info_s info; - int ret; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - ret = tbm_surface_map (surface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info); - - ... - - tbm_surface_unmap (surface); - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_map(tbm_surface_h surface, int opt, tbm_surface_info_s *info); - -/** - * @brief Unmaps the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * - * @return #TBM_SURFACE_ERROR_NONE on success, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_NONE Success - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * - * @see tbm_surface_map() - * - * @par Example - @code - #include - - tbm_surface_h surface; - tbm_surface_info_s info; - int ret; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - ret = tbm_surface_map (surface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info); - - ... - - tbm_surface_unmap (surface); - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_unmap(tbm_surface_h surface); - -/** - * @brief Gets the information of the tbm_surface. - * @details The information of tbm_surface is assigned in #tbm_surface_info_s struct. \n - * The information of tbm_surface has width, height, format, bpp, size, number of planes and information of planes. \n - * The information of planes has stride, offset, size and pointer of plane. - * - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * @param[out] info The information of the tbm_surface - * - * @return #TBM_SURFACE_ERROR_NONE on success, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_NONE Success - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION Invalid operation - * - * @see tbm_surface_map() - * - * @par Example - @code - #include - - tbm_surface_h surface; - tbm_surface_info_s info; - int ret; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - ret = tbm_surface_get_info (surface, &info); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_get_info(tbm_surface_h surface, tbm_surface_info_s *info); - -/** - * @brief Gets the width of the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * - * @return The width of the tbm_surface on success, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * - * @par Example - @code - #include - - tbm_surface_h surface; - int width; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - - ... - - width = tbm_surface_get_width (surface); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_get_width(tbm_surface_h surface); - -/** - * @brief Gets the height of the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @param[in] surface The #tbm_surface_h - * - * @return The height of the tbm_surface if this function succeeds, - * otherwise an error status value - * - * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * - * @par Example - @code - #include - - tbm_surface_h surface; - int height; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - - ... - - height = tbm_surface_get_height (surface); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_get_height(tbm_surface_h surface); - -/** - * @brief Gets the format of the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * - * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. - * - * @param[in] surface The #tbm_surface_h - * - * @return The format of the tbm_surface on success, - * otherwise @c 0 on failure - * - * @retval #tbm_format The format of surface - * - * @exception #TBM_SURFACE_ERROR_NONE Success - * @exception #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter - * - * @par Example - @code - #include - - tbm_surface_s surface; - tbm_format format; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); - - ... - - format = tbm_surface_get_format (surface); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -tbm_format tbm_surface_get_format(tbm_surface_h surface); - -#ifdef __cplusplus -} -#endif -/** -* @} -*/ -#endif /* _TBM_SURFACE_H_ */ diff --git a/utests/stubs/tbm_surface_internal.h b/utests/stubs/tbm_surface_internal.h deleted file mode 100644 index 6c85b77..0000000 --- a/utests/stubs/tbm_surface_internal.h +++ /dev/null @@ -1,367 +0,0 @@ -#ifndef _TBM_SURFACE_INTERNAL_H_ -#define _TBM_SURFACE_INTERNAL_H_ - -#include - - -/** - * @brief Queries formats which the system can support. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @remarks The formats must be released using free(). - * @param[in] bufmgr : the buffer manager - * @param[out] *formats : format array which the system can support. This pointer has to be freed by user. - * @param[out] num : the number of formats. - * @return a tbm_surface_h if this function succeeds, otherwise NULL - * @par Example - @code - #include - #include - - tbm_bufmgr bufmgr; - uint32_t *formats; - uint32_t format_num; - - bufmgr = tbm_bufmgr_create (-1); - ret = tbm_surface_internal_query_surpported_foramts (bufmgr, &formats, &format_num); - - ... - - free (foramts); - tbm_surface_bufmgr_deinit (bufmgr); - @endcode - */ -int tbm_surface_internal_query_supported_formats(uint32_t **formats, - uint32_t *num); - -/** - * @brief Creates the tbm_surface with memory type. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @details - * #TBM_BO_DEFAULT is default memory: it depends on the backend\n - * #TBM_BO_SCANOUT is scanout memory\n - * #TBM_BO_NONCACHABLE is non-cachable memory\n - * #TBM_BO_WC is write-combine memory\n - * #TBM_BO_VENDOR vendor specific memory: it depends on the tbm backend\n - * @param[in] bufmgr : the buffer manager - * @param[in] width : the width of surface - * @param[in] height : the height of surface - * @param[in] format : the format of surface - * @param[in] flags : the flags of memory type - * @return a tbm_surface_h if this function succeeds, otherwise NULL - * @retval #tbm_surface_h - * @par Example - @code - #include - #include - - int bufmgr_fd - tbm_bufmgr bufmgr; - tbm_surface_h surface; - uint32_t *format; - uint32_t format_num; - - bufmgr = tbm_bufmgr_create (bufmgr_fd); - surface = tbm_surface_internal_create_with_flags (128, 128, TBM_FORMAT_YUV420, TBM_BO_DEFAULT); - - ... - - tbm_surface_destroy (surface); - tbm_surface_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_surface_h tbm_surface_internal_create_with_flags(int width, int height, - int format, int flags); - -/** - * @brief Creates the tbm_surface with buffer objects. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] bufmgr : the buffer manager - * @param[in] width : the width of surface - * @param[in] height : the height of surface - * @param[in] format : the format of surface - * @param[in] *bos : the array pointer of buffer objects - * @param[in] num : the number of buffer objects - * @return a tbm_surface_h if this function succeeds, otherwise NULL - * @retval #tbm_surface_h - * @par Example - @code - #include - #include - #include - - int bufmgr_fd - tbm_bufmgr bufmgr; - tbm_surface_h surface; - tbm_surface_info_s info; - uint32_t *format; - uint32_t format_num; - tbm_bo bo[1]; - - bufmgr = tbm_bufmgr_init (bufmgr_fd); - bo[0] = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); - - info.width = 128; - info.height = 128; - info.format = TBM_FORMAT_ARGB8888; - info.bpp = 32; - info.size = 65536; - info.num_planes = 1; - info.planes[0].size = 65536; - info.planes[0].offset = 0; - info.planes[0].stride = 512; - - surface = tbm_surface_internal_create_with_bos (&info, bo, 1); - - ... - - tbm_surface_destroy (surface); - tbm_surface_bufmgr_deinit (bufmgr); - @endcode - */ -tbm_surface_h tbm_surface_internal_create_with_bos(tbm_surface_info_s *info, - tbm_bo *bos, int num); - -/** - * @brief Destroy the tbm surface - TODO: - */ -void tbm_surface_internal_destroy(tbm_surface_h surface); - -/** - * @brief reference the tbm surface - TODO: - */ -void tbm_surface_internal_ref(tbm_surface_h surface); - -/** - * @brief unreference the tbm surface - TODO: - */ -void tbm_surface_internal_unref(tbm_surface_h surface); - -/** - * @brief Gets the number of buffer objects associated with the tbm_surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] surface : the tbm_surface_h - * @return the number of buffer objects associated with the tbm_surface_h, otherwise 0. - * @par Example - @code - #include - #include - - tbm_surface_h surface; - int num_bos; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); - num_bos = tbm_surface_internal_get_num_bos (surface); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_internal_get_num_bos(tbm_surface_h surface); - -/** - * @brief Gets the buffor object by the bo_index. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] surface : the tbm_surface_h - * @param[in] bo_idx : the bo index in the the tbm_surface - * @return the buffer object, otherwise NULL. - * @retval #tbm_bo - * @par Example - @code - #include - #include - - tbm_surface_h surface; - int num_bos; - tbm_bo bo; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); - num_bos = tbm_surface_internal_get_num_bos (surface); - - for (i=0 ; i < num_bos ; i++) - { - bo = tbm_surface_internal_get_bo (surface, i); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -tbm_bo tbm_surface_internal_get_bo(tbm_surface_h surface, int bo_idx); - -/** - * @brief Gets the size of the surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] surface : the tbm_surface_h - * @return the size of tbm_surface, otherwise 0. - * @par Example - @code - #include - #include - - tbm_surface_h surface; - int size; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); - size = tbm_surface_internal_get_size (surface); - - tbm_surface_destroy (surface); - @endcode - */ -unsigned int tbm_surface_internal_get_size(tbm_surface_h surface); - -/** - * @brief Gets size, offset and pitch data of plane by the plane_index. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] surface : the tbm_surface_h - * @param[in] plane_idx : the bo index in the the tbm_surface - * @param[out] size : the size of plane in tbm_surface - * @param[out] offset : the offset of plane in tbm_surface - * @param[out] pitch : the pitch of plane in tbm_surface - * @return 1 if this function succeeds, otherwise 0. - * @par Example - @code - #include - #include - - tbm_surface_h surface; - uint32_t size, offset, pitch; - int ret; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); - ret = tbm_surface_internal_get_plane_data (surface, 1, &size, &offset, &pitch); - - ... - - tbm_surface_destroy (surface); - @endcode - */ -int tbm_surface_internal_get_plane_data(tbm_surface_h surface, int plane_idx, - uint32_t *size, uint32_t *offset, uint32_t *pitch); - -/** - * @brief Gets number of planes by the format. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] format : the format of surface - * @return number of planes by the format, otherwise 0. - * @par Example - @code - #include - #include - - int num; - - num = tbm_surface_internal_get_num_planes (TBM_FORMAT_YUV420); - - ... - - @endcode - */ -int tbm_surface_internal_get_num_planes(tbm_format format); - -/** - * @brief Gets bpp by the format. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - * @param[in] format : the format of surface - * @return bpp by the format, otherwise 0. - * @par Example - @code - #include - #include - - int bpp; - - bpp = tbm_surface_internal_get_bpp (TBM_FORMAT_YUV420); - - ... - - @endcode - */ -int tbm_surface_internal_get_bpp(tbm_format format); - -/** - * @brief Gets bo index of plane. - * @since_tizen 2.4 - * @param[in] surface : the tbm_surface_h - * @param[in] plane_idx : the bo index in the tbm_surface - * @return bo index of plane, otherwise 0. - * @par Example - @code - #include - #include - - int bo_idx; - tbm_surface_h surface; - - surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); - bo_idx = tbm_surface_internal_get_plane_bo_idx (surface, 0); - - ... - - @endcode - */ -int tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx); - -/** - * @brief Set the pid to the tbm_surface for debugging. - * @since_tizen 3.0 - * @param[in] surface : the tbm_surface_h - * @param[in] pid : the pid - */ -void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, - unsigned int pid); - -/** - * @brief Adds a user_data to the tbm surface. - * @since_tizen 3.0 - * @param[in] surface : the tbm surface. - * @param[in] key : the key associated with the user_data - * @param[in] data_free_func : the function pointer to free the user_data - * @return 1 if this function succeeds, otherwise 0. - * @post the tbm_surface_data_free() will be called under certain conditions, after calling tbm_surface_internal_delete_user_data(). - * @see tbm_surface_free() - * @see tbm_surface_set_user_data() - * @see tbm_surface_get_user_data() - * @see tbm_surface_delete_user_data() - */ -int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, - tbm_data_free data_free_func); - -/** - * @brief Sets a user_date to the tbm surface. - * @since_tizen 3.0 - * @param[in] surface : the tbm surface. - * @param[in] key : the key associated with the user_date - * @param[in] data : a pointer of the user_data - * @return 1 if this function succeeds, otherwise 0. - */ -int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, - void *data); - -/** - * @brief Gets a user_data from the tbm surface with the key. - * @since_tizen 3.0 - * @param[in] surface : the tbm surface. - * @param[in] key : the key associated with the user_date - * @param[out] data : to get the user data - * @return 1 if this function succeeds, otherwise 0. - */ -int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, - void **data); - -/** - * @brief Deletes the user_data in the tbm surface. - * @since_tizen 3.0 - * @param[in] surface : the tbm surface. - * @param[in] key : the key associated with the user_date - * @return 1 if this function succeeds, otherwise 0. - */ -int tbm_surface_internal_delete_user_data(tbm_surface_h surface, - unsigned long key); - -void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type); - -#endif /* _TBM_SURFACE_INTERNAL_H_ */ diff --git a/utests/stubs/tbm_surface_queue.h b/utests/stubs/tbm_surface_queue.h deleted file mode 100644 index a3216d3..0000000 --- a/utests/stubs/tbm_surface_queue.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef _TBM_SURFACE_QUEUE_H_ -#define _TBM_SURFACE_QUEUE_H_ - -#include - -typedef enum { - TBM_SURFACE_QUEUE_ERROR_NONE = 0, /**< Successful */ - TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE = -1, - TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE = -2, - TBM_SURFACE_QUEUE_ERROR_EMPTY = -3, - TBM_SURFACE_QUEUE_ERROR_INVALID_PARAMETER = -4, - TBM_SURFACE_QUEUE_ERROR_SURFACE_ALLOC_FAILED = -5, -} tbm_surface_queue_error_e; - -typedef struct _tbm_surface_queue *tbm_surface_queue_h; - -typedef void (*tbm_surface_queue_notify_cb) (tbm_surface_queue_h surface_queue, - void *data); - -typedef tbm_surface_h (*tbm_surface_alloc_cb) (tbm_surface_queue_h surface_queue, - void *data); - -typedef void (*tbm_surface_free_cb) (tbm_surface_queue_h surface_queue, - void *data, tbm_surface_h surface); - -#ifdef __cplusplus -extern "C" { -#endif - -tbm_surface_queue_error_e tbm_surface_queue_enqueue( - tbm_surface_queue_h surface_queue, tbm_surface_h surface); - -tbm_surface_queue_error_e tbm_surface_queue_dequeue( - tbm_surface_queue_h surface_queue, tbm_surface_h *surface); - -tbm_surface_queue_error_e tbm_surface_queue_release( - tbm_surface_queue_h surface_queue, tbm_surface_h surface); - -tbm_surface_queue_error_e tbm_surface_queue_acquire( - tbm_surface_queue_h surface_queue, tbm_surface_h *surface); - -int tbm_surface_queue_can_dequeue(tbm_surface_queue_h surface_queue, int wait); - -int tbm_surface_queue_can_acquire(tbm_surface_queue_h surface_queue, int wait); - -void tbm_surface_queue_destroy(tbm_surface_queue_h surface_queue); - -int tbm_surface_queue_get_width(tbm_surface_queue_h surface_queue); - -int tbm_surface_queue_get_height(tbm_surface_queue_h surface_queue); - -int tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue); - -int tbm_surface_queue_get_size(tbm_surface_queue_h surface_queue); - -tbm_surface_queue_error_e tbm_surface_queue_reset( - tbm_surface_queue_h surface_queue, int width, int height, int format); - -tbm_surface_queue_error_e tbm_surface_queue_flush(tbm_surface_queue_h surface_queue); - -tbm_surface_queue_error_e tbm_surface_queue_add_reset_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_remove_reset_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_add_destroy_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_remove_destroy_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_add_dequeuable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb dequeuable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_remove_dequeuable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb dequeuable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_add_acquirable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_remove_acquirable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_set_alloc_cb( - tbm_surface_queue_h surface_queue, - tbm_surface_alloc_cb alloc_cb, - tbm_surface_free_cb free_cb, - void *data); - -/*The functions of queue factory*/ -tbm_surface_queue_h tbm_surface_queue_create(int queue_size, int width, - int height, int format, int flags); -tbm_surface_queue_h tbm_surface_queue_sequence_create(int queue_size, int width, - int height, int format, int flags); - - -/*DEPRECATED apis*/ -tbm_surface_queue_error_e tbm_surface_queue_set_destroy_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb destroy_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_set_dequeuable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb dequeuable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_set_acquirable_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb acquirable_cb, - void *data); - -tbm_surface_queue_error_e tbm_surface_queue_set_reset_cb( - tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, - void *data); -#ifdef __cplusplus -} -#endif -#endif /* _TBM_SURFACE_H_ */ diff --git a/utests/stubs/tbm_type.h b/utests/stubs/tbm_type.h deleted file mode 100644 index ff0a705..0000000 --- a/utests/stubs/tbm_type.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _TBM_TYPE_H_ -#define _TBM_TYPE_H_ - -/** - * @addtogroup CAPI_UI_TBM_SURFACE_MODULE - * @{ - */ - -#include - -/** - * @brief Definition for the Tizen buffer surface. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef struct _tbm_surface *tbm_surface_h; -/** - * @brief Definition for the Tizen buffer surface format. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif - */ -typedef uint32_t tbm_format; - -/** -* @} -*/ - -#endif /* _TBM_TYPE_H_ */ diff --git a/utests/stubs/tdm_backend_module_subs.cpp b/utests/stubs/tdm_backend_module_subs.cpp deleted file mode 100644 index c0a38a7..0000000 --- a/utests/stubs/tdm_backend_module_subs.cpp +++ /dev/null @@ -1,387 +0,0 @@ -#include -#include -#include - -#include "tdm_backend.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct _tdm_backend_module_data { - int tmp; -}; - -struct _tdm_backend_module_output_data { - tdm_caps_output caps; -}; - -struct _tdm_backend_module_layer_data { - int tmp; -}; - -typedef struct _tdm_backend_module_data tdm_backend_module_data; -typedef struct _tdm_backend_module_output_data tdm_backend_module_output_data; -typedef struct _tdm_backend_module_layer_data tdm_backend_module_layer_data; - -tdm_backend_module_data backend_module_data; -tdm_backend_module_output_data backend_module_output[4]; -tdm_backend_module_layer_data backend_module_layer; - -tdm_error -tdm_backend_module_creat_output(tdm_backend_module_data *backend_module_data) -{ - return TDM_ERROR_NONE; -} - -void -tdm_backend_module_destroy_output(tdm_backend_module_data *backend_module_data) -{ - return; -} - -tdm_error -tdm_backend_module_creat_layer(tdm_backend_module_data *backend_module_data) -{ - return TDM_ERROR_NONE; -} - -void -tdm_backend_module_destroy_layer(tdm_backend_module_data *backend_module_data) -{ -} - -tdm_error -backend_module_display_get_pp_capability(tdm_backend_data *bdata, tdm_caps_pp *caps) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_display_get_capability(tdm_backend_data *bdata, tdm_caps_display *caps) -{ - caps->max_layer_count = 1; - return TDM_ERROR_NONE; -} - -tdm_output** -backend_module_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error) -{ - tdm_output** outputs; - *count = 4; - outputs = calloc(1, sizeof(tdm_backend_module_output_data*) * (4)); - outputs[0] = &backend_module_output[0]; - outputs[1] = &backend_module_output[1]; - outputs[2] = &backend_module_output[2]; - outputs[3] = &backend_module_output[3]; - if (error) *error = TDM_ERROR_NONE; - return outputs; -} - -tdm_pp* -backend_module_display_create_pp(tdm_backend_data *bdata, tdm_error *error) -{ - return (tdm_pp*)1; -} - -tdm_error -backend_module_display_get_capture_capability(tdm_backend_data *bdata, tdm_caps_capture *caps) -{ - return TDM_ERROR_NONE; -} - -tdm_capture* -backend_module_output_create_capture(tdm_output *output, tdm_error *error) -{ - return (tdm_capture*)1; -} -tdm_capture* -backend_module_layer_create_capture(tdm_layer *layer, tdm_error *error) -{ - return (tdm_capture*)1; -} - - -tdm_error -backend_module_output_get_capability(tdm_output *output, tdm_caps_output *caps) -{ - - tdm_backend_module_output_data *backend_output = (tdm_backend_module_output_data*)output; - memcpy(caps, &backend_output->caps, sizeof(tdm_caps_output)); - - return TDM_ERROR_NONE; -} - -tdm_layer** -backend_module_output_get_layers(tdm_output *output, int *count, tdm_error *error) -{ - tdm_layer** layers; - *count = 1; - layers = calloc(*count, sizeof(tdm_layer)); - layers[0] = &backend_module_layer; - if (error) *error = TDM_ERROR_NONE; - - return layers; - -} - -tdm_error -backend_module_output_set_property(tdm_output *output, unsigned int id, tdm_value value) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_get_property(tdm_output *output, unsigned int id, tdm_value *value) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_commit(tdm_output *output, int sync, void *user_data) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value) -{ - *dpms_value = TDM_OUTPUT_DPMS_ON; - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_set_mode(tdm_output *output, const tdm_output_mode *mode) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_output_get_mode(tdm_output *output, const tdm_output_mode **mode) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_set_info(tdm_layer *layer, tdm_info_layer *info) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_get_info(tdm_layer *layer, tdm_info_layer *info) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) -{ - return TDM_ERROR_NONE; -} - -tdm_error -backend_module_layer_unset_buffer(tdm_layer *layer) -{ - return TDM_ERROR_NONE; -} - - -void -tdm_backend_module_deinit(tdm_backend_data *bdata) -{ -} - -void -backend_module_pp_destroy(tdm_pp *pp) -{ -} -tdm_error -backend_module_pp_set_info(tdm_pp *pp, tdm_info_pp *info) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_pp_attach(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_pp_commit(tdm_pp *pp) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_pp_set_done_handler(tdm_pp *pp, tdm_pp_done_handler func, void *user_data) -{ - return TDM_ERROR_NONE; -} - -// -void -backend_module_capture_destroy(tdm_capture *capture) -{ -} -tdm_error -backend_module_capture_set_info(tdm_capture *capture, tdm_info_capture *info) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_capture_attach(tdm_capture *capture, tbm_surface_h buffer) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_capture_commit(tdm_capture *capture) -{ - return TDM_ERROR_NONE; -} -tdm_error -backend_module_capture_set_done_handler(tdm_capture *capture, - tdm_capture_done_handler func, void *user_data) -{ - return TDM_ERROR_NONE; -} - -tdm_backend_data* -tdm_backend_module_init(tdm_display *dpy, tdm_error *error) -{ - tdm_func_display backend_module_func_display; - tdm_func_output backend_module_func_output; - tdm_func_layer backend_module_func_layer; - tdm_func_capture func_capture; - tdm_func_pp func_pp; - - tdm_error ret; - - if (!dpy) { - if (error) *error = TDM_ERROR_BAD_REQUEST; - return NULL; - } - - backend_module_output[0].caps.status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - backend_module_output[0].caps.type = TDM_OUTPUT_TYPE_DSI; - backend_module_output[1].caps.status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - backend_module_output[1].caps.type = TDM_OUTPUT_TYPE_LVDS; - backend_module_output[2].caps.status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - backend_module_output[2].caps.type = TDM_OUTPUT_TYPE_HDMIA; - backend_module_output[3].caps.status = TDM_OUTPUT_CONN_STATUS_CONNECTED; - backend_module_output[3].caps.type = TDM_OUTPUT_TYPE_HDMIB; - - memset(&backend_module_func_display, 0, sizeof(backend_module_func_display)); - backend_module_func_display.display_get_pp_capability = backend_module_display_get_pp_capability; - backend_module_func_display.display_get_capability = backend_module_display_get_capability; - backend_module_func_display.display_get_outputs = backend_module_display_get_outputs; - backend_module_func_display.display_get_fd = NULL; - backend_module_func_display.display_handle_events = NULL; - - backend_module_func_display.display_create_pp = backend_module_display_create_pp; - backend_module_func_display.display_get_capture_capability = backend_module_display_get_capture_capability; - backend_module_func_output.output_create_capture = backend_module_output_create_capture; - backend_module_func_layer.layer_create_capture = backend_module_layer_create_capture; - - - memset(&backend_module_func_output, 0, sizeof(backend_module_func_output)); - backend_module_func_output.output_get_capability = backend_module_output_get_capability; - backend_module_func_output.output_get_layers = backend_module_output_get_layers; - backend_module_func_output.output_set_property = backend_module_output_set_property; - backend_module_func_output.output_get_property = backend_module_output_get_property; - backend_module_func_output.output_wait_vblank = backend_module_output_wait_vblank; - backend_module_func_output.output_set_vblank_handler = backend_module_output_set_vblank_handler; - backend_module_func_output.output_commit = backend_module_output_commit; - backend_module_func_output.output_set_commit_handler = backend_module_output_set_commit_handler; - backend_module_func_output.output_set_dpms = backend_module_output_set_dpms; - backend_module_func_output.output_get_dpms = backend_module_output_get_dpms; - backend_module_func_output.output_set_mode = backend_module_output_set_mode; - backend_module_func_output.output_get_mode = backend_module_output_get_mode; - - memset(&backend_module_func_layer, 0, sizeof(backend_module_func_layer)); - backend_module_func_layer.layer_get_capability = backend_module_layer_get_capability; - backend_module_func_layer.layer_set_property = backend_module_layer_set_property; - backend_module_func_layer.layer_get_property = backend_module_layer_get_property; - backend_module_func_layer.layer_set_info = backend_module_layer_set_info; - backend_module_func_layer.layer_get_info = backend_module_layer_get_info; - backend_module_func_layer.layer_set_buffer = backend_module_layer_set_buffer; - backend_module_func_layer.layer_unset_buffer = backend_module_layer_unset_buffer; - - memset(&func_capture, 0, sizeof(tdm_func_capture)); - func_capture.capture_attach = backend_module_capture_attach; - func_capture.capture_commit = backend_module_capture_commit; - func_capture.capture_destroy = backend_module_capture_destroy; - func_capture.capture_set_done_handler = backend_module_capture_set_done_handler; - func_capture.capture_set_info = backend_module_capture_set_info; - - - memset(&func_pp, 0, sizeof(tdm_func_pp)); - func_pp.pp_attach = backend_module_pp_attach; - func_pp.pp_commit = backend_module_pp_commit; - func_pp.pp_destroy = backend_module_pp_destroy; - func_pp.pp_set_done_handler = backend_module_pp_set_done_handler; - func_pp.pp_set_info = backend_module_pp_set_info; - - ret = tdm_backend_register_func_display(dpy, &backend_module_func_display); - ret = tdm_backend_register_func_output(dpy, &backend_module_func_output); - ret = tdm_backend_register_func_layer(dpy, &backend_module_func_layer); - ret = tdm_backend_register_func_pp(dpy, &func_pp); - ret = tdm_backend_register_func_capture(dpy, &func_capture); - - if (error) - *error = TDM_ERROR_NONE; - - return (tdm_backend_data*) &backend_module_data; -} - -tdm_backend_module tdm_backend_module_stub = { - "backend_module_stub", - "Samsung", - TDM_BACKEND_ABI_VERSION, - tdm_backend_module_init, - tdm_backend_module_deinit -}; - -#ifdef __cplusplus -} -#endif diff --git a/utests/stubs/tdm_event_loop_stubs.h b/utests/stubs/tdm_event_loop_stubs.h deleted file mode 100644 index 4869cda..0000000 --- a/utests/stubs/tdm_event_loop_stubs.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _TDM_EVENT_LOOP_STUBS_H_ -#define _TDM_EVENT_LOOP_STUBS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "tdm_private.h" - -static tdm_error -ut_tdm_event_loop_init(tdm_private_display *private_display) -{ - return TDM_ERROR_NONE; -} - -static void -ut_tdm_event_loop_deinit(tdm_private_display *private_display) -{ -} - -static void -ut_tdm_event_loop_create_backend_source(tdm_private_display *private_display) -{ -} - -static int -ut_tdm_event_loop_get_fd(tdm_private_display *private_display) -{ - return 1; -} - -static tdm_error -ut_tdm_event_loop_dispatch(tdm_private_display *private_display) -{ - return TDM_ERROR_NONE; -} - - -static void -ut_tdm_event_loop_flush(tdm_private_display *private_display) -{ -} - - -static tdm_event_loop_source * -ut_tdm_event_loop_add_fd_handler(tdm_display *dpy, int fd, tdm_event_loop_mask mask, - tdm_event_loop_fd_handler func, void *user_data, - tdm_error *error) -{ - return (tdm_event_loop_source*)1; -} - -static tdm_error -ut_tdm_event_loop_source_fd_update(tdm_event_loop_source *source, tdm_event_loop_mask mask) -{ - return TDM_ERROR_NONE; -} - -static tdm_event_loop_source * -ut_tdm_event_loop_add_timer_handler(tdm_display *dpy, tdm_event_loop_timer_handler func, - void *user_data, tdm_error *error) -{ - return (tdm_event_loop_source*)1; -} - -static tdm_error -ut_tdm_event_loop_source_timer_update(tdm_event_loop_source *source, unsigned int ms_delay) -{ - return TDM_ERROR_NONE; -} - -static void -ut_tdm_event_loop_source_remove(tdm_event_loop_source *source) -{ -} - -//-------------- -#define tdm_event_loop_init ut_tdm_event_loop_init -#define tdm_event_loop_deinit ut_tdm_event_loop_deinit -#define tdm_event_loop_create_backend_source ut_tdm_event_loop_create_backend_source -#define tdm_event_loop_get_fd ut_tdm_event_loop_get_fd -#define tdm_event_loop_dispatch ut_tdm_event_loop_dispatch -#define tdm_event_loop_flush ut_tdm_event_loop_flush -#define tdm_event_loop_add_fd_handler ut_tdm_event_loop_add_fd_handler -#define tdm_event_loop_source_fd_update ut_tdm_event_loop_source_fd_update -#define tdm_event_loop_add_timer_handler ut_tdm_event_loop_add_timer_handler -#define tdm_event_loop_source_timer_update ut_tdm_event_loop_source_timer_update -#define tdm_event_loop_source_remove ut_tdm_event_loop_source_remove - -#ifdef __cplusplus -} -#endif - -#endif /* _TDM_EVENT_LOOP_STUBS_H_ */ diff --git a/utests/stubs/tdm_log.cpp b/utests/stubs/tdm_log.cpp deleted file mode 100644 index 8cb4970..0000000 --- a/utests/stubs/tdm_log.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "tdm_log.h" - -void -tdm_log_enable_color(unsigned int enable) -{ - (void)enable; -} - -void -tdm_log_enable_dlog(unsigned int enable) -{ - (void)enable; -} - -void -tdm_log_enable_debug(unsigned int enable) -{ - (void)enable; -} - -void -tdm_log_set_debug_level(int level) -{ - (void)level; -} - -void -tdm_log_print(int level, const char *fmt, ...) -{ - (void)level; - (void)fmt; -} diff --git a/utests/stubs/tdm_server.cpp b/utests/stubs/tdm_server.cpp deleted file mode 100644 index 1ec0b9e..0000000 --- a/utests/stubs/tdm_server.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "tdm_private.h" - -tdm_error -tdm_server_init(tdm_private_loop *private_loop) -{ - (void)private_loop; - - return TDM_ERROR_NONE; -} - -void -tdm_server_deinit(tdm_private_loop *private_loop) -{ - (void)private_loop; -} diff --git a/utests/stubs/wayland-server-core.h b/utests/stubs/wayland-server-core.h deleted file mode 100644 index 3cd7f6d..0000000 --- a/utests/stubs/wayland-server-core.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef WAYLAND_SERVER_CORE_H -#define WAYLAND_SERVER_CORE_H - -#include - -static int WL_EVENT_LOOP_ADD_FD_ERROR; -static int WL_EVENT_SOURCE_FD_UPDATE_ERROR; -static int WL_EVENT_LOOP_ADD_TIMER_ERROR; -static int WL_EVENT_SOURCE_TIMER_UPDATE_ERROR; -static int WL_DISPLAY_CREATE_ERROR; - -enum { - WL_EVENT_READABLE = 0x01, - WL_EVENT_WRITABLE = 0x02, - WL_EVENT_HANGUP = 0x04, - WL_EVENT_ERROR = 0x08 -}; - -struct wl_interface { - int a; -}; - -struct wl_interface wl_tdm_interface; - -struct wl_interface wl_tdm_vblank_interface; - -typedef enum { - WL_TDM_ERROR_INVALID_NAME, - WL_TDM_ERROR_OPERATION_FAILED - -} wl_error; - -struct wl_display { - int a; -}; - -struct wl_tdm_interface { - void (*_tdm_server_cb_wait_vblank)(struct wl_client *client, - struct wl_resource *resource, - uint32_t id, const char *name, int32_t interval); -}; - -struct wl_event_loop { - int temp; -}; - -struct wl_event_source { - int temp; -}; - -wl_display ut_wl_display; -wl_event_loop ut_wl_event_loop; - -static void wl_display_flush_clients(struct wl_display *display) -{ - (void)display; -} - -static struct wl_display *wl_display_create() -{ - if (WL_DISPLAY_CREATE_ERROR) - return NULL; - return &ut_wl_display; -} - -static struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display) -{ - (void)display; - - return &ut_wl_event_loop; -} - -static void wl_display_destroy(struct wl_display *display) -{ - (void)display; -} - -static int wl_event_loop_get_fd(struct wl_event_loop *loop) -{ - (void)loop; - - return 0; -} - -typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data, - uint32_t version, uint32_t id); - -static int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout) -{ - (void)loop; - (void)timeout; - - return 0; -} - -typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t wl_mask, void *data); - -struct wl_event_source event_source; - -static struct wl_event_source *wl_event_loop_add_fd(struct wl_event_loop *loop, - int fd, uint32_t mask, - wl_event_loop_fd_func_t func, - void *data) -{ - (void)loop; - (void)fd; - (void)mask; - (void)func; - (void)data; - - if (WL_EVENT_LOOP_ADD_FD_ERROR) { - return NULL; - } - - return &event_source; -} - -static int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask) -{ - (void)source; - (void)mask; - - if (WL_EVENT_SOURCE_FD_UPDATE_ERROR) { - return -1; - } - - return 1; -} - -typedef int (*wl_event_loop_timer_func_t) (void *data); - -static struct wl_event_source *wl_event_loop_add_timer(struct wl_event_loop *loop, - wl_event_loop_timer_func_t func, - void *data) -{ - (void)loop; - (void)func; - (void)data; - - if (WL_EVENT_LOOP_ADD_TIMER_ERROR) { - return NULL; - } - - return &event_source; -} - -static int wl_event_source_timer_update(struct wl_event_source *source, int ms_delay) -{ - (void)source; - (void)ms_delay; - - if (WL_EVENT_SOURCE_TIMER_UPDATE_ERROR) { - return -1; - } - - return 1; -} - -static int wl_event_source_remove(struct wl_event_source *source) -{ - (void)source; - - return 0; -} - -typedef void (*wl_resource_destroy_func_t) (struct wl_resource *resource); - -#endif /* WAYLAND_SERVER_CORE_H */ diff --git a/utests/stubs/wayland-tbm-drm-auth-client-protocol.h b/utests/stubs/wayland-tbm-drm-auth-client-protocol.h deleted file mode 100644 index 7175fc8..0000000 --- a/utests/stubs/wayland-tbm-drm-auth-client-protocol.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef TBM_DRM_AUTH_CLIENT_PROTOCOL_H -#define TBM_DRM_AUTH_CLIENT_PROTOCOL_H - -#include -#include - -struct wl_client; -struct wl_resource; - -struct wl_tbm_drm_auth; - -extern const struct wl_interface wl_tbm_drm_auth_interface; - -struct wl_tbm_drm_auth_listener { - void (*authentication_info)(void *data, - struct wl_tbm_drm_auth *wl_tbm_drm_auth, - const char *device_name, - uint32_t capabilities, - int32_t auth_fd); -}; - -static inline int -wl_tbm_drm_auth_add_listener(struct wl_tbm_drm_auth *wl_tbm_drm_auth, - const struct wl_tbm_drm_auth_listener *listener, void *data) -{ - (void)wl_tbm_drm_auth; - (void)listener; - (void)data; - - return 0; -} - -#define WL_TBM_DRM_AUTH_GET_AUTHENTICATION_INFO 0 - -static inline void -wl_tbm_drm_auth_set_user_data(struct wl_tbm_drm_auth *wl_tbm_drm_auth, void *user_data) -{ - (void)wl_tbm_drm_auth; - (void)user_data; -} - -static inline void * -wl_tbm_drm_auth_get_user_data(struct wl_tbm_drm_auth *wl_tbm_drm_auth) -{ - (void)wl_tbm_drm_auth; - - return NULL; -} - -static inline void -wl_tbm_drm_auth_destroy(struct wl_tbm_drm_auth *wl_tbm_drm_auth) -{ - (void)wl_tbm_drm_auth; -} - -static inline void -wl_tbm_drm_auth_get_authentication_info(struct wl_tbm_drm_auth *wl_tbm_drm_auth) -{ - (void)wl_tbm_drm_auth; -} - -#endif -- 2.7.4 From 41890545a67a98a6bd2e63ee065a481e7ad08baf Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Wed, 8 Nov 2017 09:41:04 +0200 Subject: [PATCH 02/16] tdm_display_deinit: use tbm_drm_helper_unset_tbm_master_fd() for unset tbm_master_fd It is wrong to use tdm_helper_set_fd() func. to unset TDM_DRM_MASTER_FD. tdm_helper_set_fd() call tbm_drm_helper_set_tbm_master_fd() which fails when we pass -1. The error was found as result of utests. Change-Id: I5d67b5841a5fafde6424890d32ae480be7c1808a Signed-off-by: Konstantin Drabeniuk --- src/tdm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tdm.c b/src/tdm.c index d0f0e44..7c12dfe 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -41,6 +41,7 @@ #include "tdm_backend.h" #include "tdm_private.h" #include "tdm_helper.h" +#include pthread_mutex_t tdm_mutex_check_lock = PTHREAD_MUTEX_INITIALIZER; int tdm_mutex_locked; @@ -1079,7 +1080,7 @@ tdm_display_deinit(tdm_display *dpy) tbm_bufmgr_deinit(private_display->bufmgr); #endif - tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1); + tbm_drm_helper_unset_tbm_master_fd(); pthread_mutex_destroy(&private_display->lock); free(private_display); -- 2.7.4 From 24a1cb8f4dc52228e4883306bf712e23967e0c87 Mon Sep 17 00:00:00 2001 From: Andrii Sokolenko Date: Wed, 8 Nov 2017 18:21:57 +0200 Subject: [PATCH 03/16] [utest] Add 25 test cases. Change-Id: I98437b4ad61706df1c9548e178f04035f91562d3 Signed-off-by: Andrii Sokolenko --- utests/Makefile.am | 2 +- utests/src/ut_common.h | 2 +- utests/src/ut_main.cpp | 2 +- utests/src/ut_tdm.cpp | 110 ++++++++++++++-- utests/src/ut_tdm_capture.cpp | 18 ++- utests/src/ut_tdm_layer.cpp | 19 ++- utests/src/ut_tdm_output.cpp | 286 +++++++++++++++++++++++++++++++++++++++++- utests/src/ut_tdm_pp.cpp | 12 +- 8 files changed, 433 insertions(+), 18 deletions(-) diff --git a/utests/Makefile.am b/utests/Makefile.am index 3357e0c..c95689c 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -17,7 +17,7 @@ tdm_utests_CXXFLAGS = \ -I$(includedir)/gtest \ -fpermissive \ -rdynamic \ - -UFAIL_ON_UNSUPPORTED \ + -DFAIL_ON_UNSUPPORTED \ -w # The flag -w is used, because there are many warnings in libtdm's sources. # Warnings occur because we build project with g++. diff --git a/utests/src/ut_common.h b/utests/src/ut_common.h index c30269d..7a6968b 100644 --- a/utests/src/ut_common.h +++ b/utests/src/ut_common.h @@ -1,6 +1,6 @@ #ifndef UT_COMMON_H #define UT_COMMON_H -#define CHECK_FLAG(FLAG) \ +#define SKIP_FLAG(FLAG) \ do {\ if(!FLAG) {\ std::cout << "[ SKIPPED ]" << " not supported" << std::endl;\ diff --git a/utests/src/ut_main.cpp b/utests/src/ut_main.cpp index b6aeb4a..8d0544a 100644 --- a/utests/src/ut_main.cpp +++ b/utests/src/ut_main.cpp @@ -33,6 +33,6 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + ::testing::FLAGS_gtest_death_test_style = "fast"; return RUN_ALL_TESTS(); } diff --git a/utests/src/ut_tdm.cpp b/utests/src/ut_tdm.cpp index 6a6ead6..80979c4 100644 --- a/utests/src/ut_tdm.cpp +++ b/utests/src/ut_tdm.cpp @@ -29,29 +29,42 @@ **************************************************************************/ #include "gtest/gtest.h" +extern "C" { #include "tdm.h" +#include "tbm_bufmgr.h" +#include "tbm_drm_helper.h" +} class TDMInit : public ::testing::Test { protected: void SetUp(void) { setenv("TDM_DLOG", "1", 1); - setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("XDG_RUNTIME_DIR", "/tmp", 1); setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); } void TearDown(void) { + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; class TDMDefault : public ::testing::Test { protected: tdm_display *dpy = NULL; + tbm_bufmgr tbm_bufmgr = NULL; void SetUp(void) { setenv("TDM_DLOG", "1", 1); - setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("XDG_RUNTIME_DIR", "/tmp", 1); setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -60,41 +73,105 @@ protected: void TearDown(void) { tdm_display_deinit(dpy); + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; dpy = NULL; + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; -TEST_F(TDMInit, DisplayInitDeinitSuccessful) +TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithoutTBM) +{ + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + tdm_display_deinit(dpy); + dpy = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); +} + +TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM) +{ + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy[20] = {NULL}; + tbm_bufmgr tbm_bufmgr = NULL; + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); + for (int i = 0; i < 20; i++) { + dpy[i] = tdm_display_init(&error); + EXPECT_TRUE(error == TDM_ERROR_NONE); + EXPECT_FALSE(dpy[i] == NULL); + EXPECT_EQ(dpy[0], dpy[i]); + } + for (int i = 19; i > 0; i--) { + tdm_display_deinit(dpy[i]); + EXPECT_FALSE(tbm_drm_helper_get_master_fd() == -1); + EXPECT_FALSE(tbm_drm_helper_get_fd() == -1); + } + tdm_display_deinit(dpy[0]); + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); +} + +TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithTBM) { + tbm_bufmgr tbm_bufmgr = NULL; + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } -TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullError) +TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullErrorWithTBM) { + tbm_bufmgr tbm_bufmgr = NULL; + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(NULL); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } -TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimes) +TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM) { for (int i = 0; i < 20; ++i) { + tbm_bufmgr tbm_bufmgr = NULL; + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; } + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy) @@ -106,6 +183,8 @@ TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy) tdm_display_deinit(NULL); tdm_display_deinit(dpy); dpy = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } TEST_F(TDMInit, DisplayDeinitDeathWrongDpy) @@ -114,10 +193,13 @@ TEST_F(TDMInit, DisplayDeinitDeathWrongDpy) tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); - tdm_display *wrong_dpy = 0xBEAF; - EXPECT_DEATH(tdm_display_deinit(wrong_dpy), ""); + EXPECT_EXIT({tdm_display *wrong_dpy = 0xBEAF; + tdm_display_deinit(wrong_dpy); + exit(0); }, ::testing::ExitedWithCode(0), ""); tdm_display_deinit(dpy); dpy = NULL; + ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); + ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } TEST_F(TDMDefault, DisplayUpdateSuccessful) @@ -125,6 +207,13 @@ TEST_F(TDMDefault, DisplayUpdateSuccessful) ASSERT_TRUE(tdm_display_update(dpy) == TDM_ERROR_NONE); } +TEST_F(TDMDefault, DisplayUpdateFailWrongDpy) +{ + ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; + tdm_display_update(wrong_dpy); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + TEST_F(TDMDefault, DisplayUpdateFailNullDpy) { ASSERT_FALSE(tdm_display_update(NULL) == TDM_ERROR_NONE); @@ -153,6 +242,13 @@ TEST_F(TDMDefault, DisplayGetFDFailNullDpy) ASSERT_FALSE(tdm_display_get_fd(NULL, &fd) == TDM_ERROR_NONE); } +TEST_F(TDMDefault, DisplayGetFDFailWrongDpy) +{ + ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; int fd = -42; + tdm_display_get_fd(wrong_dpy, &fd); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + TEST_F(TDMDefault, DISABLED_DisplayHandleEventsSuccessful) { /* TODO Generate events*/ diff --git a/utests/src/ut_tdm_capture.cpp b/utests/src/ut_tdm_capture.cpp index 9715d1a..cffcc72 100644 --- a/utests/src/ut_tdm_capture.cpp +++ b/utests/src/ut_tdm_capture.cpp @@ -29,19 +29,27 @@ **************************************************************************/ #include "gtest/gtest.h" -#include "tdm.h" #include "ut_common.h" +extern "C" { +#include "tdm.h" +#include "tbm_bufmgr.h" +#include "tbm_drm_helper.h" +} class TDMCapture : public ::testing::Test { protected: tdm_display *dpy = NULL; tdm_capture_capability capture_capabilities = -42; bool has_capture = false; + tbm_bufmgr tbm_bufmgr = NULL; void SetUp(void) { setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -57,12 +65,18 @@ protected: { tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; TEST_F(TDMCapture, DisplayGetCaptureAvailableFormatsSuccessful) { - CHECK_FLAG(has_capture); + SKIP_FLAG(has_capture); const tbm_format * formats = NULL; int count = -42; ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_catpure_available_formats(dpy, &formats, &count)); diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index 89064c0..574fd08 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -29,12 +29,18 @@ **************************************************************************/ #include "gtest/gtest.h" -#include "tdm.h" #include "ut_common.h" +extern "C" { +#include "tdm.h" +#include "tbm_bufmgr.h" +#include "tbm_drm_helper.h" +} + class TDMLayer : public ::testing::Test { protected: tdm_display *dpy = NULL; + tbm_bufmgr tbm_bufmgr = NULL; int output_count = -42; int layer_count = -42; bool has_layers = false; @@ -43,6 +49,9 @@ protected: setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -60,12 +69,18 @@ protected: { tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; TEST_F(TDMLayer, OutputGetLayerSuccessful) { - CHECK_FLAG(has_layers); + SKIP_FLAG(has_layers); for (int i = 0; i < output_count; i++) { tdm_error error_output = TDM_ERROR_NONE; tdm_output * output = NULL; diff --git a/utests/src/ut_tdm_output.cpp b/utests/src/ut_tdm_output.cpp index 6ea9f21..460972c 100644 --- a/utests/src/ut_tdm_output.cpp +++ b/utests/src/ut_tdm_output.cpp @@ -29,19 +29,38 @@ **************************************************************************/ #include "gtest/gtest.h" -#include "tdm.h" #include "ut_common.h" +#include +extern "C" { +#include "tdm.h" +#include "tbm_bufmgr.h" +#include "tbm_drm_helper.h" +} class TDMOutput : public ::testing::Test { protected: tdm_display *dpy = NULL; int output_count = -42; bool has_output = false; + tbm_bufmgr tbm_bufmgr = NULL; + static unsigned int handle_call; + static void tdm_output_change_handler_test_func(tdm_output *output, + tdm_output_change_type type, + tdm_value value, + void *u_data) + { + if ( ((int) u_data) < -100) { + TDMOutput::handle_call++; + } + } void SetUp(void) { setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -52,20 +71,283 @@ protected: #endif if (output_count > 0) has_output = true; + handle_call = 0; } void TearDown(void) { tdm_display_deinit(dpy); dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; +unsigned int TDMOutput::handle_call = 0; + TEST_F(TDMOutput, DisplayGetOutputSuccessful) { - CHECK_FLAG(has_output); + SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error)); ASSERT_TRUE(TDM_ERROR_NONE == error); } } + +TEST_F(TDMOutput, DisplayGetOutputSuccessfulWrongIndex) +{ + SKIP_FLAG(has_output); + tdm_error error = TDM_ERROR_NONE; + ASSERT_TRUE(NULL == tdm_display_get_output(dpy, -1, &error)); + ASSERT_TRUE(TDM_ERROR_NONE == error); +} + +TEST_F(TDMOutput, DisplayGetOutputSuccessfulBigIndex) +{ + SKIP_FLAG(has_output); + tdm_error error = TDM_ERROR_NONE; + ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MAX, &error)); + ASSERT_TRUE(TDM_ERROR_NONE == error); +} + +TEST_F(TDMOutput, DisplayGetOutputSuccessfulSmallIndex) +{ + SKIP_FLAG(has_output); + tdm_error error = TDM_ERROR_NONE; + ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MIN, &error)); + ASSERT_TRUE(TDM_ERROR_NONE == error); +} + +TEST_F(TDMOutput, DisplayGetOutputSuccessfulErrorNull) +{ + SKIP_FLAG(has_output); + ASSERT_FALSE(NULL == tdm_display_get_output(dpy, 0, NULL)); +} + +TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output_capability capabilities = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, &capabilities)); + ASSERT_FALSE(-42 == capabilities); + } +} + +TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailAllNull) +{ + SKIP_FLAG(has_output); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(NULL, NULL)); +} + +TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailOnlyOutput) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, NULL)); + } +} + +TEST_F(TDMOutput, OutputGetModelInfoSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + const char * maker = NULL, * model = NULL, * name = NULL; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, &maker, &model, &name)); + ASSERT_FALSE(NULL == maker); + ASSERT_FALSE(NULL == model); + ASSERT_FALSE(NULL == name); + } +} + +TEST_F(TDMOutput, OutputGetModelInfoFailAllNull) +{ + SKIP_FLAG(has_output); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_model_info(NULL, NULL, NULL, NULL)); +} + +TEST_F(TDMOutput, OutputGetModelInfoSuccessfulOnlyOutput) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, NULL, NULL, NULL)); + } +} + +TEST_F(TDMOutput, OutputGetConnStatusSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output_conn_status status = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + ASSERT_FALSE(-42 == status); + } +} + +TEST_F(TDMOutput, OutputGetConnStatusFailAllNull) +{ + SKIP_FLAG(has_output); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(NULL, NULL)); +} + +TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, NULL)); + } +} + +TEST_F(TDMOutput, OutputSetDPMSSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + } +} + +TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, + tdm_output_change_handler_test_func, + -101)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_GT(handle_call, 0); + } +} + +TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + for (int k = 0; k < 20; k++) { + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, + tdm_output_change_handler_test_func, + (-101-k))); + } + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_GT(handle_call, 20); + } +} + + +TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull) +{ + SKIP_FLAG(has_output); + ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL)); +} + +TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, NULL, NULL)); + } +} + +TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({tdm_output *output = 0xBEAF; + tdm_output_add_change_handler(output, + tdm_output_change_handler_test_func, + -101); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) +{ + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, + tdm_output_change_handler_test_func, + -101)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_GT(handle_call, 0); + handle_call = 0; + tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, -101); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_EQ(handle_call, 0); + } +} + +TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs) +{ + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + for (int k = 0; k < 20; k++) { + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, + tdm_output_change_handler_test_func, + (-101-k))); + } + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_GT(handle_call, 20); + handle_call = 0; + for (int k = 0; k < 20; k++) { + tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (-101-k)); + } + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); + ASSERT_EQ(handle_call, 0); + } +} diff --git a/utests/src/ut_tdm_pp.cpp b/utests/src/ut_tdm_pp.cpp index 18d9a96..6fa99da 100644 --- a/utests/src/ut_tdm_pp.cpp +++ b/utests/src/ut_tdm_pp.cpp @@ -29,8 +29,12 @@ **************************************************************************/ #include "gtest/gtest.h" -#include "tdm.h" #include "ut_common.h" +extern "C" { +#include "tdm.h" +#include "tbm_bufmgr.h" +#include "tbm_drm_helper.h" +} class TDMPP : public testing::Test { protected: @@ -57,12 +61,16 @@ protected: { tdm_display_deinit(dpy); dpy = NULL; + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TBM_DISPLAY_SERVER"); } }; TEST_F(TDMPP, DisplayGetPPAvailableFormatsSuccessful) { - CHECK_FLAG(has_pp); + SKIP_FLAG(has_pp); const tbm_format * formats = NULL; int count = -42; ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count)); -- 2.7.4 From eb3242cf48230380195c9a0fef46535b85f610d0 Mon Sep 17 00:00:00 2001 From: Andrii Sokolenko Date: Thu, 9 Nov 2017 18:35:50 +0200 Subject: [PATCH 04/16] [utest] Add 9 test cases. Fix Init/Deinit behavior. Change-Id: Ib77379ef55ecc145e9b87702ca2b99969718c677 Signed-off-by: Andrii Sokolenko --- utests/Makefile.am | 3 +- utests/src/ut_tdm.cpp | 206 ++++++++++++++++++++++++++++++++---------- utests/src/ut_tdm_capture.cpp | 2 +- utests/src/ut_tdm_layer.cpp | 70 ++++++++++---- utests/src/ut_tdm_output.cpp | 139 +++++++++++++++++++++++++--- utests/src/ut_tdm_pp.cpp | 2 +- 6 files changed, 341 insertions(+), 81 deletions(-) diff --git a/utests/Makefile.am b/utests/Makefile.am index c95689c..f44d3e0 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -17,8 +17,7 @@ tdm_utests_CXXFLAGS = \ -I$(includedir)/gtest \ -fpermissive \ -rdynamic \ - -DFAIL_ON_UNSUPPORTED \ - -w + -DFAIL_ON_UNSUPPORTED # The flag -w is used, because there are many warnings in libtdm's sources. # Warnings occur because we build project with g++. # In C++ we need to use explicit types conversion. diff --git a/utests/src/ut_tdm.cpp b/utests/src/ut_tdm.cpp index 80979c4..fd5f526 100644 --- a/utests/src/ut_tdm.cpp +++ b/utests/src/ut_tdm.cpp @@ -37,6 +37,7 @@ extern "C" { class TDMInit : public ::testing::Test { protected: + int master_fd = -42, tbm_fd = -42; void SetUp(void) { setenv("TDM_DLOG", "1", 1); @@ -46,6 +47,20 @@ protected: } void TearDown(void) { + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_tbm_fd > -1) + exit(1); + close(tbm_fd); + } unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DLOG"); @@ -57,6 +72,7 @@ class TDMDefault : public ::testing::Test { protected: tdm_display *dpy = NULL; tbm_bufmgr tbm_bufmgr = NULL; + int master_fd = -42, tbm_fd = -42; void SetUp(void) { setenv("TDM_DLOG", "1", 1); @@ -69,6 +85,8 @@ protected: dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); } void TearDown(void) { @@ -76,6 +94,20 @@ protected: tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; dpy = NULL; + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_tbm_fd > -1) + exit(1); + close(tbm_fd); + } unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DLOG"); @@ -90,12 +122,31 @@ TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithoutTBM) tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); tdm_display_deinit(dpy); dpy = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } +TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithTBM) +{ + tbm_bufmgr tbm_bufmgr = NULL; + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + EXPECT_TRUE(error == TDM_ERROR_NONE); + EXPECT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + if (dpy != NULL && error == TDM_ERROR_NONE) + tdm_display_deinit(dpy); + dpy = NULL; + tbm_bufmgr_deinit(tbm_bufmgr); + tbm_bufmgr = NULL; +} + + TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM) { tdm_error error = TDM_ERROR_NONE; @@ -103,7 +154,12 @@ TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM) tbm_bufmgr tbm_bufmgr = NULL; tbm_bufmgr = tbm_bufmgr_init(-1); ASSERT_FALSE(tbm_bufmgr == NULL); - for (int i = 0; i < 20; i++) { + dpy[0] = tdm_display_init(&error); + EXPECT_TRUE(error == TDM_ERROR_NONE); + EXPECT_FALSE(dpy[0] == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + for (int i = 1; i < 20; i++) { dpy[i] = tdm_display_init(&error); EXPECT_TRUE(error == TDM_ERROR_NONE); EXPECT_FALSE(dpy[i] == NULL); @@ -111,31 +167,22 @@ TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM) } for (int i = 19; i > 0; i--) { tdm_display_deinit(dpy[i]); - EXPECT_FALSE(tbm_drm_helper_get_master_fd() == -1); - EXPECT_FALSE(tbm_drm_helper_get_fd() == -1); + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_NE(temp_master_fd, -1); + if (temp_master_fd > -1) + close(temp_master_fd); + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_NE(temp_tbm_fd, -1); + if (temp_tbm_fd > -1) + close(temp_tbm_fd); + } } tdm_display_deinit(dpy[0]); tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); -} - -TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithTBM) -{ - tbm_bufmgr tbm_bufmgr = NULL; - tbm_bufmgr = tbm_bufmgr_init(-1); - ASSERT_FALSE(tbm_bufmgr == NULL); - tdm_error error = TDM_ERROR_NONE; - tdm_display *dpy = tdm_display_init(&error); - ASSERT_TRUE(error == TDM_ERROR_NONE); - ASSERT_FALSE(dpy == NULL); - tdm_display_deinit(dpy); - dpy = NULL; - tbm_bufmgr_deinit(tbm_bufmgr); - tbm_bufmgr = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullErrorWithTBM) @@ -143,16 +190,15 @@ TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullErrorWithTBM) tbm_bufmgr tbm_bufmgr = NULL; tbm_bufmgr = tbm_bufmgr_init(-1); ASSERT_FALSE(tbm_bufmgr == NULL); - tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(NULL); - ASSERT_TRUE(error == TDM_ERROR_NONE); - ASSERT_FALSE(dpy == NULL); - tdm_display_deinit(dpy); + EXPECT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + if (dpy != NULL) + tdm_display_deinit(dpy); dpy = NULL; tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM) @@ -163,43 +209,107 @@ TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM) ASSERT_FALSE(tbm_bufmgr == NULL); tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(&error); - ASSERT_TRUE(error == TDM_ERROR_NONE); - ASSERT_FALSE(dpy == NULL); - tdm_display_deinit(dpy); + EXPECT_TRUE(error == TDM_ERROR_NONE); + EXPECT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + if (dpy != NULL) + tdm_display_deinit(dpy); dpy = NULL; tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + master_fd = -1; + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_tbm_fd > -1) + exit(1); + close(tbm_fd); + tbm_fd = -1; + } } - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } -TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy) +TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpyWithoutTBM) { tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); tdm_display_deinit(NULL); tdm_display_deinit(dpy); dpy = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); } -TEST_F(TDMInit, DisplayDeinitDeathWrongDpy) +TEST_F(TDMInit, DisplayDeinitFailWrongDpyBadAddress) { tdm_error error = TDM_ERROR_NONE; tdm_display *dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); - EXPECT_EXIT({tdm_display *wrong_dpy = 0xBEAF; + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EXIT({tdm_display *wrong_dpy = (tdm_display *) 0xBEAF; tdm_display_deinit(wrong_dpy); exit(0); }, ::testing::ExitedWithCode(0), ""); tdm_display_deinit(dpy); dpy = NULL; - ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1); - ASSERT_TRUE(tbm_drm_helper_get_fd() == -1); +} + +TEST_F(TDMInit, DisplayDeinitFailWrongDpyStackAddress) +{ + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EXIT({tdm_display *wrong_dpy = &error; + tdm_display_deinit(wrong_dpy); + exit(0); }, ::testing::ExitedWithCode(0), ""); + tdm_display_deinit(dpy); + dpy = NULL; +} + +TEST_F(TDMInit, DisplayDeinitFailWrongDpyHeapAddress) +{ + tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EXIT({tdm_display *wrong_dpy = (tdm_display *) ((unsigned long) sbrk(0) - sizeof(unsigned long)); + tdm_display_deinit(wrong_dpy); + exit(0); }, ::testing::ExitedWithCode(0), ""); + tdm_display_deinit(dpy); + dpy = NULL; +} + +TEST_F(TDMInit, DISABLED_DisplayDeinitFailRepeatWithSameDpy) +{ + EXPECT_EXIT({tdm_error error = TDM_ERROR_NONE; + tdm_display *dpy = tdm_display_init(&error); + if (error != TDM_ERROR_NONE) exit(1); + tdm_display_deinit(dpy); + if (tbm_drm_helper_get_master_fd() != -1) exit(1); + if (tbm_drm_helper_get_fd() != -1) exit(1); + tdm_display_deinit(dpy); + tdm_display *dpy2 = malloc(2048); + *((unsigned int *)dpy2) = 673282346; + tdm_display_deinit(dpy2); + tdm_display_deinit(dpy); + tdm_display_deinit(dpy2); + exit(0); }, ::testing::ExitedWithCode(0), ""); } TEST_F(TDMDefault, DisplayUpdateSuccessful) @@ -209,7 +319,7 @@ TEST_F(TDMDefault, DisplayUpdateSuccessful) TEST_F(TDMDefault, DisplayUpdateFailWrongDpy) { - ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; + ASSERT_EXIT({tdm_display *wrong_dpy = (tdm_display *)0xBEAF; tdm_display_update(wrong_dpy); exit(0);}, ::testing::ExitedWithCode(0), ""); } @@ -244,7 +354,7 @@ TEST_F(TDMDefault, DisplayGetFDFailNullDpy) TEST_F(TDMDefault, DisplayGetFDFailWrongDpy) { - ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; int fd = -42; + ASSERT_EXIT({tdm_display *wrong_dpy = (tdm_display *) 0xBEAF; int fd = -42; tdm_display_get_fd(wrong_dpy, &fd); exit(0);}, ::testing::ExitedWithCode(0), ""); } @@ -307,7 +417,7 @@ TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyMinor) TEST_F(TDMDefault, DisplayGetCapabilitiesSuccessful) { - tdm_display_capability capabilities = -42; + tdm_display_capability capabilities = (tdm_display_capability) -42; ASSERT_TRUE(tdm_display_get_capabilities(dpy, &capabilities) == TDM_ERROR_NONE); ASSERT_FALSE(capabilities == -1); } @@ -324,7 +434,7 @@ TEST_F(TDMDefault, DisplayGetCapabilitiesFailSetOnlyDpy) TEST_F(TDMDefault, DisplayGetPPCapabilitiesSuccessful) { - tdm_pp_capability capabilities = -42; + tdm_pp_capability capabilities = (tdm_pp_capability) -42; tdm_error error = TDM_ERROR_NONE; error = tdm_display_get_pp_capabilities(dpy, &capabilities); ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY); @@ -340,7 +450,7 @@ TEST_F(TDMDefault, DisplayGetPPCapabilitiesFailNullAll) TEST_F(TDMDefault, DisplayGetCaptureCapabilitiesSuccessful) { - tdm_capture_capability capabilities = -42; + tdm_capture_capability capabilities = (tdm_capture_capability) -42; tdm_error error = TDM_ERROR_NONE; error = tdm_display_get_capture_capabilities(dpy, &capabilities); ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY); @@ -358,7 +468,7 @@ TEST_F(TDMDefault, DisplayGetMaxLayerCountSuccessful) { int max_count = -42; ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_max_layer_count(dpy, &max_count)); - ASSERT_FALSE(-42 == max_count); + ASSERT_NE(max_count, -42); } TEST_F(TDMDefault, DisplayGetMaxLayerCountFailNullAll) diff --git a/utests/src/ut_tdm_capture.cpp b/utests/src/ut_tdm_capture.cpp index cffcc72..ad75d2a 100644 --- a/utests/src/ut_tdm_capture.cpp +++ b/utests/src/ut_tdm_capture.cpp @@ -39,7 +39,7 @@ extern "C" { class TDMCapture : public ::testing::Test { protected: tdm_display *dpy = NULL; - tdm_capture_capability capture_capabilities = -42; + tdm_capture_capability capture_capabilities = (tdm_capture_capability) -42; bool has_capture = false; tbm_bufmgr tbm_bufmgr = NULL; void SetUp(void) diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index 574fd08..98c148e 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -41,8 +41,8 @@ class TDMLayer : public ::testing::Test { protected: tdm_display *dpy = NULL; tbm_bufmgr tbm_bufmgr = NULL; - int output_count = -42; - int layer_count = -42; + int master_fd = -42, tbm_fd = -42, layer_count = 0; + tdm_layer ** tdm_layer_array = NULL; bool has_layers = false; void SetUp(void) { @@ -56,10 +56,37 @@ protected: dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); - error = tdm_display_get_output_count(dpy, &output_count); - error = tdm_display_get_max_layer_count(dpy, &layer_count); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); + int output_count = 0; + if (tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE) { + for (int i = 0; i < output_count; i++) { + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (TDM_ERROR_NONE != error || NULL == output) + continue; + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status)) + continue; + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; + int temp_layer_count = 0; + if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count)) + continue; + if (0 == temp_layer_count) + continue; + tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array, + (layer_count + temp_layer_count)*sizeof(tdm_layer *)); + ASSERT_FALSE(NULL == tdm_layer_array); + for (int k = layer_count; k < (layer_count + temp_layer_count); k++) { + tdm_layer_array[k] = tdm_output_get_layer(output, k, &error); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_FALSE(NULL == tdm_layer_array[k]); + } + layer_count+=temp_layer_count; + } + } + #ifdef FAIL_ON_UNSUPPORTED - ASSERT_GT(output_count, 0); ASSERT_GT(layer_count, 0); #endif if (layer_count > 0) @@ -71,6 +98,22 @@ protected: dpy = NULL; tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; + if (tdm_layer_array) + free(tdm_layer_array); + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_tbm_fd > -1) + exit(1); + close(tbm_fd); + } unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DLOG"); @@ -78,19 +121,12 @@ protected: } }; -TEST_F(TDMLayer, OutputGetLayerSuccessful) +TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful) { SKIP_FLAG(has_layers); - for (int i = 0; i < output_count; i++) { - tdm_error error_output = TDM_ERROR_NONE; - tdm_output * output = NULL; - output = tdm_display_get_output(dpy, i, &error_output); - ASSERT_FALSE(NULL == output); - ASSERT_TRUE(TDM_ERROR_NONE == error_output); - for (int k = 0; k < layer_count; k++) { - tdm_error error_layer = TDM_ERROR_NONE; - ASSERT_FALSE(NULL == tdm_output_get_layer(output, k, &error_layer)); - ASSERT_TRUE(TDM_ERROR_NONE == error_layer); - } + for (int i = 0; i < layer_count; i++) { + tdm_layer_capability capabilities = (tdm_layer_capability) -42; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_layer_get_capabilities(tdm_layer_array[i], &capabilities)); + ASSERT_NE(capabilities, -42); } } diff --git a/utests/src/ut_tdm_output.cpp b/utests/src/ut_tdm_output.cpp index 460972c..f510e20 100644 --- a/utests/src/ut_tdm_output.cpp +++ b/utests/src/ut_tdm_output.cpp @@ -40,7 +40,7 @@ extern "C" { class TDMOutput : public ::testing::Test { protected: tdm_display *dpy = NULL; - int output_count = -42; + int output_count = -42, master_fd = -42, tbm_fd = -42; bool has_output = false; tbm_bufmgr tbm_bufmgr = NULL; static unsigned int handle_call; @@ -65,6 +65,8 @@ protected: dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); + tbm_fd = tbm_drm_helper_get_fd(); error = tdm_display_get_output_count(dpy, &output_count); #ifdef FAIL_ON_UNSUPPORTED ASSERT_GT(output_count, 0); @@ -79,6 +81,20 @@ protected: dpy = NULL; tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; + if (master_fd > -1) { + int temp_master_fd = tbm_drm_helper_get_master_fd(); + EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_master_fd > -1) + exit(1); + close(master_fd); + } + if (tbm_fd > -1) { + int temp_tbm_fd = tbm_drm_helper_get_fd(); + EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; + if (temp_tbm_fd > -1) + exit(1); + close(tbm_fd); + } unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DLOG"); @@ -133,7 +149,7 @@ TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful) SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; - tdm_output_capability capabilities = -42; + tdm_output_capability capabilities = (tdm_output_capability) -42; tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); @@ -199,7 +215,7 @@ TEST_F(TDMOutput, OutputGetConnStatusSuccessful) SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; - tdm_output_conn_status status = -42; + tdm_output_conn_status status = (tdm_output_conn_status) -42; tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); @@ -231,9 +247,13 @@ TEST_F(TDMOutput, OutputSetDPMSSuccessful) SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; + tdm_output_conn_status status; tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND)); @@ -249,9 +269,13 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful) tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); + tdm_output_conn_status status; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, - -101)); + (void *) -101)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_GT(handle_call, 0); @@ -266,10 +290,14 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); + tdm_output_conn_status status; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; for (int k = 0; k < 20; k++) { ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, - (-101-k))); + (void *) (-101-k))); } ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); @@ -281,7 +309,7 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull) { SKIP_FLAG(has_output); - ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL)); + ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(NULL, NULL, NULL)); } TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput) @@ -299,28 +327,33 @@ TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput) TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput) { SKIP_FLAG(has_output); - ASSERT_EXIT({tdm_output *output = 0xBEAF; + ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF; tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, - -101); + (void *) -101); exit(0);}, ::testing::ExitedWithCode(0), ""); } TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) { + SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); + tdm_output_conn_status status; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, - -101)); + (void *) -101)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_GT(handle_call, 0); handle_call = 0; - tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, -101); + tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) -101); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_EQ(handle_call, 0); @@ -329,25 +362,107 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs) { + SKIP_FLAG(has_output); for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); ASSERT_FALSE(NULL == output); ASSERT_TRUE(TDM_ERROR_NONE == error); + tdm_output_conn_status status; + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; for (int k = 0; k < 20; k++) { ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, - (-101-k))); + (void *) (-101-k))); } ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_GT(handle_call, 20); handle_call = 0; for (int k = 0; k < 20; k++) { - tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (-101-k)); + tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) (-101-k)); } ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_EQ(handle_call, 0); } } + +TEST_F(TDMOutput, OutputRemoveChangeHandlerFailAllNull) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({tdm_output_remove_change_handler(NULL, NULL, NULL); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputRemoveChangeHandlerFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + tdm_output_remove_change_handler(output, NULL, NULL); + } exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputRemoveChangeHandlerFailWrongOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF; + tdm_output_remove_change_handler(output, + tdm_output_change_handler_test_func, + (void *) -101); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetOutputTypeSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output_type type = (tdm_output_type) -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_output_type(output, &type)); + ASSERT_NE(type, -42); + } +} + +TEST_F(TDMOutput, OutputGetOutputTypeFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_output_type(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetOutputTypeFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_output_type(output, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetLayerCountSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int count = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_layer_count(output, &count)); + ASSERT_NE(count, -42); + } +} diff --git a/utests/src/ut_tdm_pp.cpp b/utests/src/ut_tdm_pp.cpp index 6fa99da..5ea127a 100644 --- a/utests/src/ut_tdm_pp.cpp +++ b/utests/src/ut_tdm_pp.cpp @@ -39,7 +39,7 @@ extern "C" { class TDMPP : public testing::Test { protected: tdm_display *dpy = NULL; - tdm_pp_capability pp_capabilities = -42; + tdm_pp_capability pp_capabilities = (tdm_pp_capability) -42; bool has_pp = false; void SetUp(void) { -- 2.7.4 From 8655628cc6dfb24f134438681d250cf2c9227db9 Mon Sep 17 00:00:00 2001 From: Andrii Sokolenko Date: Fri, 10 Nov 2017 17:29:44 +0200 Subject: [PATCH 05/16] [utest] Add 34 test cases Change-Id: I688da85318260b6a3ba342eb7b28ce0d1a99b04d Signed-off-by: Andrii Sokolenko --- utests/src/ut_tdm_layer.cpp | 100 ++++++++--- utests/src/ut_tdm_output.cpp | 395 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 469 insertions(+), 26 deletions(-) diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index 98c148e..265281c 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -41,7 +41,7 @@ class TDMLayer : public ::testing::Test { protected: tdm_display *dpy = NULL; tbm_bufmgr tbm_bufmgr = NULL; - int master_fd = -42, tbm_fd = -42, layer_count = 0; + int master_fd = -42, tbm_fd = -42, layer_count = 0, output_count = 0; tdm_layer ** tdm_layer_array = NULL; bool has_layers = false; void SetUp(void) @@ -58,32 +58,30 @@ protected: ASSERT_FALSE(dpy == NULL); master_fd = tbm_drm_helper_get_master_fd(); tbm_fd = tbm_drm_helper_get_fd(); - int output_count = 0; - if (tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE) { - for (int i = 0; i < output_count; i++) { - tdm_output * output = tdm_display_get_output(dpy, i, &error); - if (TDM_ERROR_NONE != error || NULL == output) - continue; - tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; - if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status)) - continue; - if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) - continue; - int temp_layer_count = 0; - if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count)) - continue; - if (0 == temp_layer_count) - continue; - tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array, - (layer_count + temp_layer_count)*sizeof(tdm_layer *)); - ASSERT_FALSE(NULL == tdm_layer_array); - for (int k = layer_count; k < (layer_count + temp_layer_count); k++) { - tdm_layer_array[k] = tdm_output_get_layer(output, k, &error); - ASSERT_TRUE(TDM_ERROR_NONE == error); - ASSERT_FALSE(NULL == tdm_layer_array[k]); - } - layer_count+=temp_layer_count; + ASSERT_TRUE(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE); + for (int i = 0; i < output_count; i++) { + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (TDM_ERROR_NONE != error || NULL == output) + continue; + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; + if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status)) + continue; + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + continue; + int temp_layer_count = 0; + if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count)) + continue; + if (0 == temp_layer_count) + continue; + tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array, + (layer_count + temp_layer_count)*sizeof(tdm_layer *)); + ASSERT_FALSE(NULL == tdm_layer_array); + for (int k = layer_count; k < (layer_count + temp_layer_count); k++) { + tdm_layer_array[k] = tdm_output_get_layer(output, k, &error); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_FALSE(NULL == tdm_layer_array[k]); } + layer_count+=temp_layer_count; } #ifdef FAIL_ON_UNSUPPORTED @@ -130,3 +128,53 @@ TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful) ASSERT_NE(capabilities, -42); } } + +TEST_F(TDMLayer, LayerGetCapabilitiesFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_layer_get_capabilities(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetCapabilitiesFailOnlyLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_capabilities(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, OutputGetPrimaryIndexSuccessful) +{ + SKIP_FLAG(has_layers); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int index = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_primary_index(output, &index)); + ASSERT_NE(index, -42); + } +} + +TEST_F(TDMLayer, OutputGetPrimaryIndexFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_output_get_primary_index(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, OutputGetPrimaryIndexFailOnlyOutput) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_primary_index(output, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} diff --git a/utests/src/ut_tdm_output.cpp b/utests/src/ut_tdm_output.cpp index f510e20..e3178c1 100644 --- a/utests/src/ut_tdm_output.cpp +++ b/utests/src/ut_tdm_output.cpp @@ -245,6 +245,7 @@ TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput) TEST_F(TDMOutput, OutputSetDPMSSuccessful) { SKIP_FLAG(has_output); + bool checked = false; for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output_conn_status status; @@ -254,16 +255,21 @@ TEST_F(TDMOutput, OutputSetDPMSSuccessful) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + checked = true; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND)); ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); } + if (false == checked) { + FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl; + } } TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful) { SKIP_FLAG(has_output); + bool checked = false; for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); @@ -273,6 +279,7 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + checked = true; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, (void *) -101)); @@ -280,11 +287,15 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_GT(handle_call, 0); } + if (false == checked) { + FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl; + } } TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) { SKIP_FLAG(has_output); + bool checked = false; for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); @@ -294,6 +305,7 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + checked = true; for (int k = 0; k < 20; k++) { ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, @@ -303,6 +315,9 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_GT(handle_call, 20); } + if (false == checked) { + FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl; + } } @@ -337,6 +352,7 @@ TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput) TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) { SKIP_FLAG(has_output); + bool checked = false; for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); @@ -346,6 +362,7 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + checked = true; ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, (void *) -101)); @@ -358,11 +375,15 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_EQ(handle_call, 0); } + if (false == checked) { + FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl; + } } TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs) { SKIP_FLAG(has_output); + bool checked = false; for (int i = 0; i < output_count; i++) { tdm_error error = TDM_ERROR_NONE; tdm_output * output = tdm_display_get_output(dpy, i, &error); @@ -372,6 +393,7 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status)); if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + checked = true; for (int k = 0; k < 20; k++) { ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, tdm_output_change_handler_test_func, @@ -388,6 +410,9 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs) ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF)); ASSERT_EQ(handle_call, 0); } + if (false == checked) { + FAIL() << "All outputs are disconnected. Testcase skipped" << std::endl; + } } TEST_F(TDMOutput, OutputRemoveChangeHandlerFailAllNull) @@ -466,3 +491,373 @@ TEST_F(TDMOutput, OutputGetLayerCountSuccessful) ASSERT_NE(count, -42); } } + +TEST_F(TDMOutput, OutputGetLayerCountFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_layer_count(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetLayerCountFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_layer_count(output, NULL)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailablePropertiesSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int count = -42; + const tdm_prop *tdm_prop_array = (const tdm_prop *) 0xBEAF; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_properties(output, + &tdm_prop_array, + &count)); + ASSERT_NE(count, -42); + ASSERT_NE(tdm_prop_array, 0xBEAF); + } +} + +TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_available_properties(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailablePropertiesFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_properties(output, NULL, NULL)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullCount) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + const tdm_prop *tdm_prop_array = NULL; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_properties(output, + &tdm_prop_array, + NULL)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailablePropertiesFailNullProperty) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int count = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_properties(output, + NULL, + &count)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableModesSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int count = -42; + const tdm_output_mode *modes_array = (const tdm_output_mode *) 0xBEAF; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_modes(output, + &modes_array, + &count)); + ASSERT_NE(count, -42); + ASSERT_NE(modes_array, 0xBEAF); + } +} + +TEST_F(TDMOutput, OutputGetAvailableModesFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_available_modes(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableModesFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_modes(output, NULL, NULL)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableModesFailNullCount) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + const tdm_output_mode *modes_array = NULL; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_modes(output, + &modes_array, + NULL)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableModesFailNullModes) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int count = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (TDM_ERROR_NONE == tdm_output_get_available_modes(output, + NULL, + &count)) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableSizeSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int min_w = -42, min_h = -42, max_w = -42, max_h = -42, preferred_align = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_available_size(output, &min_w, &min_h, + &max_w, &max_h, &preferred_align)); + ASSERT_NE(min_w, -42); + ASSERT_NE(min_h, -42); + ASSERT_NE(max_w, -42); + ASSERT_NE(max_h, -42); + ASSERT_NE(preferred_align, -42); + } +} + +TEST_F(TDMOutput, OutputGetAvailableSizeFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_available_size(NULL, NULL, NULL, + NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetAvailableSizeSuccessfulOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_available_size(output, NULL, NULL, + NULL, NULL, NULL) != TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetCursorAvailableSizeSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + int min_w = -42, min_h = -42, max_w = -42, max_h = -42, preferred_align = -42; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_cursor_available_size(output, &min_w, &min_h, + &max_w, &max_h, &preferred_align)); + ASSERT_NE(min_w, -42); + ASSERT_NE(min_h, -42); + ASSERT_NE(max_w, -42); + ASSERT_NE(max_h, -42); + ASSERT_NE(preferred_align, -42); + } +} + +TEST_F(TDMOutput, OutputGetCursorAvailableSizeFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_cursor_available_size(NULL, NULL, NULL, + NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetCursorAvailableSizeSuccessfulOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_cursor_available_size(output, NULL, NULL, + NULL, NULL, NULL) != TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetPhysicalSizeSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + unsigned int mmWidth = UINT_MAX, mmHeight = UINT_MAX; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_physical_size(output, &mmWidth, &mmHeight)); + ASSERT_NE(mmWidth, UINT_MAX); + ASSERT_NE(mmHeight, UINT_MAX); + } +} + +TEST_F(TDMOutput, OutputGetPhysicalSizeFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_physical_size(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetPhysicalSuccessfulOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_physical_size(output, NULL, NULL) != TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetSubpixelSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + unsigned int subpixel = UINT_MAX; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_subpixel(output, &subpixel)); + ASSERT_NE(subpixel, UINT_MAX); + } +} + +TEST_F(TDMOutput, OutputGetSubpixelFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_subpixel(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetSubpixelFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_subpixel(output, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetPipeSuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + unsigned int pipe = UINT_MAX; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_pipe(output, &pipe)); + ASSERT_NE(pipe, UINT_MAX); + } +} + +TEST_F(TDMOutput, OutputGetPipeFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({if (tdm_output_get_pipe(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputGetPipeFailOnlyOutput) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + if (NULL == output) exit(1); + if (TDM_ERROR_NONE != error) exit(1); + if (tdm_output_get_pipe(output, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMOutput, OutputSetPropertySuccessful) +{ + SKIP_FLAG(has_output); + for (int i = 0; i < output_count; i++) { + tdm_error error = TDM_ERROR_NONE; + tdm_value value = {.u32 = 0}; + tdm_output * output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(NULL == output); + ASSERT_TRUE(TDM_ERROR_NONE == error); + error = tdm_output_set_property(output, UINT_MAX, value); + ASSERT_TRUE(error == TDM_ERROR_NOT_IMPLEMENTED || error == TDM_ERROR_OPERATION_FAILED); + } +} + +TEST_F(TDMOutput, OutputSetPropertyFailNullAll) +{ + SKIP_FLAG(has_output); + ASSERT_EXIT({tdm_error error = TDM_ERROR_NONE; + tdm_value value = {.u32 = 0}; + error = tdm_output_set_property(NULL, 0, value); + if (error == TDM_ERROR_NONE || error == TDM_ERROR_NOT_IMPLEMENTED || + error == TDM_ERROR_OPERATION_FAILED) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} -- 2.7.4 From 4132be9593526d9358888f77186c9e00b3d81891 Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Fri, 10 Nov 2017 17:39:07 +0200 Subject: [PATCH 06/16] [utest] Add 108 test cases Covered API funcs. from the tdm_vblank.c file. Change-Id: I7bc8557863c088fd9623a12bb83fa2415e4351b8 Signed-off-by: Konstantin Drabeniuk --- utests/Makefile.am | 3 +- utests/src/ut_tdm_vblank.cpp | 2125 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2127 insertions(+), 1 deletion(-) create mode 100644 utests/src/ut_tdm_vblank.cpp diff --git a/utests/Makefile.am b/utests/Makefile.am index f44d3e0..6317645 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -6,7 +6,8 @@ tdm_utests_SOURCES = \ src/ut_tdm_pp.cpp \ src/ut_tdm_capture.cpp \ src/ut_tdm_output.cpp \ - src/ut_tdm_layer.cpp + src/ut_tdm_layer.cpp \ + src/ut_tdm_vblank.cpp tdm_utests_CXXFLAGS = \ $(CXXFLAGS) \ diff --git a/utests/src/ut_tdm_vblank.cpp b/utests/src/ut_tdm_vblank.cpp new file mode 100644 index 0000000..cde635f --- /dev/null +++ b/utests/src/ut_tdm_vblank.cpp @@ -0,0 +1,2125 @@ +/************************************************************************** + * + * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved. + * + * Contact: Konstantin Drabeniuk + * Contact: Andrii Sokolenko + * Contact: Roman Marchenko + * + * 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 "tdm.h" +#include "tbm_bufmgr.h" +#include "ut_common.h" +#include +#include +#include + +class TDMVblankWithoutCreating: public ::testing::Test { +protected: + tbm_bufmgr bufmgr; + tdm_display *dpy; + int output_count; + bool has_output; + tdm_output *connected_output; + const tdm_output_mode *preferred_mode; + tdm_output *disconnected_output; + tdm_output *default_output; + + void SetUp(void) { + tdm_output *output; + tdm_output_conn_status status; + tdm_error error = TDM_ERROR_NONE; + + bufmgr = NULL; + dpy = NULL; + output_count = 0; + connected_output = NULL; + connected_output = NULL; + default_output = NULL; + preferred_mode = NULL; + + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(bufmgr == NULL); + + dpy = tdm_display_init(&error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + + error = tdm_display_get_output_count(dpy, &output_count); + ASSERT_TRUE(error == TDM_ERROR_NONE); + if (output_count > 0) + has_output = true; + else + has_output = false; + + for(int i = 0; i < output_count; i++) { + output = tdm_display_get_output(dpy, i, &error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_FALSE(dpy == NULL); + + error = tdm_output_get_conn_status(output, &status); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) + connected_output = output; + else + disconnected_output = output; + } + + default_output = disconnected_output; + + if (connected_output) { + int output_modes_cnt = 0; + const tdm_output_mode* output_modes; + + error = tdm_output_get_available_modes(connected_output, &output_modes, &output_modes_cnt); + ASSERT_TRUE(error == TDM_ERROR_NONE); + if (output_modes_cnt <= 0) { + connected_output = NULL; + return; + } + + for(int i = 0; i < output_modes_cnt; i++) { + if(output_modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED) { + preferred_mode = &output_modes[i]; + + error = tdm_output_set_mode(connected_output, preferred_mode); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_ON); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + default_output = connected_output; + + return; + } + } + } + + connected_output = NULL; + } + void TearDown(void) + { + if (connected_output) + tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); + + if (bufmgr) + tbm_bufmgr_deinit(bufmgr); + if (dpy) + tdm_display_deinit(dpy); + + bufmgr = NULL; + dpy = NULL; + } +}; + +class TDMVblank: public TDMVblankWithoutCreating { +protected: + tdm_vblank *con_output_vblank; + tdm_vblank *discon_output_vblank; + tdm_output *default_vblank; + + void SetUp(void) + { + tdm_error error; + con_output_vblank = NULL; + discon_output_vblank = NULL; + default_vblank = NULL; + + TDMVblankWithoutCreating::SetUp(); + + if (disconnected_output) { + discon_output_vblank = tdm_vblank_create(dpy, disconnected_output, &error); + EXPECT_TRUE(discon_output_vblank != NULL); + EXPECT_TRUE(error == TDM_ERROR_NONE); + } + + if (connected_output) { + con_output_vblank = tdm_vblank_create(dpy, connected_output, &error); + EXPECT_TRUE(con_output_vblank != NULL); + EXPECT_TRUE(error == TDM_ERROR_NONE); + } + + if (connected_output) + default_vblank = discon_output_vblank; + else + default_vblank = con_output_vblank; + + ASSERT_TRUE(default_vblank != NULL); + } +}; + +class TDMVblankWait : public TDMVblank { +public: + static int utVblankHandlerIsCalled; + static void UtVblankHandler(tdm_vblank *vblank, tdm_error error, unsigned int sequence, + unsigned int tv_sec, unsigned int tv_usec, void *user_data) + { + int *data = (int *)user_data; + + if (data) + *data = 1; + + utVblankHandlerIsCalled = 1; + } + int utWaitVblankThreadHndlResult; + friend void *UtWaitVblankThreadHndl(void *ptr); + int utWaitVblankSeqThreadHndlResult; + friend void *UtWaitVblankSeqThreadHndl(void *ptr); + +private: + int epFd; + int timerFd; + int tdmFd; + static const int timeLimitSec = 1; + +protected: + void SetUp(void) + { + struct epoll_event ep; + + epFd = -1; + timerFd = -1; + utVblankHandlerIsCalled = 0; + utWaitVblankThreadHndlResult = -1; + utWaitVblankSeqThreadHndlResult = -1; + + TDMVblank::SetUp(); + + epFd = epoll_create1(0); + ASSERT_TRUE(epFd != -1); + + timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); + ASSERT_TRUE(timerFd != -1); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = timerFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0); + + ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = tdmFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0); + } + + void UtHandleVblankEvent() + { + struct itimerspec its; + int count; + struct epoll_event ep_event[2]; + + if (utVblankHandlerIsCalled) + return; + + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + its.it_value.tv_sec = timeLimitSec; + its.it_value.tv_nsec = 0; + + ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0); + + while (1) { + count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1); + ASSERT_TRUE(count >= 0); + + for (int i = 0; i < count; i++) { + if (ep_event[i].data.fd == timerFd) { + return; + } else { + ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE); + if (utVblankHandlerIsCalled) + return; + } + } + } + } +}; + +class TDMVblankWaitThread : public TDMVblankWait { +protected: + void SetUp(void) + { + setenv("TDM_THREAD", "1", 1); + TDMVblankWait::SetUp(); + } +}; + +int TDMVblankWait::utVblankHandlerIsCalled = 0; + +/* tdm_vblank_enable_global_fps() */ + +TEST_F(TDMVblankWithoutCreating, VblankEnableGlobalFpFailFpsNull) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + ASSERT_EXIT({error = tdm_vblank_enable_global_fps(1, 0); + if (error == TDM_ERROR_NONE) + exit(1); + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblankWithoutCreating, VblankEnableGlobalFpsSuccessEnable) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + ASSERT_EXIT({error = tdm_vblank_enable_global_fps(1, 60); + if (error != TDM_ERROR_NONE) + exit(1); + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblankWithoutCreating, VblankEnableGlobalFpsSuccessDisable) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + ASSERT_EXIT({error = tdm_vblank_enable_global_fps(0, 0); + if (error != TDM_ERROR_NONE) + exit(1); + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +/* tdm_vblank_create() */ + +TEST_F(TDMVblankWithoutCreating, VblankCreateFailNullAll) +{ + tdm_vblank *ret_vblank; + + SKIP_FLAG(has_output); + + ret_vblank = tdm_vblank_create(NULL, NULL, NULL); + ASSERT_TRUE(ret_vblank == NULL); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateFailNullDpy) +{ + tdm_vblank *ret_vblank; + tdm_error error; + + SKIP_FLAG(has_output); + + ret_vblank = tdm_vblank_create(NULL, default_output, &error); + ASSERT_TRUE(ret_vblank == NULL); + ASSERT_TRUE(error == TDM_ERROR_INVALID_PARAMETER); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateFailNullOutput) +{ + tdm_vblank *ret_vblank; + tdm_error error; + + SKIP_FLAG(has_output); + + ret_vblank = tdm_vblank_create(dpy, NULL, &error); + ASSERT_TRUE(ret_vblank == NULL); + ASSERT_TRUE(error == TDM_ERROR_INVALID_PARAMETER); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateFailWrongDpy) +{ + tdm_vblank *ret_vblank = NULL; + tdm_error error; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({ret_vblank = tdm_vblank_create((tdm_display *)0xFFFFFFFF, default_output, &error); + if (ret_vblank || error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateFailWrongOutput) +{ + tdm_vblank *ret_vblank = NULL; + tdm_error error; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({ret_vblank = tdm_vblank_create(dpy, (tdm_output *)0xFFFFFFFF, &error); + if (ret_vblank || error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateSuccessForConnectedOutput) +{ + tdm_vblank *ret_vblank; + tdm_error error; + + SKIP_FLAG(has_output); + + if (!connected_output) + return; + + ret_vblank = tdm_vblank_create(dpy, connected_output, &error); + ASSERT_TRUE(ret_vblank != NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWithoutCreating, VblankCreateSuccessForDisconnectedOutput) +{ + tdm_vblank *ret_vblank; + tdm_error error; + + SKIP_FLAG(has_output); + + if (!disconnected_output) + return; + + ret_vblank = tdm_vblank_create(dpy, disconnected_output, &error); + ASSERT_TRUE(ret_vblank != NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_destroy() */ + +TEST_F(TDMVblank, VblankDestroyWrongVblankPtr) +{ + SKIP_FLAG(has_output); + + ASSERT_EXIT({tdm_vblank_destroy((tdm_vblank *)0xFFFFFFFF);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankDestroySuccess) +{ + tdm_error error; + SKIP_FLAG(has_output); + + tdm_vblank_destroy(con_output_vblank); + + error = tdm_vblank_set_enable_fake(default_vblank, 1); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +/* tdm_vblank_set_name() */ + +TEST_F(TDMVblank, VblankSetNameFailNullAll) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_name(NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetNameFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_set_name((tdm_vblank *)0xFFFFFFFF, "ut_vblank"); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankSetNameSuccess) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_name(default_vblank, "ut_vblank"); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetNameSuccessNullName) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_name(default_vblank, NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_get_name() */ + +TEST_F(TDMVblank, VblankGetNameFailNullAll) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_name(NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetNameFailNullVblank) +{ + tdm_error error; + const char *ret_name; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_name(NULL, &ret_name); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetNameFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + const char *ret_name; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_name((tdm_vblank *)0xFFFFFFFF, &ret_name); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankGetNameFailNullName) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_name(default_vblank, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetNameSuccessWhithoutSetName) +{ + tdm_error error; + const char *ret_name; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_name(default_vblank, &ret_name); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetNameSuccess) +{ + tdm_error error; + const char *ret_name; + SKIP_FLAG(has_output); + const char *set_name = "ut_vblank"; + + error = tdm_vblank_set_name(default_vblank, set_name); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_get_name(default_vblank, &ret_name); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + ASSERT_STREQ(set_name, ret_name); +} + +/* tdm_vblank_set_fps() */ + +TEST_F(TDMVblank, VblankSetFpsFailNullVblank) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_fps(NULL, 10); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetFpsFailFpsNull) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_fps(default_vblank, 0); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetFpsFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_set_fps((tdm_vblank *)0xFFFFFFFF, 60); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankSetFpsSuccess) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_fps(default_vblank, 60); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetFpsSuccessSetTwice) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_fps(default_vblank, 60); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(default_vblank, 60); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_get_fps() */ + +TEST_F(TDMVblank, VblankGetFpsFailNullAll) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_fps(NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetFpsFailNullVblank) +{ + tdm_error error; + unsigned int ret_fps; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_fps(NULL, &ret_fps); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetFpsFailNullFps) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_fps(default_vblank, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetFpsFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + unsigned int ret_fps; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_fps((tdm_vblank *)0xFFFFFFFF, &ret_fps); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankGetNameSuccessWhithoutSetFps) +{ + tdm_error error; + unsigned int ret_fps; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_fps(default_vblank, &ret_fps); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetFpsSuccess) +{ + tdm_error error; + unsigned int ret_fps = 10; + SKIP_FLAG(has_output); + unsigned int set_fps = 50; + + error = tdm_vblank_set_fps(default_vblank, set_fps); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_get_fps(default_vblank, &ret_fps); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + ASSERT_TRUE(set_fps == ret_fps); +} + +/* tdm_vblank_ignore_global_fps() */ + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsFailNullVblank) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_ignore_global_fps(NULL, 1); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_ignore_global_fps((tdm_vblank *)0xFFFFFFFF, 1); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsSuccessUnset) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_ignore_global_fps(default_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsSuccessUnsetTwice) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_ignore_global_fps(default_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_ignore_global_fps(default_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsSuccessSet) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_ignore_global_fps(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankIgnoreGlobalFpsSuccessSetTwice) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_ignore_global_fps(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_ignore_global_fps(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_set_offset() */ + +TEST_F(TDMVblank, VblankSetOffsetFailNullVblank) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_offset(NULL, 10); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetOffsetFailFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_set_offset((tdm_vblank *)0xFFFFFFFF, 10); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankSetOffsetSuccess) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_offset(default_vblank, 50); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetOffsetSuccessSuccessSetTwice) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_offset(default_vblank, 50); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(default_vblank, 50); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_get_offset() */ + +TEST_F(TDMVblank, VblankGetOffsetFailNullAll) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_offset(NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetOffsetFailNullVblank) +{ + tdm_error error; + int offset; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_offset(NULL, &offset); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetOffsetFailNullOffset) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_offset(default_vblank, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetOffsetFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + int offset; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_offset((tdm_vblank *)0xFFFFFFFF, &offset); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankGetOffsetFailWrongOffsetPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_offset(default_vblank, (int *)0xFFFFFFFF); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankGetOffsetSuccesWithoutSet) +{ + tdm_error error; + int offset; + + SKIP_FLAG(has_output); + + error = tdm_vblank_get_offset(default_vblank, &offset); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetOffsetSucces) +{ + tdm_error error; + int set_offset = 567; + int ret_offset; + + SKIP_FLAG(has_output); + + error = tdm_vblank_set_offset(default_vblank, set_offset); + ASSERT_TRUE(error != TDM_ERROR_NONE); + + error = tdm_vblank_get_offset(default_vblank, &ret_offset); + ASSERT_TRUE(error != TDM_ERROR_NONE); + + ASSERT_TRUE(set_offset == ret_offset); +} + +/* tdm_vblank_set_enable_fake() */ + +TEST_F(TDMVblank, VblankSetEnableFakeFailNullVblank) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_enable_fake(NULL, 1); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetEnableFakeFailFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_set_enable_fake((tdm_vblank *)0xFFFFFFFF, 1); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankSetEnableFakeSuccessSet) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_enable_fake(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankSetEnableFakeSuccessSetTwice) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_set_enable_fake(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_enable_fake(default_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +/* tdm_vblank_get_enable_fake() */ + +TEST_F(TDMVblank, VblankGetEnableFakeFailNullAll) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_enable_fake(NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetEnableFakeFailNullVblank) +{ + tdm_error error; + unsigned int enable_fake; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_enable_fake(NULL, &enable_fake); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetEnableFakeFailNullEnableFake) +{ + tdm_error error; + SKIP_FLAG(has_output); + + error = tdm_vblank_get_enable_fake(default_vblank, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetEnableFakeFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + unsigned int enable_fake; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_enable_fake((tdm_vblank *)0xFFFFFFFF, &enable_fake); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, DISABLED_VblankGetEnableFakeFailWrongOffsetPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_get_enable_fake(default_vblank, (unsigned int *)0xFFFFFFFF); + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblank, VblankGetEnableFakeSuccessWithoutSet) +{ + tdm_error error; + unsigned int enable_fake; + + SKIP_FLAG(has_output); + + error = tdm_vblank_get_enable_fake(default_vblank, &enable_fake); + ASSERT_TRUE(error == TDM_ERROR_NONE); +} + +TEST_F(TDMVblank, VblankGetEnableFakeSuccess) +{ + tdm_error error; + unsigned int set_enable_fake = 1; + unsigned int ret_enable_fake; + + SKIP_FLAG(has_output); + + error = tdm_vblank_set_enable_fake(default_vblank, set_enable_fake); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_get_enable_fake(default_vblank, &ret_enable_fake); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + ASSERT_TRUE(set_enable_fake == ret_enable_fake); +} + +/* tdm_vblank_set_client_vblank_fps() */ + +/* TODO: need to create the tdm client */ +TEST_F(TDMVblank, VblankSetClientVblankFpsFailNullAll) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_set_client_vblank_fps(0, 0, 0); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +/* TODO: need to create the tdm client */ +TEST_F(TDMVblank, VblankSetClientVblankFpsFailNullPid) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_set_client_vblank_fps(0, 0, 0); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +/* tdm_vblank_wait() */ + +TEST_F(TDMVblank, VblankWaitFailNullAll) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait(NULL, 0, 0, 0, NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitFailNullVblank) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait(NULL, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitFailNullFunc) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait(default_vblank, 0, 0, 1, NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_wait((tdm_vblank *)0xFFFFFFFF, 0, 0, 1, UtVblankHandler, NULL);; + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +void *UtWaitVblankThreadHndl(void *ptr) +{ + tdm_error error; + TDMVblankWait *vblankWait = (TDMVblankWait *)ptr; + + error = tdm_vblank_wait(vblankWait->default_vblank, 0, 0, 1, TDMVblankWait::UtVblankHandler, NULL); + if (error != TDM_ERROR_NONE) + vblankWait->utWaitVblankThreadHndlResult = 0; + else + vblankWait->utWaitVblankThreadHndlResult = 0; +} + +TEST_F(TDMVblankWait, VblankWaitFailInOtherThread) +{ + pthread_t thread; + + SKIP_FLAG(has_output); + + ASSERT_FALSE(pthread_create(&thread, NULL, UtWaitVblankThreadHndl, this)); + + ASSERT_FALSE(pthread_join(thread, NULL)); + + ASSERT_FALSE(utWaitVblankThreadHndlResult); +} + +TEST_F(TDMVblankWait, VblankWaitFailDisconnectedOutput) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_wait(discon_output_vblank, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitFailDpmsOff) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessFpsNonMultipleVrefresh) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessFpsNonMultipleVrefreshRepeatedly) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSuccessDisconnectedOutput) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(discon_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessDisconnectedOutputRepeatedly) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(discon_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSuccessHW) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessDestroy) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + tdm_vblank_destroy(con_output_vblank); + + ASSERT_TRUE(utVblankHandlerIsCalled == 0); + ASSERT_TRUE(data == 0); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessChangeDpms) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessChangeDpmsWithEnableFake) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_enable_fake(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessHWRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSuccessOffsenGreaterThanZero) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSuccessOffsenGreaterThanZeroRepeatedly) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessFpsNonMultipleVrefresh) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessFpsNonMultipleVrefreshRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessDisconnectedOutput) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(discon_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessDisconnectedOutputRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(discon_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessHW) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessHWRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessOffsenGreaterThanZero) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWaitThread, VblankWaitSuccessOffsenGreaterThanZeroRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 0; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +/* tdm_vblank_wait_seq() */ + +TEST_F(TDMVblank, VblankWaitSeqFailNullAll) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait_seq(NULL, 0, 0, 0, NULL, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailNullVblank) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait_seq(NULL, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailWrongVblankPtr) +{ + tdm_error error = TDM_ERROR_BAD_MODULE; + SKIP_FLAG(has_output); + + ASSERT_EXIT({error = tdm_vblank_wait_seq((tdm_vblank *)0xFFFFFFFF, 0, 0, 1, UtVblankHandler, NULL);; + if (error == TDM_ERROR_NONE) + exit(1); + else + exit(0);}, + ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailNullFunc) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + error = tdm_vblank_wait_seq(NULL, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +void *UtWaitVblankSeqThreadHndl(void *ptr) +{ + tdm_error error; + TDMVblankWait *vblankWait = (TDMVblankWait *)ptr; + + error = tdm_vblank_wait_seq(vblankWait->default_vblank, 0, 0, 1, TDMVblankWait::UtVblankHandler, NULL); + if (error != TDM_ERROR_NONE) + vblankWait->utWaitVblankSeqThreadHndlResult = 0; + else + vblankWait->utWaitVblankSeqThreadHndlResult = 0; +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailInOtherThread) +{ + pthread_t thread; + + SKIP_FLAG(has_output); + + ASSERT_FALSE(pthread_create(&thread, NULL, UtWaitVblankSeqThreadHndl, this)); + + ASSERT_FALSE(pthread_join(thread, NULL)); + + ASSERT_FALSE(utWaitVblankSeqThreadHndlResult); +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailDisconnectedOutput) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_wait_seq(discon_output_vblank, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitSeqFailDpmsOff) +{ + tdm_error error; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, 1, UtVblankHandler, NULL); + ASSERT_TRUE(error != TDM_ERROR_NONE); +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessFpsNonMultipleVrefresh) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessFpsNonMultipleVrefreshRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh - 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessDisconnectedOutput) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait_seq(discon_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessDisconnectedOutputRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!discon_output_vblank) + return; + + error = tdm_vblank_set_enable_fake(discon_output_vblank, 1); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(discon_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessHW) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessHWRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessOffsenGreaterThanZero) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, 1, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessOffsenGreaterThanZeroRepeatedly) +{ + tdm_error error; + int data; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_enable_global_fps(1, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 10); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessRepeatedlyWithSameSeq) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_offset(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, 2, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessRepeatedlyWithBigFps) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, 5000); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + if (i < 4) + continue; + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} + +TEST_F(TDMVblankWait, VblankWaitSeqSuccessRepeatedlyWithDelay) +{ + tdm_error error; + int data = 0; + + SKIP_FLAG(has_output); + + if (!con_output_vblank) + return; + + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_vblank_set_fps(con_output_vblank, preferred_mode->vrefresh); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + for (int i = 1; i < 10; ++i) { + utVblankHandlerIsCalled = 0; + data = 0; + + error = tdm_vblank_wait_seq(con_output_vblank, 0, 0, i, UtVblankHandler, &data); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + usleep(100000); + + UtHandleVblankEvent(); + + ASSERT_TRUE(utVblankHandlerIsCalled == 1); + ASSERT_TRUE(data == 1); + } +} -- 2.7.4 From c61e3aaef986c13175c299570e8bc3ef09a4d50a Mon Sep 17 00:00:00 2001 From: Sergey Sizonov Date: Thu, 9 Nov 2017 12:04:24 +0300 Subject: [PATCH 07/16] [hwc] adopt COMMIT_PER_VBLANK functionality for each ouptut The new TDM HWC API made us to provide the COMMIT_PER_VBLANK functionality for each output independently. An output tdm-backend provides the hwc capability for isn't intended to be managed by tdm_layer_xxx functions, so there's no need to have the COMMIT_PER_VBLANK functionality turned on for such output, in contrast to outputs tdm-backend doesn't provide the hwc capability for. So now the COMMIT_PER_VBLANK functionality for the outputs which don't support hwc behaves depend on a TDM_COMMIT_PER_VBLANK env variable while outputs which support are always have this functionality turned off (like they read TDM_COMMIT_PER_VBLANK as '0') Change-Id: I8454915d635016edfcb2dca3ac4bd455c48f4c44 Signed-off-by: Sergey Sizonov --- include/tdm_helper.h | 10 ++++++++++ src/tdm.c | 44 ++++++++++++++++---------------------------- src/tdm_helper.c | 14 ++++++++++---- src/tdm_layer.c | 23 +++++++++++------------ src/tdm_monitor_server.c | 31 +++++++++++++++++++++---------- src/tdm_output.c | 35 ++++++++++++++++++++++++++++------- src/tdm_private.h | 12 ++++++------ 7 files changed, 102 insertions(+), 67 deletions(-) diff --git a/include/tdm_helper.h b/include/tdm_helper.h index 3d1d252..8bae8fa 100644 --- a/include/tdm_helper.h +++ b/include/tdm_helper.h @@ -221,10 +221,20 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len); * @brief Get whether the commit-per-vblank functionality is enabled or not. * @param[in] dpy A display object * @return 1 if enabled. Otherwise, 0. + * + * @deprecated use @c tdm_helper_output_commit_per_vblank_enabled instead */ int tdm_helper_commit_per_vblank_enabled(tdm_display *dpy); +/** + * @brief Get whether the commit-per-vblank functionality is enabled or not for the output. + * @param[in] output An output the functionality has to be checked for + * @return -1 if error occurred, 1 if enabled, 0 if disabled. + */ +int +tdm_helper_output_commit_per_vblank_enabled(tdm_output *output); + #ifdef __cplusplus } #endif diff --git a/src/tdm.c b/src/tdm.c index 7c12dfe..2246fc4 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -943,14 +943,6 @@ tdm_display_init(tdm_error *error) if (str) tdm_display_enable_path(str); - str = getenv("TDM_COMMIT_PER_VBLANK"); - if (str) { - char *end; - int enable = strtol(str, &end, 10); - - tdm_display_enable_commit_per_vblank(private_display, enable); - } - if (pthread_mutex_init(&private_display->lock, NULL)) { ret = TDM_ERROR_OPERATION_FAILED; TDM_ERR("mutex init failed: %m"); @@ -1010,7 +1002,6 @@ tdm_display_init(tdm_error *error) tdm_event_loop_create_backend_source(private_display); private_display->init_count = 1; - private_display->commit_type = TDM_COMMIT_TYPE_NONE; tdm_private_output *o = NULL; LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link) { @@ -1018,6 +1009,22 @@ tdm_display_init(tdm_error *error) tdm_output_need_validate_event_init(o); } + /* the COMMIT_PER_VBLANK functionality is ability of an output to support + * several operational modes (commit_per_vblank modes) related to tdm_commit; + * this functionality can be turned off which means a default mode */ + str = getenv("TDM_COMMIT_PER_VBLANK"); + if (str) { + tdm_private_output *o = NULL; + char *end; + int mode = strtol(str, &end, 10); + + /* outputs which support hwc capability can work only + * if commit_per_vblank mode is '0' (default mode) */ + LIST_FOR_EACH_ENTRY(o, &private_display->output_list, link) + if (!(o->caps.capabilities & TDM_OUTPUT_CAPABILITY_HWC)) + tdm_output_choose_commit_per_vblank_mode(o, mode); + } + g_private_display = private_display; if (error) @@ -1331,25 +1338,6 @@ enable_fail: } INTERN tdm_error -tdm_display_enable_commit_per_vblank(tdm_private_display *private_display, int enable) -{ - private_display->commit_per_vblank = enable; - - if (private_display->commit_per_vblank == 0) - TDM_INFO("commit per vblank: disable"); - else if (private_display->commit_per_vblank == 1) - TDM_INFO("commit per vblank: enable (1 layer)"); - else if (private_display->commit_per_vblank == 2) - TDM_INFO("commit per vblank: enable (previous commit)"); - else { - private_display->commit_per_vblank = 1; - TDM_INFO("commit per vblank: enable (changed to 1 layer)"); - } - - return TDM_ERROR_NONE; -} - -INTERN tdm_error tdm_display_enable_fps(tdm_private_display *private_display, int enable) { private_display->print_fps = enable; diff --git a/src/tdm_helper.c b/src/tdm_helper.c index a22e0cc..bcd7aec 100644 --- a/src/tdm_helper.c +++ b/src/tdm_helper.c @@ -1064,12 +1064,18 @@ tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len) EXTERN int tdm_helper_commit_per_vblank_enabled(tdm_display *dpy) { - tdm_private_display *private_display; + TDM_ERR("the deprecated function, use 'tdm_helper_output_commit_per_vblank_enabled' instead."); - TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0); + return 0; +} - private_display = dpy; +EXTERN int +tdm_helper_output_commit_per_vblank_enabled(tdm_output *output) +{ + tdm_private_output *private_output = output; + + TDM_RETURN_VAL_IF_FAIL(private_output != NULL, -1); - return private_display->commit_per_vblank; + return !!private_output->commit_per_vblank; } diff --git a/src/tdm_layer.c b/src/tdm_layer.c index cb4ef55..c1a5d6b 100644 --- a/src/tdm_layer.c +++ b/src/tdm_layer.c @@ -713,9 +713,8 @@ static int _tdm_layer_commit_possible(tdm_private_layer *private_layer) { tdm_private_output *private_output = private_layer->private_output; - tdm_private_display *private_display = private_output->private_display; - TDM_RETURN_VAL_IF_FAIL(private_display->commit_per_vblank > 0, 1); + TDM_RETURN_VAL_IF_FAIL(private_output->commit_per_vblank > 0, 1); /* There is a previous commit request which is not done and displayed on screen yet. * We can't commit at this time. @@ -726,7 +725,7 @@ _tdm_layer_commit_possible(tdm_private_layer *private_layer) return 0; } - if (private_display->commit_per_vblank == 1 && _tdm_lauer_get_output_used_layer_count(private_output) > 1) { + if (private_output->commit_per_vblank == 1 && _tdm_lauer_get_output_used_layer_count(private_output) > 1) { if (tdm_debug_module & TDM_DEBUG_COMMIT) TDM_INFO("layer(%p) commit: not possible(more than 2 layers)", private_layer); return 0; @@ -836,8 +835,8 @@ _tdm_layer_commit(tdm_layer *layer, tdm_layer_commit_handler func, void *user_da private_layer, private_layer->waiting_buffer, (layer_commit_handler->committed_buffer) ? layer_commit_handler->committed_buffer->buffer : NULL); - if (!private_display->commit_per_vblank) { - TDM_GOTO_IF_FAIL(private_display->commit_type == TDM_COMMIT_TYPE_OUTPUT, commit_failed); + if (!private_output->commit_per_vblank) { + TDM_GOTO_IF_FAIL(private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT, commit_failed); LIST_ADDTAIL(&layer_commit_handler->link, &private_output->layer_commit_handler_list); ret = tdm_output_commit_internal(private_layer->private_output, 0, _tdm_layer_cb_output_commit, layer_commit_handler); @@ -846,7 +845,7 @@ _tdm_layer_commit(tdm_layer *layer, tdm_layer_commit_handler func, void *user_da if (tdm_debug_module & TDM_DEBUG_COMMIT) TDM_INFO("layer(%p) commit: no commit-per-vblank", private_layer); } else { - TDM_GOTO_IF_FAIL(private_display->commit_type == TDM_COMMIT_TYPE_LAYER, commit_failed); + TDM_GOTO_IF_FAIL(private_output->commit_type == TDM_COMMIT_TYPE_LAYER, commit_failed); if (private_layer->committing) TDM_WRN("layer(%d) too many commit", private_layer->index); @@ -908,11 +907,11 @@ tdm_layer_commit(tdm_layer *layer, tdm_layer_commit_handler func, void *user_dat _pthread_mutex_lock(&private_display->lock); - if (private_display->commit_type == TDM_COMMIT_TYPE_NONE) { - if (!private_display->commit_per_vblank) - private_display->commit_type = TDM_COMMIT_TYPE_OUTPUT; + if (private_output->commit_type == TDM_COMMIT_TYPE_NONE) { + if (!private_output->commit_per_vblank) + private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT; else - private_display->commit_type = TDM_COMMIT_TYPE_LAYER; + private_output->commit_type = TDM_COMMIT_TYPE_LAYER; } if (private_output->current_dpms_value > TDM_OUTPUT_DPMS_ON) { @@ -1077,11 +1076,11 @@ _tbm_layer_queue_acquirable_cb(tbm_surface_queue_h surface_queue, void *data) TDM_INFO("layer(%p) waiting_buffer(%p)", private_layer, private_layer->waiting_buffer->buffer); - if (private_display->commit_type == TDM_COMMIT_TYPE_OUTPUT) { + if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) { ret = tdm_output_commit_internal(private_layer->private_output, 0, NULL, NULL); if (ret != TDM_ERROR_NONE) TDM_ERR("tdm_output_commit_internal() is fail"); - } else if (private_display->commit_type == TDM_COMMIT_TYPE_LAYER) { + } else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) { ret = _tdm_layer_commit(private_layer, NULL, NULL); if (ret != TDM_ERROR_NONE) TDM_ERR("layer(%p) _tdm_layer_commit() is fail", private_layer); diff --git a/src/tdm_monitor_server.c b/src/tdm_monitor_server.c index e7844a5..07c2487 100644 --- a/src/tdm_monitor_server.c +++ b/src/tdm_monitor_server.c @@ -220,23 +220,34 @@ done: } static void -_tdm_monitor_server_commit_per_vblank(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy) +_tdm_monitor_server_choose_commit_per_vblank_mode(unsigned int pid, char *cwd, int argc, char *argv[], char *reply, int *len, tdm_display *dpy) { - int enable; + int output_idx; + int mode; char *arg; char *end; + tdm_error err; - if (argc < 3) { + /* TODO: do we have to provide an ability to choose commit_per_vblank mode outside? */ + + if (argc < 4) { _tdm_monitor_server_usage(argv[0], reply, len); return; } arg = argv[2]; - enable = strtol(arg, &end, 10); + output_idx = strtol(arg, &end, 10); - tdm_display_enable_commit_per_vblank(dpy, enable); + arg = argv[3]; + mode = strtol(arg, &end, 10); - TDM_SNPRINTF(reply, len, "%s the commit-per-vblank\n", (enable) ? "enable" : "disable"); + err = tdm_output_choose_commit_per_vblank_mode(tdm_display_get_output(dpy, output_idx, NULL), mode); + if (err != TDM_ERROR_NONE) { + TDM_SNPRINTF(reply, len, "an error: output_idx or mode is wrong\n"); + return; + } + + TDM_SNPRINTF(reply, len, "the mode's been set\n"); } static void @@ -539,10 +550,10 @@ static struct { "console" }, { - "commit_per_vblank", _tdm_monitor_server_commit_per_vblank, - "enable/disable the commit per vblank", - "", - "0 or 1" + "choose_commit_per_vblank_mode", _tdm_monitor_server_choose_commit_per_vblank_mode, + "choose a commit_per_vblank mode for the output", + " ", + "0 1 or 1 2 or 2 0" }, { "fps", _tdm_monitor_server_fps, diff --git a/src/tdm_output.c b/src/tdm_output.c index 3dd945c..d445914 100644 --- a/src/tdm_output.c +++ b/src/tdm_output.c @@ -690,7 +690,7 @@ tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence, TDM_INFO("handler(%p)", output_commit_handler); } - if (private_display->commit_type == TDM_COMMIT_TYPE_OUTPUT) { + if (private_output->commit_type == TDM_COMMIT_TYPE_OUTPUT) { /* In case of layer commit, the below will be handled in the layer commit callback */ LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) { if (private_layer->committed_buffer) @@ -922,7 +922,7 @@ tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handl /* TODO: this is ugly. But before using tdm_output_get_dpms_internal, we have * to check if all backends's DPMS operation has no problem. */ - if (private_display->commit_per_vblank) + if (private_output->commit_per_vblank) tdm_output_get_dpms_internal(output, &dpms_value); else dpms_value = private_output->current_dpms_value; @@ -999,15 +999,15 @@ tdm_output_commit(tdm_output *output, int sync, tdm_output_commit_handler func, _pthread_mutex_lock(&private_display->lock); - if (private_display->commit_type == TDM_COMMIT_TYPE_NONE) - private_display->commit_type = TDM_COMMIT_TYPE_OUTPUT; - else if (private_display->commit_type == TDM_COMMIT_TYPE_LAYER) { + if (private_output->commit_type == TDM_COMMIT_TYPE_NONE) + private_output->commit_type = TDM_COMMIT_TYPE_OUTPUT; + else if (private_output->commit_type == TDM_COMMIT_TYPE_LAYER) { TDM_ERR("Can't supported. Use tdm_layer_commit"); _pthread_mutex_unlock(&private_display->lock); return TDM_ERROR_BAD_REQUEST; } - if (private_display->commit_per_vblank) { + if (private_output->commit_per_vblank) { TDM_ERR("Use tdm_layer_commit"); _pthread_mutex_unlock(&private_display->lock); return TDM_ERROR_BAD_REQUEST; @@ -1298,7 +1298,7 @@ tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value) } /* TODO: this is ugly. But we have to check if all backends's DPMS operation has no problem. */ - if (private_display->commit_per_vblank) + if (private_output->commit_per_vblank) if (*dpms_value != private_output->current_dpms_value) { private_output->current_dpms_value = *dpms_value; TDM_ERR("output(%d) dpms changed suddenly: %s", @@ -1727,3 +1727,24 @@ tdm_output_need_validate_event_init(tdm_output *output) return ret; } + +INTERN tdm_error +tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode) +{ + if (!private_output) + return TDM_ERROR_INVALID_PARAMETER; + + if (mode < 0 || mode > 2) + return TDM_ERROR_INVALID_PARAMETER; + + private_output->commit_per_vblank = mode; + + if (private_output->commit_per_vblank == 0) + TDM_INFO("commit per vblank: disable"); + else if (private_output->commit_per_vblank == 1) + TDM_INFO("commit per vblank: enable (1 layer)"); + else if (private_output->commit_per_vblank == 2) + TDM_INFO("commit per vblank: enable (previous commit)"); + + return TDM_ERROR_NONE; +} diff --git a/src/tdm_private.h b/src/tdm_private.h index e6c0801..2a927db 100644 --- a/src/tdm_private.h +++ b/src/tdm_private.h @@ -177,10 +177,6 @@ struct _tdm_private_display { /* output order */ tdm_output **outputs; - /* calling a output commit per a vblank */ - int commit_per_vblank; - tdm_commit_type commit_type; - int print_fps; }; @@ -231,6 +227,10 @@ struct _tdm_private_output { tdm_output_need_validate_handler hndl; int event_fd; } need_validate; + + /* calling a output commit per a vblank */ + int commit_per_vblank; + tdm_commit_type commit_type; }; struct _tdm_private_layer { @@ -464,6 +464,8 @@ tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value); tdm_error tdm_output_need_validate_event_init(tdm_output *output); +tdm_error +tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode); void tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data); @@ -741,8 +743,6 @@ tdm_display_enable_path(const char *path); tdm_error tdm_display_enable_ttrace_vblank(tdm_display *dpy, tdm_output *output, int enable); tdm_error -tdm_display_enable_commit_per_vblank(tdm_private_display *private_display, int enable); -tdm_error tdm_display_enable_fps(tdm_private_display *private_display, int enable); void -- 2.7.4 From 0a608ca64083320a01c213bede7ad8e548f7387c Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Mon, 13 Nov 2017 13:48:13 +0900 Subject: [PATCH 08/16] dump layer buffer when calling tdm_layer_set_buffer Change-Id: Id0fdf736a3590a2251d59f1fb32f3d7beb692e62 --- src/tdm_layer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tdm_layer.c b/src/tdm_layer.c index c1a5d6b..2465675 100644 --- a/src/tdm_layer.c +++ b/src/tdm_layer.c @@ -410,6 +410,10 @@ tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) _pthread_mutex_lock(&private_display->lock); + /* dump buffer */ + if (tdm_dump_enable && !(private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO)) + _tdm_layer_dump_buffer(private_layer, buffer); + if (tdm_debug_dump & TDM_DUMP_FLAG_LAYER && !(private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO)) { char str[TDM_PATH_LEN]; @@ -780,10 +784,6 @@ tdm_layer_commit_pending_data(tdm_private_layer *private_layer) TDM_INFO("layer(%p) pending_buffer(%p) committed", private_layer, private_layer->pending_buffer); - /* dump buffer */ - if (tdm_dump_enable && !(private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO)) - _tdm_layer_dump_buffer(private_layer, private_layer->pending_buffer); - if (ret == TDM_ERROR_NONE) { if (private_layer->waiting_buffer) _tdm_layer_free_buffer(private_layer, private_layer->waiting_buffer); -- 2.7.4 From 0bf830de4e5b74b0e7f5374ab0220dc81e95950a Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Tue, 14 Nov 2017 10:15:41 +0200 Subject: [PATCH 09/16] utests: fix errors in the vblank's test cases - set mode and dpms only for the TDMVblankWait's test cases - make commit for primary layer Change-Id: I3953fbdec743e7177b2a7725f223601bb1f5b47b Signed-off-by: Konstantin Drabeniuk --- utests/src/ut_tdm_vblank.cpp | 128 ++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/utests/src/ut_tdm_vblank.cpp b/utests/src/ut_tdm_vblank.cpp index cde635f..746d4c7 100644 --- a/utests/src/ut_tdm_vblank.cpp +++ b/utests/src/ut_tdm_vblank.cpp @@ -38,28 +38,20 @@ class TDMVblankWithoutCreating: public ::testing::Test { protected: - tbm_bufmgr bufmgr; - tdm_display *dpy; - int output_count; - bool has_output; - tdm_output *connected_output; - const tdm_output_mode *preferred_mode; - tdm_output *disconnected_output; - tdm_output *default_output; + tbm_bufmgr bufmgr = NULL; + tdm_display *dpy = NULL; + int output_count = 0; + bool has_output = 0; + tdm_output *connected_output = NULL; + const tdm_output_mode *preferred_mode = NULL; + tdm_output *disconnected_output = NULL; + tdm_output *default_output = NULL; void SetUp(void) { tdm_output *output; tdm_output_conn_status status; tdm_error error = TDM_ERROR_NONE; - bufmgr = NULL; - dpy = NULL; - output_count = 0; - connected_output = NULL; - connected_output = NULL; - default_output = NULL; - preferred_mode = NULL; - setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); @@ -110,12 +102,6 @@ protected: if(output_modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED) { preferred_mode = &output_modes[i]; - error = tdm_output_set_mode(connected_output, preferred_mode); - ASSERT_TRUE(error == TDM_ERROR_NONE); - - error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_ON); - ASSERT_TRUE(error == TDM_ERROR_NONE); - default_output = connected_output; return; @@ -129,7 +115,6 @@ protected: { if (connected_output) tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_OFF); - if (bufmgr) tbm_bufmgr_deinit(bufmgr); if (dpy) @@ -142,38 +127,95 @@ protected: class TDMVblank: public TDMVblankWithoutCreating { protected: - tdm_vblank *con_output_vblank; - tdm_vblank *discon_output_vblank; - tdm_output *default_vblank; + tdm_vblank *con_output_vblank = NULL; + tdm_vblank *discon_output_vblank = NULL; + tdm_output *default_vblank = NULL; + int setModeAndDpms = 0; + tbm_surface_h buffer = NULL; + tdm_layer *layer = NULL; void SetUp(void) { tdm_error error; - con_output_vblank = NULL; - discon_output_vblank = NULL; - default_vblank = NULL; TDMVblankWithoutCreating::SetUp(); + if (connected_output && setModeAndDpms) { + int primary_index; + tdm_info_layer info = {0}; + + error = tdm_output_set_mode(connected_output, preferred_mode); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_get_primary_index(connected_output, &primary_index); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + layer = tdm_output_get_layer(connected_output, primary_index, &error); + ASSERT_TRUE(error == TDM_ERROR_NONE); + ASSERT_TRUE(layer != NULL); + + info.src_config.size.h = preferred_mode->hdisplay; + info.src_config.size.v = preferred_mode->vdisplay; + info.src_config.pos.x = 0; + info.src_config.pos.y = 0; + info.src_config.pos.w = preferred_mode->hdisplay; + info.src_config.pos.h = preferred_mode->vdisplay; + info.src_config.format = TBM_FORMAT_ARGB8888; + info.dst_pos.x = 0; + info.dst_pos.y = 0; + info.dst_pos.w = preferred_mode->hdisplay; + info.dst_pos.h = preferred_mode->vdisplay; + info.transform = TDM_TRANSFORM_NORMAL; + + error = tdm_layer_set_info(layer, &info); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(connected_output, TDM_OUTPUT_DPMS_ON); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + buffer = tbm_surface_internal_create_with_flags(preferred_mode->hdisplay, + preferred_mode->vdisplay, + TBM_FORMAT_ARGB8888, + TBM_BO_SCANOUT); + ASSERT_TRUE(buffer != NULL); + + error = tdm_layer_set_buffer(layer, buffer); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_commit(connected_output, 0, NULL, NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); + /* TODO: use a commit handler instead of an usleep to wait when + * commit will be applied */ + usleep(20000); + } + if (disconnected_output) { discon_output_vblank = tdm_vblank_create(dpy, disconnected_output, &error); EXPECT_TRUE(discon_output_vblank != NULL); EXPECT_TRUE(error == TDM_ERROR_NONE); + default_vblank = discon_output_vblank; } if (connected_output) { con_output_vblank = tdm_vblank_create(dpy, connected_output, &error); EXPECT_TRUE(con_output_vblank != NULL); EXPECT_TRUE(error == TDM_ERROR_NONE); - } - - if (connected_output) - default_vblank = discon_output_vblank; - else default_vblank = con_output_vblank; + } ASSERT_TRUE(default_vblank != NULL); } + + void TearDown(void) + { + if (buffer) { + tdm_layer_unset_buffer(layer); + tdm_output_commit(connected_output, 0, NULL, NULL); + tbm_surface_destroy(buffer); + } + + TDMVblankWithoutCreating::TearDown(); + } }; class TDMVblankWait : public TDMVblank { @@ -189,15 +231,15 @@ public: utVblankHandlerIsCalled = 1; } - int utWaitVblankThreadHndlResult; + int utWaitVblankThreadHndlResult = -1; friend void *UtWaitVblankThreadHndl(void *ptr); - int utWaitVblankSeqThreadHndlResult; + int utWaitVblankSeqThreadHndlResult = -1; friend void *UtWaitVblankSeqThreadHndl(void *ptr); private: - int epFd; - int timerFd; - int tdmFd; + int epFd = -1; + int timerFd = -1; + int tdmFd = -1; static const int timeLimitSec = 1; protected: @@ -205,12 +247,9 @@ protected: { struct epoll_event ep; - epFd = -1; - timerFd = -1; utVblankHandlerIsCalled = 0; - utWaitVblankThreadHndlResult = -1; - utWaitVblankSeqThreadHndlResult = -1; + setModeAndDpms = 1; TDMVblank::SetUp(); epFd = epoll_create1(0); @@ -1296,6 +1335,9 @@ TEST_F(TDMVblankWait, VblankWaitSuccessChangeDpms) if (!con_output_vblank) return; + error = tdm_vblank_set_enable_fake(con_output_vblank, 0); + ASSERT_TRUE(error == TDM_ERROR_NONE); + error = tdm_vblank_ignore_global_fps(con_output_vblank, 0); ASSERT_TRUE(error == TDM_ERROR_NONE); -- 2.7.4 From d0c65220e105f248ecdc9b0939a68b4ff71a5969 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 14 Nov 2017 20:31:02 +0900 Subject: [PATCH 10/16] change the version of hwc_window. this version change is for the developement temporarily Change-Id: I4a64f37ef1f9b85f412e200ec2c1542dcfb0cfe5 --- src/tdm_backend.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tdm_backend.c b/src/tdm_backend.c index 9c1992d..482c933 100644 --- a/src/tdm_backend.c +++ b/src/tdm_backend.c @@ -139,7 +139,10 @@ tdm_backend_register_func_hwc_window(tdm_display *dpy, tdm_func_hwc_window *func TDM_RETURN_VAL_IF_FAIL(func_hwc_window != NULL, TDM_ERROR_INVALID_PARAMETER); module = private_display->module_data; - if (_check_abi_version(module, 2, 0) < 0) + /* FIX ME: + Temporarily, we set the version of hwc window to 1.1 for the development. + Originally the hwc window version is 2.0. */ + if (_check_abi_version(module, 1, 1) < 0) return TDM_ERROR_BAD_MODULE; private_display->func_hwc_window = *func_hwc_window; -- 2.7.4 From 6f2511f8cdd9dbe079ee9eb7d2ff3f79b5ce0d44 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Tue, 14 Nov 2017 20:32:07 +0900 Subject: [PATCH 11/16] package version up to 1.8.3 Change-Id: I2d6461dfd3f65790f7aa5c00a7f19a4a3978e81b --- packaging/libtdm.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtdm.spec b/packaging/libtdm.spec index 6496af0..80787c9 100644 --- a/packaging/libtdm.spec +++ b/packaging/libtdm.spec @@ -1,7 +1,7 @@ %define UTEST_PACKAGE 0 Name: libtdm -Version: 1.8.2 +Version: 1.8.3 Release: 0 Summary: User Library of Tizen Display Manager Group: Development/Libraries -- 2.7.4 From 59675d9656a392e50cb8a5714f23708318d7b0e6 Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Wed, 15 Nov 2017 14:09:02 +0200 Subject: [PATCH 12/16] utests: Add 83 test cases Covered API funcs. from the tdm_layer.c file. Change-Id: I27317f987320ee40d1e03ecb98a8e6eac6e28008 Signed-off-by: Konstantin Drabeniuk --- utests/src/ut_tdm_layer.cpp | 1705 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1699 insertions(+), 6 deletions(-) diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index 265281c..dbcceab 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -30,11 +30,17 @@ #include "gtest/gtest.h" #include "ut_common.h" +#include +#include +#include +#include -extern "C" { #include "tdm.h" +extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" +#include "tbm_surface.h" +#include "tbm_surface_queue.h" } class TDMLayer : public ::testing::Test { @@ -42,32 +48,76 @@ protected: tdm_display *dpy = NULL; tbm_bufmgr tbm_bufmgr = NULL; int master_fd = -42, tbm_fd = -42, layer_count = 0, output_count = 0; - tdm_layer ** tdm_layer_array = NULL; + tdm_layer **tdm_layer_array = NULL; + tbm_surface_h *tdm_layers_buffer_array = NULL; + tbm_surface_queue_h *tdm_layers_buffer_queue_array = NULL; + int *tdm_layer_output_idx = NULL; + const tdm_output_mode **preferred_mode_array = NULL; bool has_layers = false; - void SetUp(void) + virtual void SetEnv() { + setenv("TDM_DEBUG_MODULE", "all", 1); + setenv("TDM_DEBUG", "1", 1); + setenv("TDM_THREAD", "0", 1); + setenv("TDM_COMMIT_PER_VBLANK", "1", 1); setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); + } + void SetUp(void) + { + const tdm_output_mode *preferred_mode = NULL; + tdm_error error = TDM_ERROR_NONE; + + SetEnv(); + tbm_bufmgr = tbm_bufmgr_init(-1); ASSERT_FALSE(tbm_bufmgr == NULL); - tdm_error error = TDM_ERROR_NONE; + dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); + master_fd = tbm_drm_helper_get_master_fd(); tbm_fd = tbm_drm_helper_get_fd(); ASSERT_TRUE(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE); + + tdm_layer_output_idx = (int *) calloc(output_count, sizeof(int)); + ASSERT_FALSE(NULL == tdm_layer_output_idx); + + preferred_mode_array = (const tdm_output_mode **)calloc(output_count, sizeof(tdm_output_mode *)); + ASSERT_FALSE(NULL == preferred_mode_array); + for (int i = 0; i < output_count; i++) { - tdm_output * output = tdm_display_get_output(dpy, i, &error); + tdm_output *output = tdm_display_get_output(dpy, i, &error); + int output_modes_cnt = 0; + const tdm_output_mode *output_modes; + if (TDM_ERROR_NONE != error || NULL == output) continue; + tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status)) continue; + if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) continue; + + error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt); + if (TDM_ERROR_NONE != error) + continue; + if (output_modes_cnt <= 0) { + continue; + } + + for(int j = 0; j < output_modes_cnt; j++) + if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED) + preferred_mode = &output_modes[j]; + + if (!preferred_mode) + continue; + int temp_layer_count = 0; if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count)) continue; @@ -75,15 +125,25 @@ protected: continue; tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array, (layer_count + temp_layer_count)*sizeof(tdm_layer *)); + ASSERT_FALSE(NULL == tdm_layer_array); + for (int k = layer_count; k < (layer_count + temp_layer_count); k++) { tdm_layer_array[k] = tdm_output_get_layer(output, k, &error); + tdm_layer_output_idx[k] = i; ASSERT_TRUE(TDM_ERROR_NONE == error); ASSERT_FALSE(NULL == tdm_layer_array[k]); } - layer_count+=temp_layer_count; + layer_count += temp_layer_count; + preferred_mode_array[i] = preferred_mode; } + tdm_layers_buffer_array = (tbm_surface_h *) calloc(layer_count, sizeof(tbm_surface_h)); + ASSERT_FALSE(NULL == tdm_layers_buffer_array); + + tdm_layers_buffer_queue_array = (tbm_surface_queue_h *) calloc(layer_count, sizeof(tbm_surface_queue_h)); + ASSERT_FALSE(NULL == tdm_layers_buffer_queue_array); + #ifdef FAIL_ON_UNSUPPORTED ASSERT_GT(layer_count, 0); #endif @@ -92,12 +152,32 @@ protected: } void TearDown(void) { + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_unset_buffer(tdm_layer_array[i]); + EXPECT_TRUE(error == TDM_ERROR_NONE); + + if (tdm_layers_buffer_array[i]) + tbm_surface_destroy(tdm_layers_buffer_array[i]); + + if (tdm_layers_buffer_queue_array[i]) + tbm_surface_queue_destroy(tdm_layers_buffer_queue_array[i]); + + tdm_layers_buffer_array[i] = NULL; + tdm_layers_buffer_queue_array[i] = NULL; + } + tdm_display_deinit(dpy); dpy = NULL; tbm_bufmgr_deinit(tbm_bufmgr); tbm_bufmgr = NULL; if (tdm_layer_array) free(tdm_layer_array); + if (tdm_layer_output_idx) + free(tdm_layer_output_idx); + if (preferred_mode_array) + free(preferred_mode_array); if (master_fd > -1) { int temp_master_fd = tbm_drm_helper_get_master_fd(); EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl; @@ -112,13 +192,194 @@ protected: exit(1); close(tbm_fd); } + + unsetenv("TDM_DEBUG_MODULE"); + unsetenv("TDM_DEBUG"); + unsetenv("TDM_THREAD"); + unsetenv("TDM_COMMIT_PER_VBLANK"); unsetenv("TDM_DLOG"); unsetenv("XDG_RUNTIME_DIR"); unsetenv("TBM_DLOG"); unsetenv("TBM_DISPLAY_SERVER"); } + + tbm_surface_h UtCreateBufferForLayer(int layer_idx, int width, int height, + int format, int flags) + { + tbm_surface_h buffer; + + buffer = tbm_surface_internal_create_with_flags(width, height, format, flags); + + tdm_layers_buffer_array[layer_idx] = buffer; + + return buffer; + } + + tbm_surface_queue_h UtCreateBufferQueueForLayer(int layer_idx, int width, int height, + int format, int flags) + { + tbm_surface_queue_h buffer_queue; + + buffer_queue = tbm_surface_queue_create(2, width, height, format, flags); + + tdm_layers_buffer_queue_array[layer_idx] = buffer_queue; + + return buffer_queue; + } +}; + +class TDMLayerCommit : public TDMLayer +{ +private: + int epFd = -1; + int timerFd = -1; + int tdmFd = -1; + static const int timeLimitSec = 0; + static const int timeLimitNsec = 100000000; + +protected: + static int utLayerCommitHandlerCounter; + static void UtLayerCommitHandler(tdm_layer *layer, unsigned int sequence, + unsigned int tv_sec, unsigned int tv_usec, + void *user_data) + { + int *data = (int *)user_data; + if (data) + (*data)++; + + utLayerCommitHandlerCounter++; + } + + void SetUp(void) + { + tdm_error error; + tdm_output *output; + struct epoll_event ep; + + utLayerCommitHandlerCounter = 0; + + TDMLayer::SetUp(); + for (int i = 0; i < output_count; ++i) { + if (!preferred_mode_array[i]) + continue; + + output = tdm_display_get_output(dpy, i, &error); + ASSERT_FALSE(output == NULL); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_mode(output, preferred_mode_array[i]); + ASSERT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON); + ASSERT_TRUE(error == TDM_ERROR_NONE); + } + + epFd = epoll_create1(0); + ASSERT_TRUE(epFd != -1); + + timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); + ASSERT_TRUE(timerFd != -1); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = timerFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0); + + ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = tdmFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0); + } + + void TearDown(void) + { + tdm_output *output; + tdm_error error; + + for (int i = 0; i < output_count; ++i) { + if (!preferred_mode_array[i]) + continue; + + output = tdm_display_get_output(dpy, i, &error); + EXPECT_FALSE(output == NULL); + EXPECT_TRUE(error == TDM_ERROR_NONE); + + error = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF); + EXPECT_TRUE(error == TDM_ERROR_NONE); + } + + TDMLayer::TearDown(); + } + + void UtHandleCommitEvent(int num_waiting_layers) + { + struct itimerspec its; + int count; + struct epoll_event ep_event[2]; + + if (utLayerCommitHandlerCounter == num_waiting_layers) + return; + + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + its.it_value.tv_sec = timeLimitSec; + its.it_value.tv_nsec = timeLimitNsec; + + ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0); + + while (1) { + count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1); + ASSERT_TRUE(count >= 0); + + for (int i = 0; i < count; i++) { + if (ep_event[i].data.fd == timerFd) { + return; + } else { + ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE); + if (utLayerCommitHandlerCounter == num_waiting_layers) + return; + } + } + } + } +}; + +class TDMLayerCommitThread : public TDMLayerCommit +{ +protected: + void SetEnv() + { + setenv("TDM_DEBUG_MODULE", "all", 1); + setenv("TDM_DEBUG", "1", 1); + setenv("TDM_THREAD", "1", 1); + setenv("TDM_COMMIT_PER_VBLANK", "1", 1); + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + } +}; + +class TDMLayerCommitWithDisabledCommitPerVblank : public TDMLayerCommit +{ +protected: + void SetEnv() + { + setenv("TDM_DEBUG_MODULE", "all", 1); + setenv("TDM_DEBUG", "1", 1); + setenv("TDM_THREAD", "0", 1); + setenv("TDM_COMMIT_PER_VBLANK", "0", 1); + setenv("TDM_DLOG", "1", 1); + setenv("XDG_RUNTIME_DIR", ".", 1); + setenv("TBM_DLOG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + } }; +int TDMLayerCommit::utLayerCommitHandlerCounter = 0; + TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful) { SKIP_FLAG(has_layers); @@ -178,3 +439,1435 @@ TEST_F(TDMLayer, OutputGetPrimaryIndexFailOnlyOutput) } exit(0);}, ::testing::ExitedWithCode(0), ""); } + +/* tdm_layer_get_available_formats() */ + +TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_layer_get_available_formats(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({const tbm_format *formats; + int count; + if (tdm_layer_get_available_formats(NULL, &formats, &count) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullFormats) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({int count; + for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_available_formats(tdm_layer_array[i], NULL, &count) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullCount) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({const tbm_format *formats; + for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_available_formats(tdm_layer_array[i], &formats, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailableFormatsSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + const tbm_format *formats; + int count; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_available_formats(tdm_layer_array[i], &formats, &count); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(NULL, formats); + ASSERT_NE(0, count); + } +} + +/* tdm_layer_get_available_properties() */ + +TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_layer_get_available_properties(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({const tdm_prop *props; + int count; + if (tdm_layer_get_available_properties(NULL, &props, &count) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullFormats) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({int count; + for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_available_properties(tdm_layer_array[i], NULL, &count) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullCount) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({const tdm_prop *props; + for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_available_properties(tdm_layer_array[i], &props, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetAvailablePropertiesSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + const tdm_prop *props; + int count; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_available_properties(tdm_layer_array[i], &props, &count); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_get_zpos() */ + +TEST_F(TDMLayer, LayerGetZposFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_layer_get_zpos(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetZposFailNullLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({const tdm_prop *props; + int zpos; + if (tdm_layer_get_zpos(NULL, &zpos) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetZposFailNullZpos) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({int count; + for (int i = 0; i < layer_count; i++) { + if (tdm_layer_get_zpos(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetZposSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + int zpos = INT_MIN; + error = tdm_layer_get_zpos(tdm_layer_array[i], &zpos); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(INT_MIN, zpos); + } +} + +/* tdm_layer_set_property() */ + +TEST_F(TDMLayer, LayerSetPropertyFailNullLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({tdm_value value; + int id = INT_MAX; + if (tdm_layer_set_property(NULL, id, value) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetPropertyFailWrongId) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_value value; + int id = INT_MAX; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_set_property(tdm_layer_array[i], id, value); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_get_property() */ + +TEST_F(TDMLayer, LayerGetPropertyFailNullLayer) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({tdm_value value; + int id = INT_MAX; + if (tdm_layer_get_property(NULL, id, &value) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetPropertyFailNullValue) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({tdm_value value; + int id = INT_MAX; + for (int i = 0; i < layer_count; ++i) { + if (tdm_layer_get_property(tdm_layer_array[i], id, NULL) == TDM_ERROR_NONE) exit(1); + } + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetPropertyFailWrongId) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_value value; + int id = INT_MAX; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_property(tdm_layer_array[i], id, &value); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_set_info() */ + +TEST_F(TDMLayer, LayerSetInfoFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({tdm_value value; + int id = INT_MAX; + if (tdm_layer_set_info(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetInfoFailNullLayer) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_info_layer info = {0}; + if (tdm_layer_set_info(NULL, &info) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetInfoFailNullInfo) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_info_layer info = {0}; + for (int i = 0; i < layer_count; ++i) + if (tdm_layer_set_info(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +tdm_error +_ut_tdm_layer_set_info(tdm_layer *layer, int w, int h) +{ + tdm_info_layer info = {0}; + + info.src_config.size.h = w; + info.src_config.size.v = h; + info.src_config.pos.x = 0; + info.src_config.pos.y = 0; + info.src_config.pos.w = w; + info.src_config.pos.h = h; + info.src_config.format = TBM_FORMAT_ARGB8888; + info.dst_pos.x = 0; + info.dst_pos.y = 0; + info.dst_pos.w = w; + info.dst_pos.h = h; + info.transform = TDM_TRANSFORM_NORMAL; + + return tdm_layer_set_info(layer, &info); +} + +TEST_F(TDMLayer, LayerSetInfoSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + error = _ut_tdm_layer_set_info(tdm_layer_array[i], 128, 128); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_get_info() */ + +TEST_F(TDMLayer, LayerGetInfoFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({tdm_value value; + int id = INT_MAX; + if (tdm_layer_get_info(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetInfoFailNullLayer) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_info_layer info = {0}; + if (tdm_layer_get_info(NULL, &info) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetInfoFailNullInfo) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_info_layer info = {0}; + for (int i = 0; i < layer_count; ++i) + if (tdm_layer_get_info(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetInfoSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_info_layer set_info = {0}; + tdm_info_layer ret_info = {0}; + + set_info.src_config.size.h = 128; + set_info.src_config.size.v = 128; + set_info.src_config.pos.x = 0; + set_info.src_config.pos.y = 0; + set_info.src_config.pos.w = 128; + set_info.src_config.pos.h = 128; + set_info.src_config.format = TBM_FORMAT_ARGB8888; + set_info.dst_pos.x = 0; + set_info.dst_pos.y = 0; + set_info.dst_pos.w = 128; + set_info.dst_pos.h = 128; + set_info.transform = TDM_TRANSFORM_NORMAL; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_info(tdm_layer_array[i], &set_info); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_get_info(tdm_layer_array[i], &ret_info); + ASSERT_EQ(TDM_ERROR_NONE, error); + + ASSERT_TRUE(!memcmp(&ret_info, &set_info, sizeof(tdm_info_layer))); + } +} + +/* tdm_layer_set_buffer() */ + +TEST_F(TDMLayer, LayerSetBufferFailNullAll) +{ + SKIP_FLAG(has_layers); + ASSERT_EXIT({if (tdm_layer_set_buffer(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferFailNullLayer) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + tbm_surface_h buffer = UtCreateBufferForLayer(0, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + if (!buffer) exit(1); + error = tdm_layer_set_buffer(NULL, buffer); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferFailNullBuffer) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({for (int i = 0; i < layer_count; ++i) + if (tdm_layer_set_buffer(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferSuccess) +{ + SKIP_FLAG(has_layers); + tbm_surface_h buffer; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayer, LayerSetBufferSuccessTwice) +{ + SKIP_FLAG(has_layers); + tbm_surface_h buffer; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_unset_buffer() */ + +TEST_F(TDMLayer, LayerUnsetBufferFailNullLayer) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_unset_buffer(NULL); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerUnsetBufferSuccess) +{ + SKIP_FLAG(has_layers); + tbm_surface_h buffer; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_unset_buffer(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_commit() */ + +TEST_F(TDMLayer, LayerCommitFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_commit(NULL, NULL, NULL); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerCommitFailDpmsOff) +{ + SKIP_FLAG(has_layers); + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_commit(tdm_layer_array[i], NULL, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayerCommit, LayerCommitSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + + ASSERT_EQ(layer_count, utLayerCommitHandlerCounter); + ASSERT_EQ(layer_count, data); +} + +TEST_F(TDMLayerCommitThread, LayerCommitSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + + ASSERT_EQ(layer_count, utLayerCommitHandlerCounter); + ASSERT_EQ(layer_count, data); +} + +TEST_F(TDMLayerCommit, LayerCommitSuccessOnlyPrimaryLayers) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + int num_waiting_layers = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) + continue; + + num_waiting_layers++; + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(num_waiting_layers); + + ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter); + ASSERT_EQ(num_waiting_layers, data); +} + +TEST_F(TDMLayerCommitThread, LayerCommitSuccessOnlyPrimaryLayers) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + int num_waiting_layers = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) + continue; + + num_waiting_layers++; + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(num_waiting_layers); + + ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter); + ASSERT_EQ(num_waiting_layers, data); +} + +TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerCommitSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + + ASSERT_EQ(layer_count, utLayerCommitHandlerCounter); + ASSERT_EQ(layer_count, data); +} + +TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerCommitSuccessOnlyPrimaryLayers) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + int num_waiting_layers = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) + continue; + + num_waiting_layers++; + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(num_waiting_layers); + + ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter); + ASSERT_EQ(num_waiting_layers, data); +} + +TEST_F(TDMLayerCommit, LayerCommitSuccessUnsetAfterCommit) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_unset_buffer(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + ASSERT_EQ(0, utLayerCommitHandlerCounter); + ASSERT_EQ(0, data); +} + +TEST_F(TDMLayerCommit, LayerCommitSuccessUnsetBeforeCommit_2) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + ASSERT_EQ(layer_count, utLayerCommitHandlerCounter); + ASSERT_EQ(layer_count, data); + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_unset_buffer(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_is_committing() */ + +TEST_F(TDMLayer, LayerIsCommittingFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_is_committing(NULL, NULL); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsCommittingFailNullLayer) +{ + SKIP_FLAG(has_layers); + unsigned int committing; + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_is_committing(NULL, &committing); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsCommittingFailNullCommitting) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_is_committing(tdm_layer_array[0], NULL); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsCommittingSuccessWithoutCommit) +{ + SKIP_FLAG(has_layers); + tdm_error error; + unsigned int committing; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_is_committing(tdm_layer_array[0], &committing); + ASSERT_EQ(TDM_ERROR_NONE, error); + + ASSERT_EQ(0, committing); + } +} + +TEST_F(TDMLayerCommit, LayerIsCommittingSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + unsigned int committing; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], NULL, NULL); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_is_committing(tdm_layer_array[0], &committing); + ASSERT_EQ(TDM_ERROR_NONE, error); + + ASSERT_EQ(1, committing); + } +} + +/* tdm_layer_remove_commit_handler() */ + +TEST_F(TDMLayer, LayerRemoveCommitHandlerFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({tdm_error error; + error = tdm_layer_remove_commit_handler(NULL, NULL, NULL); + if (error == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayerCommit, LayerRemoveCommitHandlerSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_remove_commit_handler(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + ASSERT_EQ(0, utLayerCommitHandlerCounter); + ASSERT_EQ(0, data); +} + +/* tdm_layer_get_displaying_buffer() */ + +TEST_F(TDMLayerCommit, LayerGetDisplayingBufferFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_get_displaying_buffer(NULL, NULL) != NULL) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayerCommit, LayerGetDisplayingBufferFailWithoutCommit) +{ + SKIP_FLAG(has_layers); + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error)); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayerCommit, LayerGetDisplayingBufferSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + int data = 0; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer = NULL; + tdm_layer_capability layer_capability; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + UtHandleCommitEvent(layer_count); + ASSERT_EQ(layer_count, utLayerCommitHandlerCounter); + ASSERT_EQ(layer_count, data); + + for (int i = 0; i < layer_count; ++i) { + ASSERT_EQ(tdm_layers_buffer_array[i], tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error)); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_is_usable() */ + +TEST_F(TDMLayer, LayerIsUsableFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_is_usable(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsUsableFailNullLayer) +{ + SKIP_FLAG(has_layers); + unsigned int usable; + + ASSERT_EXIT({if (tdm_layer_is_usable(NULL, &usable) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsUsableFailNullUsable) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_is_usable(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerIsUsableSuccessAllUsable) +{ + SKIP_FLAG(has_layers); + unsigned int usable; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_is_usable(tdm_layer_array[i], &usable); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(0, usable); + } +} + +TEST_F(TDMLayer, LayerIsUsableSuccessAllUsable_2) +{ + SKIP_FLAG(has_layers); + unsigned int usable; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_unset_buffer(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_is_usable(tdm_layer_array[i], &usable); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(0, usable); + } +} + +TEST_F(TDMLayer, LayerIsUsableSuccessAllNoUsable) +{ + SKIP_FLAG(has_layers); + unsigned int usable; + tdm_error error; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h buffer; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer); + + error = tdm_layer_set_buffer(tdm_layer_array[i], buffer); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_is_usable(tdm_layer_array[i], &usable); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_EQ(0, usable); + } +} + +/* tdm_layer_set_video_pos() */ + +TEST_F(TDMLayer, LayerSetVideoPosFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_set_video_pos(NULL, -1) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetVideoPosFailNoVideoLayers) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (layer_capability & TDM_LAYER_CAPABILITY_VIDEO) + continue; + + error = tdm_layer_set_video_pos(tdm_layer_array[i], -1); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayer, LayerSetVideoPosSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_VIDEO)) + continue; + + error = tdm_layer_set_video_pos(tdm_layer_array[i], -1); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_create_capture() */ + +TEST_F(TDMLayer, LayerCreateCaptureNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_create_capture(NULL, NULL) != NULL) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerCreateCaptureSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tdm_capture *capture; + + for (int i = 0; i < layer_count; ++i) { + capture = tdm_layer_create_capture(tdm_layer_array[i], &error); + if (error == TDM_ERROR_NO_CAPABILITY) + return; + + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(NULL, capture); + } +} + +/* tdm_layer_get_buffer_flags() */ + +TEST_F(TDMLayer, LayerGetBufferFlagsNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_get_buffer_flags(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetBufferFlagsNullLayer) +{ + SKIP_FLAG(has_layers); + unsigned int flags; + + ASSERT_EXIT({if (tdm_layer_get_buffer_flags(NULL, &flags) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetBufferFlagsNullFlags) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_get_buffer_flags(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerGetBufferFlagsSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + unsigned int flags; + + for (int i = 0; i < layer_count; ++i) { + error = tdm_layer_get_buffer_flags(tdm_layer_array[i], &flags); + if (error == TDM_ERROR_NOT_IMPLEMENTED) + return; + + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_set_buffer_queue() */ + +TEST_F(TDMLayer, LayerSetBufferQueueFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_set_buffer_queue(NULL, NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferQueueFailNullLayer) +{ + SKIP_FLAG(has_layers); + tbm_surface_queue_h bufer_queue; + + bufer_queue = UtCreateBufferQueueForLayer(0, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, bufer_queue); + + ASSERT_EXIT({if (tdm_layer_set_buffer_queue(NULL, bufer_queue) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferQueueFailNullBufferQueue) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_set_buffer_queue(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerSetBufferQueueSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tbm_surface_queue_h buffer_queue; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer_queue); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayer, LayerSetBufferQueueSuccessTwice) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tbm_surface_queue_h buffer_queue; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer_queue); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayerCommitThread, LayerSetBufferQueueSuccessRemoveBufferQueue) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tbm_surface_queue_error_e tbm_err; + tbm_surface_queue_h buffer_queue; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h surface; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer_queue); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + + tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + + tdm_layer_commit(tdm_layer_array[i], NULL, NULL); + + tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + } + + /* FIXME: use another func. */ + UtHandleCommitEvent(1); + + for (int i = 0; i < layer_count; ++i) { + ASSERT_NE(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error)); + ASSERT_EQ(TDM_ERROR_NONE, error); + + tbm_surface_queue_destroy(tdm_layers_buffer_queue_array[i]); + tdm_layers_buffer_queue_array[i] = NULL; + + ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error)); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerSetBufferQueueSuccessRemoveBufferQueue) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tbm_surface_queue_error_e tbm_err; + tbm_surface_queue_h buffer_queue; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h surface; + + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h); + ASSERT_EQ(TDM_ERROR_NONE, error); + + buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer_queue); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + + tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + + tdm_layer_commit(tdm_layer_array[i], NULL, NULL); + + tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + } + + /* FIXME: use another func. */ + UtHandleCommitEvent(1); + + for (int i = 0; i < layer_count; ++i) { + tbm_surface_h surface; + + tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + + tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface); + ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); + + error = tdm_layer_unset_buffer_queue(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + } + + /* FIXME: use another func. */ + UtHandleCommitEvent(1); + + for (int i = 0; i < layer_count; ++i) { + ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error)); + ASSERT_NE(TDM_ERROR_NONE, error); + } +} + +/* tdm_layer_unset_buffer_queue() */ + +TEST_F(TDMLayer, LayerUnsetBufferQueueFailNullAll) +{ + SKIP_FLAG(has_layers); + + ASSERT_EXIT({if (tdm_layer_unset_buffer_queue(NULL) == TDM_ERROR_NONE) exit(1); + exit(0);}, ::testing::ExitedWithCode(0), ""); +} + +TEST_F(TDMLayer, LayerUnsetBufferQueueSuccess) +{ + SKIP_FLAG(has_layers); + tdm_error error; + tbm_surface_queue_h buffer_queue; + tdm_layer_capability layer_capability; + + for (int i = 0; i < layer_count; ++i) { + int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay; + int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay; + + error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability); + ASSERT_EQ(TDM_ERROR_NONE, error); + + if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) { + w /= 2; + h /= 2; + } + + buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + ASSERT_NE(NULL, buffer_queue); + + error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = tdm_layer_unset_buffer_queue(tdm_layer_array[i]); + ASSERT_EQ(TDM_ERROR_NONE, error); + } +} -- 2.7.4 From ad16a60799dc5fe99e85931ef835dba6f6793ade Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Wed, 15 Nov 2017 14:29:24 +0200 Subject: [PATCH 13/16] add excluding coverage comments for tdm_layer.c add excluding coverage comments for tdm_layer.c for folowing code: - fail if the backend's function don't exist; - dump; - print fps; - calloc fail; - fail in the TBM. Change-Id: I9e1046f32315147d97930f786047878daca21690 Signed-off-by: Konstantin Drabeniuk --- src/tdm_layer.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/tdm_layer.c b/src/tdm_layer.c index 2465675..cca078e 100644 --- a/src/tdm_layer.c +++ b/src/tdm_layer.c @@ -167,9 +167,11 @@ tdm_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value) private_layer->usable = 0; if (!func_layer->layer_set_property) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } ret = func_layer->layer_set_property(private_layer->layer_backend, id, value); @@ -192,9 +194,11 @@ tdm_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value) func_layer = &private_display->func_layer; if (!func_layer->layer_get_property) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_SOP */ } ret = func_layer->layer_get_property(private_layer->layer_backend, id, value); @@ -224,9 +228,11 @@ tdm_layer_set_info(tdm_layer *layer, tdm_info_layer *info) private_layer->usable = 0; if (!func_layer->layer_set_info) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } if (info->src_config.format) @@ -264,9 +270,11 @@ tdm_layer_get_info(tdm_layer *layer, tdm_info_layer *info) func_layer = &private_display->func_layer; if (!func_layer->layer_get_info) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } ret = func_layer->layer_get_info(private_layer->layer_backend, info); @@ -276,6 +284,7 @@ tdm_layer_get_info(tdm_layer *layer, tdm_info_layer *info) return ret; } +/* LCOV_EXCL_START */ static void _tdm_layer_dump_buffer(tdm_layer *layer, tbm_surface_h buffer) { @@ -305,6 +314,7 @@ _tdm_layer_dump_buffer(tdm_layer *layer, tbm_surface_h buffer) return; } +/* LCOV_EXCL_STOP */ static void _tdm_layer_free_buffer(tdm_private_layer *private_layer, tdm_private_layer_buffer *layer_buffer) @@ -410,6 +420,7 @@ tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) _pthread_mutex_lock(&private_display->lock); + /* LCOV_EXCL_START */ /* dump buffer */ if (tdm_dump_enable && !(private_layer->caps.capabilities & TDM_LAYER_CAPABILITY_VIDEO)) _tdm_layer_dump_buffer(private_layer, buffer); @@ -422,6 +433,7 @@ tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) private_output->index, private_layer->index, i++); tdm_helper_dump_buffer_str(buffer, tdm_debug_dump_dir, str); } + /* LCOV_EXCL_STOP */ func_layer = &private_display->func_layer; @@ -431,9 +443,11 @@ tdm_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer) private_layer->usable = 0; if (!func_layer->layer_set_buffer) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_START */ } private_layer->pending_buffer_changed = 1; @@ -476,9 +490,11 @@ tdm_layer_unset_buffer(tdm_layer *layer) TDM_INFO("layer(%p) now usable", private_layer); if (!func_layer->layer_unset_buffer) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_START */ } ret = func_layer->layer_unset_buffer(private_layer->layer_backend); @@ -495,6 +511,7 @@ tdm_layer_committed(tdm_private_layer *private_layer, tdm_private_layer_buffer * tdm_private_output *private_output = private_layer->private_output; tdm_private_display *private_display = private_output->private_display; + /* LCOV_EXCL_START */ if (private_display->print_fps) { double curr = tdm_helper_get_time(); if (private_layer->fps_stamp == 0) { @@ -509,6 +526,7 @@ tdm_layer_committed(tdm_private_layer *private_layer, tdm_private_layer_buffer * private_layer->fps_stamp = 0; private_layer->fps_count = 0; } + /* LCOV_EXCL_STOP */ if (private_layer->showing_buffer) _tdm_layer_free_buffer(private_layer, private_layer->showing_buffer); @@ -815,8 +833,10 @@ _tdm_layer_commit(tdm_layer *layer, tdm_layer_commit_handler func, void *user_da layer_commit_handler = calloc(1, sizeof(tdm_private_layer_commit_handler)); if (!layer_commit_handler) { + /* LCOV_EXCL_START */ TDM_ERR("failed: alloc memory"); return TDM_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ } if (tdm_debug_module & TDM_DEBUG_COMMIT) @@ -1036,25 +1056,31 @@ _tbm_layer_queue_acquirable_cb(tbm_surface_queue_h surface_queue, void *data) func_layer = &private_display->func_layer; if (!func_layer->layer_set_buffer) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); return; + /* LCOV_EXCL_STOP */ } layer_buffer = calloc(1, sizeof(tdm_private_layer_buffer)); if (!layer_buffer) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("alloc failed"); return; + /* LCOV_EXCL_STOP */ } LIST_INITHEAD(&layer_buffer->link); if (TBM_SURFACE_QUEUE_ERROR_NONE != tbm_surface_queue_acquire(private_layer->buffer_queue, &surface) || surface == NULL) { + /* LCOV_EXCL_START */ TDM_ERR("layer(%p) tbm_surface_queue_acquire() failed surface:%p", private_layer, surface); _pthread_mutex_unlock(&private_display->lock); free(layer_buffer); return; + /* LCOV_EXCL_STOP */ } /* we don't need to handle pending data here because the changes in this function @@ -1128,9 +1154,11 @@ tdm_layer_set_buffer_queue(tdm_layer *layer, tbm_surface_queue_h buffer_queue) private_layer->usable = 0; if (!func_layer->layer_set_buffer) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } if (buffer_queue == private_layer->buffer_queue) { @@ -1198,9 +1226,11 @@ tdm_layer_set_video_pos(tdm_layer *layer, int zpos) } if (!func_layer->layer_set_video_pos) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } ret = func_layer->layer_set_video_pos(private_layer->layer_backend, zpos); @@ -1237,9 +1267,11 @@ tdm_layer_get_buffer_flags(tdm_layer *layer, unsigned int *flags) func_layer = &private_display->func_layer; if (!func_layer->layer_get_buffer_flags) { + /* LCOV_EXCL_START */ _pthread_mutex_unlock(&private_display->lock); TDM_ERR("not implemented!!"); return TDM_ERROR_NOT_IMPLEMENTED; + /* LCOV_EXCL_STOP */ } ret = func_layer->layer_get_buffer_flags(private_layer->layer_backend, flags); -- 2.7.4 From a938b82fd7a7b9fae8484dc8a3156ebf7cfef0b6 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 16 Nov 2017 13:53:25 +0900 Subject: [PATCH 14/16] output: return current_dpms_value if commit_per_vblank is false To use the stored value to reduce the interaction between frontend and backend. If commit_per_vblank is true, tdm_output_get_dpms_internal calls backend's output_get_dpms always function to get dpms status. Some backends doesn't work properly for DPMS. In future, we'd better use new env instead of using commit_per_vblank variable to distinguish whether we use the stored value or backend's output_get_dpms. Change-Id: I464e5d0dee98985e657f6db636b4386258ffaa8e --- src/tdm_output.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tdm_output.c b/src/tdm_output.c index d445914..2307b7a 100644 --- a/src/tdm_output.c +++ b/src/tdm_output.c @@ -919,13 +919,8 @@ tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handl return TDM_ERROR_NOT_IMPLEMENTED; } - /* TODO: this is ugly. But before using tdm_output_get_dpms_internal, we have - * to check if all backends's DPMS operation has no problem. - */ - if (private_output->commit_per_vblank) - tdm_output_get_dpms_internal(output, &dpms_value); - else - dpms_value = private_output->current_dpms_value; + ret = tdm_output_get_dpms_internal(output, &dpms_value); + TDM_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, ret); if (dpms_value == TDM_OUTPUT_DPMS_ON) { if (func) { @@ -1283,6 +1278,16 @@ tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value) TDM_RETURN_VAL_IF_FAIL(private_output != NULL, TDM_ERROR_INVALID_PARAMETER); + /* TODO: this is ugly. But before calling backend's output_get_dpms(), we have + * to check if all backends's DPMS operation has no problem. In future, we'd + * better use new env instead of using commit_per_vblank variable to distinguish + * whether we use the stored value or backend's output_get_dpms. + */ + if (!private_output->commit_per_vblank) { + *dpms_value = private_output->current_dpms_value; + return TDM_ERROR_NONE; + } + func_output = &private_display->func_output; if (!func_output->output_get_dpms) { -- 2.7.4 From 44a3f54843be1106a072319ff76aef82955197d9 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Thu, 16 Nov 2017 13:56:37 +0900 Subject: [PATCH 15/16] vblank: using tdm_output function to get DPMS status. Storing DPMS value made inconsistency with output's DPMS value Change-Id: I303486cda38c2d8c9c01346facf1e7848b9c63e3 --- src/tdm_vblank.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/tdm_vblank.c b/src/tdm_vblank.c index 931842d..b2ccb95 100644 --- a/src/tdm_vblank.c +++ b/src/tdm_vblank.c @@ -98,7 +98,6 @@ typedef struct _tdm_private_vblank { tdm_display *dpy; tdm_output *output; tdm_output_conn_status connection; - tdm_output_dpms dpms; unsigned int vrefresh; tdm_vblank_event_type last_type; @@ -323,7 +322,6 @@ _tdm_vblank_update_output_info(tdm_private_vblank *private_vblank) { tdm_output *output = private_vblank->output; tdm_output_conn_status connection = TDM_OUTPUT_CONN_STATUS_DISCONNECTED; - tdm_output_dpms dpms = TDM_OUTPUT_DPMS_OFF; unsigned int vrefresh = 0; tdm_output_get_conn_status(output, &connection); @@ -335,7 +333,6 @@ _tdm_vblank_update_output_info(tdm_private_vblank *private_vblank) vrefresh = mode->vrefresh; else VWR("mode not setted!!!"); - tdm_output_get_dpms(output, &dpms); } if (vrefresh == 0) { @@ -343,7 +340,6 @@ _tdm_vblank_update_output_info(tdm_private_vblank *private_vblank) vrefresh = TDM_VBLANK_DEFAULT_VREFRESH; } - private_vblank->dpms = dpms; private_vblank->connection = connection; private_vblank->vrefresh = vrefresh; private_vblank->HW_vblank_gap = 1.0 / private_vblank->vrefresh; @@ -351,8 +347,8 @@ _tdm_vblank_update_output_info(tdm_private_vblank *private_vblank) if (private_vblank->fps_changeable) private_vblank->fps = vrefresh; - VIN("dpms(%d) connection(%d) vrefresh(%d) fps(%d) fps_changeable(%d)", - private_vblank->dpms, private_vblank->connection, + VIN("connection(%d) vrefresh(%d) fps(%d) fps_changeable(%d)", + private_vblank->connection, private_vblank->vrefresh, private_vblank->fps, private_vblank->fps_changeable); } @@ -366,12 +362,9 @@ _tdm_vblank_cb_output_change(tdm_output *output, tdm_output_change_type type, switch (type) { case TDM_OUTPUT_CHANGE_DPMS: - if (private_vblank->dpms == value.u32) - break; VIN("dpms %s", tdm_dpms_str(value.u32)); - _tdm_vblank_update_output_info(private_vblank); private_vblank->check_HW_or_SW = 1; - if (private_vblank->dpms != TDM_OUTPUT_DPMS_ON) { + if (value.u32 != TDM_OUTPUT_DPMS_ON) { if (private_vblank->enable_fake) _tdm_vblank_change_to_SW(private_vblank); else @@ -514,8 +507,8 @@ tdm_vblank_create(tdm_display *dpy, tdm_output *output, tdm_error *error) _tdm_vblank_valid_list_add(&private_vblank->valid_link, &valid_vblank_list); - VIN("created. vrefresh(%d) dpms(%d) connection(%d)", - private_vblank->vrefresh, private_vblank->dpms, private_vblank->connection); + VIN("created. vrefresh(%d) connection(%d)", + private_vblank->vrefresh, private_vblank->connection); return (tdm_vblank *)private_vblank; } @@ -1055,6 +1048,7 @@ tdm_vblank_wait(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_usec, { tdm_private_vblank *private_vblank = vblank; tdm_vblank_wait_info *wait_info; + tdm_output_dpms dpms = TDM_OUTPUT_DPMS_OFF; unsigned int fps; tdm_error ret; @@ -1066,12 +1060,14 @@ tdm_vblank_wait(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_usec, return TDM_ERROR_BAD_REQUEST; } + tdm_output_get_dpms(private_vblank->output, &dpms); + if (!private_vblank->enable_fake) { if (private_vblank->connection == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) { VER("can't wait a vblank: output disconnected"); return TDM_ERROR_OUTPUT_DISCONNECTED; } - if (private_vblank->dpms != TDM_OUTPUT_DPMS_ON) { + if (dpms != TDM_OUTPUT_DPMS_ON) { VER("can't wait a vblank: DPMS off"); return TDM_ERROR_DPMS_OFF; } @@ -1122,7 +1118,7 @@ tdm_vblank_wait(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_usec, */ if (private_vblank->vrefresh % fps) wait_info->type = VBLANK_TYPE_SW; - else if (private_vblank->dpms == TDM_OUTPUT_DPMS_OFF || + else if (dpms == TDM_OUTPUT_DPMS_OFF || private_vblank->connection == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) wait_info->type = VBLANK_TYPE_SW_FAKE; else if (private_vblank->offset == 0) -- 2.7.4 From 2acecc2d251e1f11a79488899424ec984e579e19 Mon Sep 17 00:00:00 2001 From: Konstantin Drabeniuk Date: Thu, 16 Nov 2017 17:17:12 +0200 Subject: [PATCH 16/16] utest: Add 26 test cases Covered API funcs. from the tdm_pp.c file. Change-Id: I3c0c123d90fdde0929b88cdccb56a456b3d6853a Signed-off-by: Konstantin Drabeniuk --- utests/src/ut_tdm_layer.cpp | 11 +- utests/src/ut_tdm_pp.cpp | 714 ++++++++++++++++++++++++++++++++++++++++++- utests/src/ut_tdm_vblank.cpp | 15 +- 3 files changed, 717 insertions(+), 23 deletions(-) diff --git a/utests/src/ut_tdm_layer.cpp b/utests/src/ut_tdm_layer.cpp index dbcceab..21a552d 100644 --- a/utests/src/ut_tdm_layer.cpp +++ b/utests/src/ut_tdm_layer.cpp @@ -72,8 +72,12 @@ protected: SetEnv(); + /* FIXME: fix the error. If we initialize TBM before TDM we get fail + * in the tdm_output_set_dpms */ +#if 0 tbm_bufmgr = tbm_bufmgr_init(-1); ASSERT_FALSE(tbm_bufmgr == NULL); +#endif dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -258,7 +262,8 @@ protected: utLayerCommitHandlerCounter = 0; - TDMLayer::SetUp(); + ASSERT_NO_FATAL_FAILURE(TDMLayer::SetUp()); + for (int i = 0; i < output_count; ++i) { if (!preferred_mode_array[i]) continue; @@ -1813,10 +1818,10 @@ TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerSetBufferQueueSuccessRemo for (int i = 0; i < layer_count; ++i) { tbm_surface_h surface; - tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface); + tbm_err = tbm_surface_queue_dequeue(tdm_layers_buffer_queue_array[i], &surface); ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); - tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface); + tbm_err = tbm_surface_queue_enqueue(tdm_layers_buffer_queue_array[i], surface); ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error); error = tdm_layer_unset_buffer_queue(tdm_layer_array[i]); diff --git a/utests/src/ut_tdm_pp.cpp b/utests/src/ut_tdm_pp.cpp index 5ea127a..fdd1353 100644 --- a/utests/src/ut_tdm_pp.cpp +++ b/utests/src/ut_tdm_pp.cpp @@ -30,50 +30,734 @@ #include "gtest/gtest.h" #include "ut_common.h" -extern "C" { #include "tdm.h" +extern "C" { #include "tbm_bufmgr.h" #include "tbm_drm_helper.h" } -class TDMPP : public testing::Test { +#include +#include +#include +#include + +#define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1)) + +class TDMPPWithoutCreation : public testing::Test { protected: tdm_display *dpy = NULL; - tdm_pp_capability pp_capabilities = (tdm_pp_capability) -42; + tbm_bufmgr bufmgr; + tdm_display_capability display_capability = (tdm_display_capability)0; bool has_pp = false; - void SetUp(void) + std::list buffers_list; + + virtual void SetEnvs() { setenv("TDM_DLOG", "1", 1); setenv("XDG_RUNTIME_DIR", ".", 1); setenv("TBM_DLOG", "1", 1); + setenv("TDM_DEBUG_MODULE", "all", 1); + setenv("TDM_DEBUG", "1", 1); + setenv("TBM_DISPLAY_SERVER", "1", 1); + } + + virtual void UnsetEnvs() + { + unsetenv("TDM_DLOG"); + unsetenv("XDG_RUNTIME_DIR"); + unsetenv("TBM_DLOG"); + unsetenv("TDM_DEBUG_MODULE"); + unsetenv("TDM_DEBUG"); + unsetenv("TBM_DISPLAY_SERVER"); + } + + void SetUp(void) + { tdm_error error = TDM_ERROR_NONE; + + SetEnvs(); + + bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(bufmgr == NULL); + dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); ASSERT_FALSE(dpy == NULL); - error = tdm_display_get_pp_capabilities(dpy, &pp_capabilities); + + error = tdm_display_get_capabilities(dpy, &display_capability); #ifdef FAIL_ON_UNSUPPORTED - ASSERT_GT(pp_capabilities, 0); + ASSERT_TRUE(display_capability & TDM_DISPLAY_CAPABILITY_PP); #endif - if (pp_capabilities > 0) + ASSERT_TRUE(error == TDM_ERROR_NONE); + + if (display_capability & TDM_DISPLAY_CAPABILITY_PP) has_pp = true; } + void TearDown(void) { - tdm_display_deinit(dpy); - dpy = NULL; - unsetenv("TDM_DLOG"); - unsetenv("XDG_RUNTIME_DIR"); - unsetenv("TBM_DLOG"); - unsetenv("TBM_DISPLAY_SERVER"); + if (dpy) + tdm_display_deinit(dpy); + if (bufmgr) + tbm_bufmgr_deinit(bufmgr); + + UnsetEnvs(); + } +}; + +class TDMPP : public TDMPPWithoutCreation { +protected: + tdm_pp *pp = NULL; + const tbm_format *formats = NULL; + int format_count = 0; + int min_w = 0; + int min_h = 0; + int max_w = 0; + int max_h = 0; + int preferred_align = 0; + int default_src_w = 128; + int default_src_h = 256; + int default_dst_w = 512; + int default_dst_h = 1024; + + void SetUp(void) + { + tdm_error error; + + ASSERT_NO_FATAL_FAILURE(TDMPPWithoutCreation::SetUp()); + + if (!has_pp) + return; + + pp = tdm_display_create_pp(dpy, &error); + ASSERT_NE(NULL, pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + error = + tdm_display_get_pp_available_formats(dpy, &formats, &format_count); + ASSERT_EQ(TDM_ERROR_NONE, error); + ASSERT_NE(NULL, formats); + ASSERT_GE(format_count, 0); + + error = + tdm_display_get_pp_available_size(dpy, &min_w, &min_h, + &max_w, &max_h, &preferred_align); + ASSERT_EQ(TDM_ERROR_NONE, error); + if (preferred_align > 0) { + default_src_w = SIZE_ALIGN(default_src_w, preferred_align); + default_src_h = SIZE_ALIGN(default_src_h, preferred_align); + default_dst_w = SIZE_ALIGN(default_dst_w, preferred_align); + default_dst_h = SIZE_ALIGN(default_dst_h, preferred_align); + } + if (min_w > default_src_w) + default_src_w = min_w; + if (min_h > default_src_h) + default_src_h = min_h; + if (max_w > 0 && max_w < default_dst_w) + default_dst_w = max_w; + if (max_h > 0 && max_h < default_dst_h) + default_dst_h = max_h; + } + + void TearDown(void) + { + if (pp) + tdm_pp_destroy(pp); + + for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) { + tbm_surface_destroy(*it); + } + + buffers_list.clear(); + + TDMPPWithoutCreation::TearDown(); + } + + void UtGetPPInfoWithScale(tdm_info_pp *info) + { + memset((void *)info, 0, sizeof(tdm_info_pp)); + + info->src_config.size.h = default_src_w; + info->src_config.size.v = default_src_h; + info->src_config.pos.x = 0; + info->src_config.pos.y = 0; + info->src_config.pos.w = default_src_w; + info->src_config.pos.h = default_src_h; + info->src_config.format = formats[0]; + info->dst_config.size.h = default_dst_w; + info->dst_config.size.v = default_dst_h; + info->dst_config.pos.x = 0; + info->dst_config.pos.y = 0; + info->dst_config.pos.w = default_dst_w; + info->dst_config.pos.h = default_dst_h; + info->dst_config.format = formats[0]; + } + + void UtGetPPInfoWithScaleAndTransform(tdm_info_pp *info) + { + UtGetPPInfoWithScale(info); + + info->transform = TDM_TRANSFORM_180; + } + + void UtGetPPInfoWithWrongInfo(tdm_info_pp *info) + { + info->src_config.size.h = UINT_MAX; + info->src_config.size.v = UINT_MAX; + info->src_config.pos.x = 0; + info->src_config.pos.y = 0; + info->src_config.pos.w = UINT_MAX; + info->src_config.pos.h = UINT_MAX; + info->src_config.format = INT_MAX; + info->dst_config.size.h = UINT_MAX; + info->dst_config.size.v = UINT_MAX; + info->dst_config.pos.x = 0; + info->dst_config.pos.y = 0; + info->dst_config.pos.w = UINT_MAX; + info->dst_config.pos.h = UINT_MAX; + info->dst_config.format = INT_MAX; + } + + tbm_surface_h + UtCreateBuffer(int w, int h, tbm_format format) + { + tbm_surface_h buffer; + + buffer = tbm_surface_create(w, h, format); + if (buffer) + buffers_list.push_back(buffer); + + return buffer; } }; -TEST_F(TDMPP, DisplayGetPPAvailableFormatsSuccessful) +void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src, + tbm_surface_h dst, void *user_data); + +class TDMPPCommit : public TDMPP { +public: + friend void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src, + tbm_surface_h dst, void *user_data); +private: + int epFd = -1; + int timerFd = -1; + int tdmFd = -1; + static const int timeLimitSec = 0; + static const int timeLimitNsec = 100000000; +protected: + int utPpDoneHandlerSuccessCounter = 0; + + void SetUp(void) + { + tdm_error error; + tdm_output *output; + struct epoll_event ep; + tdm_pp_capability pp_capability; + + ASSERT_NO_FATAL_FAILURE(TDMPP::SetUp()); + + epFd = epoll_create1(0); + ASSERT_TRUE(epFd != -1); + + timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); + ASSERT_TRUE(timerFd != -1); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = timerFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0); + + ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE); + + memset(&ep, 0, sizeof ep); + ep.events |= EPOLLIN; + ep.data.fd = tdmFd; + ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0); + } + + void TearDown(void) + { + tdm_error error; + + if (epFd) + close(epFd); + if (timerFd) + close(timerFd); + + TDMPP::TearDown(); + } + + void UtHandlePPEvent(int num_attached_buffers) + { + struct itimerspec its; + int count; + struct epoll_event ep_event[2]; + + if (utPpDoneHandlerSuccessCounter == num_attached_buffers) + return; + + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + its.it_value.tv_sec = timeLimitSec; + its.it_value.tv_nsec = timeLimitNsec; + + ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0); + + while (1) { + count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1); + ASSERT_TRUE(count >= 0); + + for (int i = 0; i < count; i++) { + if (ep_event[i].data.fd == timerFd) { + return; + } else { + ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE); + if (utPpDoneHandlerSuccessCounter == num_attached_buffers) + return; + } + } + } + } + + int UtPrepareToPP(tdm_info_pp *info) + { + tdm_error error; + tbm_surface_h src_buf, dst_buf; + + error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this); + EXPECT_EQ(TDM_ERROR_NONE, error); + if (error != TDM_ERROR_NONE) + return -1; + + error = tdm_pp_set_info(pp, info); + EXPECT_EQ(TDM_ERROR_NONE, error); + if (error != TDM_ERROR_NONE) + return -1; + + src_buf = UtCreateBuffer(info->src_config.pos.w, info->src_config.pos.h, + info->src_config.format); + EXPECT_NE(NULL, src_buf); + if (!src_buf) + return -1; + + dst_buf = UtCreateBuffer(info->dst_config.pos.w, info->dst_config.pos.h, + info->dst_config.format); + EXPECT_NE(NULL, dst_buf); + if (!dst_buf) + return -1; + + error = tdm_pp_attach(pp, src_buf, dst_buf); + EXPECT_EQ(TDM_ERROR_NONE, error); + if (error != TDM_ERROR_NONE) + return -1; + + } + + int UtPrepareToPPWithScale() + { + tdm_info_pp info = {0}; + tdm_error error; + tbm_surface_h src_buf, dst_buf; + + UtGetPPInfoWithScale(&info); + + return UtPrepareToPP(&info); + } + + int UtPrepareToPPWithScaleAndTransform() + { + tdm_info_pp info = {0}; + tdm_error error; + tbm_surface_h src_buf, dst_buf; + + UtGetPPInfoWithScaleAndTransform(&info); + + return UtPrepareToPP(&info); + } + + int UtPrepareToPPWithWrongInfo() + { + tdm_info_pp info = {0}; + tdm_error error; + tbm_surface_h src_buf, dst_buf; + int ret; + + UtGetPPInfoWithScale(&info); + + ret = UtPrepareToPP(&info); + if (ret < 0) + return ret; + + UtGetPPInfoWithWrongInfo(&info); + + error = tdm_pp_set_info(pp, &info); + EXPECT_EQ(TDM_ERROR_NONE, error); + if (error != TDM_ERROR_NONE) + return -1; + + return 0; + } + +}; + +class TDMPPCommitThread : public TDMPPCommit { +protected: + void SetEnvs() + { + TDMPPCommit::SetEnvs(); + setenv("TDM_THREAD", "1", 1); + } + void UnsetEnvs() + { + TDMPPCommit::UnsetEnvs(); + unsetenv("TDM_THREAD"); + } +}; + +void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src, + tbm_surface_h dst, void *user_data) +{ + TDMPPCommit *pp_commit = (TDMPPCommit *)user_data; + bool src_valid, dst_valid; + + if (!pp_commit) + return; + + for (auto it = pp_commit->buffers_list.begin(); it != pp_commit->buffers_list.end(); ++it) { + if (*it == src) + src_valid = true; + if (*it == dst) + dst_valid = true; + } + + if (src_valid && dst_valid) + pp_commit->utPpDoneHandlerSuccessCounter++; +} + +TEST_F(TDMPPWithoutCreation, DisplayGetPPAvailableFormatsSuccessful) { SKIP_FLAG(has_pp); - const tbm_format * formats = NULL; + const tbm_format *formats = NULL; int count = -42; ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count)); ASSERT_FALSE(-42 == count); ASSERT_FALSE(NULL == formats); } + +/* tdm_display_create_pp() */ + +TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullAll) +{ + SKIP_FLAG(has_pp); + tdm_pp *pp; + + pp = tdm_display_create_pp(NULL, NULL); + ASSERT_EQ(NULL, pp); +} + +TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullDpy) +{ + SKIP_FLAG(has_pp); + tdm_pp *pp; + tdm_error error; + + pp = tdm_display_create_pp(NULL, &error); + ASSERT_EQ(NULL, pp); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccessNullError) +{ + SKIP_FLAG(has_pp); + tdm_pp *pp; + + pp = tdm_display_create_pp(dpy, NULL); + ASSERT_NE(NULL, pp); +} + +TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccess) +{ + SKIP_FLAG(has_pp); + tdm_pp *pp; + tdm_error error; + + pp = tdm_display_create_pp(dpy, &error); + ASSERT_NE(NULL, pp); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + +/* tdm_pp_set_info() */ + +TEST_F(TDMPP, PpSetInfoNullAll) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_set_info(NULL, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetInfoNullPP) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tdm_info_pp info; + + error = tdm_pp_set_info(NULL, &info); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetInfoNullInfo) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_set_info(pp, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetInfoSuccess) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tdm_info_pp info; + + UtGetPPInfoWithScale(&info); + + error = tdm_pp_set_info(pp, &info); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + +/* tdm_pp_set_done_handler() */ + +TEST_F(TDMPP, PpSetDoneHandlerFailNullAll) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_set_done_handler(NULL, NULL, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetDoneHandlerFailNullPP) +{ + SKIP_FLAG(has_pp); + tdm_error error; + int data; + + error = tdm_pp_set_done_handler(NULL, UtPpDoneHandler, this); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetDoneHandlerSuccessNullFailNullFunc) +{ + SKIP_FLAG(has_pp); + tdm_error error; + int data; + + error = tdm_pp_set_done_handler(pp, NULL, &data); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetDoneHandlerSuccessNullData) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpSetDoneHandlerSuccess) +{ + SKIP_FLAG(has_pp); + tdm_error error; + int data; + + error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + +/* tdm_pp_attach() */ + +TEST_F(TDMPP, PpAttachFailNullAll) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_attach(NULL, NULL, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpAttachFailNullPp) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tbm_surface_h dst_buf, src_buf; + + src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]); + ASSERT_NE(NULL, src_buf); + + dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]); + ASSERT_NE(NULL, dst_buf); + + error = tdm_pp_attach(NULL, src_buf, dst_buf); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpAttachFailNullSrc) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tbm_surface_h dst_buf; + + dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]); + ASSERT_NE(NULL, dst_buf); + + error = tdm_pp_attach(pp, NULL, dst_buf); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpAttachFailNullDst) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tbm_surface_h src_buf; + + src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]); + ASSERT_NE(NULL, src_buf); + + error = tdm_pp_attach(pp, src_buf, NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPP, PpAttachSuccess) +{ + SKIP_FLAG(has_pp); + tdm_error error; + tbm_surface_h dst_buf, src_buf; + + src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]); + ASSERT_NE(NULL, src_buf); + + dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]); + ASSERT_NE(NULL, dst_buf); + + error = tdm_pp_attach(pp, src_buf, dst_buf); + ASSERT_EQ(TDM_ERROR_NONE, error); +} + +/* tdm_pp_commit() */ + +TEST_F(TDMPP, PpCommitFailNullPP) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + error = tdm_pp_commit(NULL); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPPCommit, PpCommitFailWrongInfo) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + ASSERT_NE(-1, UtPrepareToPPWithWrongInfo()); + + error = tdm_pp_commit(pp); + ASSERT_NE(TDM_ERROR_NONE, error); +} + +TEST_F(TDMPPCommit, PpCommitSuccessScale) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + ASSERT_NE(-1, UtPrepareToPPWithScale()); + + error = tdm_pp_commit(pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + UtHandlePPEvent(1); + + ASSERT_EQ(1, utPpDoneHandlerSuccessCounter); +} + +TEST_F(TDMPPCommit, PpCommitSuccessScaleAndTransform) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + ASSERT_NE(-1, UtPrepareToPPWithScale()); + + error = tdm_pp_commit(pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + UtHandlePPEvent(1); + + ASSERT_EQ(1, utPpDoneHandlerSuccessCounter); +} + +TEST_F(TDMPPCommitThread, PpCommitSuccessScale) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + ASSERT_NE(-1, UtPrepareToPPWithScale()); + + error = tdm_pp_commit(pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + UtHandlePPEvent(1); + + ASSERT_EQ(1, utPpDoneHandlerSuccessCounter); +} + +TEST_F(TDMPPCommitThread, PpCommitSuccessScaleAndTransform) +{ + SKIP_FLAG(has_pp); + tdm_error error; + + ASSERT_NE(-1, UtPrepareToPPWithScale()); + + error = tdm_pp_commit(pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + UtHandlePPEvent(1); + + ASSERT_EQ(1, utPpDoneHandlerSuccessCounter); +} + +/* tdm_pp_destroy() */ + +void UtBufferReleaseHandler(tbm_surface_h buffer, + void *user_data) +{ + int *data = (int *)user_data; + if (!data) + return; + + (*data)++; +} + +TEST_F(TDMPPCommit, PPDestroySuccessAfterCommit) +{ + SKIP_FLAG(has_pp); + tdm_error error; + int release_data = 0; + + ASSERT_NE(-1, UtPrepareToPPWithScale()); + + for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) { + tdm_buffer_add_release_handler((tbm_surface_h)*it, UtBufferReleaseHandler, &release_data); + } + + error = tdm_pp_commit(pp); + ASSERT_EQ(TDM_ERROR_NONE, error); + + tdm_pp_destroy(pp); + pp = NULL; + + ASSERT_EQ(2, release_data); +} diff --git a/utests/src/ut_tdm_vblank.cpp b/utests/src/ut_tdm_vblank.cpp index 746d4c7..b8701ab 100644 --- a/utests/src/ut_tdm_vblank.cpp +++ b/utests/src/ut_tdm_vblank.cpp @@ -57,8 +57,12 @@ protected: setenv("TBM_DLOG", "1", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); - bufmgr = tbm_bufmgr_init(-1); - ASSERT_FALSE(bufmgr == NULL); + /* FIXME: fix the error. If we initialize TBM before TDM we get fail + * in the tdm_output_set_dpms */ +#if 0 + tbm_bufmgr = tbm_bufmgr_init(-1); + ASSERT_FALSE(tbm_bufmgr == NULL); +#endif dpy = tdm_display_init(&error); ASSERT_TRUE(error == TDM_ERROR_NONE); @@ -138,7 +142,7 @@ protected: { tdm_error error; - TDMVblankWithoutCreating::SetUp(); + ASSERT_NO_FATAL_FAILURE(TDMVblankWithoutCreating::SetUp()); if (connected_output && setModeAndDpms) { int primary_index; @@ -250,7 +254,8 @@ protected: utVblankHandlerIsCalled = 0; setModeAndDpms = 1; - TDMVblank::SetUp(); + + ASSERT_NO_FATAL_FAILURE(TDMVblank::SetUp()); epFd = epoll_create1(0); ASSERT_TRUE(epFd != -1); @@ -309,7 +314,7 @@ protected: void SetUp(void) { setenv("TDM_THREAD", "1", 1); - TDMVblankWait::SetUp(); + ASSERT_NO_FATAL_FAILURE(TDMVblankWait::SetUp()); } }; -- 2.7.4