1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6 * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7 * Contact: Roman Marchenko <r.marchenko@samsung.com>
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:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
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.
29 **************************************************************************/
37 class TDMHwc : public TDMOutput
49 error = TDM_ERROR_NONE;
52 void TDMHwc::SetUp(void)
57 void TDMHwc::TearDown(void)
59 TDMOutput::TearDown();
63 _tc_tdm_hwc_commit_cb(tdm_hwc *hwc, unsigned int sequence,
64 unsigned int tv_sec, unsigned int tv_usec,
67 bool *done = (bool*)user_data;
72 /* tdm_hwc_window * tdm_hwc_create_window(tdm_output *output, tdm_error *error); */
73 TEST_P(TDMHwc, CreateWindowFailNull)
75 TDM_UT_SKIP_FLAG(has_outputs);
77 ASSERT_EQ(NULL, tdm_hwc_create_window(NULL, &error));
78 ASSERT_NE(TDM_ERROR_NONE, error);
81 TEST_P(TDMHwc, CreateWindowSuccessful)
83 TDM_UT_SKIP_FLAG(has_outputs);
87 tdm_hwc_window * hw = NULL;
89 for (int o = 0; o < output_count; o++) {
90 hwc = tdm_output_get_hwc(outputs[o], &error);
92 hw = tdm_hwc_create_window(hwc, &error);
93 ASSERT_EQ(TDM_ERROR_NONE, error);
94 tdm_hwc_window_destroy(hw);
96 ASSERT_EQ(NULL, tdm_hwc_create_window(hwc, &error));
97 ASSERT_NE(TDM_ERROR_NONE, error);
102 /* tdm_hwc_get_supported_formats() */
103 TEST_P(TDMHwc, GetSupportedFormatsFailNull)
105 TDM_UT_SKIP_FLAG(has_outputs);
109 error = tdm_hwc_get_video_supported_formats(NULL, NULL, NULL);
110 ASSERT_NE(TDM_ERROR_NONE, error);
113 TEST_P(TDMHwc, GetSupportedFormatsSuccessful)
115 TDM_UT_SKIP_FLAG(has_outputs);
118 tdm_error error = TDM_ERROR_NONE;
119 const tbm_format *formats;
122 for (int o = 0; o < output_count; o++) {
123 hwc = tdm_output_get_hwc(outputs[o], &error);
125 error = tdm_hwc_get_video_supported_formats(hwc, &formats, &count);
126 if (error != TDM_ERROR_NOT_IMPLEMENTED) {
127 ASSERT_EQ(TDM_ERROR_NONE, error);
129 ASSERT_NE(NULL, formats);
132 error = tdm_hwc_get_video_supported_formats(hwc, &formats, &count);
133 ASSERT_NE(TDM_ERROR_NONE, error);
138 /* tdm_hwc_get_available_properties() */
139 TEST_P(TDMHwc, GetAvailablePropertiesFailNullWin)
141 TDM_UT_SKIP_FLAG(has_outputs);
144 tdm_error error = TDM_ERROR_NONE;
145 const tdm_prop *props;
148 for (int o = 0; o < output_count; o++) {
149 hwc = tdm_output_get_hwc(outputs[o], &error);
151 error = tdm_hwc_get_available_properties(NULL, &props, &count);
152 ASSERT_NE(TDM_ERROR_NONE, error);
154 error = tdm_hwc_get_available_properties(hwc, NULL, &count);
155 ASSERT_NE(TDM_ERROR_NONE, error);
157 error = tdm_hwc_get_available_properties(hwc, &props, NULL);
158 ASSERT_NE(TDM_ERROR_NONE, error);
160 error = tdm_hwc_get_available_properties(hwc, &props, &count);
161 ASSERT_NE(TDM_ERROR_NONE, error);
166 TEST_P(TDMHwc, GetAvailablePropertiesSuccess)
168 TDM_UT_SKIP_FLAG(has_outputs);
171 tdm_error error = TDM_ERROR_NONE;
172 const tdm_prop *props;
175 for (int o = 0; o < output_count; o++) {
176 hwc = tdm_output_get_hwc(outputs[o], &error);
178 error = tdm_hwc_get_available_properties(hwc, &props, &count);
179 ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
181 error = tdm_hwc_get_available_properties(hwc, &props, &count);
182 ASSERT_NE(TDM_ERROR_NONE, error);
188 /* tdm_hwc_get_client_target_buffer_queue() */
189 TEST_P(TDMHwc, GetClientTargetBufferQueueFailNullObject)
191 TDM_UT_SKIP_FLAG(has_outputs);
194 tdm_error error = TDM_ERROR_NONE;
195 tbm_surface_queue_h queue = NULL;
197 for (int o = 0; o < output_count; o++) {
198 hwc = tdm_output_get_hwc(outputs[o], &error);
200 queue = tdm_hwc_get_client_target_buffer_queue(NULL, &error);
201 ASSERT_NE(TDM_ERROR_NONE, error);
202 ASSERT_EQ(NULL, queue);
204 queue = tdm_hwc_get_client_target_buffer_queue(NULL, NULL);
205 ASSERT_EQ(NULL, queue);
207 ASSERT_EQ(NULL, queue);
212 TEST_P(TDMHwc, GetClientTargetBufferQueueFailNoHwc)
214 TDM_UT_SKIP_FLAG(has_outputs);
217 tdm_error error = TDM_ERROR_NONE;
218 tbm_surface_queue_h queue = NULL;
220 for (int o = 0; o < output_count; o++) {
221 hwc = tdm_output_get_hwc(outputs[o], &error);
223 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
224 ASSERT_NE(TDM_ERROR_NONE, error);
225 ASSERT_EQ(NULL, queue);
227 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
228 ASSERT_NE(TDM_ERROR_NONE, error);
229 ASSERT_EQ(NULL, queue);
234 TEST_P(TDMHwc, GetClientTargetBufferQueueSuccessful)
236 TDM_UT_SKIP_FLAG(has_outputs);
239 tdm_error error = TDM_ERROR_NONE;
240 tbm_surface_queue_h queue = NULL;
242 for (int o = 0; o < output_count; o++) {
243 ASSERT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
244 hwc = tdm_output_get_hwc(outputs[o], &error);
246 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
247 tbm_surface_queue_destroy(queue);
248 ASSERT_EQ(TDM_ERROR_NONE, error);
249 ASSERT_NE(NULL, queue);
251 queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
252 tbm_surface_queue_destroy(queue);
253 ASSERT_EQ(TDM_ERROR_NONE, error);
254 ASSERT_NE(NULL, queue);
256 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
257 ASSERT_NE(TDM_ERROR_NONE, error);
258 ASSERT_EQ(NULL, queue);
260 queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
261 ASSERT_NE(TDM_ERROR_NONE, error);
262 ASSERT_EQ(NULL, queue);
267 /* tdm_hwc_set_client_target_buffer() */
268 TEST_P(TDMHwc, SetClientTargetBufferFailNullOutput)
270 TDM_UT_SKIP_FLAG(has_outputs);
272 tdm_region damage = {.num_rects = 0, .rects = NULL};
273 tbm_surface_h target_buff = NULL;
275 target_buff = tbm_surface_internal_create_with_flags(720, 1024,
276 TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
277 ASSERT_NE(NULL, target_buff);
279 error = tdm_hwc_set_client_target_buffer(NULL, target_buff, damage);
280 tbm_surface_internal_destroy(target_buff);
281 ASSERT_NE(TDM_ERROR_NONE, error);
284 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulSetBuff)
286 TDM_UT_SKIP_FLAG(has_outputs);
289 tdm_error error = TDM_ERROR_NONE;
290 tdm_region damage = {.num_rects = 0, .rects = NULL};
291 const tdm_output_mode *mode = NULL;
292 tbm_surface_h target_buff = NULL;
294 for (int o = 0; o < output_count; o++) {
295 ASSERT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
296 hwc = tdm_output_get_hwc(outputs[o], &error);
298 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
299 ASSERT_NE(mode, NULL);
300 target_buff = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay,
301 TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
302 ASSERT_NE(NULL, target_buff);
304 error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
305 tbm_surface_internal_destroy(target_buff);
306 ASSERT_EQ(TDM_ERROR_NONE, error);
308 error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
309 ASSERT_NE(TDM_ERROR_NONE, error);
314 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulResetBuff)
316 TDM_UT_SKIP_FLAG(has_outputs);
319 tdm_error error = TDM_ERROR_NONE;
320 tdm_region damage = {.num_rects = 0, .rects = NULL};
322 for (int o = 0; o < output_count; o++) {
323 ASSERT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
324 hwc = tdm_output_get_hwc(outputs[o], &error);
326 error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
327 ASSERT_EQ(TDM_ERROR_NONE, error);
329 error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
330 ASSERT_NE(TDM_ERROR_NONE, error);
335 /* tdm_hwc_validate() */
336 TEST_P(TDMHwc, ValidateFailNull)
338 TDM_UT_SKIP_FLAG(has_outputs);
341 tdm_error error = TDM_ERROR_NONE;
344 error = tdm_hwc_validate(NULL, NULL, 0, &num_types);
345 ASSERT_NE(TDM_ERROR_NONE, error);
347 for (int o = 0; o < output_count; o++) {
348 hwc = tdm_output_get_hwc(outputs[o], &error);
350 error = tdm_hwc_validate(hwc, NULL, 0, NULL);
351 ASSERT_NE(TDM_ERROR_NONE, error);
353 error = tdm_hwc_validate(hwc, NULL, 0, NULL);
354 ASSERT_NE(TDM_ERROR_NONE, error);
359 /* tdm_hwc_get_changed_composition_types() */
360 TEST_P(TDMHwc, GetChangedCompositionTypesFailNull)
362 TDM_UT_SKIP_FLAG(has_outputs);
365 tdm_error error = TDM_ERROR_NONE;
366 uint32_t num_elements;
368 error = tdm_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
369 ASSERT_NE(TDM_ERROR_NONE, error);
371 for (int o = 0; o < output_count; o++) {
372 hwc = tdm_output_get_hwc(outputs[o], &error);
374 error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
375 ASSERT_NE(TDM_ERROR_NONE, error);
377 error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
378 ASSERT_NE(TDM_ERROR_NONE, error);
383 /* tdm_error tdm_hwc_accept_validation() */
384 TEST_P(TDMHwc, AcceptChangesFailNull)
386 TDM_UT_SKIP_FLAG(has_outputs);
388 error = tdm_hwc_accept_validation(NULL);
389 ASSERT_NE(TDM_ERROR_NONE, error);
392 TEST_P(TDMHwc, AcceptChangesFailNoHwc)
395 tdm_error error = TDM_ERROR_NONE;
397 for (int o = 0; o < output_count; o++) {
398 hwc = tdm_output_get_hwc(outputs[o], &error);
400 error = tdm_hwc_accept_validation(hwc);
401 ASSERT_EQ(TDM_ERROR_NONE, error);
403 error = tdm_hwc_accept_validation(hwc);
404 ASSERT_NE(TDM_ERROR_NONE, error);
409 TEST_P(TDMHwc, AcceptChangesSuccessful)
411 TDM_UT_SKIP_FLAG(has_outputs);
414 tdm_error error = TDM_ERROR_NONE;
415 tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
416 tdm_hwc_window **changed_hwc_window = NULL;
417 tdm_hwc_window_composition *composition_types = NULL;
419 uint32_t get_num = 0;
421 for (int o = 0; o < output_count; o++) {
422 ASSERT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
423 hwc = tdm_output_get_hwc(outputs[o], &error);
425 for (int w = 0; w < HWC_WIN_NUM; w++) {
426 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
427 ASSERT_EQ(TDM_ERROR_NONE, error);
428 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_HWC_WIN_COMPOSITION_DEVICE);
429 ASSERT_EQ(TDM_ERROR_NONE, error);
432 error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
433 ASSERT_EQ(TDM_ERROR_NONE, error);
436 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
437 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
440 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
441 ASSERT_EQ(TDM_ERROR_NONE, error);
442 ASSERT_EQ(get_num, num_types);
444 error = tdm_hwc_accept_validation(hwc);
445 ASSERT_EQ(TDM_ERROR_NONE, error);
447 free(composition_types);
448 free(changed_hwc_window);
451 for (int w = 0; w < HWC_WIN_NUM; w++)
452 tdm_hwc_window_destroy(hwc_wnds[w]);
454 ASSERT_EQ(TDM_ERROR_NONE, error);
459 /* tdm_error tdm_hwc_commit() */
460 TEST_P(TDMHwc, CommitFailNull)
462 TDM_UT_SKIP_FLAG(has_outputs);
464 error = tdm_hwc_commit(NULL, 1, NULL, NULL);
465 ASSERT_NE(TDM_ERROR_NONE, error);
468 TEST_P(TDMHwc, CommitSuccessful)
470 TDM_UT_SKIP_FLAG(has_outputs);
473 tdm_error error = TDM_ERROR_NONE;
474 tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
475 tdm_hwc_window **changed_hwc_window = NULL;
476 tdm_hwc_window_composition *composition_types = NULL;
478 uint32_t get_num = 0;
480 for (int o = 0; o < output_count; o++) {
481 ASSERT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
482 hwc = tdm_output_get_hwc(outputs[o], &error);
484 for (int w = 0; w < HWC_WIN_NUM; w++) {
485 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
486 ASSERT_EQ(TDM_ERROR_NONE, error);
487 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_HWC_WIN_COMPOSITION_DEVICE);
488 ASSERT_EQ(TDM_ERROR_NONE, error);
491 error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
492 ASSERT_EQ(TDM_ERROR_NONE, error);
495 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
496 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
499 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
500 ASSERT_EQ(TDM_ERROR_NONE, error);
501 ASSERT_EQ(get_num, num_types);
503 error = tdm_hwc_accept_validation(hwc);
504 ASSERT_EQ(TDM_ERROR_NONE, error);
506 free(composition_types);
507 free(changed_hwc_window);
510 error = tdm_hwc_commit(hwc, 0, _tc_tdm_hwc_commit_cb, NULL);
511 ASSERT_EQ(TDM_ERROR_NONE, error);
513 for (int w = 0; w < HWC_WIN_NUM; w++)
514 tdm_hwc_window_destroy(hwc_wnds[w]);
516 ASSERT_EQ(TDM_ERROR_NONE, error);
521 #ifdef TDM_UT_TEST_WITH_PARAMS
522 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
524 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
526 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
528 Values(TDM_DEFAULT_MODULE));