1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6 * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7 * Contact: Roman Marchenko <r.marchenko@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sub license, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
31 #include "gtest/gtest.h"
32 #include "ut_common.h"
36 #include "tbm_bufmgr.h"
37 #include "tbm_drm_helper.h"
40 class TDMOutput : public ::testing::Test {
42 tdm_display *dpy = NULL;
43 int output_count = -42;
44 bool has_output = false;
45 tbm_bufmgr tbm_bufmgr = NULL;
46 static unsigned int handle_call;
47 static void tdm_output_change_handler_test_func(tdm_output *output,
48 tdm_output_change_type type,
52 if ( ((int) u_data) < -100) {
53 TDMOutput::handle_call++;
58 setenv("TDM_DLOG", "1", 1);
59 setenv("XDG_RUNTIME_DIR", ".", 1);
60 setenv("TBM_DLOG", "1", 1);
61 setenv("TBM_DISPLAY_SERVER", "1", 1);
62 tbm_bufmgr = tbm_bufmgr_init(-1);
63 ASSERT_FALSE(tbm_bufmgr == NULL);
64 tdm_error error = TDM_ERROR_NONE;
65 dpy = tdm_display_init(&error);
66 ASSERT_TRUE(error == TDM_ERROR_NONE);
67 ASSERT_FALSE(dpy == NULL);
68 error = tdm_display_get_output_count(dpy, &output_count);
69 #ifdef FAIL_ON_UNSUPPORTED
70 ASSERT_GT(output_count, 0);
78 tdm_display_deinit(dpy);
80 tbm_bufmgr_deinit(tbm_bufmgr);
83 unsetenv("XDG_RUNTIME_DIR");
85 unsetenv("TBM_DISPLAY_SERVER");
89 unsigned int TDMOutput::handle_call = 0;
91 TEST_F(TDMOutput, DisplayGetOutputSuccessful)
93 SKIP_FLAG(has_output);
94 for (int i = 0; i < output_count; i++) {
95 tdm_error error = TDM_ERROR_NONE;
96 ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error));
97 ASSERT_TRUE(TDM_ERROR_NONE == error);
101 TEST_F(TDMOutput, DisplayGetOutputSuccessfulWrongIndex)
103 SKIP_FLAG(has_output);
104 tdm_error error = TDM_ERROR_NONE;
105 ASSERT_TRUE(NULL == tdm_display_get_output(dpy, -1, &error));
106 ASSERT_TRUE(TDM_ERROR_NONE == error);
109 TEST_F(TDMOutput, DisplayGetOutputSuccessfulBigIndex)
111 SKIP_FLAG(has_output);
112 tdm_error error = TDM_ERROR_NONE;
113 ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MAX, &error));
114 ASSERT_TRUE(TDM_ERROR_NONE == error);
117 TEST_F(TDMOutput, DisplayGetOutputSuccessfulSmallIndex)
119 SKIP_FLAG(has_output);
120 tdm_error error = TDM_ERROR_NONE;
121 ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MIN, &error));
122 ASSERT_TRUE(TDM_ERROR_NONE == error);
125 TEST_F(TDMOutput, DisplayGetOutputSuccessfulErrorNull)
127 SKIP_FLAG(has_output);
128 ASSERT_FALSE(NULL == tdm_display_get_output(dpy, 0, NULL));
131 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful)
133 SKIP_FLAG(has_output);
134 for (int i = 0; i < output_count; i++) {
135 tdm_error error = TDM_ERROR_NONE;
136 tdm_output_capability capabilities = -42;
137 tdm_output * output = tdm_display_get_output(dpy, i, &error);
138 ASSERT_FALSE(NULL == output);
139 ASSERT_TRUE(TDM_ERROR_NONE == error);
140 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, &capabilities));
141 ASSERT_FALSE(-42 == capabilities);
145 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailAllNull)
147 SKIP_FLAG(has_output);
148 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(NULL, NULL));
151 TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailOnlyOutput)
153 SKIP_FLAG(has_output);
154 for (int i = 0; i < output_count; i++) {
155 tdm_error error = TDM_ERROR_NONE;
156 tdm_output * output = tdm_display_get_output(dpy, i, &error);
157 ASSERT_FALSE(NULL == output);
158 ASSERT_TRUE(TDM_ERROR_NONE == error);
159 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, NULL));
163 TEST_F(TDMOutput, OutputGetModelInfoSuccessful)
165 SKIP_FLAG(has_output);
166 for (int i = 0; i < output_count; i++) {
167 tdm_error error = TDM_ERROR_NONE;
168 const char * maker = NULL, * model = NULL, * name = NULL;
169 tdm_output * output = tdm_display_get_output(dpy, i, &error);
170 ASSERT_FALSE(NULL == output);
171 ASSERT_TRUE(TDM_ERROR_NONE == error);
172 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, &maker, &model, &name));
173 ASSERT_FALSE(NULL == maker);
174 ASSERT_FALSE(NULL == model);
175 ASSERT_FALSE(NULL == name);
179 TEST_F(TDMOutput, OutputGetModelInfoFailAllNull)
181 SKIP_FLAG(has_output);
182 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_model_info(NULL, NULL, NULL, NULL));
185 TEST_F(TDMOutput, OutputGetModelInfoSuccessfulOnlyOutput)
187 SKIP_FLAG(has_output);
188 for (int i = 0; i < output_count; i++) {
189 tdm_error error = TDM_ERROR_NONE;
190 tdm_output * output = tdm_display_get_output(dpy, i, &error);
191 ASSERT_FALSE(NULL == output);
192 ASSERT_TRUE(TDM_ERROR_NONE == error);
193 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, NULL, NULL, NULL));
197 TEST_F(TDMOutput, OutputGetConnStatusSuccessful)
199 SKIP_FLAG(has_output);
200 for (int i = 0; i < output_count; i++) {
201 tdm_error error = TDM_ERROR_NONE;
202 tdm_output_conn_status status = -42;
203 tdm_output * output = tdm_display_get_output(dpy, i, &error);
204 ASSERT_FALSE(NULL == output);
205 ASSERT_TRUE(TDM_ERROR_NONE == error);
206 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
207 ASSERT_FALSE(-42 == status);
211 TEST_F(TDMOutput, OutputGetConnStatusFailAllNull)
213 SKIP_FLAG(has_output);
214 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(NULL, NULL));
217 TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput)
219 SKIP_FLAG(has_output);
220 for (int i = 0; i < output_count; i++) {
221 tdm_error error = TDM_ERROR_NONE;
222 tdm_output * output = tdm_display_get_output(dpy, i, &error);
223 ASSERT_FALSE(NULL == output);
224 ASSERT_TRUE(TDM_ERROR_NONE == error);
225 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, NULL));
229 TEST_F(TDMOutput, OutputSetDPMSSuccessful)
231 SKIP_FLAG(has_output);
232 for (int i = 0; i < output_count; i++) {
233 tdm_error error = TDM_ERROR_NONE;
234 tdm_output * output = tdm_display_get_output(dpy, i, &error);
235 ASSERT_FALSE(NULL == output);
236 ASSERT_TRUE(TDM_ERROR_NONE == error);
237 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
238 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY));
239 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND));
240 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
244 TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful)
246 SKIP_FLAG(has_output);
247 for (int i = 0; i < output_count; i++) {
248 tdm_error error = TDM_ERROR_NONE;
249 tdm_output * output = tdm_display_get_output(dpy, i, &error);
250 ASSERT_FALSE(NULL == output);
251 ASSERT_TRUE(TDM_ERROR_NONE == error);
252 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
253 tdm_output_change_handler_test_func,
255 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
256 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
257 ASSERT_GT(handle_call, 0);
261 TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
263 SKIP_FLAG(has_output);
264 for (int i = 0; i < output_count; i++) {
265 tdm_error error = TDM_ERROR_NONE;
266 tdm_output * output = tdm_display_get_output(dpy, i, &error);
267 ASSERT_FALSE(NULL == output);
268 ASSERT_TRUE(TDM_ERROR_NONE == error);
269 for (int k = 0; k < 20; k++) {
270 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
271 tdm_output_change_handler_test_func,
274 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
275 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
276 ASSERT_GT(handle_call, 20);
281 TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull)
283 SKIP_FLAG(has_output);
284 ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL));
287 TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
289 SKIP_FLAG(has_output);
290 for (int i = 0; i < output_count; i++) {
291 tdm_error error = TDM_ERROR_NONE;
292 tdm_output * output = tdm_display_get_output(dpy, i, &error);
293 ASSERT_FALSE(NULL == output);
294 ASSERT_TRUE(TDM_ERROR_NONE == error);
295 ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, NULL, NULL));
299 TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput)
301 SKIP_FLAG(has_output);
302 ASSERT_EXIT({tdm_output *output = 0xBEAF;
303 tdm_output_add_change_handler(output,
304 tdm_output_change_handler_test_func,
306 exit(0);}, ::testing::ExitedWithCode(0), "");
309 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
311 for (int i = 0; i < output_count; i++) {
312 tdm_error error = TDM_ERROR_NONE;
313 tdm_output * output = tdm_display_get_output(dpy, i, &error);
314 ASSERT_FALSE(NULL == output);
315 ASSERT_TRUE(TDM_ERROR_NONE == error);
316 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
317 tdm_output_change_handler_test_func,
319 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
320 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
321 ASSERT_GT(handle_call, 0);
323 tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, -101);
324 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
325 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
326 ASSERT_EQ(handle_call, 0);
330 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs)
332 for (int i = 0; i < output_count; i++) {
333 tdm_error error = TDM_ERROR_NONE;
334 tdm_output * output = tdm_display_get_output(dpy, i, &error);
335 ASSERT_FALSE(NULL == output);
336 ASSERT_TRUE(TDM_ERROR_NONE == error);
337 for (int k = 0; k < 20; k++) {
338 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
339 tdm_output_change_handler_test_func,
342 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
343 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
344 ASSERT_GT(handle_call, 20);
346 for (int k = 0; k < 20; k++) {
347 tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (-101-k));
349 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
350 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
351 ASSERT_EQ(handle_call, 0);