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
41 TDMHelper::TDMHelper()
45 void TDMHelper::SetUp(void)
50 void TDMHelper::TearDown(void)
52 TDMOutput::TearDown();
55 TEST_P(TDMHelper, HelperGetTime)
57 ASSERT_GT(tdm_helper_get_time(), 0.0);
60 TEST_P(TDMHelper, HelperDumpBuffer)
64 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
65 ASSERT_NE(buffer, NULL);
67 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
70 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
71 tdm_helper_dump_buffer(buffer, (const char*)filename);
73 tbm_surface_destroy(buffer);
76 TEST_P(TDMHelper, HelperDumpBufferNullObject)
79 tdm_helper_dump_buffer(NULL, (const char*)filename);
82 TEST_P(TDMHelper, HelperDumpBufferNullOther)
84 tbm_surface_h buffer = (tbm_surface_h)TDM_UT_INVALID_VALUE;
85 tdm_helper_dump_buffer(buffer, NULL);
88 TEST_P(TDMHelper, HelperClearBufferPos)
91 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
93 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
94 ASSERT_NE(buffer, NULL);
96 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
98 tdm_helper_clear_buffer_pos(buffer, &pos);
101 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
102 tdm_helper_dump_buffer(buffer, (const char*)filename);
104 tbm_surface_destroy(buffer);
107 TEST_P(TDMHelper, HelperClearBufferColor)
109 tbm_surface_h buffer;
110 tdm_pos pos = {.x = 40, .y = 40, .w = TDM_UT_BUFFER_SIZE - 80, .h = TDM_UT_BUFFER_SIZE - 80};
111 unsigned int color = 0xffffff00;
113 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
114 ASSERT_NE(buffer, NULL);
116 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
118 tdm_helper_clear_buffer_color(buffer, &pos, color);
121 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
122 tdm_helper_dump_buffer(buffer, (const char*)filename);
124 tbm_surface_destroy(buffer);
127 TEST_P(TDMHelper, HelperClearBufferARGB)
129 tbm_surface_h buffer;
131 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
132 ASSERT_NE(buffer, NULL);
134 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
136 tdm_helper_clear_buffer(buffer);
139 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
140 tdm_helper_dump_buffer(buffer, (const char*)filename);
142 tbm_surface_destroy(buffer);
145 TEST_P(TDMHelper, HelperClearBufferXRGB)
147 tbm_surface_h buffer;
149 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_XRGB8888);
150 ASSERT_NE(buffer, NULL);
152 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
154 tdm_helper_clear_buffer(buffer);
157 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
158 tdm_helper_dump_buffer(buffer, (const char*)filename);
160 tbm_surface_destroy(buffer);
163 TEST_P(TDMHelper, HelperClearBufferYUV420)
165 tbm_surface_h buffer;
167 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
168 ASSERT_NE(buffer, NULL);
170 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
172 tdm_helper_clear_buffer(buffer);
175 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
176 tdm_helper_dump_buffer(buffer, (const char*)filename);
178 tbm_surface_destroy(buffer);
181 TEST_P(TDMHelper, HelperClearBufferNV12)
183 tbm_surface_h buffer;
185 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV12);
186 ASSERT_NE(buffer, NULL);
188 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
190 tdm_helper_clear_buffer(buffer);
193 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
194 tdm_helper_dump_buffer(buffer, (const char*)filename);
196 tbm_surface_destroy(buffer);
199 TEST_P(TDMHelper, HelperClearBufferNV21)
201 tbm_surface_h buffer;
203 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_NV21);
204 ASSERT_NE(buffer, NULL);
206 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
208 tdm_helper_clear_buffer(buffer);
211 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
212 tdm_helper_dump_buffer(buffer, (const char*)filename);
214 tbm_surface_destroy(buffer);
217 TEST_P(TDMHelper, HelperClearBufferYUYV)
219 tbm_surface_h buffer;
221 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUYV);
222 ASSERT_NE(buffer, NULL);
224 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
226 tdm_helper_clear_buffer(buffer);
229 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
230 tdm_helper_dump_buffer(buffer, (const char*)filename);
232 tbm_surface_destroy(buffer);
235 TEST_P(TDMHelper, HelperClearBufferUYVY)
237 tbm_surface_h buffer;
239 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_UYVY);
240 ASSERT_NE(buffer, NULL);
242 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
244 tdm_helper_clear_buffer(buffer);
247 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
248 tdm_helper_dump_buffer(buffer, (const char*)filename);
250 tbm_surface_destroy(buffer);
253 TEST_P(TDMHelper, HelperGetBufferFullSize)
255 tbm_surface_h buffer;
256 int w = TDM_UT_INVALID_VALUE, h = TDM_UT_INVALID_VALUE;
258 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
259 ASSERT_NE(buffer, NULL);
261 tdm_helper_get_buffer_full_size(buffer, &w, &h);
262 ASSERT_NE(w, TDM_UT_INVALID_VALUE);
263 ASSERT_GE(w, tbm_surface_get_width(buffer));
264 ASSERT_NE(h, TDM_UT_INVALID_VALUE);
265 ASSERT_GE(h, tbm_surface_get_height(buffer));
267 tbm_surface_destroy(buffer);
270 TEST_P(TDMHelper, HelperConvertBufferRotate0)
272 tbm_surface_h buffer, temp;
275 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
276 ASSERT_NE(buffer, NULL);
277 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
279 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
280 ASSERT_NE(temp, NULL);
282 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
283 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
285 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0), TDM_ERROR_NONE);
288 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
289 tdm_helper_dump_buffer(temp, (const char*)filename);
291 tbm_surface_destroy(buffer);
292 tbm_surface_destroy(temp);
295 TEST_P(TDMHelper, HelperConvertBufferRotate0Flip)
297 tbm_surface_h buffer, temp;
300 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
301 ASSERT_NE(buffer, NULL);
302 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
304 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
305 ASSERT_NE(temp, NULL);
307 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
308 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
310 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_FLIPPED, 0), TDM_ERROR_NONE);
313 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
314 tdm_helper_dump_buffer(temp, (const char*)filename);
316 tbm_surface_destroy(buffer);
317 tbm_surface_destroy(temp);
320 TEST_P(TDMHelper, HelperConvertBufferRotate90)
322 tbm_surface_h buffer, temp;
325 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
326 ASSERT_NE(buffer, NULL);
327 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
329 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
330 ASSERT_NE(temp, NULL);
332 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
333 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
335 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_90, 0), TDM_ERROR_NONE);
338 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
339 tdm_helper_dump_buffer(temp, (const char*)filename);
341 tbm_surface_destroy(buffer);
342 tbm_surface_destroy(temp);
345 TEST_P(TDMHelper, HelperConvertBufferRotate180)
347 tbm_surface_h buffer, temp;
350 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
351 ASSERT_NE(buffer, NULL);
352 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
354 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
355 ASSERT_NE(temp, NULL);
357 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
358 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
360 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_180, 0), TDM_ERROR_NONE);
363 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
364 tdm_helper_dump_buffer(temp, (const char*)filename);
366 tbm_surface_destroy(buffer);
367 tbm_surface_destroy(temp);
370 TEST_P(TDMHelper, HelperConvertBufferRotate270)
372 tbm_surface_h buffer, temp;
375 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
376 ASSERT_NE(buffer, NULL);
377 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
379 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_ARGB8888);
380 ASSERT_NE(temp, NULL);
382 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
383 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
385 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_270, 0), TDM_ERROR_NONE);
388 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
389 tdm_helper_dump_buffer(temp, (const char*)filename);
391 tbm_surface_destroy(buffer);
392 tbm_surface_destroy(temp);
395 TEST_P(TDMHelper, HelperConvertBufferYUV420)
397 tbm_surface_h buffer, temp;
400 buffer = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_YUV420);
401 ASSERT_NE(buffer, NULL);
402 tdm_test_buffer_fill(buffer, PATTERN_SMPTE);
404 temp = tbm_surface_create(TDM_UT_BUFFER_SIZE * 2, TDM_UT_BUFFER_SIZE * 2, TBM_FORMAT_YUV420);
405 ASSERT_NE(temp, NULL);
407 sp.x = sp.y = 0, sp.w = sp.h = TDM_UT_BUFFER_SIZE;
408 dp.x = dp.y = 0, dp.w = dp.h = TDM_UT_BUFFER_SIZE * 2;
410 ASSERT_EQ(tdm_helper_convert_buffer(buffer, temp, &sp, &dp, TDM_TRANSFORM_NORMAL, 0), TDM_ERROR_OPERATION_FAILED);
412 tbm_surface_destroy(buffer);
413 tbm_surface_destroy(temp);
416 TEST_P(TDMHelper, HelperGetFD)
418 int fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
421 fd = tdm_helper_get_fd("BLURBLUR");
425 TEST_P(TDMHelper, HelperSetFD)
427 tdm_helper_set_fd("TDM_DRM_MASTER_FD", -1);
428 tdm_helper_set_fd("BLURBLUR", -1);
431 TEST_P(TDMHelper, HelperDumpStart)
435 snprintf(path, sizeof path, "blurblur");
436 tdm_helper_dump_start(path, &count);
437 tdm_helper_dump_stop();
441 _ut_tdm_helper_capture_cb(tbm_surface_h buffer, void *user_data)
445 TEST_P(TDMHelper, HelperCaptureOutput)
450 for (int o = 0; o < output_count; o++) {
453 output = tdm_display_get_output(dpy, o, &ret);
454 ASSERT_EQ(ret, TDM_ERROR_NONE);
455 ASSERT_NE(output, NULL);
457 if (!ut_tdm_output_is_connected(output))
460 ASSERT_EQ(ut_tdm_output_prepare(dpy, output, true), true);
462 dump = tbm_surface_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, TBM_FORMAT_ARGB8888);
463 ASSERT_NE(dump, NULL);
465 ASSERT_EQ(tdm_helper_capture_output(output, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
466 _ut_tdm_helper_capture_cb, NULL), TDM_ERROR_NONE);
469 snprintf(filename, sizeof filename, "%s.png", typeid(*this).name());
470 tdm_helper_dump_buffer(dump, (const char*)filename);
472 tbm_surface_destroy(dump);
477 TEST_P(TDMHelper, HelperCaptureOutputNullObject)
479 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
481 ASSERT_EQ(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
482 _ut_tdm_helper_capture_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
485 TEST_P(TDMHelper, HelperCaptureOutputNullOther)
487 for (int o = 0; o < output_count; o++) {
489 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
490 ASSERT_EQ(ret, TDM_ERROR_NONE);
491 ASSERT_NE(output, NULL);
492 tdm_helper_output_commit_per_vblank_enabled(output);
495 tbm_surface_h dump = (tbm_surface_h)TDM_UT_INVALID_VALUE;
497 ASSERT_EQ(tdm_helper_capture_output(NULL, dump, 0, 0, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE,
498 _ut_tdm_helper_capture_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
501 TEST_P(TDMHelper, HelperGetDisplayInformation)
504 int len = sizeof reply;
506 for (int o = 0; o < output_count; o++) {
508 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
509 ASSERT_EQ(ret, TDM_ERROR_NONE);
510 ASSERT_NE(output, NULL);
511 if (!ut_tdm_output_is_connected(output))
513 ASSERT_EQ(ut_tdm_output_prepare(dpy, output, true), true);
516 tdm_helper_get_display_information(dpy, reply, &len);
517 TDM_INFO("%s", reply);
520 TEST_P(TDMHelper, HelperGetDisplayInformationNullObject)
523 int len = sizeof reply;
525 tdm_helper_get_display_information(NULL, reply, &len);
528 TEST_P(TDMHelper, HelperGetDisplayInformationNullOther)
530 tdm_helper_get_display_information(dpy, NULL, NULL);
533 TEST_P(TDMHelper, HelperCommitPerVblankEnabled)
535 tdm_helper_commit_per_vblank_enabled(dpy);
538 TEST_P(TDMHelper, HelperCommitPerVblankEnabledNullOBject)
540 tdm_helper_commit_per_vblank_enabled(NULL);
543 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabled)
545 for (int o = 0; o < output_count; o++) {
547 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
548 ASSERT_EQ(ret, TDM_ERROR_NONE);
549 ASSERT_NE(output, NULL);
550 tdm_helper_output_commit_per_vblank_enabled(output);
554 TEST_P(TDMHelper, HelperOutputCommitPerVblankEnabledNullObject)
556 tdm_helper_output_commit_per_vblank_enabled(NULL);
559 #ifdef TDM_UT_TEST_WITH_PARAMS
560 INSTANTIATE_TEST_CASE_P(TDMHelperParams,
562 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
564 INSTANTIATE_TEST_CASE_P(TDMHelperParams,
566 Values(TDM_DEFAULT_MODULE));