utest: Add 26 test cases
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_pp.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
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:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
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.
28  *
29 **************************************************************************/
30
31 #include "gtest/gtest.h"
32 #include "ut_common.h"
33 #include "tdm.h"
34 extern "C" {
35 #include "tbm_bufmgr.h"
36 #include "tbm_drm_helper.h"
37 }
38
39 #include <sys/epoll.h>
40 #include <sys/timerfd.h>
41 #include <list>
42 #include <limits.h>
43
44 #define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
45
46 class TDMPPWithoutCreation : public testing::Test {
47 protected:
48         tdm_display *dpy = NULL;
49         tbm_bufmgr bufmgr;
50         tdm_display_capability display_capability = (tdm_display_capability)0;
51         bool has_pp = false;
52         std::list<tbm_surface_h> buffers_list;
53
54         virtual void SetEnvs()
55         {
56                 setenv("TDM_DLOG", "1", 1);
57                 setenv("XDG_RUNTIME_DIR", ".", 1);
58                 setenv("TBM_DLOG", "1", 1);
59                 setenv("TDM_DEBUG_MODULE", "all", 1);
60                 setenv("TDM_DEBUG", "1", 1);
61                 setenv("TBM_DISPLAY_SERVER", "1", 1);
62         }
63
64         virtual void UnsetEnvs()
65         {
66                 unsetenv("TDM_DLOG");
67                 unsetenv("XDG_RUNTIME_DIR");
68                 unsetenv("TBM_DLOG");
69                 unsetenv("TDM_DEBUG_MODULE");
70                 unsetenv("TDM_DEBUG");
71                 unsetenv("TBM_DISPLAY_SERVER");
72         }
73
74         void SetUp(void)
75         {
76                 tdm_error error = TDM_ERROR_NONE;
77
78                 SetEnvs();
79
80                 bufmgr = tbm_bufmgr_init(-1);
81                 ASSERT_FALSE(bufmgr == NULL);
82
83                 dpy = tdm_display_init(&error);
84                 ASSERT_TRUE(error == TDM_ERROR_NONE);
85                 ASSERT_FALSE(dpy == NULL);
86
87                 error = tdm_display_get_capabilities(dpy, &display_capability);
88 #ifdef FAIL_ON_UNSUPPORTED
89                 ASSERT_TRUE(display_capability & TDM_DISPLAY_CAPABILITY_PP);
90 #endif
91                 ASSERT_TRUE(error == TDM_ERROR_NONE);
92
93                 if (display_capability & TDM_DISPLAY_CAPABILITY_PP)
94                         has_pp = true;
95         }
96
97         void TearDown(void)
98         {
99                 if (dpy)
100                         tdm_display_deinit(dpy);
101                 if (bufmgr)
102                         tbm_bufmgr_deinit(bufmgr);
103
104                 UnsetEnvs();
105         }
106 };
107
108 class TDMPP : public TDMPPWithoutCreation {
109 protected:
110         tdm_pp *pp = NULL;
111         const tbm_format *formats = NULL;
112         int format_count = 0;
113         int min_w = 0;
114         int min_h = 0;
115         int max_w = 0;
116         int max_h = 0;
117         int preferred_align = 0;
118         int default_src_w = 128;
119         int default_src_h = 256;
120         int default_dst_w = 512;
121         int default_dst_h = 1024;
122
123         void SetUp(void)
124         {
125                 tdm_error error;
126
127                 ASSERT_NO_FATAL_FAILURE(TDMPPWithoutCreation::SetUp());
128
129                 if (!has_pp)
130                         return;
131
132                 pp = tdm_display_create_pp(dpy, &error);
133                 ASSERT_NE(NULL, pp);
134                 ASSERT_EQ(TDM_ERROR_NONE, error);
135
136                 error =
137                         tdm_display_get_pp_available_formats(dpy, &formats, &format_count);
138                 ASSERT_EQ(TDM_ERROR_NONE, error);
139                 ASSERT_NE(NULL, formats);
140                 ASSERT_GE(format_count, 0);
141
142                 error =
143                                 tdm_display_get_pp_available_size(dpy, &min_w, &min_h,
144                                                                                                   &max_w, &max_h, &preferred_align);
145                 ASSERT_EQ(TDM_ERROR_NONE, error);
146                 if (preferred_align > 0) {
147                         default_src_w = SIZE_ALIGN(default_src_w, preferred_align);
148                         default_src_h = SIZE_ALIGN(default_src_h, preferred_align);
149                         default_dst_w = SIZE_ALIGN(default_dst_w, preferred_align);
150                         default_dst_h = SIZE_ALIGN(default_dst_h, preferred_align);
151                 }
152                 if (min_w > default_src_w)
153                         default_src_w = min_w;
154                 if (min_h > default_src_h)
155                         default_src_h = min_h;
156                 if (max_w > 0 && max_w < default_dst_w)
157                         default_dst_w = max_w;
158                 if (max_h > 0 && max_h < default_dst_h)
159                         default_dst_h = max_h;
160         }
161
162         void TearDown(void)
163         {
164                 if (pp)
165                         tdm_pp_destroy(pp);
166
167                 for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) {
168                         tbm_surface_destroy(*it);
169                 }
170
171                 buffers_list.clear();
172
173                 TDMPPWithoutCreation::TearDown();
174         }
175
176         void UtGetPPInfoWithScale(tdm_info_pp *info)
177         {
178                 memset((void *)info, 0, sizeof(tdm_info_pp));
179
180                 info->src_config.size.h = default_src_w;
181                 info->src_config.size.v = default_src_h;
182                 info->src_config.pos.x = 0;
183                 info->src_config.pos.y = 0;
184                 info->src_config.pos.w = default_src_w;
185                 info->src_config.pos.h = default_src_h;
186                 info->src_config.format = formats[0];
187                 info->dst_config.size.h = default_dst_w;
188                 info->dst_config.size.v = default_dst_h;
189                 info->dst_config.pos.x = 0;
190                 info->dst_config.pos.y = 0;
191                 info->dst_config.pos.w = default_dst_w;
192                 info->dst_config.pos.h = default_dst_h;
193                 info->dst_config.format = formats[0];
194         }
195
196         void UtGetPPInfoWithScaleAndTransform(tdm_info_pp *info)
197         {
198                 UtGetPPInfoWithScale(info);
199
200                 info->transform = TDM_TRANSFORM_180;
201         }
202
203         void UtGetPPInfoWithWrongInfo(tdm_info_pp *info)
204         {
205                 info->src_config.size.h = UINT_MAX;
206                 info->src_config.size.v = UINT_MAX;
207                 info->src_config.pos.x = 0;
208                 info->src_config.pos.y = 0;
209                 info->src_config.pos.w = UINT_MAX;
210                 info->src_config.pos.h = UINT_MAX;
211                 info->src_config.format = INT_MAX;
212                 info->dst_config.size.h = UINT_MAX;
213                 info->dst_config.size.v = UINT_MAX;
214                 info->dst_config.pos.x = 0;
215                 info->dst_config.pos.y = 0;
216                 info->dst_config.pos.w = UINT_MAX;
217                 info->dst_config.pos.h = UINT_MAX;
218                 info->dst_config.format = INT_MAX;
219         }
220
221         tbm_surface_h
222         UtCreateBuffer(int w, int h, tbm_format format)
223         {
224                 tbm_surface_h buffer;
225
226                 buffer = tbm_surface_create(w, h, format);
227                 if (buffer)
228                         buffers_list.push_back(buffer);
229
230                 return buffer;
231         }
232 };
233
234 void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
235                                                         tbm_surface_h dst, void *user_data);
236
237 class TDMPPCommit : public TDMPP {
238 public:
239         friend void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
240                                                                 tbm_surface_h dst, void *user_data);
241 private:
242         int epFd = -1;
243         int timerFd = -1;
244         int tdmFd = -1;
245         static const int timeLimitSec = 0;
246         static const int timeLimitNsec = 100000000;
247 protected:
248         int utPpDoneHandlerSuccessCounter = 0;
249
250         void SetUp(void)
251         {
252                 tdm_error error;
253                 tdm_output *output;
254                 struct epoll_event ep;
255                 tdm_pp_capability pp_capability;
256
257                 ASSERT_NO_FATAL_FAILURE(TDMPP::SetUp());
258
259                 epFd = epoll_create1(0);
260                 ASSERT_TRUE(epFd != -1);
261
262                 timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
263                 ASSERT_TRUE(timerFd != -1);
264
265                 memset(&ep, 0, sizeof ep);
266                 ep.events |= EPOLLIN;
267                 ep.data.fd = timerFd;
268                 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0);
269
270                 ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE);
271
272                 memset(&ep, 0, sizeof ep);
273                 ep.events |= EPOLLIN;
274                 ep.data.fd = tdmFd;
275                 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0);
276         }
277
278         void TearDown(void)
279         {
280                 tdm_error error;
281
282                 if (epFd)
283                         close(epFd);
284                 if (timerFd)
285                         close(timerFd);
286
287                 TDMPP::TearDown();
288         }
289
290         void UtHandlePPEvent(int num_attached_buffers)
291         {
292                 struct itimerspec its;
293                 int count;
294                 struct epoll_event ep_event[2];
295
296                 if (utPpDoneHandlerSuccessCounter == num_attached_buffers)
297                         return;
298
299                 its.it_interval.tv_sec = 0;
300                 its.it_interval.tv_nsec = 0;
301                 its.it_value.tv_sec = timeLimitSec;
302                 its.it_value.tv_nsec = timeLimitNsec;
303
304                 ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0);
305
306                 while (1) {
307                         count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1);
308                         ASSERT_TRUE(count >= 0);
309
310                         for (int i = 0; i < count; i++) {
311                                 if (ep_event[i].data.fd == timerFd) {
312                                         return;
313                                 } else {
314                                         ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE);
315                                         if (utPpDoneHandlerSuccessCounter == num_attached_buffers)
316                                                 return;
317                                 }
318                         }
319                 }
320         }
321
322         int UtPrepareToPP(tdm_info_pp *info)
323         {
324                 tdm_error error;
325                 tbm_surface_h src_buf, dst_buf;
326
327                 error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
328                 EXPECT_EQ(TDM_ERROR_NONE, error);
329                 if (error != TDM_ERROR_NONE)
330                         return -1;
331
332                 error = tdm_pp_set_info(pp, info);
333                 EXPECT_EQ(TDM_ERROR_NONE, error);
334                 if (error != TDM_ERROR_NONE)
335                         return -1;
336
337                 src_buf = UtCreateBuffer(info->src_config.pos.w, info->src_config.pos.h,
338                                                                  info->src_config.format);
339                 EXPECT_NE(NULL, src_buf);
340                 if (!src_buf)
341                         return -1;
342
343                 dst_buf = UtCreateBuffer(info->dst_config.pos.w, info->dst_config.pos.h,
344                                                                  info->dst_config.format);
345                 EXPECT_NE(NULL, dst_buf);
346                 if (!dst_buf)
347                         return -1;
348
349                 error = tdm_pp_attach(pp, src_buf, dst_buf);
350                 EXPECT_EQ(TDM_ERROR_NONE, error);
351                 if (error != TDM_ERROR_NONE)
352                         return -1;
353
354         }
355
356         int UtPrepareToPPWithScale()
357         {
358                 tdm_info_pp info = {0};
359                 tdm_error error;
360                 tbm_surface_h src_buf, dst_buf;
361
362                 UtGetPPInfoWithScale(&info);
363
364                 return UtPrepareToPP(&info);
365         }
366
367         int UtPrepareToPPWithScaleAndTransform()
368         {
369                 tdm_info_pp info = {0};
370                 tdm_error error;
371                 tbm_surface_h src_buf, dst_buf;
372
373                 UtGetPPInfoWithScaleAndTransform(&info);
374
375                 return UtPrepareToPP(&info);
376         }
377
378         int UtPrepareToPPWithWrongInfo()
379         {
380                 tdm_info_pp info = {0};
381                 tdm_error error;
382                 tbm_surface_h src_buf, dst_buf;
383                 int ret;
384
385                 UtGetPPInfoWithScale(&info);
386
387                 ret = UtPrepareToPP(&info);
388                 if (ret < 0)
389                         return ret;
390
391                 UtGetPPInfoWithWrongInfo(&info);
392
393                 error = tdm_pp_set_info(pp, &info);
394                 EXPECT_EQ(TDM_ERROR_NONE, error);
395                 if (error != TDM_ERROR_NONE)
396                         return -1;
397
398                 return 0;
399         }
400
401 };
402
403 class TDMPPCommitThread : public TDMPPCommit {
404 protected:
405         void SetEnvs()
406         {
407                 TDMPPCommit::SetEnvs();
408                 setenv("TDM_THREAD", "1", 1);
409         }
410         void UnsetEnvs()
411         {
412                 TDMPPCommit::UnsetEnvs();
413                 unsetenv("TDM_THREAD");
414         }
415 };
416
417 void UtPpDoneHandler(tdm_pp *pp, tbm_surface_h src,
418                                                         tbm_surface_h dst, void *user_data)
419 {
420         TDMPPCommit *pp_commit = (TDMPPCommit *)user_data;
421         bool src_valid, dst_valid;
422
423         if (!pp_commit)
424                 return;
425
426         for (auto it = pp_commit->buffers_list.begin(); it != pp_commit->buffers_list.end(); ++it) {
427                 if (*it == src)
428                         src_valid = true;
429                 if (*it == dst)
430                         dst_valid = true;
431         }
432
433         if (src_valid && dst_valid)
434                 pp_commit->utPpDoneHandlerSuccessCounter++;
435 }
436
437 TEST_F(TDMPPWithoutCreation, DisplayGetPPAvailableFormatsSuccessful)
438 {
439         SKIP_FLAG(has_pp);
440         const tbm_format *formats = NULL;
441         int count = -42;
442         ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count));
443         ASSERT_FALSE(-42 == count);
444         ASSERT_FALSE(NULL == formats);
445 }
446
447 /* tdm_display_create_pp() */
448
449 TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullAll)
450 {
451         SKIP_FLAG(has_pp);
452         tdm_pp *pp;
453
454         pp = tdm_display_create_pp(NULL, NULL);
455         ASSERT_EQ(NULL, pp);
456 }
457
458 TEST_F(TDMPPWithoutCreation, DisplayCreatePPNullDpy)
459 {
460         SKIP_FLAG(has_pp);
461         tdm_pp *pp;
462         tdm_error error;
463
464         pp = tdm_display_create_pp(NULL, &error);
465         ASSERT_EQ(NULL, pp);
466         ASSERT_NE(TDM_ERROR_NONE, error);
467 }
468
469 TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccessNullError)
470 {
471         SKIP_FLAG(has_pp);
472         tdm_pp *pp;
473
474         pp = tdm_display_create_pp(dpy, NULL);
475         ASSERT_NE(NULL, pp);
476 }
477
478 TEST_F(TDMPPWithoutCreation, DisplayCreatePPSuccess)
479 {
480         SKIP_FLAG(has_pp);
481         tdm_pp *pp;
482         tdm_error error;
483
484         pp = tdm_display_create_pp(dpy, &error);
485         ASSERT_NE(NULL, pp);
486         ASSERT_EQ(TDM_ERROR_NONE, error);
487 }
488
489 /* tdm_pp_set_info() */
490
491 TEST_F(TDMPP, PpSetInfoNullAll)
492 {
493         SKIP_FLAG(has_pp);
494         tdm_error error;
495
496         error = tdm_pp_set_info(NULL, NULL);
497         ASSERT_NE(TDM_ERROR_NONE, error);
498 }
499
500 TEST_F(TDMPP, PpSetInfoNullPP)
501 {
502         SKIP_FLAG(has_pp);
503         tdm_error error;
504         tdm_info_pp info;
505
506         error = tdm_pp_set_info(NULL, &info);
507         ASSERT_NE(TDM_ERROR_NONE, error);
508 }
509
510 TEST_F(TDMPP, PpSetInfoNullInfo)
511 {
512         SKIP_FLAG(has_pp);
513         tdm_error error;
514
515         error = tdm_pp_set_info(pp, NULL);
516         ASSERT_NE(TDM_ERROR_NONE, error);
517 }
518
519 TEST_F(TDMPP, PpSetInfoSuccess)
520 {
521         SKIP_FLAG(has_pp);
522         tdm_error error;
523         tdm_info_pp info;
524
525         UtGetPPInfoWithScale(&info);
526
527         error = tdm_pp_set_info(pp, &info);
528         ASSERT_EQ(TDM_ERROR_NONE, error);
529 }
530
531 /* tdm_pp_set_done_handler() */
532
533 TEST_F(TDMPP, PpSetDoneHandlerFailNullAll)
534 {
535         SKIP_FLAG(has_pp);
536         tdm_error error;
537
538         error = tdm_pp_set_done_handler(NULL, NULL, NULL);
539         ASSERT_NE(TDM_ERROR_NONE, error);
540 }
541
542 TEST_F(TDMPP, PpSetDoneHandlerFailNullPP)
543 {
544         SKIP_FLAG(has_pp);
545         tdm_error error;
546         int data;
547
548         error = tdm_pp_set_done_handler(NULL, UtPpDoneHandler, this);
549         ASSERT_NE(TDM_ERROR_NONE, error);
550 }
551
552 TEST_F(TDMPP, PpSetDoneHandlerSuccessNullFailNullFunc)
553 {
554         SKIP_FLAG(has_pp);
555         tdm_error error;
556         int data;
557
558         error = tdm_pp_set_done_handler(pp, NULL, &data);
559         ASSERT_NE(TDM_ERROR_NONE, error);
560 }
561
562 TEST_F(TDMPP, PpSetDoneHandlerSuccessNullData)
563 {
564         SKIP_FLAG(has_pp);
565         tdm_error error;
566
567         error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
568         ASSERT_EQ(TDM_ERROR_NONE, error);
569 }
570
571 TEST_F(TDMPP, PpSetDoneHandlerSuccess)
572 {
573         SKIP_FLAG(has_pp);
574         tdm_error error;
575         int data;
576
577         error = tdm_pp_set_done_handler(pp, UtPpDoneHandler, this);
578         ASSERT_EQ(TDM_ERROR_NONE, error);
579 }
580
581 /* tdm_pp_attach() */
582
583 TEST_F(TDMPP, PpAttachFailNullAll)
584 {
585         SKIP_FLAG(has_pp);
586         tdm_error error;
587
588         error = tdm_pp_attach(NULL, NULL, NULL);
589         ASSERT_NE(TDM_ERROR_NONE, error);
590 }
591
592 TEST_F(TDMPP, PpAttachFailNullPp)
593 {
594         SKIP_FLAG(has_pp);
595         tdm_error error;
596         tbm_surface_h dst_buf, src_buf;
597
598         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
599         ASSERT_NE(NULL, src_buf);
600
601         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
602         ASSERT_NE(NULL, dst_buf);
603
604         error = tdm_pp_attach(NULL, src_buf, dst_buf);
605         ASSERT_NE(TDM_ERROR_NONE, error);
606 }
607
608 TEST_F(TDMPP, PpAttachFailNullSrc)
609 {
610         SKIP_FLAG(has_pp);
611         tdm_error error;
612         tbm_surface_h dst_buf;
613
614         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
615         ASSERT_NE(NULL, dst_buf);
616
617         error = tdm_pp_attach(pp, NULL, dst_buf);
618         ASSERT_NE(TDM_ERROR_NONE, error);
619 }
620
621 TEST_F(TDMPP, PpAttachFailNullDst)
622 {
623         SKIP_FLAG(has_pp);
624         tdm_error error;
625         tbm_surface_h src_buf;
626
627         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
628         ASSERT_NE(NULL, src_buf);
629
630         error = tdm_pp_attach(pp, src_buf, NULL);
631         ASSERT_NE(TDM_ERROR_NONE, error);
632 }
633
634 TEST_F(TDMPP, PpAttachSuccess)
635 {
636         SKIP_FLAG(has_pp);
637         tdm_error error;
638         tbm_surface_h dst_buf, src_buf;
639
640         src_buf = UtCreateBuffer(default_src_w, default_src_h, formats[0]);
641         ASSERT_NE(NULL, src_buf);
642
643         dst_buf = UtCreateBuffer(default_dst_w, default_dst_h, formats[0]);
644         ASSERT_NE(NULL, dst_buf);
645
646         error = tdm_pp_attach(pp, src_buf, dst_buf);
647         ASSERT_EQ(TDM_ERROR_NONE, error);
648 }
649
650 /* tdm_pp_commit() */
651
652 TEST_F(TDMPP, PpCommitFailNullPP)
653 {
654         SKIP_FLAG(has_pp);
655         tdm_error error;
656
657         error = tdm_pp_commit(NULL);
658         ASSERT_NE(TDM_ERROR_NONE, error);
659 }
660
661 TEST_F(TDMPPCommit, PpCommitFailWrongInfo)
662 {
663         SKIP_FLAG(has_pp);
664         tdm_error error;
665
666         ASSERT_NE(-1, UtPrepareToPPWithWrongInfo());
667
668         error = tdm_pp_commit(pp);
669         ASSERT_NE(TDM_ERROR_NONE, error);
670 }
671
672 TEST_F(TDMPPCommit, PpCommitSuccessScale)
673 {
674         SKIP_FLAG(has_pp);
675         tdm_error error;
676
677         ASSERT_NE(-1, UtPrepareToPPWithScale());
678
679         error = tdm_pp_commit(pp);
680         ASSERT_EQ(TDM_ERROR_NONE, error);
681
682         UtHandlePPEvent(1);
683
684         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
685 }
686
687 TEST_F(TDMPPCommit, PpCommitSuccessScaleAndTransform)
688 {
689         SKIP_FLAG(has_pp);
690         tdm_error error;
691
692         ASSERT_NE(-1, UtPrepareToPPWithScale());
693
694         error = tdm_pp_commit(pp);
695         ASSERT_EQ(TDM_ERROR_NONE, error);
696
697         UtHandlePPEvent(1);
698
699         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
700 }
701
702 TEST_F(TDMPPCommitThread, PpCommitSuccessScale)
703 {
704         SKIP_FLAG(has_pp);
705         tdm_error error;
706
707         ASSERT_NE(-1, UtPrepareToPPWithScale());
708
709         error = tdm_pp_commit(pp);
710         ASSERT_EQ(TDM_ERROR_NONE, error);
711
712         UtHandlePPEvent(1);
713
714         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
715 }
716
717 TEST_F(TDMPPCommitThread, PpCommitSuccessScaleAndTransform)
718 {
719         SKIP_FLAG(has_pp);
720         tdm_error error;
721
722         ASSERT_NE(-1, UtPrepareToPPWithScale());
723
724         error = tdm_pp_commit(pp);
725         ASSERT_EQ(TDM_ERROR_NONE, error);
726
727         UtHandlePPEvent(1);
728
729         ASSERT_EQ(1, utPpDoneHandlerSuccessCounter);
730 }
731
732 /* tdm_pp_destroy() */
733
734 void UtBufferReleaseHandler(tbm_surface_h buffer,
735                                                            void *user_data)
736 {
737         int *data = (int *)user_data;
738         if (!data)
739                 return;
740
741         (*data)++;
742 }
743
744 TEST_F(TDMPPCommit, PPDestroySuccessAfterCommit)
745 {
746         SKIP_FLAG(has_pp);
747         tdm_error error;
748         int release_data = 0;
749
750         ASSERT_NE(-1, UtPrepareToPPWithScale());
751
752         for (auto it = buffers_list.begin(); it != buffers_list.end(); ++it) {
753                 tdm_buffer_add_release_handler((tbm_surface_h)*it, UtBufferReleaseHandler, &release_data);
754         }
755
756         error = tdm_pp_commit(pp);
757         ASSERT_EQ(TDM_ERROR_NONE, error);
758
759         tdm_pp_destroy(pp);
760         pp = NULL;
761
762         ASSERT_EQ(2, release_data);
763 }