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 **************************************************************************/
33 class TDMHelper : public TDMOutput {
40 TDMHelper::TDMHelper()
44 void TDMHelper::SetUp(void)
49 void TDMHelper::TearDown(void)
51 TDMOutput::TearDown();
54 #ifdef UT_TDM_HELPER_ENABLE
56 TEST_P(TDMHelper, HelperGetTime)
58 ASSERT_TRUE(tdm_helper_get_time() > 0.0);
61 TEST_P(TDMHelper, HelperDumpBuffer)
65 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
66 ASSERT_TRUE(buffer != NULL);
68 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
71 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
72 tdm_helper_dump_buffer(buffer, (const char*)filename);
74 tbm_surface_destroy(buffer);
77 TEST_P(TDMHelper, HelperDumpBufferNullObject)
80 tdm_helper_dump_buffer(NULL, (const char*)filename);
83 TEST_P(TDMHelper, HelperDumpBufferNullOther)
85 tbm_surface_h buffer = (tbm_surface_h)TDM_UT_INVALID_VALUE;
86 tdm_helper_dump_buffer(buffer, NULL);
89 TEST_P(TDMHelper, HelperClearBufferPos)
92 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
94 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
95 ASSERT_TRUE(buffer != NULL);
97 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
99 tdm_helper_clear_buffer_pos(buffer, &pos);
102 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
103 tdm_helper_dump_buffer(buffer, (const char*)filename);
105 tbm_surface_destroy(buffer);
108 TEST_P(TDMHelper, HelperClearBufferColor)
110 tbm_surface_h buffer;
111 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
112 unsigned int color = 0xffffff00;
114 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
115 ASSERT_TRUE(buffer != NULL);
117 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
119 tdm_helper_clear_buffer_color(buffer, &pos, color);
122 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
123 tdm_helper_dump_buffer(buffer, (const char*)filename);
125 tbm_surface_destroy(buffer);
128 TEST_P(TDMHelper, HelperClearBufferARGB)
130 tbm_surface_h buffer;
132 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
133 ASSERT_TRUE(buffer != NULL);
135 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
137 tdm_helper_clear_buffer(buffer);
140 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
141 tdm_helper_dump_buffer(buffer, (const char*)filename);
143 tbm_surface_destroy(buffer);
146 TEST_P(TDMHelper, HelperClearBufferXRGB)
148 tbm_surface_h buffer;
150 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_XRGB8888);
151 ASSERT_TRUE(buffer != NULL);
153 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
155 tdm_helper_clear_buffer(buffer);
158 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
159 tdm_helper_dump_buffer(buffer, (const char*)filename);
161 tbm_surface_destroy(buffer);
164 TEST_P(TDMHelper, HelperClearBufferYUV420)
166 tbm_surface_h buffer;
168 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
169 ASSERT_TRUE(buffer != NULL);
171 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
173 tdm_helper_clear_buffer(buffer);
176 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
177 tdm_helper_dump_buffer(buffer, (const char*)filename);
179 tbm_surface_destroy(buffer);
182 TEST_P(TDMHelper, HelperClearBufferNV12)
184 tbm_surface_h buffer;
186 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV12);
187 ASSERT_TRUE(buffer != NULL);
189 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
191 tdm_helper_clear_buffer(buffer);
194 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
195 tdm_helper_dump_buffer(buffer, (const char*)filename);
197 tbm_surface_destroy(buffer);
200 TEST_P(TDMHelper, HelperClearBufferNV21)
202 tbm_surface_h buffer;
204 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV21);
205 ASSERT_TRUE(buffer != NULL);
207 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
209 tdm_helper_clear_buffer(buffer);
212 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
213 tdm_helper_dump_buffer(buffer, (const char*)filename);
215 tbm_surface_destroy(buffer);
218 TEST_P(TDMHelper, HelperClearBufferYUYV)
220 tbm_surface_h buffer;
222 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUYV);
223 ASSERT_TRUE(buffer != NULL);
225 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
227 tdm_helper_clear_buffer(buffer);
230 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
231 tdm_helper_dump_buffer(buffer, (const char*)filename);
233 tbm_surface_destroy(buffer);
236 TEST_P(TDMHelper, HelperClearBufferUYVY)
238 tbm_surface_h buffer;
240 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_UYVY);
241 ASSERT_TRUE(buffer != NULL);
243 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
245 tdm_helper_clear_buffer(buffer);
248 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
249 tdm_helper_dump_buffer(buffer, (const char*)filename);
251 tbm_surface_destroy(buffer);
254 TEST_P(TDMHelper, HelperGetBufferFullSize)
256 tbm_surface_h buffer;
257 int w = TDM_UT_INVALID_VALUE, h = TDM_UT_INVALID_VALUE;
259 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
260 ASSERT_TRUE(buffer != NULL);
262 tdm_helper_get_buffer_full_size(buffer, &w, &h);
263 ASSERT_TRUE(w != TDM_UT_INVALID_VALUE);
264 ASSERT_TRUE(w >= tbm_surface_get_width(buffer));
265 ASSERT_TRUE(h != TDM_UT_INVALID_VALUE);
266 ASSERT_TRUE(h >= tbm_surface_get_height(buffer));
268 tbm_surface_destroy(buffer);
271 TEST_P(TDMHelper, HelperConvertBufferRotate0)
273 tbm_surface_h buffer, temp;
276 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
277 ASSERT_TRUE(buffer != NULL);
278 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
280 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
281 ASSERT_TRUE(temp != NULL);
283 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
284 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
286 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0) == TDM_ERROR_NONE);
289 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
290 tdm_helper_dump_buffer(temp, (const char*)filename);
292 tbm_surface_destroy(buffer);
293 tbm_surface_destroy(temp);
296 TEST_P(TDMHelper, HelperConvertBufferRotate0Flip)
298 tbm_surface_h buffer, temp;
301 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
302 ASSERT_TRUE(buffer != NULL);
303 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
305 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
306 ASSERT_TRUE(temp != NULL);
308 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
309 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
311 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_FLIPPED, 0) == TDM_ERROR_NONE);
314 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
315 tdm_helper_dump_buffer(temp, (const char*)filename);
317 tbm_surface_destroy(buffer);
318 tbm_surface_destroy(temp);
321 TEST_P(TDMHelper, HelperConvertBufferRotate90)
323 tbm_surface_h buffer, temp;
326 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
327 ASSERT_TRUE(buffer != NULL);
328 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
330 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
331 ASSERT_TRUE(temp != NULL);
333 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
334 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
336 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_90, 0) == TDM_ERROR_NONE);
339 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
340 tdm_helper_dump_buffer(temp, (const char*)filename);
342 tbm_surface_destroy(buffer);
343 tbm_surface_destroy(temp);
346 TEST_P(TDMHelper, HelperConvertBufferRotate180)
348 tbm_surface_h buffer, temp;
351 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
352 ASSERT_TRUE(buffer != NULL);
353 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
355 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
356 ASSERT_TRUE(temp != NULL);
358 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
359 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
361 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_180, 0) == TDM_ERROR_NONE);
364 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
365 tdm_helper_dump_buffer(temp, (const char*)filename);
367 tbm_surface_destroy(buffer);
368 tbm_surface_destroy(temp);
371 TEST_P(TDMHelper, HelperConvertBufferRotate270)
373 tbm_surface_h buffer, temp;
376 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
377 ASSERT_TRUE(buffer != NULL);
378 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
380 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
381 ASSERT_TRUE(temp != NULL);
383 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
384 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
386 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_270, 0) == TDM_ERROR_NONE);
389 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
390 tdm_helper_dump_buffer(temp, (const char*)filename);
392 tbm_surface_destroy(buffer);
393 tbm_surface_destroy(temp);
396 TEST_P(TDMHelper, HelperConvertBufferYUV420)
398 tbm_surface_h buffer, temp;
401 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
402 ASSERT_TRUE(buffer != NULL);
403 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
405 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_YUV420);
406 ASSERT_TRUE(temp != NULL);
408 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
409 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
411 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0) == TDM_ERROR_OPERATION_FAILED);
413 tbm_surface_destroy(buffer);
414 tbm_surface_destroy(temp);
417 TEST_P(TDMHelper, HelperGetFD)
419 int fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
420 ASSERT_TRUE(fd >= 0);
422 fd = tdm_helper_get_fd("BLURBLUR");
423 ASSERT_TRUE(fd == -1);
426 TEST_P(TDMHelper, HelperSetFD)
428 tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
429 tdm_helper_set_fd("BLURBLUR", -1);
432 TEST_P(TDMHelper, HelperDumpStart)
436 snprintf(path, sizeof path, "blurblur");
437 tdm_helper_dump_start(path, &count);
438 tdm_helper_dump_stop();
442 _ut_tdm_helper_capture_cb(tbm_surface_h buffer, void *user_data)
446 TEST_P(TDMHelper, HelperCaptureOutput)
451 for (int o = 0; o < output_count; o++) {
454 output = tdm_display_get_output(dpy, o, &ret);
455 ASSERT_TRUE(ret == TDM_ERROR_NONE);
456 ASSERT_TRUE(output != NULL);
458 if (!ut_tdm_output_is_connected(output))
461 ASSERT_TRUE(ut_tdm_output_prepare(dpy, output) == true);
463 dump = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
464 ASSERT_TRUE(dump != NULL);
466 ASSERT_TRUE(tdm_helper_capture_output(output, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
467 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_NONE);
470 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
471 tdm_helper_dump_buffer(dump, (const char*)filename);
473 tbm_surface_destroy(dump);
478 TEST_P(TDMHelper, HelperCaptureOutputNullObject)
480 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
482 ASSERT_TRUE(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
483 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_INVALID_PARAMETER);
486 TEST_P(TDMHelper, HelperCaptureOutputNullOther)
488 for (int o = 0; o < output_count; o++) {
490 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
491 ASSERT_TRUE(ret == TDM_ERROR_NONE);
492 ASSERT_TRUE(output != NULL);
493 tdm_helper_output_commit_per_vblank_enabled(output);
496 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
498 ASSERT_TRUE(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
499 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_INVALID_PARAMETER);
502 TEST_P(TDMHelper, HelperGetDisplayInformation)
505 int len = sizeof reply;
507 for (int o = 0; o < output_count; o++) {
509 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
510 ASSERT_TRUE(ret == TDM_ERROR_NONE);
511 ASSERT_TRUE(output != NULL);
512 if (!ut_tdm_output_is_connected(output))
514 ASSERT_TRUE(ut_tdm_output_prepare(dpy, output) == true);
517 tdm_helper_get_display_information(dpy, reply, &len);
518 TDM_INFO("%s", reply);
521 TEST_P(TDMHelper, HelperGetDisplayInformationNullObject)
524 int len = sizeof reply;
526 tdm_helper_get_display_information(NULL, reply, &len);
529 TEST_P(TDMHelper, HelperGetDisplayInformationNullOther)
531 tdm_helper_get_display_information(dpy, NULL, NULL);
534 TEST_P(TDMHelper, HelperCommitPerVblankEnabled)
536 tdm_helper_commit_per_vblank_enabled(dpy);
539 TEST_P(TDMHelper, HelperCommitPerVblankEnabledNullOBject)
541 tdm_helper_commit_per_vblank_enabled(NULL);
544 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabled)
546 for (int o = 0; o < output_count; o++) {
548 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
549 ASSERT_TRUE(ret == TDM_ERROR_NONE);
550 ASSERT_TRUE(output != NULL);
551 tdm_helper_output_commit_per_vblank_enabled(output);
555 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabledNullObject)
557 tdm_helper_output_commit_per_vblank_enabled(NULL);
560 INSTANTIATE_TEST_CASE_P(TDMHelperParams,
562 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));