1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "../stubs/stub_dlfcn.h"
30 #include "gtest/gtest.h"
32 /*------ stubs -----------------*/
33 #include "tdm_event_loop_stubs.h"
34 #include "tbm_stubs.h"
35 #include "stub_pthread.h"
36 #include "stub_tdm_vblank.h"
37 #include "stub_stdlib.h"
38 #include "stub_stdio.h"
39 #include "stub_unistd.h"
40 #include "tdm_event_loop_stubs.h"
42 /*------ tested file -----------*/
44 static void _init_test()
52 stub_tdm_vblank_init();
53 g_private_display = NULL;
56 extern tdm_backend_module tdm_backend_module_stub;
59 /* tdm_display_update */
61 TEST(tdm_display_update, work_flow_success_1)
63 tdm_error error = TDM_ERROR_NONE;
64 tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
68 error = tdm_display_update(NULL);
70 ASSERT_EQ(error, expected_error);
73 /* tdm_display_init() */
74 TEST(tdm_display_init, work_flow_success_1___first_call)
76 tdm_error error = TDM_ERROR_BAD_REQUEST;
81 //to download tdm_backend_module;
82 stub_dlfcn_ctrl.dlopen_returned_val = (void*)1;
83 stub_dlfcn_ctrl.dlsym_returned_val = &tdm_backend_module_stub;
85 setenv("TDM_DEBUG_MODULE", "all", 1);
86 setenv("TDM_DEBUG_DUMP", "capture,pp,layer,all", 1);
87 setenv("TDM_DEBUG_PATH", "log.txt", 1);
88 stub_getenv_return_real_value = 1;
90 disp = tdm_display_init(&error);
92 ASSERT_EQ(TDM_ERROR_NONE, error);
93 ASSERT_TRUE(g_private_display != NULL);
94 ASSERT_TRUE(g_private_display == disp);
95 ASSERT_EQ(1, g_private_display->init_count);
98 TEST(tdm_display_init, work_flow_success_2___second_call)
100 tdm_error error = TDM_ERROR_BAD_REQUEST;
102 tdm_private_display display;
105 memset(&display, 0, sizeof(display));
106 g_private_display = &display;
107 g_private_display->init_count = 1;
109 disp = tdm_display_init(&error);
111 ASSERT_EQ(TDM_ERROR_NONE, error);
112 ASSERT_TRUE(g_private_display != NULL);
113 ASSERT_TRUE(g_private_display == disp);
114 ASSERT_EQ(2, g_private_display->init_count);
118 TEST(tdm_display_init, work_flow_error_1___calloc_error)
120 tdm_error error = TDM_ERROR_BAD_REQUEST;
126 disp = tdm_display_init(&error);
128 ASSERT_EQ(TDM_ERROR_OUT_OF_MEMORY, error);
129 ASSERT_TRUE(disp == NULL);
130 ASSERT_TRUE(g_private_display == NULL);
133 TEST(tdm_display_init, work_flow_error_2___mutex_init_error)
135 tdm_error error = TDM_ERROR_BAD_REQUEST;
139 PTHREAD_MUTEX_INIT_ERROR = 1;
141 disp = tdm_display_init(&error);
143 ASSERT_NE(TDM_ERROR_NONE, error);
144 ASSERT_TRUE(disp == NULL);
145 ASSERT_TRUE(g_private_display == NULL);
148 /* tdm_display_deinit */
150 TEST(tdm_display_deinit, work_flow_success_1___init_count_more_then_one)
152 tdm_private_display *dpy;
153 unsigned int expected = 2;
158 dpy = (tdm_private_display *)calloc(1, sizeof(tdm_private_display));
159 g_private_display = dpy;
162 tdm_display_deinit(dpy);
164 actual = dpy->init_count;
168 ASSERT_NE(g_private_display, NULL);
169 ASSERT_EQ(actual, expected);
172 TEST(tdm_display_deinit, work_flow_success_2___init_count_is_one)
174 unsigned int expected = 2;
177 tdm_error error = TDM_ERROR_BAD_REQUEST;
182 //to download tdm_backend_module;
183 stub_dlfcn_ctrl.dlopen_returned_val = (void*)1;
184 stub_dlfcn_ctrl.dlsym_returned_val = &tdm_backend_module_stub;
186 disp = tdm_display_init(&error);
188 ASSERT_EQ(TDM_ERROR_NONE, error);
190 //call tested function
191 tdm_display_deinit(disp);
193 ASSERT_EQ(NULL, g_private_display);
194 ASSERT_TRUE(FREE_CALLED);
198 /* tdm_display_check_module_abi */
199 TEST(tdm_display_check_module_abi, work_flow_success_1)
202 tdm_private_display private_display;
203 tdm_backend_module module;
204 private_display.module_data = &module;
205 module.abi_version = 0x00010001;
207 res = tdm_display_check_module_abi(&private_display, 1, 1);
212 TEST(tdm_display_check_module_abi, work_flow_error_1___wrong_version)
215 tdm_private_display private_display;
216 tdm_backend_module module;
217 private_display.module_data = &module;
218 module.abi_version = 0x00010001;
221 res = tdm_display_check_module_abi(&private_display, 1, 2);
225 res = tdm_display_check_module_abi(&private_display, 2, 1);
229 /* tdm_display_check_module_abi */
230 TEST(tdm_display_enable_debug_module, work_flow_success_1)
235 error = tdm_display_enable_debug_module("all");
236 ASSERT_EQ(0xFFFFFFFF, tdm_debug_module);
237 ASSERT_EQ(TDM_ERROR_NONE, error);
240 error = tdm_display_enable_debug_module("none");
241 ASSERT_EQ(0, tdm_debug_module);
242 ASSERT_EQ(TDM_ERROR_NONE, error);
244 //check buffer,thread,mutex,vblank
245 error = tdm_display_enable_debug_module("buffer,thread,mutex,vblank");
246 ASSERT_EQ((TDM_DEBUG_BUFFER | TDM_DEBUG_THREAD | TDM_DEBUG_MUTEX | TDM_DEBUG_VBLANK) ,
248 ASSERT_EQ(TDM_ERROR_NONE, error);
252 TEST(tdm_display_enable_debug_module, work_flow_error_1___bad_module)
257 error = tdm_display_enable_debug_module("bufer");
258 ASSERT_EQ(0 , tdm_debug_module);
259 ASSERT_NE(TDM_ERROR_NONE, error);
262 /* tdm_display_enable_ttrace_vblank */
263 TEST(tdm_display_enable_ttrace_vblank, work_flow_success_1)
266 tdm_private_display private_display;
267 tdm_private_output output;
268 tdm_output_mode current_mode;
272 stub_tdm_vblank_create_returned = &vblank;
274 output.current_mode = ¤t_mode;
275 output.private_display = &private_display;
277 error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1);
278 ASSERT_EQ(TDM_ERROR_NONE, error);
280 error = tdm_display_enable_ttrace_vblank(&private_display, &output, 0);
283 TEST(tdm_display_enable_ttrace_vblank, work_flow_error_1___vblank_wait_fail)
286 tdm_private_display private_display;
287 tdm_private_output output;
288 tdm_output_mode current_mode;
293 output.current_mode = ¤t_mode;
294 output.private_display = &private_display;
295 stub_tdm_vblank_create_returned = &vblank;
297 stub_tdm_vblank_wait_error = 1;
299 error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1);
300 ASSERT_NE(TDM_ERROR_NONE, error);
303 TEST(tdm_display_enable_ttrace_vblank, work_flow_error_2___vblank_create_fail)
306 tdm_private_display private_display;
307 tdm_private_output output;
308 tdm_output_mode current_mode;
311 stub_tdm_vblank_create_returned = NULL;
313 output.current_mode = ¤t_mode;
314 output.private_display = &private_display;
316 error = tdm_display_enable_ttrace_vblank(&private_display, &output, 1);
317 ASSERT_EQ(TDM_ERROR_NONE, error);