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