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