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_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_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_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, GetClientTargetBufferQueueFainNoHwc)
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_EQ(TDM_ERROR_NONE, error);
225 ASSERT_NE(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 hwc = tdm_output_get_hwc(outputs[o], &error);
245 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
246 tbm_surface_queue_destroy(queue);
247 ASSERT_EQ(TDM_ERROR_NONE, error);
248 ASSERT_NE(NULL, queue);
250 queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
251 tbm_surface_queue_destroy(queue);
252 ASSERT_EQ(TDM_ERROR_NONE, error);
253 ASSERT_NE(NULL, queue);
255 queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
256 ASSERT_NE(TDM_ERROR_NONE, error);
257 ASSERT_EQ(NULL, queue);
259 queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
260 ASSERT_NE(TDM_ERROR_NONE, error);
261 ASSERT_EQ(NULL, queue);
266 /* tdm_hwc_set_client_target_buffer() */
267 TEST_P(TDMHwc, SetClientTargetBufferFailNullOutput)
269 TDM_UT_SKIP_FLAG(has_outputs);
271 tdm_region damage = {.num_rects = 0, .rects = NULL};
272 tbm_surface_h target_buff = NULL;
274 target_buff = tbm_surface_internal_create_with_flags(720, 1024,
275 TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
276 ASSERT_NE(NULL, target_buff);
278 error = tdm_hwc_set_client_target_buffer(NULL, target_buff, damage);
279 tbm_surface_internal_destroy(target_buff);
280 ASSERT_NE(TDM_ERROR_NONE, error);
283 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulSetBuff)
285 TDM_UT_SKIP_FLAG(has_outputs);
288 tdm_error error = TDM_ERROR_NONE;
289 tdm_region damage = {.num_rects = 0, .rects = NULL};
290 const tdm_output_mode *mode = NULL;
291 tbm_surface_h target_buff = NULL;
293 for (int o = 0; o < output_count; o++) {
294 hwc = tdm_output_get_hwc(outputs[o], &error);
296 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
297 target_buff = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay,
298 TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
299 ASSERT_NE(NULL, target_buff);
301 error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
302 tbm_surface_internal_destroy(target_buff);
303 ASSERT_EQ(TDM_ERROR_NONE, error);
305 error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
306 ASSERT_NE(TDM_ERROR_NONE, error);
311 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulResetBuff)
313 TDM_UT_SKIP_FLAG(has_outputs);
316 tdm_error error = TDM_ERROR_NONE;
317 tdm_region damage = {.num_rects = 0, .rects = NULL};
318 tbm_surface_h target_buff = NULL;
320 for (int o = 0; o < output_count; o++) {
321 hwc = tdm_output_get_hwc(outputs[o], &error);
323 error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
324 tbm_surface_internal_destroy(target_buff);
325 ASSERT_EQ(TDM_ERROR_NONE, error);
327 error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
328 ASSERT_NE(TDM_ERROR_NONE, error);
333 /* tdm_hwc_validate() */
334 TEST_P(TDMHwc, ValidateFailNull)
336 TDM_UT_SKIP_FLAG(has_outputs);
339 tdm_error error = TDM_ERROR_NONE;
342 error = tdm_hwc_validate(NULL, NULL, 0, &num_types);
343 ASSERT_NE(TDM_ERROR_NONE, error);
345 for (int o = 0; o < output_count; o++) {
346 hwc = tdm_output_get_hwc(outputs[o], &error);
348 error = tdm_hwc_validate(hwc, NULL, 0, NULL);
349 ASSERT_NE(TDM_ERROR_NONE, error);
351 error = tdm_hwc_validate(hwc, NULL, 0, NULL);
352 ASSERT_NE(TDM_ERROR_NONE, error);
357 /* tdm_hwc_get_changed_composition_types() */
358 TEST_P(TDMHwc, GetChangedCompositionTypesFailNull)
360 TDM_UT_SKIP_FLAG(has_outputs);
363 tdm_error error = TDM_ERROR_NONE;
364 uint32_t num_elements;
366 error = tdm_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
367 ASSERT_NE(TDM_ERROR_NONE, error);
369 for (int o = 0; o < output_count; o++) {
370 hwc = tdm_output_get_hwc(outputs[o], &error);
372 error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
373 ASSERT_NE(TDM_ERROR_NONE, error);
375 error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
376 ASSERT_NE(TDM_ERROR_NONE, error);
381 /* tdm_error tdm_hwc_accept_changes() */
382 TEST_P(TDMHwc, AcceptChangesFailNull)
384 TDM_UT_SKIP_FLAG(has_outputs);
386 error = tdm_hwc_accept_changes(NULL);
387 ASSERT_NE(TDM_ERROR_NONE, error);
390 TEST_P(TDMHwc, AcceptChangesFailNoHwc)
393 tdm_error error = TDM_ERROR_NONE;
395 for (int o = 0; o < output_count; o++) {
396 hwc = tdm_output_get_hwc(outputs[o], &error);
398 error = tdm_hwc_accept_changes(hwc);
399 ASSERT_NE(TDM_ERROR_NONE, error);
401 error = tdm_hwc_accept_changes(hwc);
402 ASSERT_NE(TDM_ERROR_NONE, error);
407 TEST_P(TDMHwc, AcceptChangesSuccessful)
409 TDM_UT_SKIP_FLAG(has_outputs);
412 tdm_error error = TDM_ERROR_NONE;
413 tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
414 tdm_hwc_window **changed_hwc_window = NULL;
415 tdm_hwc_window_composition *composition_types = NULL;
417 uint32_t get_num = 0;
419 for (int o = 0; o < output_count; o++) {
420 hwc = tdm_output_get_hwc(outputs[o], &error);
422 for (int w = 0; w < HWC_WIN_NUM; w++) {
423 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
424 ASSERT_EQ(TDM_ERROR_NONE, error);
425 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
426 ASSERT_EQ(TDM_ERROR_NONE, error);
429 error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
430 ASSERT_EQ(TDM_ERROR_NONE, error);
433 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
434 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
436 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
437 ASSERT_EQ(TDM_ERROR_NONE, error);
438 ASSERT_EQ(get_num, num_types);
440 error = tdm_hwc_accept_changes(hwc);
441 ASSERT_EQ(TDM_ERROR_NONE, error);
443 free(composition_types);
444 free(changed_hwc_window);
447 for (int w = 0; w < HWC_WIN_NUM; w++)
448 tdm_hwc_window_destroy(hwc_wnds[w]);
450 ASSERT_EQ(TDM_ERROR_NONE, error);
455 /* tdm_error tdm_hwc_commit() */
456 TEST_P(TDMHwc, CommitFailNull)
458 TDM_UT_SKIP_FLAG(has_outputs);
460 error = tdm_hwc_commit(NULL, 1, NULL, NULL);
461 ASSERT_NE(TDM_ERROR_NONE, error);
464 TEST_P(TDMHwc, CommitSuccessful)
466 TDM_UT_SKIP_FLAG(has_outputs);
469 tdm_error error = TDM_ERROR_NONE;
470 tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
471 tdm_hwc_window **changed_hwc_window = NULL;
472 tdm_hwc_window_composition *composition_types = NULL;
474 uint32_t get_num = 0;
476 for (int o = 0; o < output_count; o++) {
477 hwc = tdm_output_get_hwc(outputs[o], &error);
479 for (int w = 0; w < HWC_WIN_NUM; w++) {
480 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
481 ASSERT_EQ(TDM_ERROR_NONE, error);
482 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
483 ASSERT_EQ(TDM_ERROR_NONE, error);
486 error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
487 ASSERT_EQ(TDM_ERROR_NONE, error);
490 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
491 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
493 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
494 ASSERT_EQ(TDM_ERROR_NONE, error);
495 ASSERT_EQ(get_num, num_types);
497 error = tdm_hwc_accept_changes(hwc);
498 ASSERT_EQ(TDM_ERROR_NONE, error);
500 free(composition_types);
501 free(changed_hwc_window);
504 error = tdm_hwc_commit(hwc, 0, _tc_tdm_hwc_commit_cb, NULL);
505 ASSERT_NE(TDM_ERROR_NONE, error);
507 for (int w = 0; w < HWC_WIN_NUM; w++)
508 tdm_hwc_window_destroy(hwc_wnds[w]);
510 ASSERT_EQ(TDM_ERROR_NONE, error);
515 #ifdef TDM_UT_TEST_WITH_PARAMS
516 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
518 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
520 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
522 Values(TDM_DEFAULT_MODULE));