monitor: move to tools
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_output_hwc.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 class TDMOutputHwc : public TDMOutput
34 {
35 public:
36         TDMOutputHwc();
37         void SetUp(void);
38         void TearDown(void);
39
40         tdm_error error;
41 };
42
43 TDMOutputHwc::TDMOutputHwc()
44 {
45         error = TDM_ERROR_NONE;
46 }
47
48 void TDMOutputHwc::SetUp(void)
49 {
50         TDMOutput::SetUp();
51 }
52
53 void TDMOutputHwc::TearDown(void)
54 {
55         TDMOutput::TearDown();
56 }
57
58 /* tdm_hwc_window * tdm_output_hwc_create_window(tdm_output *output, tdm_error *error); */
59 TEST_P(TDMOutputHwc, CreateWindowFailNull)
60 {
61         TDM_UT_SKIP_FLAG(has_outputs);
62
63         ASSERT_EQ(NULL, tdm_output_hwc_create_window(NULL, &error));
64         ASSERT_NE(TDM_ERROR_NONE, error);
65 }
66
67 TEST_P(TDMOutputHwc, CreateWindowSuccessful)
68 {
69         TDM_UT_SKIP_FLAG(has_outputs);
70
71         tdm_hwc_window * hw = NULL;
72
73         for (int o = 0; o < output_count; o++) {
74                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
75                         hw = tdm_output_hwc_create_window(outputs[o], &error);
76                         ASSERT_EQ(TDM_ERROR_NONE, error);
77                         error = tdm_output_hwc_destroy_window(outputs[o], hw);
78                         ASSERT_EQ(TDM_ERROR_NONE, error);
79                 } else {
80                         ASSERT_EQ(NULL, tdm_output_hwc_create_window(outputs[o], &error));
81                         ASSERT_NE(TDM_ERROR_NONE, error);
82                 }
83         }
84 }
85
86 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
87                                                                                  tbm_surface_h target_buffer, tdm_hwc_region damage,
88                                                                                  tdm_hwc_window *composited_wnds, uint32_t num_wnds); */
89 /* TDOO: need to be fixed
90 TEST_P(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
91 {
92         TDM_UT_SKIP_FLAG(has_outputs);
93
94         tdm_hwc_region reg;
95         tbm_surface_h target_buff = CreateBufferForOutput(0);
96         error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg, NULL, 0 );
97         tbm_surface_internal_destroy(target_buff);
98         ASSERT_NE(TDM_ERROR_NONE, error);
99 }
100
101 TEST_P(TDMOutputHwc, SetClientTargetBufferFailNoHwc)
102 {
103         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
104
105         for (int o = 0; o < output_count; o++) {
106                 tbm_surface_h target_buff = CreateBufferForOutput(i);
107                 ASSERT_NE(NULL, target_buff);
108                 error = tdm_output_hwc_set_client_target_buffer(outputs[o], target_buff, damage, NULL, 0);
109                 tbm_surface_internal_destroy(target_buff);
110                 ASSERT_NE(TDM_ERROR_NONE, error);
111         }
112 }
113
114 TEST_P(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
115 {
116         TDM_UT_SKIP_FLAG(has_outputs);
117
118         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
119
120         for (int o = 0; o < output_count; o++) {
121                 tbm_surface_h target_buff = CreateBufferForOutput(i);
122                 ASSERT_NE(NULL, target_buff);
123                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
124                         error = tdm_output_hwc_set_client_target_buffer(outputs[o], target_buff, damage,
125                                         NULL, 0);
126                         tbm_surface_internal_destroy(target_buff);
127                         ASSERT_EQ(TDM_ERROR_NONE, error);
128                 } else {
129                         error = tdm_output_hwc_set_client_target_buffer(outputs[o], target_buff, damage,
130                                         NULL, 0);
131                         tbm_surface_internal_destroy(target_buff);
132                         ASSERT_NE(TDM_ERROR_NONE, error);
133                 }
134         }
135 }
136
137 TEST_P(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
138 {
139         TDM_UT_SKIP_FLAG(has_outputs);
140
141         tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
142
143         for (int o = 0; o < output_count; o++) {
144                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
145                         error = tdm_output_hwc_set_client_target_buffer(outputs[o], NULL, damage,
146                                         NULL, 0);
147                         ASSERT_EQ(TDM_ERROR_NONE, error);
148                 } else {
149                         error = tdm_output_hwc_set_client_target_buffer(outputs[o], NULL, damage,
150                                         NULL, 0);
151                         ASSERT_NE(TDM_ERROR_NONE, error);
152                 }
153         }
154 }
155 */
156
157 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
158 TEST_P(TDMOutputHwc, GetTargetBufferQueueFailNullObject)
159 {
160         TDM_UT_SKIP_FLAG(has_outputs);
161
162         tbm_surface_queue_h queue = NULL;
163
164         queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
165         ASSERT_NE(TDM_ERROR_NONE, error);
166         ASSERT_EQ(NULL, queue);
167
168         queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
169         ASSERT_EQ(NULL, queue);
170 }
171
172 TEST_P(TDMOutputHwc, GetTargetBufferQueueFainNoHwc)
173 {
174         TDM_UT_SKIP_FLAG(has_outputs);
175
176         tbm_surface_queue_h queue = NULL;
177
178         for (int o = 0; o < output_count; o++) {
179                 queue = tdm_output_hwc_get_target_buffer_queue(outputs[o], &error);
180                 ASSERT_NE(TDM_ERROR_NONE, error);
181                 ASSERT_EQ(NULL, queue);
182         }
183 }
184
185 TEST_P(TDMOutputHwc, GetTargetBufferQueueSuccessful)
186 {
187         TDM_UT_SKIP_FLAG(has_outputs);
188
189         tbm_surface_queue_h queue = NULL;
190
191         for (int o = 0; o < output_count; o++) {
192                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
193                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[o], &error);
194                         tbm_surface_queue_destroy(queue);
195                         ASSERT_EQ(TDM_ERROR_NONE, error);
196                         ASSERT_NE(NULL, queue);
197
198                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[o], NULL);
199                         tbm_surface_queue_destroy(queue);
200                         ASSERT_EQ(TDM_ERROR_NONE, error);
201                         ASSERT_NE(NULL, queue);
202                 } else {
203                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[o], &error);
204                         ASSERT_NE(TDM_ERROR_NONE, error);
205                         ASSERT_EQ(NULL, queue);
206
207                         queue = tdm_output_hwc_get_target_buffer_queue(outputs[o], NULL);
208                         ASSERT_NE(TDM_ERROR_NONE, error);
209                         ASSERT_EQ(NULL, queue);
210                 }
211         }
212 }
213
214 /* tdm_error tdm_output_hwc_validate(tdm_output *output, tdm_hwc_window **composited_wnds, uint32_t num_wnds,
215                                         uint32_t *num_types); */
216 /* TODO: fix the validate test later.
217 TEST_P(TDMOutputHwc, ValidateFailNull)
218 {
219         TDM_UT_SKIP_FLAG(has_outputs);
220
221         uint32_t num_types;
222         error = tdm_output_hwc_validate(NULL, NULL, 0, &num_types);
223         ASSERT_NE(TDM_ERROR_NONE, error);
224
225         if (outputs[0]) {
226                 error = tdm_output_hwc_validate(outputs[0], NULL, 0, NULL);
227                 ASSERT_NE(TDM_ERROR_NONE, error);
228         }
229 }
230
231 TEST_P(TDMOutputHwc, ValidateFailNoHwc)
232 {
233         TDM_UT_SKIP_FLAG(has_outputs);
234
235         uint32_t num_types;
236
237         for (int o = 0; o < output_count; o++) {
238                 error = tdm_output_hwc_validate(outputs[o], &num_types);
239                 ASSERT_NE(TDM_ERROR_NONE, error);
240         }
241 }
242
243 TEST_P(TDMOutputHwc, ValidateSuccessful)
244 {
245         TDM_UT_SKIP_FLAG(has_outputs);
246
247         uint32_t num_types;
248         for (int o = 0; o < output_count; o++) {
249                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
250                         error = tdm_output_hwc_validate(outputs[o], &num_types);
251                         ASSERT_EQ(TDM_ERROR_NONE, error);
252                 } else {
253                         error = tdm_output_hwc_validate(outputs[o], &num_types);
254                         ASSERT_NE(TDM_ERROR_NONE, error);
255                 }
256         }
257 }
258 TODO: */
259
260 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
261                                                                                  uint32_t *num_elements, tdm_hwc_window **hwc_window,
262                                                                                  tdm_hwc_window_composition *composition_types); */
263
264 TEST_P(TDMOutputHwc, GetChangedCompositionTypesFailNull)
265 {
266         TDM_UT_SKIP_FLAG(has_outputs);
267
268         uint32_t num_elements;
269
270         error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
271         ASSERT_NE(TDM_ERROR_NONE, error);
272
273         if (outputs[0]) {
274                 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
275                 ASSERT_NE(TDM_ERROR_NONE, error);
276         }
277 }
278
279 TEST_P(TDMOutputHwc, GetChangedCompositionTypesFailNoHwc)
280 {
281         TDM_UT_SKIP_FLAG(has_outputs);
282
283         uint32_t get_num = 10;
284
285         for (int o = 0; o < output_count; o++) {
286                 error = tdm_output_hwc_get_changed_composition_types(outputs[o], &get_num, NULL, NULL);
287                 ASSERT_NE(TDM_ERROR_NONE, error);
288         }
289 }
290
291 /* TODO: fix the validate test later.
292 TEST_P(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
293 {
294         TDM_UT_SKIP_FLAG(has_outputs);
295
296         uint32_t validate_num;
297         uint32_t get_num = 0;
298
299         tdm_hwc_window_composition *composition_types;
300         tdm_hwc_window **hwc_wnds;
301
302         for (int i = 0; i < hwc_count; i++) {
303                 error = tdm_hwc_window_set_composition_type(hwc_wins[o], TDM_COMPOSITION_DEVICE);
304                 ASSERT_EQ(TDM_ERROR_NONE, error);
305         }
306
307
308         for (int i = 0; i < output_count; i++) {
309                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
310                         error = tdm_output_hwc_validate(outputs[o], &validate_num);
311                         ASSERT_EQ(TDM_ERROR_NONE, error);
312
313                         error = tdm_output_hwc_get_changed_composition_types(outputs[o], &get_num, NULL, NULL);
314                         ASSERT_EQ(TDM_ERROR_NONE, error);
315
316                         ASSERT_EQ(get_num, validate_num);
317                         hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
318                         composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
319
320                         error = tdm_output_hwc_get_changed_composition_types(outputs[o], &get_num, hwc_wnds, composition_types);
321
322                         free(hwc_wnds);
323                         free(composition_types);
324
325                         ASSERT_EQ(TDM_ERROR_NONE, error);
326                 } else {
327                         error = tdm_output_hwc_get_changed_composition_types(outputs[o], &get_num, NULL, NULL);
328                         ASSERT_NE(TDM_ERROR_NONE, error);
329                 }
330         }
331 }
332 */
333
334 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
335
336 TEST_P(TDMOutputHwc, AcceptChangesFailNull)
337 {
338         TDM_UT_SKIP_FLAG(has_outputs);
339
340         error = tdm_output_hwc_accept_changes(NULL);
341         ASSERT_NE(TDM_ERROR_NONE, error);
342 }
343
344 TEST_P(TDMOutputHwc, AcceptChangesFailNoHwc)
345 {
346         for (int o = 0; o < output_count; o++) {
347                 error = tdm_output_hwc_accept_changes(outputs[o]);
348                 ASSERT_NE(TDM_ERROR_NONE, error);
349         }
350 }
351
352 /* TODO: fix the validate test later.
353 TEST_P(TDMHwcWindow, AcceptChangesSuccessful)
354 {
355         TDM_UT_SKIP_FLAG(has_outputs);
356
357         uint32_t validate_num;
358
359         for (int i = 0; i < hwc_count; i++) {
360                 error = tdm_hwc_window_set_composition_type(hwc_wins[o], TDM_COMPOSITION_DEVICE);
361                 ASSERT_EQ(TDM_ERROR_NONE, error);
362         }
363
364         for (int i = 0; i < output_count; i++) {
365                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
366                         error = tdm_output_hwc_validate(outputs[o], &validate_num);
367                         ASSERT_EQ(TDM_ERROR_NONE, error);
368
369                         if (validate_num > 0) {
370                                 error =  tdm_output_hwc_accept_changes(outputs[o]);
371                                 ASSERT_EQ(TDM_ERROR_NONE, error);
372                         }
373                 }
374         }
375 }
376 */
377
378 /* tdm_hwc_window * tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error); */
379 TEST_P(TDMOutputHwc, CreateVideoWindowFailNull)
380 {
381         TDM_UT_SKIP_FLAG(has_outputs);
382
383         ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(NULL, &error));
384         ASSERT_NE(TDM_ERROR_NONE, error);
385 }
386
387 TEST_P(TDMOutputHwc, CreateVideoWindowSuccessful)
388 {
389         TDM_UT_SKIP_FLAG(has_outputs);
390
391         tdm_hwc_window *hw = NULL;
392
393         for (int o = 0; o < output_count; o++) {
394                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
395                         hw = tdm_output_hwc_create_video_window(outputs[o], &error);
396                         if (error != TDM_ERROR_NOT_IMPLEMENTED) {
397                                 ASSERT_EQ(TDM_ERROR_NONE, error);
398                                 ASSERT_NE(NULL, hw);
399                                 error = tdm_output_hwc_destroy_window(outputs[o], hw);
400                                 ASSERT_EQ(TDM_ERROR_NONE, error);
401                         }
402                 } else {
403                         ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(outputs[o], &error));
404                         ASSERT_NE(TDM_ERROR_NONE, error);
405                 }
406         }
407 }
408
409 /* tdm_output_hwc_get_video_supported_formats() */
410 TEST_P(TDMOutputHwc, GetVideoSupportedFormatsFailNull)
411 {
412         TDM_UT_SKIP_FLAG(has_outputs);
413
414         tdm_error error;
415
416         error = tdm_output_hwc_get_video_supported_formats(NULL, NULL, NULL);
417         ASSERT_NE(TDM_ERROR_NONE, error);
418 }
419
420 TEST_P(TDMOutputHwc, GetVideoSupportedFormatsSuccessful)
421 {
422         TDM_UT_SKIP_FLAG(has_outputs);
423
424         tdm_error error;
425         const tbm_format *formats;
426         int count;
427
428         for (int o = 0; o < output_count; o++) {
429                 if (ut_tdm_output_is_hwc_enable(outputs[o])) {
430                         error = tdm_output_hwc_get_video_supported_formats(outputs[o], &formats, &count);
431                         if (error != TDM_ERROR_NOT_IMPLEMENTED) {
432                                 ASSERT_EQ(TDM_ERROR_NONE, error);
433                                 if (count > 0)
434                                         ASSERT_NE(NULL, formats);
435                         }
436                 } else {
437                         error = tdm_output_hwc_get_video_supported_formats(outputs[o], &formats, &count);
438                         ASSERT_NE(TDM_ERROR_NONE, error);
439                 }
440         }
441 }
442
443 #ifdef TDM_UT_TEST_WITH_PARAMS
444 INSTANTIATE_TEST_CASE_P(TDMOutputHwcParams,
445                                                 TDMOutputHwc,
446                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
447 #else
448 INSTANTIATE_TEST_CASE_P(TDMOutputHwcParams,
449                                                 TDMOutputHwc,
450                                                 Values(TDM_DEFAULT_MODULE));
451 #endif