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