a5dd08e5d585dc49cab2bbcf7eff56d2f374df03
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_backend_display.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
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:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
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.
28  *
29 **************************************************************************/
30
31 #include "ut_tdm.h"
32
33 /* LCOV_EXCL_START */
34
35 #define TDM_UT_BACKEND_TEST_CNT   20
36
37 TDMBackendBasic::TDMBackendBasic()
38 {
39         dpy = NULL;
40         outputs = NULL;
41         output_count = 0;
42         layers = NULL;
43         layer_count = 0;
44
45         for (int b = 0; b < 3; b++)
46                 buffers[b] = NULL;
47 }
48
49 void TDMBackendBasic::SetUp(void)
50 {
51         tdm_error ret;
52
53         TDMBackendEnv::SetUp();
54
55         dpy = tdm_display_init(&ret);
56         ASSERT_EQ(ret, TDM_ERROR_NONE);
57         ASSERT_NE(dpy, NULL);
58
59         ASSERT_EQ(tdm_display_get_output_count(dpy, &output_count), TDM_ERROR_NONE);
60         ASSERT_GE(output_count, 0);
61
62         if (output_count > 0) {
63                 outputs = (tdm_output**)calloc(output_count, sizeof(tdm_output*));
64                 ASSERT_NE(outputs, NULL);
65
66                 for (int o = 0; o < output_count; o++) {
67                         tdm_error ret;
68                         tdm_output *output = tdm_display_get_output(dpy, o, &ret);
69                         ASSERT_EQ(ret, TDM_ERROR_NONE);
70                         ASSERT_NE(output, NULL);
71                         outputs[o] = output;
72                 }
73         }
74
75         for (int o = 0; o < output_count; o++) {
76                 int old_layer_count = layer_count, count = TDM_UT_INVALID_VALUE;
77                 tdm_error ret;
78
79                 if (ut_tdm_output_is_hwc_enable(outputs[o]))
80                         continue;
81
82                 ASSERT_EQ(tdm_output_get_layer_count(outputs[o], &count), TDM_ERROR_NONE);
83                 ASSERT_GT(count, 0);
84
85                 layer_count += count;
86                 layers = (tdm_layer**)realloc(layers, layer_count * sizeof(tdm_layer*));
87                 ASSERT_NE(layers, NULL);
88
89                 for (int l = 0; l < count; l++) {
90                         tdm_layer *layer = tdm_output_get_layer(outputs[o], l, &ret);
91                         ASSERT_NE(layer, NULL);
92                         ASSERT_EQ(ret, TDM_ERROR_NONE);
93                         layers[old_layer_count + l] = layer;
94                 }
95         }
96 }
97
98 void TDMBackendBasic::TearDown(void)
99 {
100         tdm_display_deinit(dpy);
101         dpy = NULL;
102
103         free(outputs);
104         outputs = NULL;
105         output_count = 0;
106
107         free(layers);
108         layers = NULL;
109         layer_count = 0;
110
111         DestroyBuffers();
112
113         ASSERT_EQ(tbm_bufmgr_debug_get_ref_count(), 0);
114
115         TDMBackendEnv::TearDown();
116 }
117
118 void TDMBackendBasic::DestroyBuffers(void)
119 {
120         for (int b = 0; b < 3; b++) {
121                 if (buffers[b])
122                         tbm_surface_destroy(buffers[b]);
123                 buffers[b] = NULL;
124         }
125 }
126
127 char
128 ut_tdm_backend_getchar(void)
129 {
130         int c = getchar();
131         int ch = c;
132
133         if (ch == '\n' || ch == '\r')
134                 ch = 'y';
135         else if (ch < 'a')
136                 ch += ('a' - 'A');
137
138         while (c != '\n' && c != EOF)
139                 c = getchar();
140
141         return ch;
142 }
143
144 TEST_P(TDMBackendBasic, VerifyOutputObject)
145 {
146         tdm_error ret;
147         int output_count = 0;
148
149         ASSERT_EQ(tdm_display_get_output_count(dpy, &output_count), TDM_ERROR_NONE);
150         TDM_UT_ASSERT_TRUE(output_count > 0, "output count(%d) should be greater than 0. Check display_get_outputs().");
151
152         for (int o = 0; o < output_count; o++) {
153                 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
154                 ASSERT_EQ(ret, TDM_ERROR_NONE);
155                 TDM_UT_ASSERT_TRUE(output != NULL, "no output. (output: %d). Check display_get_outputs().", o);
156         }
157 }
158
159 TEST_P(TDMBackendBasic, VerifyLayerObject)
160 {
161         tdm_error ret;
162         int output_count = 0;
163
164         ASSERT_EQ(tdm_display_get_output_count(dpy, &output_count), TDM_ERROR_NONE);
165
166         for (int o = 0; o < output_count; o++) {
167                 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
168                 ASSERT_EQ(ret, TDM_ERROR_NONE);
169
170                 int layer_count = 0;
171                 ASSERT_EQ(tdm_output_get_layer_count(output, &layer_count), TDM_ERROR_NONE);
172                 TDM_UT_ASSERT_TRUE(layer_count > 0,
173                                                    "layer count(%d) should be greater than 0. (output: %d). Check output_get_layers().",
174                                                    layer_count, o);
175
176                 for (int l = 0; l < layer_count; l++) {
177                         tdm_layer *layer = tdm_output_get_layer(output, l, &ret);
178                         TDM_UT_ASSERT_TRUE(layer != NULL, "no layer. (output: %d, layer: %d). Check output_get_layers().", o, l);
179                 }
180         }
181 }
182
183 TEST_P(TDMBackendBasic, VerifyOutputGetProperty)
184 {
185         tdm_error ret;
186         int output_count = 0;
187
188         ASSERT_EQ(tdm_display_get_output_count(dpy, &output_count), TDM_ERROR_NONE);
189
190         for (int o = 0; o < output_count; o++) {
191                 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
192                 ASSERT_EQ(ret, TDM_ERROR_NONE);
193
194                 const tdm_prop *props = NULL;
195                 int prop_count = 0;
196                 ASSERT_EQ(tdm_output_get_available_properties(output, &props, &prop_count), TDM_ERROR_NONE);
197
198                 if (prop_count > 0)
199                         TDM_UT_ASSERT_TRUE(props != NULL, "no props. (output: %d). Check output_get_capability(), tdm_caps_output.", o);
200
201                 for (int p = 0; p < prop_count; p++) {
202                         tdm_value value;
203                         value.s32 = TDM_UT_INVALID_VALUE;
204                         ASSERT_EQ(tdm_output_get_property(output, props[p].id, &value), TDM_ERROR_NONE);
205                         TDM_UT_ASSERT_TRUE(value.s32 != TDM_UT_INVALID_VALUE,
206                                                            "Getting a prop failed. (output: %d, prop_id: %d). Check output_get_property().",
207                                                            o, props[p].id);
208                 }
209         }
210 }
211
212 TEST_P(TDMBackendBasic, VerifyLayerGetProperty)
213 {
214         tdm_error ret;
215         int output_count = 0;
216
217         ASSERT_EQ(tdm_display_get_output_count(dpy, &output_count), TDM_ERROR_NONE);
218
219         for (int o = 0; o < output_count; o++) {
220                 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
221                 ASSERT_EQ(ret, TDM_ERROR_NONE);
222
223                 int layer_count = 0;
224                 ASSERT_EQ(tdm_output_get_layer_count(output, &layer_count), TDM_ERROR_NONE);
225
226                 for (int l = 0; l < layer_count; l++) {
227                         tdm_layer *layer = tdm_output_get_layer(output, l, &ret);
228                         ASSERT_EQ(ret, TDM_ERROR_NONE);
229
230                         const tdm_prop *props = NULL;
231                         int prop_count = 0;
232                         ASSERT_EQ(tdm_layer_get_available_properties(layer, &props, &prop_count), TDM_ERROR_NONE);
233
234                         if (prop_count > 0)
235                                 TDM_UT_ASSERT_TRUE(props != NULL, "no props. (output: %d, layer: %d). Check output_get_capability(), tdm_caps_output.", o, l);
236
237                         for (int p = 0; p < prop_count; p++) {
238                                 tdm_value value;
239                                 value.s32 = TDM_UT_INVALID_VALUE;
240                                 ASSERT_EQ(tdm_layer_get_property(layer, props[p].id, &value), TDM_ERROR_NONE);
241                                 TDM_UT_ASSERT_TRUE(value.s32 != TDM_UT_INVALID_VALUE,
242                                                                    "Getting a prop failed. (output: %d, layer: %d, prop_id: %d). Check output_get_property().",
243                                                                    o, l, props[p].id);
244                         }
245                 }
246         }
247 }
248
249 TEST_P(TDMBackendBasic, VerifyOutputSetMode)
250 {
251         for (int o = 0; o < output_count; o++) {
252                 const tdm_output_mode *got_mode = NULL;
253                 const tdm_output_mode *modes = (const tdm_output_mode *)TDM_UT_INVALID_VALUE;
254                 const tdm_output_mode *set_mode = NULL;
255                 const tdm_output_mode *best = NULL;
256                 int count = TDM_UT_INVALID_VALUE;
257
258                 if (!ut_tdm_output_is_connected(outputs[o]))
259                         continue;
260
261                 ASSERT_EQ(tdm_output_get_available_modes(outputs[o], &modes, &count), TDM_ERROR_NONE);
262                 TDM_UT_ASSERT_TRUE(count > 0, "mode's count should be greater than 0. Check output_get_capability(), tdm_caps_output.");
263                 TDM_UT_ASSERT_TRUE(modes != NULL, "mode's count should be greater than 0. Check output_get_capability(), tdm_caps_output.");
264
265                 for (int i = 0; i < count; i++) {
266                         if (!best)
267                                 best = &modes[i];
268                         if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
269                                 set_mode = &modes[i];
270                 }
271                 if (!set_mode && best)
272                         set_mode = best;
273                 ASSERT_NE(set_mode, NULL);
274
275                 ASSERT_EQ(tdm_output_set_mode(outputs[o], set_mode), TDM_ERROR_NONE);
276                 ASSERT_EQ(tdm_output_get_mode(outputs[o], &got_mode), TDM_ERROR_NONE);
277                 TDM_UT_ASSERT_TRUE(set_mode == got_mode, "The mode which is set and got are different. Check output_set_mode(), output_get_mode()");
278         }
279 }
280
281 TEST_P(TDMBackendBasic, VerifyOutputSetDpms)
282 {
283         for (int o = 0; o < output_count; o++) {
284                 const tdm_output_mode *got_mode = NULL;
285                 const tdm_output_mode *modes = (const tdm_output_mode *)TDM_UT_INVALID_VALUE;
286                 const tdm_output_mode *set_mode = NULL;
287                 const tdm_output_mode *best = NULL;
288                 int count = TDM_UT_INVALID_VALUE;
289                 tdm_output_dpms got_dpms = TDM_OUTPUT_DPMS_OFF;
290                 tdm_output_dpms set_dpms = TDM_OUTPUT_DPMS_ON;
291
292                 if (!ut_tdm_output_is_connected(outputs[o]))
293                         continue;
294
295                 ASSERT_EQ(tdm_output_get_available_modes(outputs[o], &modes, &count), TDM_ERROR_NONE);
296                 ASSERT_GT(count, 0);
297                 ASSERT_NE(modes, NULL);
298
299                 for (int i = 0; i < count; i++) {
300                         if (!best)
301                                 best = &modes[i];
302                         if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
303                                 set_mode = &modes[i];
304                 }
305                 if (!set_mode && best)
306                         set_mode = best;
307
308                 ASSERT_NE(set_mode, NULL);
309                 ASSERT_EQ(tdm_output_set_mode(outputs[o], set_mode), TDM_ERROR_NONE);
310                 ASSERT_EQ(tdm_output_get_mode(outputs[o], &got_mode), TDM_ERROR_NONE);
311                 ASSERT_EQ(set_mode, got_mode);
312
313                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], set_dpms), TDM_ERROR_NONE);
314                 ASSERT_EQ(tdm_output_get_dpms(outputs[o], &got_dpms), TDM_ERROR_NONE);
315                 TDM_UT_ASSERT_TRUE(set_dpms == got_dpms, "The dpms value which is set and got are different. Check output_set_dpms(), output_get_dpms()");
316         }
317 }
318
319 TEST_P(TDMBackendBasic, VerifyPrimaryLayerShowOneFrame)
320 {
321         for (int o = 0; o < output_count; o++) {
322                 tdm_layer *layer;
323
324                 if (!ut_tdm_output_is_connected(outputs[o]))
325                         continue;
326
327                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
328                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
329
330                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
331                 ASSERT_NE(layer, NULL);
332
333 retry:
334                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, true), true);
335                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
336                 DestroyBuffers();
337
338                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
339
340                 TDM_UT_ASK_YNR("* Successed to display a frame to a primary layer? (output: %d)", o);
341
342                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
343                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
344
345         }
346 }
347
348 TEST_P(TDMBackendBasic, VerifyPrimaryLayerShowManyFrames)
349 {
350         for (int o = 0; o < output_count; o++) {
351                 tdm_layer *layer;
352                 int next_buffer = 0;
353
354                 if (!ut_tdm_output_is_connected(outputs[o]))
355                         continue;
356
357                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
358                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
359
360                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
361                 ASSERT_NE(layer, NULL);
362
363 retry:
364                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 3, true), true);
365
366                 /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
367                 for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
368                         ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[next_buffer]), true);
369                         ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
370                         usleep(40000); /* 40 ms */
371                         next_buffer++;
372                         if (next_buffer == 3)
373                                 next_buffer = 0;
374                 }
375
376                 DestroyBuffers();
377
378                 TDM_UT_ASK_YNR("* Successed to display many frames to a primary layer? (output: %d)", o);
379
380                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
381                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
382         }
383 }
384
385 static void
386 _ut_tdm_backend_output_commit_cb(tdm_output *output, unsigned int sequence,
387                                                                  unsigned int tv_sec, unsigned int tv_usec,
388                                                                  void *user_data)
389 {
390         bool *done = (bool*)user_data;
391         if (done)
392                 *done = true;
393 }
394
395 TEST_P(TDMBackendBasic, VerifyPrimaryLayerShowOneFrameWithCommitHandler)
396 {
397         for (int o = 0; o < output_count; o++) {
398                 tdm_layer *layer;
399
400                 if (!ut_tdm_output_is_connected(outputs[o]))
401                         continue;
402
403                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
404                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
405
406                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
407                 ASSERT_NE(layer, NULL);
408
409 retry:
410                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, true), true);
411                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
412                 DestroyBuffers();
413
414                 bool done = false;
415                 TDM_UT_ASSERT_TRUE(tdm_output_commit(outputs[o], 0, _ut_tdm_backend_output_commit_cb, &done) == TDM_ERROR_NONE,
416                                                    "Check output_commit(), output_set_commit_handler()");
417                 while (!done)
418                         TDM_UT_ASSERT_TRUE(ut_tdm_display_handle_events(dpy) == TDM_ERROR_NONE,
419                                                            "Check display_get_fd(), display_handle_events()");
420
421                 TDM_UT_ASK_YNR("* Successed to display a frame to a primary layer? (output: %d)", o);
422
423                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
424                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
425         }
426 }
427
428 TEST_P(TDMBackendBasic, VerifyOverlayLayersShowOneFrame)
429 {
430         for (int o = 0; o < output_count; o++) {
431                 tdm_layer *layer;
432
433                 if (!ut_tdm_output_is_connected(outputs[o]))
434                         continue;
435
436                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
437                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
438
439                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
440                 ASSERT_NE(layer, NULL);
441
442                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, false), true);
443                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
444                 DestroyBuffers();
445
446                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
447                 usleep(40000); /* 40 ms */
448
449 retry:
450                 for (int l = 0; l < layer_count; l++) {
451                         tdm_error ret;
452
453                         if (tdm_layer_get_output(layers[l], &ret) != outputs[o])
454                                 continue;
455                         ASSERT_EQ(ret, TDM_ERROR_NONE);
456                         if (ut_tdm_layer_is_primary_layer(layers[l]))
457                                 continue;
458                         if (ut_tdm_layer_is_cursor_layer(layers[l]))
459                                 continue;
460                         ASSERT_EQ(ut_tdm_layer_prepare_buffer(layers[l], buffers, 1, true), true);
461                         ASSERT_EQ(ut_tdm_layer_set_buffer(layers[l], buffers[0]), true);
462                         DestroyBuffers();
463                 }
464
465                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
466
467                 TDM_UT_ASK_YNR("* Successed to display frames to all overlay layers? (output: %d)", o);
468
469                 for (int l = 0; l < layer_count; l++)
470                         ASSERT_EQ(tdm_layer_unset_buffer(layers[l]), TDM_ERROR_NONE);
471                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
472         }
473 }
474
475 TEST_P(TDMBackendBasic, VerifyOverlayLayersShowManyFrames)
476 {
477         for (int o = 0; o < output_count; o++) {
478                 tdm_layer *layer;
479
480                 if (!ut_tdm_output_is_connected(outputs[o]))
481                         continue;
482
483                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
484                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
485
486                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
487                 ASSERT_NE(layer, NULL);
488
489                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, false), true);
490                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
491                 DestroyBuffers();
492
493                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
494                 usleep(40000); /* 40 ms */
495
496                 for (int l = 0; l < layer_count; l++) {
497                         tdm_error ret;
498                         int next_buffer = 0;
499
500                         if (tdm_layer_get_output(layers[l], &ret) != outputs[o])
501                                 continue;
502                         ASSERT_EQ(ret, TDM_ERROR_NONE);
503                         if (ut_tdm_layer_is_primary_layer(layers[l]))
504                                 continue;
505                         if (ut_tdm_layer_is_cursor_layer(layers[l]))
506                                 continue;
507
508 retry:
509                         ASSERT_EQ(ut_tdm_layer_prepare_buffer(layers[l], buffers, 3, true), true);
510
511                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
512                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
513                                 ASSERT_EQ(ut_tdm_layer_set_buffer(layers[l], buffers[next_buffer]), true);
514                                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
515                                 usleep(40000); /* 40 ms */
516                                 next_buffer++;
517                                 if (next_buffer == 3)
518                                         next_buffer = 0;
519                         }
520
521                         DestroyBuffers();
522
523                         TDM_UT_ASK_YNR("* Successed to display many frames to a layer? (output: %d, layer: %d)", o, l);
524
525                         ASSERT_EQ(tdm_layer_unset_buffer(layers[l]), TDM_ERROR_NONE);
526                         ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
527                         usleep(40000); /* 40 ms */
528                 }
529         }
530 }
531
532 TEST_P(TDMBackendBasic, DISABLED_VerifyCursorLayer)
533 {
534 }
535
536 static void
537 _ut_tdm_backend_output_done_cb(tdm_output *output, unsigned int sequence,
538                                                            unsigned int tv_sec, unsigned int tv_usec,
539                                                            void *user_data)
540 {
541         bool *done = (bool*)user_data;
542         if (done)
543                 *done = true;
544 }
545
546 TEST_P(TDMBackendBasic, VerifyOutputWaitVblank)
547 {
548         for (int o = 0; o < output_count; o++) {
549                 tdm_layer *layer;
550
551                 if (!ut_tdm_output_is_connected(outputs[o]))
552                         continue;
553
554                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
555                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
556
557                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
558                 ASSERT_NE(layer, NULL);
559
560                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, true), true);
561                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
562                 DestroyBuffers();
563
564                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
565
566                 /* start from 1 */
567                 for (int t = 1; t < 10; t++) {
568                         double start, end, interval;
569                         bool done;
570
571                         interval = ut_tdm_output_get_vblank_interval_time(outputs[o]);
572
573                         done = false;
574                         start = tdm_helper_get_time();
575                         TDM_UT_ASSERT_TRUE(tdm_output_wait_vblank(outputs[o], t, 0, _ut_tdm_backend_output_done_cb, &done) == TDM_ERROR_NONE,
576                                                            "Check output_wait_vblank(), output_set_vblank_handler()");
577                         while (!done)
578                                 TDM_UT_ASSERT_TRUE(ut_tdm_display_handle_events(dpy) == TDM_ERROR_NONE,
579                                                                    "Check display_get_fd(), display_handle_events()");
580                         end = tdm_helper_get_time();
581
582                         /* "+ interval" consider the delay of socket communication between kernel and platform */
583                         TDM_UT_ASSERT_TRUE((end - start) > (interval * (t - 1)),
584                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
585                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
586                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
587                         TDM_UT_ASSERT_TRUE((end - start) < (interval * t + interval),
588                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
589                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
590                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
591
592                 }
593         }
594 }
595
596 TEST_P(TDMBackendBasic, VerifyOutputWaitVblankInterval)
597 {
598         for (int o = 0; o < output_count; o++) {
599                 tdm_layer *layer;
600
601                 if (!ut_tdm_output_is_connected(outputs[o]))
602                         continue;
603
604                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
605                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
606
607                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
608                 ASSERT_NE(layer, NULL);
609
610                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, true), true);
611                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
612                 DestroyBuffers();
613
614                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
615
616                 /* start from 1 */
617                 for (int t = 1; t < 10; t++) {
618                         double start, end, interval;
619                         bool done;
620
621                         interval = ut_tdm_output_get_vblank_interval_time(outputs[o]);
622
623                         done = false;
624                         start = tdm_helper_get_time();
625                         ASSERT_EQ(tdm_output_wait_vblank(outputs[o], t, 0, _ut_tdm_backend_output_done_cb, &done), TDM_ERROR_NONE);
626                         while (!done)
627                                 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
628                         end = tdm_helper_get_time();
629
630                         /* "+ interval" consider the delay of socket communication between kernel and platform */
631                         TDM_UT_ASSERT_TRUE((end - start) > (interval * (t - 1)),
632                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
633                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
634                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
635                         TDM_UT_ASSERT_TRUE((end - start) < (interval * t + interval),
636                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
637                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
638                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
639                 }
640         }
641 }
642
643 TEST_P(TDMBackendBasic, VerifyOutputWaitVblankFewTimesInOneVblank)
644 {
645         for (int o = 0; o < output_count; o++) {
646                 tdm_layer *layer;
647
648                 if (!ut_tdm_output_is_connected(outputs[o]))
649                         continue;
650
651                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
652                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
653
654                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
655                 ASSERT_NE(layer, NULL);
656
657                 ASSERT_EQ(ut_tdm_layer_prepare_buffer(layer, buffers, 1, true), true);
658                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[0]), true);
659                 DestroyBuffers();
660
661                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
662
663                 /* start from 1 */
664                 for (int t = 1; t < 10; t++) {
665                         double start, end, interval;
666                         bool done1, done2, done3;
667
668                         interval = ut_tdm_output_get_vblank_interval_time(outputs[o]);
669
670                         done1 = done2 = done3 = false;
671                         ASSERT_EQ(tdm_output_wait_vblank(outputs[o], t, 0, _ut_tdm_backend_output_done_cb, &done1), TDM_ERROR_NONE);
672                         ASSERT_EQ(tdm_output_wait_vblank(outputs[o], t, 0, _ut_tdm_backend_output_done_cb, &done2), TDM_ERROR_NONE);
673                         ASSERT_EQ(tdm_output_wait_vblank(outputs[o], t, 0, _ut_tdm_backend_output_done_cb, &done3), TDM_ERROR_NONE);
674                         start = tdm_helper_get_time();
675                         while (!done1 || !done2 || !done3)
676                                 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
677                         end = tdm_helper_get_time();
678
679                         /* "+ interval" consider the delay of socket communication between kernel and platform */
680                         TDM_UT_ASSERT_TRUE((end - start) > (interval * (t - 1)),
681                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
682                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
683                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
684                         TDM_UT_ASSERT_TRUE((end - start) < (interval * t + interval),
685                                                            "The vblank event should happen after %d vsync intervals(%d ms).\n"
686                                                            "\t But it happened at %d ms. Check output_wait_vblank(), output_set_vblank_handler()",
687                                                            t, (int)(t * interval * 1000), (int)((end - start) * 1000));
688                 }
689         }
690 }
691
692 TEST_P(TDMBackendBasic, VerifyPPObject)
693 {
694         tdm_error ret;
695         tdm_pp *pp;
696
697         if (!ut_tdm_display_has_pp_capability(dpy)) {
698                 TDM_UT_INFO("PP not supported");
699                 return;
700         }
701
702         pp = tdm_display_create_pp(dpy, &ret);
703         TDM_UT_ASSERT_TRUE(ret == TDM_ERROR_NONE, "can't create a PP object. Check display_create_pp()");
704         TDM_UT_ASSERT_TRUE(pp != NULL, "can't create a PP object. Check display_create_pp()");
705
706         tdm_pp_destroy(pp);
707 }
708
709 TEST_P(TDMBackendBasic, VerifyPPCapabilities)
710 {
711         tdm_pp_capability capabilities = (tdm_pp_capability)0;
712
713         if (!ut_tdm_display_has_pp_capability(dpy)) {
714                 TDM_UT_INFO("PP not supported");
715                 return;
716         }
717
718         TDM_UT_ASSERT_TRUE(tdm_display_get_pp_capabilities(dpy, &capabilities) == TDM_ERROR_NONE,
719                                            "Check display_get_pp_capability(), tdm_caps_pp, tdm_pp_capability.");
720         TDM_UT_ASSERT_TRUE(capabilities != (tdm_pp_capability)0,
721                                            "PP has no capability. Check display_get_pp_capability(), tdm_caps_pp, tdm_pp_capability.");
722 }
723
724 TEST_P(TDMBackendBasic, VerifyPPAvaiableSize)
725 {
726         if (!ut_tdm_display_has_pp_capability(dpy)) {
727                 TDM_UT_INFO("PP not supported");
728                 return;
729         }
730
731         int min_w = 0;
732         int min_h = 0;
733         int max_w = 0;
734         int max_h = 0;
735         int preferred_align = 0;
736         ASSERT_EQ(tdm_display_get_pp_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
737         ASSERT_NE(min_w, 0);
738         ASSERT_NE(min_h, 0);
739         ASSERT_NE(max_w, 0);
740         ASSERT_NE(max_h, 0);
741         ASSERT_NE(preferred_align, 0);
742 }
743
744 TEST_P(TDMBackendBasic, VerifyPPAvaiableFormats)
745 {
746         if (!ut_tdm_display_has_pp_capability(dpy)) {
747                 TDM_UT_INFO("PP not supported");
748                 return;
749         }
750
751         const tbm_format *formats = NULL;
752         int format_count = 0;
753         TDM_UT_ASSERT_TRUE(tdm_display_get_pp_available_formats(dpy, &formats, &format_count) == TDM_ERROR_NONE,
754                                            "Check display_get_pp_capability(), tdm_caps_pp");
755         TDM_UT_ASSERT_TRUE(formats != NULL, "Should have a format table. Check display_get_pp_capability(), tdm_caps_pp.");
756         TDM_UT_ASSERT_TRUE(format_count > 0, "Format count should be greater than 0. Check display_get_pp_capability(), tdm_caps_pp.");
757 }
758
759 TEST_P(TDMBackendBasic, VerifyCaptureObject)
760 {
761         if (!ut_tdm_display_has_capture_capability(dpy)) {
762                 TDM_UT_INFO("Capture not supported.");
763                 return;
764         }
765
766         for (int o = 0; o < output_count; o++) {
767                 tdm_capture *capture;
768                 tdm_error ret;
769
770                 unsigned int has_capability = 0;
771                 ASSERT_EQ(tdm_output_has_capture_capability(outputs[o], &has_capability), TDM_ERROR_NONE);
772                 if (!has_capability) {
773                         TDM_UT_INFO("Capture not supported. (output: %d)", o);
774                         continue;
775                 }
776
777                 if (!ut_tdm_output_is_connected(outputs[o]))
778                         continue;
779
780                 capture = tdm_output_create_capture(outputs[o], &ret);
781                 TDM_UT_ASSERT_TRUE(ret == TDM_ERROR_NONE, "Can't create a capture object. Check output_create_capture().");
782                 TDM_UT_ASSERT_TRUE(capture != NULL, "Can't create a capture object. Check output_create_capture().");
783
784                 tdm_capture_destroy(capture);
785         }
786 }
787
788 TEST_P(TDMBackendBasic, VerifyCaptureAvaiableSize)
789 {
790         if (!ut_tdm_display_has_capture_capability(dpy)) {
791                 TDM_UT_INFO("Capture not supported.");
792                 return;
793         }
794
795         int min_w = 0;
796         int min_h = 0;
797         int max_w = 0;
798         int max_h = 0;
799         int preferred_align = 0;
800         ASSERT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
801         ASSERT_NE(min_w, 0);
802         ASSERT_NE(min_h, 0);
803         ASSERT_NE(max_w, 0);
804         ASSERT_NE(max_h, 0);
805         ASSERT_NE(preferred_align, 0);
806 }
807
808 TEST_P(TDMBackendBasic, VerifyCaptureAvaiableFormats)
809 {
810         if (!ut_tdm_display_has_capture_capability(dpy)) {
811                 TDM_UT_INFO("Capture not supported.");
812                 return;
813         }
814
815         const tbm_format *formats = NULL;
816         int format_count = 0;
817         TDM_UT_ASSERT_TRUE(tdm_display_get_capture_available_formats(dpy, &formats, &format_count) == TDM_ERROR_NONE,
818                                            "Check display_get_capture_capability(), tdm_caps_capture.");
819         TDM_UT_ASSERT_TRUE(formats != NULL, "Should have a format table. Check display_get_capture_capability(), tdm_caps_capture.");
820         TDM_UT_ASSERT_TRUE(format_count > 0, "The format count should be greater than 0. Check display_get_capture_capability(), tdm_caps_capture.");
821 }
822
823 #ifdef TDM_UT_TEST_WITH_PARAMS
824 INSTANTIATE_TEST_CASE_P(TDMBackendBasicParams,
825                                                 TDMBackendBasic,
826                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
827 #else
828 INSTANTIATE_TEST_CASE_P(TDMBackendBasicParams,
829                                                 TDMBackendBasic,
830                                                 Values(TDM_DEFAULT_MODULE));
831 #endif
832
833 TEST_P(TDMBackendDisplay, VerifyPirmaryLayerFormat)
834 {
835         for (int o = 0; o < output_count; o++) {
836                 tdm_layer *layer;
837                 int next_buffer = 0;
838                 bool done = false;
839                 tdm_error ret;
840                 const tbm_format *formats;
841                 int format_count = 0;
842                 const tdm_output_mode *mode = NULL;
843                 unsigned int flags = 0;
844
845                 if (!ut_tdm_output_is_connected(outputs[o]))
846                         continue;
847
848                 layer = ut_tdm_output_get_primary_layer(outputs[o]);
849                 ASSERT_NE(layer, NULL);
850
851                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
852                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
853
854                 for (int f = 0; f < format_count; f++) {
855                         ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
856                         ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
857                         ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
858                         ASSERT_NE(mode, NULL);
859
860 retry:
861                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
862                         ASSERT_EQ(ut_tdm_buffer_create(mode->hdisplay, mode->vdisplay, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
863
864                         /* set buffer & commit for 60 times */
865                         for (int t = 0; t < 60; t++) {
866                                 tbm_surface_h displaying_buffer;
867                                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[next_buffer]), true);
868                                 done = false;
869                                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
870                                 while (!done)
871                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
872                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
873                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
874                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
875                                 next_buffer++;
876                                 if (next_buffer == 3)
877                                         next_buffer = 0;
878                         }
879
880                         DestroyBuffers();
881
882                         TDM_UT_ASK_YNR("* Successed to display '%c%c%c%c' frames to a primary layer? (output: %d)", FOURCC_STR(formats[f]), o);
883                 }
884         }
885 }
886
887 TEST_P(TDMBackendDisplay, VerifyOverlayLayerFormat)
888 {
889         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, false), true);
890
891         for (int l = 0; l < layer_count; l++) {
892                 tdm_error ret;
893                 tdm_output *output;
894                 tdm_layer *layer;
895                 int next_buffer = 0;
896                 bool done = false;
897                 const tbm_format *formats;
898                 int format_count = 0;
899                 const tdm_output_mode *mode = NULL;
900                 unsigned int flags = 0;
901                 unsigned int pipe = 0;
902
903                 layer = layers[l];
904
905                 output = tdm_layer_get_output(layer, &ret);
906                 ASSERT_EQ(ret, TDM_ERROR_NONE);
907
908                 if (!ut_tdm_output_is_connected(output))
909                         continue;
910                 if (ut_tdm_layer_is_primary_layer(layer))
911                         continue;
912                 if (ut_tdm_layer_is_cursor_layer(layer))
913                         continue;
914
915                 ASSERT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
916
917                 TDM_UT_INFO("* testing for (output: %d, layer: %d)", pipe, l);
918
919                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
920                 ASSERT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
921                 ASSERT_NE(mode, NULL);
922
923                 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
924
925                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
926
927                 for (int f = 0; f < format_count; f++) {
928 retry:
929                         TDM_UT_INFO("** testing for %c%c%c%c", FOURCC_STR(formats[f]));
930                         ASSERT_EQ(ut_tdm_buffer_create(mode->hdisplay, mode->vdisplay, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
931
932                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
933                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
934                                 tbm_surface_h displaying_buffer;
935                                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[next_buffer]), true);
936                                 done = false;
937                                 ASSERT_EQ(tdm_output_commit(output, 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
938                                 while (!done)
939                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
940                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
941                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
942                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
943                                 next_buffer++;
944                                 if (next_buffer == 3)
945                                         next_buffer = 0;
946                         }
947
948                         TDM_UT_ASK_YNR("* Successed to display '%c%c%c%c' frames to a layer? (output: %d, layer: %d)", FOURCC_STR(formats[f]), pipe, l);
949
950                         DestroyBuffers();
951                 }
952
953                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
954         }
955 }
956
957 TEST_P(TDMBackendDisplay, VerifyOverlayLayerSize)
958 {
959         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, false), true);
960
961         for (int l = 0; l < layer_count; l++) {
962                 tdm_error ret;
963                 tdm_output *output;
964                 tdm_layer *layer;
965                 int next_buffer = 0;
966                 bool done = false;
967                 const tbm_format *formats;
968                 int format_count = 0;
969                 const tdm_output_mode *mode = NULL;
970                 unsigned int flags = 0;
971                 unsigned int pipe = 0;
972
973                 layer = layers[l];
974
975                 output = tdm_layer_get_output(layer, &ret);
976                 ASSERT_EQ(ret, TDM_ERROR_NONE);
977
978                 if (!ut_tdm_output_is_connected(output))
979                         continue;
980                 if (ut_tdm_layer_is_primary_layer(layer))
981                         continue;
982                 if (ut_tdm_layer_is_cursor_layer(layer))
983                         continue;
984
985                 ASSERT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
986
987                 TDM_UT_INFO("* testing for (output: %d, layer: %d)", pipe, l);
988
989                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
990                 ASSERT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
991                 ASSERT_NE(mode, NULL);
992
993                 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
994
995                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
996
997                 for (int f = 0; f < format_count; f++) {
998                         int diffw = mode->hdisplay / (format_count + 2);
999                         int diffh = mode->vdisplay / (format_count + 2);
1000                         int w = mode->hdisplay - diffw * (f + 1);
1001                         int h = mode->vdisplay - diffh * (f + 1);
1002 retry:
1003                         TDM_UT_INFO("** testing for %c%c%c%c", FOURCC_STR(formats[f]));
1004                         ASSERT_EQ(ut_tdm_buffer_create(w, h, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
1005
1006                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
1007                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
1008                                 tbm_surface_h displaying_buffer;
1009                                 ASSERT_EQ(ut_tdm_layer_set_buffer(layer, buffers[next_buffer]), true);
1010                                 done = false;
1011                                 ASSERT_EQ(tdm_output_commit(output, 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
1012                                 while (!done)
1013                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1014                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
1015                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1016                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
1017                                 next_buffer++;
1018                                 if (next_buffer == 3)
1019                                         next_buffer = 0;
1020                         }
1021
1022                         DestroyBuffers();
1023
1024                         TDM_UT_ASK_YNR("* Successed to display '%c%c%c%c' small size(%dx%d) frames to a layer? (output: %d, layer: %d)",
1025                                                    FOURCC_STR(formats[f]), w, h, pipe, l);
1026                 }
1027
1028                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1029         }
1030 }
1031
1032 TEST_P(TDMBackendDisplay, VerifyOverlayLayerScale)
1033 {
1034         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, false), true);
1035
1036         for (int l = 0; l < layer_count; l++) {
1037                 tdm_error ret;
1038                 tdm_output *output;
1039                 tdm_layer *layer;
1040                 int next_buffer = 0;
1041                 bool done = false;
1042                 const tbm_format *formats;
1043                 int format_count = 0;
1044                 const tdm_output_mode *mode = NULL;
1045                 unsigned int flags = 0;
1046                 unsigned int pipe = 0;
1047
1048                 layer = layers[l];
1049
1050                 output = tdm_layer_get_output(layer, &ret);
1051                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1052
1053                 ASSERT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
1054
1055                 if (!ut_tdm_output_is_connected(output))
1056                         continue;
1057                 if (ut_tdm_layer_is_primary_layer(layer))
1058                         continue;
1059                 if (ut_tdm_layer_is_cursor_layer(layer))
1060                         continue;
1061                 if (!ut_tdm_layer_support_scale(layer)) {
1062                         TDM_UT_INFO("no scale capability. (output: %d, layer: %d)", pipe, l);
1063                         continue;
1064                 }
1065
1066                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
1067                 ASSERT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
1068                 ASSERT_NE(mode, NULL);
1069
1070                 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
1071
1072                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
1073
1074                 for (int f = 0; f < format_count; f++) {
1075 retry:
1076                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
1077                         ASSERT_EQ(ut_tdm_buffer_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
1078
1079                         tdm_info_layer info;
1080                         memset(&info, 0, sizeof info);
1081                         info.src_config.size.h = TDM_UT_BUFFER_SIZE;
1082                         info.src_config.size.v = TDM_UT_BUFFER_SIZE;
1083                         info.src_config.pos.x = 0;
1084                         info.src_config.pos.y = 0;
1085                         info.src_config.pos.w = TDM_UT_BUFFER_SIZE;
1086                         info.src_config.pos.h = TDM_UT_BUFFER_SIZE;
1087                         info.src_config.format = formats[f];
1088                         info.dst_pos.x = 0;
1089                         info.dst_pos.y = 0;
1090                         info.dst_pos.w = mode->hdisplay;
1091                         info.dst_pos.h = mode->vdisplay;
1092                         info.transform = TDM_TRANSFORM_NORMAL;
1093                         ASSERT_EQ(tdm_layer_set_info(layer, &info), TDM_ERROR_NONE);
1094
1095                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
1096                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
1097                                 tbm_surface_h displaying_buffer;
1098                                 ASSERT_EQ(tdm_layer_set_buffer(layer, buffers[next_buffer]), TDM_ERROR_NONE);
1099                                 done = false;
1100                                 ASSERT_EQ(tdm_output_commit(output, 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
1101                                 while (!done)
1102                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1103                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
1104                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1105                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
1106                                 next_buffer++;
1107                                 if (next_buffer == 3)
1108                                         next_buffer = 0;
1109                         }
1110
1111                         DestroyBuffers();
1112
1113                         TDM_UT_ASK_YNR("* Successed to scale '%c%c%c%c' small size(%dx%d) frames to fullsreen? (output: %d, layer: %d)",
1114                                                    FOURCC_STR(formats[f]), TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, pipe, l);
1115                 }
1116
1117                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1118         }
1119 }
1120
1121 TEST_P(TDMBackendDisplay, VerifyOverlayLayerMovePosition)
1122 {
1123         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, false), true);
1124
1125         for (int l = 0; l < layer_count; l++) {
1126                 tdm_error ret;
1127                 tdm_output *output;
1128                 tdm_layer *layer;
1129                 int next_buffer = 0;
1130                 bool done = false;
1131                 const tbm_format *formats;
1132                 int format_count = 0;
1133                 const tdm_output_mode *mode = NULL;
1134                 unsigned int flags = 0;
1135                 unsigned int pipe = 0;
1136
1137                 layer = layers[l];
1138
1139                 output = tdm_layer_get_output(layer, &ret);
1140                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1141
1142                 if (!ut_tdm_output_is_connected(output))
1143                         continue;
1144                 if (ut_tdm_layer_is_primary_layer(layer))
1145                         continue;
1146                 if (ut_tdm_layer_is_cursor_layer(layer))
1147                         continue;
1148
1149                 ASSERT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
1150
1151                 TDM_UT_INFO("* testing for (output: %d, layer: %d)", pipe, l);
1152
1153                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
1154                 ASSERT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
1155                 ASSERT_NE(mode, NULL);
1156
1157                 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
1158
1159                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
1160
1161                 for (int f = 0; f < format_count; f++) {
1162 retry:
1163                         TDM_UT_INFO("** testing for %c%c%c%c", FOURCC_STR(formats[f]));
1164                         ASSERT_EQ(ut_tdm_buffer_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
1165
1166                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
1167                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
1168                                 tbm_surface_h displaying_buffer;
1169
1170                                 tdm_info_layer info;
1171                                 memset(&info, 0, sizeof info);
1172                                 info.src_config.size.h = TDM_UT_BUFFER_SIZE;
1173                                 info.src_config.size.v = TDM_UT_BUFFER_SIZE;
1174                                 info.src_config.pos.x = 0;
1175                                 info.src_config.pos.y = 0;
1176                                 info.src_config.pos.w = TDM_UT_BUFFER_SIZE;
1177                                 info.src_config.pos.h = TDM_UT_BUFFER_SIZE;
1178                                 info.src_config.format = formats[f];
1179                                 info.dst_pos.x = ((mode->hdisplay - TDM_UT_BUFFER_SIZE) / TDM_UT_BACKEND_TEST_CNT) * t;
1180                                 info.dst_pos.y = ((mode->vdisplay - TDM_UT_BUFFER_SIZE) / TDM_UT_BACKEND_TEST_CNT) * t;
1181                                 info.dst_pos.w = TDM_UT_BUFFER_SIZE;
1182                                 info.dst_pos.h = TDM_UT_BUFFER_SIZE;
1183                                 info.transform = TDM_TRANSFORM_NORMAL;
1184                                 ASSERT_EQ(tdm_layer_set_info(layer, &info), TDM_ERROR_NONE);
1185
1186                                 ASSERT_EQ(tdm_layer_set_buffer(layer, buffers[next_buffer]), TDM_ERROR_NONE);
1187                                 done = false;
1188                                 ASSERT_EQ(tdm_output_commit(output, 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
1189                                 while (!done)
1190                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1191                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
1192                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1193                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
1194                                 next_buffer++;
1195                                 if (next_buffer == 3)
1196                                         next_buffer = 0;
1197                         }
1198
1199                         DestroyBuffers();
1200
1201                         TDM_UT_ASK_YNR("* Successed to move '%c%c%c%c' small size(%dx%d) frames on screen? (output: %d, layer: %d)",
1202                                                    FOURCC_STR(formats[f]), TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, pipe, l);
1203                 }
1204
1205                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1206         }
1207 }
1208
1209 TEST_P(TDMBackendDisplay, VerifyOverlayLayerCrop)
1210 {
1211         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, false), true);
1212
1213         for (int l = 0; l < layer_count; l++) {
1214                 tdm_error ret;
1215                 tdm_output *output;
1216                 tdm_layer *layer;
1217                 int next_buffer = 0;
1218                 bool done = false;
1219                 const tbm_format *formats;
1220                 int format_count = 0;
1221                 const tdm_output_mode *mode = NULL;
1222                 unsigned int flags = 0;
1223                 unsigned int pipe = 0;
1224
1225                 layer = layers[l];
1226
1227                 output = tdm_layer_get_output(layer, &ret);
1228                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1229
1230                 ASSERT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
1231
1232                 if (!ut_tdm_output_is_connected(output))
1233                         continue;
1234                 if (ut_tdm_layer_is_primary_layer(layer))
1235                         continue;
1236                 if (ut_tdm_layer_is_cursor_layer(layer))
1237                         continue;
1238                 if (ut_tdm_layer_support_no_crop(layer)) {
1239                         TDM_UT_INFO("no crop capability. (output: %d, layer: %d)", pipe, l);
1240                         continue;
1241                 }
1242
1243                 TDM_UT_INFO("* testing for (output: %d, layer: %d)", pipe, l);
1244
1245                 ASSERT_EQ(tdm_layer_get_buffer_flags(layer, &flags), TDM_ERROR_NONE);
1246                 ASSERT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
1247                 ASSERT_NE(mode, NULL);
1248
1249                 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
1250
1251                 ASSERT_EQ(tdm_layer_get_available_formats(layer, &formats, &format_count), TDM_ERROR_NONE);
1252
1253                 for (int f = 0; f < format_count; f++) {
1254 retry:
1255                         TDM_UT_INFO("** testing for %c%c%c%c", FOURCC_STR(formats[f]));
1256                         ASSERT_EQ(ut_tdm_buffer_create(mode->hdisplay, mode->vdisplay, formats[f], flags | TBM_BO_SCANOUT, true, 3, buffers), true);
1257
1258                         tdm_info_layer info;
1259                         memset(&info, 0, sizeof info);
1260                         info.src_config.size.h = mode->hdisplay;
1261                         info.src_config.size.v = mode->vdisplay;
1262                         info.src_config.pos.x = mode->hdisplay / 2;
1263                         info.src_config.pos.y = mode->vdisplay / 2;
1264                         info.src_config.pos.w = info.src_config.size.h / 2;
1265                         info.src_config.pos.h = info.src_config.size.v / 2;
1266                         info.src_config.format = formats[f];
1267                         info.dst_pos.x = info.src_config.pos.x;
1268                         info.dst_pos.y = info.src_config.pos.y;
1269                         info.dst_pos.w = info.src_config.pos.w;
1270                         info.dst_pos.h = info.src_config.pos.h;
1271                         info.transform = TDM_TRANSFORM_NORMAL;
1272                         ASSERT_EQ(tdm_layer_set_info(layer, &info), TDM_ERROR_NONE);
1273
1274                         /* set buffer & commit for TDM_UT_BACKEND_TEST_CNT times */
1275                         for (int t = 0; t < TDM_UT_BACKEND_TEST_CNT; t++) {
1276                                 tbm_surface_h displaying_buffer;
1277                                 ASSERT_EQ(tdm_layer_set_buffer(layer, buffers[next_buffer]), TDM_ERROR_NONE);
1278                                 done = false;
1279                                 ASSERT_EQ(tdm_output_commit(output, 0, _ut_tdm_backend_output_commit_cb, &done), TDM_ERROR_NONE);
1280                                 while (!done)
1281                                         ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1282                                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
1283                                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1284                                 ASSERT_EQ(displaying_buffer, buffers[next_buffer]);
1285                                 next_buffer++;
1286                                 if (next_buffer == 3)
1287                                         next_buffer = 0;
1288                         }
1289
1290                         DestroyBuffers();
1291
1292                         TDM_UT_ASK_YNR("* Successed to crop '%c%c%c%c' frames and display it? (output: %d, layer: %d)",
1293                                                    FOURCC_STR(formats[f]), pipe, l);
1294                 }
1295
1296                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1297         }
1298 }
1299
1300 /* should be debugged int emulator kernel */
1301 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsFromOnToOff)
1302 {
1303         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, true), true);
1304
1305         for (int o = 0; o < output_count; o++) {
1306                 if (!ut_tdm_output_is_connected(outputs[o]))
1307                         continue;
1308
1309                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
1310         }
1311 }
1312
1313 /* should be debugged int emulator kernel */
1314 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsFromOffToOn)
1315 {
1316         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, true), true);
1317
1318         for (int o = 0; o < output_count; o++) {
1319                 if (!ut_tdm_output_is_connected(outputs[o]))
1320                         continue;
1321
1322                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
1323                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
1324         }
1325 }
1326
1327 /* should be debugged int emulator kernel */
1328 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsToOnBeforeSet)
1329 {
1330         for (int o = 0; o < output_count; o++) {
1331                 if (!ut_tdm_output_is_connected(outputs[o]))
1332                         continue;
1333
1334                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
1335                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_ON), TDM_ERROR_NONE);
1336         }
1337 }
1338
1339 /* should be debugged int emulator kernel */
1340 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsToOffBeforeSet)
1341 {
1342         for (int o = 0; o < output_count; o++) {
1343                 if (!ut_tdm_output_is_connected(outputs[o]))
1344                         continue;
1345
1346                 ASSERT_EQ(ut_tdm_output_mode_setting(outputs[o]), true);
1347                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
1348         }
1349 }
1350
1351 /* should be debugged int emulator kernel */
1352 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsToOffAfterUnsetWithoutCommit)
1353 {
1354         for (int o = 0; o < output_count; o++) {
1355                 if (!ut_tdm_output_is_connected(outputs[o]))
1356                         continue;
1357
1358                 ASSERT_EQ(ut_tdm_output_prepare(dpy, outputs[o], true), true);
1359
1360                 tdm_layer *layer = ut_tdm_output_get_primary_layer(outputs[o]);
1361                 ASSERT_NE(layer, NULL);
1362
1363                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1364
1365                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
1366         }
1367 }
1368
1369 /* should be debugged int emulator kernel */
1370 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsToOffAfterUnsetWithCommit)
1371 {
1372         for (int o = 0; o < output_count; o++) {
1373                 if (!ut_tdm_output_is_connected(outputs[o]))
1374                         continue;
1375
1376                 ASSERT_EQ(ut_tdm_output_prepare(dpy, outputs[o], true), true);
1377
1378                 tdm_layer *layer = ut_tdm_output_get_primary_layer(outputs[o]);
1379                 ASSERT_NE(layer, NULL);
1380
1381                 ASSERT_EQ(tdm_layer_unset_buffer(layer), TDM_ERROR_NONE);
1382                 ASSERT_EQ(tdm_output_commit(outputs[o], 0, NULL, NULL), TDM_ERROR_NONE);
1383
1384                 ASSERT_EQ(tdm_output_set_dpms(outputs[o], TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
1385         }
1386 }
1387
1388 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputSetDpmsAsync)
1389 {
1390 }
1391
1392 TEST_P(TDMBackendDisplay, VerifyLayerGetInfo)
1393 {
1394         ASSERT_EQ(ut_tdm_output_prepare_all_output(dpy, outputs, output_count, true), true);
1395
1396         for (int o = 0; o < output_count; o++) {
1397                 if (!ut_tdm_output_is_connected(outputs[o]))
1398                         continue;
1399
1400                 tbm_surface_h displaying_buffer;
1401                 tdm_error ret;
1402                 tdm_info_layer info, temp;
1403                 tdm_layer *layer = ut_tdm_output_get_primary_layer(outputs[o]);
1404                 ASSERT_NE(layer, NULL);
1405
1406                 displaying_buffer = tdm_layer_get_displaying_buffer(layer, &ret);
1407                 ASSERT_NE(displaying_buffer, NULL);
1408                 ASSERT_EQ(ret, TDM_ERROR_NONE);
1409                 ASSERT_EQ(ut_tdm_layer_fill_info(layer, displaying_buffer, NULL, &info), true);
1410                 ASSERT_EQ(tdm_layer_get_info(layer, &temp), TDM_ERROR_NONE);
1411                 ASSERT_EQ(memcmp(&info, &temp, sizeof info), 0);
1412         }
1413 }
1414
1415 TEST_P(TDMBackendDisplay, DISABLED_VerifyOutputWaitVblankBeforeDpmsOff)  /* TODO */
1416 {
1417 }
1418
1419 TEST_P(TDMBackendDisplay, DISABLED_VerifyLayerSetVideoPos)
1420 {
1421 }
1422
1423 #ifdef TDM_UT_TEST_WITH_PARAMS
1424 INSTANTIATE_TEST_CASE_P(TDMBackendDisplayParams,
1425                                                 TDMBackendDisplay,
1426                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
1427 #else
1428 INSTANTIATE_TEST_CASE_P(TDMBackendDisplayParams,
1429                                                 TDMBackendDisplay,
1430                                                 Values(TDM_DEFAULT_MODULE));
1431 #endif
1432
1433 /* LCOV_EXCL_END */