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 TEST_P(TDMHelper, HelperGetTime)
56 ASSERT_TRUE(tdm_helper_get_time() > 0.0);
59 TEST_P(TDMHelper, HelperDumpBuffer)
63 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
64 ASSERT_TRUE(buffer != NULL);
66 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
69 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
70 tdm_helper_dump_buffer(buffer, (const char*)filename);
72 tbm_surface_destroy(buffer);
75 TEST_P(TDMHelper, HelperDumpBufferNullObject)
78 tdm_helper_dump_buffer(NULL, (const char*)filename);
81 TEST_P(TDMHelper, HelperDumpBufferNullOther)
83 tbm_surface_h buffer = (tbm_surface_h)TDM_UT_INVALID_VALUE;
84 tdm_helper_dump_buffer(buffer, NULL);
87 TEST_P(TDMHelper, HelperClearBufferPos)
90 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
92 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
93 ASSERT_TRUE(buffer != NULL);
95 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
97 tdm_helper_clear_buffer_pos(buffer, &pos);
100 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
101 tdm_helper_dump_buffer(buffer, (const char*)filename);
103 tbm_surface_destroy(buffer);
106 TEST_P(TDMHelper, HelperClearBufferColor)
108 tbm_surface_h buffer;
109 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
110 unsigned int color = 0xffffff00;
112 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
113 ASSERT_TRUE(buffer != NULL);
115 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
117 tdm_helper_clear_buffer_color(buffer, &pos, color);
120 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
121 tdm_helper_dump_buffer(buffer, (const char*)filename);
123 tbm_surface_destroy(buffer);
126 TEST_P(TDMHelper, HelperClearBufferARGB)
128 tbm_surface_h buffer;
130 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
131 ASSERT_TRUE(buffer != NULL);
133 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
135 tdm_helper_clear_buffer(buffer);
138 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
139 tdm_helper_dump_buffer(buffer, (const char*)filename);
141 tbm_surface_destroy(buffer);
144 TEST_P(TDMHelper, HelperClearBufferXRGB)
146 tbm_surface_h buffer;
148 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_XRGB8888);
149 ASSERT_TRUE(buffer != NULL);
151 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
153 tdm_helper_clear_buffer(buffer);
156 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
157 tdm_helper_dump_buffer(buffer, (const char*)filename);
159 tbm_surface_destroy(buffer);
162 TEST_P(TDMHelper, HelperClearBufferYUV420)
164 tbm_surface_h buffer;
166 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
167 ASSERT_TRUE(buffer != NULL);
169 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
171 tdm_helper_clear_buffer(buffer);
174 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
175 tdm_helper_dump_buffer(buffer, (const char*)filename);
177 tbm_surface_destroy(buffer);
180 TEST_P(TDMHelper, HelperClearBufferNV12)
182 tbm_surface_h buffer;
184 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV12);
185 ASSERT_TRUE(buffer != NULL);
187 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
189 tdm_helper_clear_buffer(buffer);
192 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
193 tdm_helper_dump_buffer(buffer, (const char*)filename);
195 tbm_surface_destroy(buffer);
198 TEST_P(TDMHelper, HelperClearBufferNV21)
200 tbm_surface_h buffer;
202 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV21);
203 ASSERT_TRUE(buffer != NULL);
205 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
207 tdm_helper_clear_buffer(buffer);
210 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
211 tdm_helper_dump_buffer(buffer, (const char*)filename);
213 tbm_surface_destroy(buffer);
216 TEST_P(TDMHelper, HelperClearBufferYUYV)
218 tbm_surface_h buffer;
220 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUYV);
221 ASSERT_TRUE(buffer != NULL);
223 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
225 tdm_helper_clear_buffer(buffer);
228 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
229 tdm_helper_dump_buffer(buffer, (const char*)filename);
231 tbm_surface_destroy(buffer);
234 TEST_P(TDMHelper, HelperClearBufferUYVY)
236 tbm_surface_h buffer;
238 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_UYVY);
239 ASSERT_TRUE(buffer != NULL);
241 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
243 tdm_helper_clear_buffer(buffer);
246 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
247 tdm_helper_dump_buffer(buffer, (const char*)filename);
249 tbm_surface_destroy(buffer);
252 TEST_P(TDMHelper, HelperGetBufferFullSize)
254 tbm_surface_h buffer;
255 int w = TDM_UT_INVALID_VALUE, h = TDM_UT_INVALID_VALUE;
257 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
258 ASSERT_TRUE(buffer != NULL);
260 tdm_helper_get_buffer_full_size(buffer, &w, &h);
261 ASSERT_TRUE(w != TDM_UT_INVALID_VALUE);
262 ASSERT_TRUE(w >= tbm_surface_get_width(buffer));
263 ASSERT_TRUE(h != TDM_UT_INVALID_VALUE);
264 ASSERT_TRUE(h >= tbm_surface_get_height(buffer));
266 tbm_surface_destroy(buffer);
269 TEST_P(TDMHelper, HelperConvertBufferRotate0)
271 tbm_surface_h buffer, temp;
274 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
275 ASSERT_TRUE(buffer != NULL);
276 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
278 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
279 ASSERT_TRUE(temp != NULL);
281 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
282 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
284 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0) == TDM_ERROR_NONE);
287 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
288 tdm_helper_dump_buffer(temp, (const char*)filename);
290 tbm_surface_destroy(buffer);
291 tbm_surface_destroy(temp);
294 TEST_P(TDMHelper, HelperConvertBufferRotate0Flip)
296 tbm_surface_h buffer, temp;
299 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
300 ASSERT_TRUE(buffer != NULL);
301 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
303 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
304 ASSERT_TRUE(temp != NULL);
306 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
307 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
309 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_FLIPPED, 0) == TDM_ERROR_NONE);
312 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
313 tdm_helper_dump_buffer(temp, (const char*)filename);
315 tbm_surface_destroy(buffer);
316 tbm_surface_destroy(temp);
319 TEST_P(TDMHelper, HelperConvertBufferRotate90)
321 tbm_surface_h buffer, temp;
324 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
325 ASSERT_TRUE(buffer != NULL);
326 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
328 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
329 ASSERT_TRUE(temp != NULL);
331 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
332 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
334 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_90, 0) == TDM_ERROR_NONE);
337 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
338 tdm_helper_dump_buffer(temp, (const char*)filename);
340 tbm_surface_destroy(buffer);
341 tbm_surface_destroy(temp);
344 TEST_P(TDMHelper, HelperConvertBufferRotate180)
346 tbm_surface_h buffer, temp;
349 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
350 ASSERT_TRUE(buffer != NULL);
351 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
353 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
354 ASSERT_TRUE(temp != NULL);
356 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
357 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
359 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_180, 0) == TDM_ERROR_NONE);
362 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
363 tdm_helper_dump_buffer(temp, (const char*)filename);
365 tbm_surface_destroy(buffer);
366 tbm_surface_destroy(temp);
369 TEST_P(TDMHelper, HelperConvertBufferRotate270)
371 tbm_surface_h buffer, temp;
374 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
375 ASSERT_TRUE(buffer != NULL);
376 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
378 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
379 ASSERT_TRUE(temp != NULL);
381 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
382 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
384 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_270, 0) == TDM_ERROR_NONE);
387 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
388 tdm_helper_dump_buffer(temp, (const char*)filename);
390 tbm_surface_destroy(buffer);
391 tbm_surface_destroy(temp);
394 TEST_P(TDMHelper, HelperConvertBufferYUV420)
396 tbm_surface_h buffer, temp;
399 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
400 ASSERT_TRUE(buffer != NULL);
401 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
403 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_YUV420);
404 ASSERT_TRUE(temp != NULL);
406 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
407 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
409 ASSERT_TRUE(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0) == TDM_ERROR_OPERATION_FAILED);
411 tbm_surface_destroy(buffer);
412 tbm_surface_destroy(temp);
415 TEST_P(TDMHelper, HelperGetFD)
417 int fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
418 ASSERT_TRUE(fd >= 0);
420 fd = tdm_helper_get_fd("BLURBLUR");
421 ASSERT_TRUE(fd == -1);
424 TEST_P(TDMHelper, HelperSetFD)
426 tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
427 tdm_helper_set_fd("BLURBLUR", -1);
430 TEST_P(TDMHelper, HelperDumpStart)
434 snprintf(path, sizeof path, "blurblur");
435 tdm_helper_dump_start(path, &count);
436 tdm_helper_dump_stop();
440 _ut_tdm_helper_capture_cb(tbm_surface_h buffer, void *user_data)
444 TEST_P(TDMHelper, HelperCaptureOutput)
449 for (int o = 0; o < output_count; o++) {
452 output = tdm_display_get_output(dpy, o, &ret);
453 ASSERT_TRUE(ret == TDM_ERROR_NONE);
454 ASSERT_TRUE(output != NULL);
456 if (!ut_tdm_output_is_connected(output))
459 ASSERT_TRUE(ut_tdm_output_prepare(dpy, output, true) == true);
461 dump = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
462 ASSERT_TRUE(dump != NULL);
464 ASSERT_TRUE(tdm_helper_capture_output(output, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
465 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_NONE);
468 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
469 tdm_helper_dump_buffer(dump, (const char*)filename);
471 tbm_surface_destroy(dump);
476 TEST_P(TDMHelper, HelperCaptureOutputNullObject)
478 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
480 ASSERT_TRUE(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
481 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_INVALID_PARAMETER);
484 TEST_P(TDMHelper, HelperCaptureOutputNullOther)
486 for (int o = 0; o < output_count; o++) {
488 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
489 ASSERT_TRUE(ret == TDM_ERROR_NONE);
490 ASSERT_TRUE(output != NULL);
491 tdm_helper_output_commit_per_vblank_enabled(output);
494 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
496 ASSERT_TRUE(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
497 _ut_tdm_helper_capture_cb, NULL) == TDM_ERROR_INVALID_PARAMETER);
500 TEST_P(TDMHelper, HelperGetDisplayInformation)
503 int len = sizeof reply;
505 for (int o = 0; o < output_count; o++) {
507 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
508 ASSERT_TRUE(ret == TDM_ERROR_NONE);
509 ASSERT_TRUE(output != NULL);
510 if (!ut_tdm_output_is_connected(output))
512 ASSERT_TRUE(ut_tdm_output_prepare(dpy, output, true) == true);
515 tdm_helper_get_display_information(dpy, reply, &len);
516 TDM_INFO("%s", reply);
519 TEST_P(TDMHelper, HelperGetDisplayInformationNullObject)
522 int len = sizeof reply;
524 tdm_helper_get_display_information(NULL, reply, &len);
527 TEST_P(TDMHelper, HelperGetDisplayInformationNullOther)
529 tdm_helper_get_display_information(dpy, NULL, NULL);
532 TEST_P(TDMHelper, HelperCommitPerVblankEnabled)
534 tdm_helper_commit_per_vblank_enabled(dpy);
537 TEST_P(TDMHelper, HelperCommitPerVblankEnabledNullOBject)
539 tdm_helper_commit_per_vblank_enabled(NULL);
542 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabled)
544 for (int o = 0; o < output_count; o++) {
546 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
547 ASSERT_TRUE(ret == TDM_ERROR_NONE);
548 ASSERT_TRUE(output != NULL);
549 tdm_helper_output_commit_per_vblank_enabled(output);
553 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabledNullObject)
555 tdm_helper_output_commit_per_vblank_enabled(NULL);
558 #ifdef TDM_UT_TEST_WITH_PARAMS
559 INSTANTIATE_TEST_CASE_P(TDMHelperParams,
561 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
563 INSTANTIATE_TEST_CASE_P(TDMHelperParams,
565 Values(TDM_DEFAULT_MODULE));