1 /**************************************************************************
3 * Copyright 2017 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>
8 * Contact: Sergey Sizonov <s.sizonov@samsung.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sub license, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
34 #include <sys/signalfd.h>
36 #include <sys/prctl.h>
39 #include "tdm_client.h"
45 TDM_UT_PIPE_MSG_REPLY,
46 TDM_UT_PIPE_MSG_SERVER_READY,
47 TDM_UT_PIPE_MSG_SERVER_FAILED,
48 TDM_UT_PIPE_MSG_DPMS_ON,
49 TDM_UT_PIPE_MSG_DPMS_OFF,
50 TDM_UT_PIPE_MSG_TERMINATE_SERVER,
53 #define TDM_UT_WAIT(fmt, ...) \
57 printf(fmt" [n]):next ", ##__VA_ARGS__); \
58 ch = tc_tdm_getchar(); \
59 } while (ch != 'n'); \
62 static int _tc_tdm_pipe_read_msg(int fd);
63 static bool _tc_tdm_pipe_write_msg(int fd, int reply_fd, int msg);
64 static pid_t _tc_tdm_client_server_fork(int *pipe_to_parent, int *pipe_to_child);
66 class TDMClient : public TDMEnv
69 static pid_t server_pid;
71 /* 0: read, 1: write */
72 static int pipe_parent[2];
73 static int pipe_child[2];
76 tdm_client_output *output;
77 tdm_client_vblank *vblank;
78 tdm_client_voutput *voutput;
80 double vrefresh_interval, start, end;
86 bool PrepareClient(void);
87 bool PrepareOutput(void);
88 bool PrepareVblank(void);
90 static void TearDownTestCase(void);
91 static void ServerFork(void);
92 static void ServerKill(void);
95 pid_t TDMClient::server_pid = -1;
96 int TDMClient::pipe_parent[2] = {-1, -1};
97 int TDMClient::pipe_child[2] = {-1, -1};
99 void TDMClient::TearDownTestCase(void)
104 void TDMClient::ServerFork(void)
109 server_pid = _tc_tdm_client_server_fork(pipe_parent, pipe_child);
110 ASSERT_GT(server_pid, 0);
113 void TDMClient::ServerKill(void)
115 if (pipe_child[0] >= 0)
116 close(pipe_child[0]);
117 if (pipe_child[1] >= 0) {
118 if (server_pid > 0) {
119 bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER);
121 if (waitpid(server_pid, NULL, 0) == server_pid)
122 TDM_INFO("*** server terminated ***");
124 TDM_ERR("*** failed to terminate server ***");
126 if (kill(server_pid, 9) < 0)
127 TDM_ERR("*** failed to kill server ***");
130 close(pipe_child[1]);
133 if (pipe_parent[0] >= 0)
134 close(pipe_parent[0]);
135 if (pipe_parent[1] >= 0)
136 close(pipe_parent[1]);
139 pipe_parent[0] = pipe_parent[1] = -1;
140 pipe_child[0] = pipe_child[1] = -1;
143 TDMClient::TDMClient()
149 vrefresh_interval = start = end = 0.0;
152 void TDMClient::SetUp(void)
156 if (server_pid == -1)
160 void TDMClient::TearDown(void)
163 tdm_client_vblank_destroy(vblank);
165 tdm_client_destroy(client);
170 bool TDMClient::PrepareClient(void)
173 client = tdm_client_create(&ret);
174 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
175 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
180 bool TDMClient::PrepareOutput(void)
184 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
186 output = tdm_client_get_output(client, NULL, &ret);
187 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
188 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
193 bool TDMClient::PrepareVblank(void)
196 unsigned int refresh;
198 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
200 vblank = tdm_client_output_create_vblank(output, &ret);
201 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
202 TDM_UT_RETURN_FALSE_IF_FAIL(vblank != NULL);
204 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_client_output_get_refresh_rate(output, &refresh) == TDM_ERROR_NONE);
205 TDM_UT_RETURN_FALSE_IF_FAIL(refresh > 0);
207 vrefresh_interval = 1.0 / (double)refresh;
208 TDM_UT_RETURN_FALSE_IF_FAIL(vrefresh_interval > 0);
219 if (ch == '\n' || ch == '\r')
224 while (c != '\n' && c != EOF)
231 _tc_tdm_pipe_read_msg(int fd)
237 len = read(fd, &msg, sizeof msg);
238 } while (len < 0 && errno == EINTR);
241 msg = TDM_UT_PIPE_MSG_NONE;
247 _tc_tdm_pipe_write_msg(int fd, int reply_fd, int msg)
249 ssize_t len = write(fd, &msg, sizeof msg);
250 TDM_UT_RETURN_FALSE_IF_FAIL(len == sizeof msg);
253 int reply = _tc_tdm_pipe_read_msg(reply_fd);
254 TDM_UT_RETURN_FALSE_IF_FAIL(reply == TDM_UT_PIPE_MSG_REPLY);
261 _tc_tdm_server_set_output_dpms(tdm_display *dpy, int msg)
265 tdm_output_dpms dpms;
267 output = tdm_display_find_output(dpy, "primary", &ret);
268 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
269 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
271 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_dpms(output, &dpms) == TDM_ERROR_NONE);
274 case TDM_UT_PIPE_MSG_DPMS_ON:
275 if (dpms != TDM_OUTPUT_DPMS_ON)
276 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON) == TDM_ERROR_NONE);
278 case TDM_UT_PIPE_MSG_DPMS_OFF:
279 if (dpms != TDM_OUTPUT_DPMS_OFF)
280 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF) == TDM_ERROR_NONE);
290 _tc_tdm_server_run(int *pipe_parent, int *pipe_child)
292 tdm_display *dpy = NULL;
294 struct pollfd fds[2];
296 int output_count = 0;
298 dpy = tdm_display_init(&ret);
299 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
300 TDM_UT_GOTO_IF_FAIL(dpy != NULL, failed);
302 TDM_UT_GOTO_IF_FAIL(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE, failed);
304 for (int o = 0; o < output_count; o++) {
305 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
306 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
307 TDM_UT_GOTO_IF_FAIL(output != NULL, failed);
309 if (!tc_tdm_output_is_connected(output))
312 TDM_UT_GOTO_IF_FAIL(tc_tdm_output_prepare(dpy, output, true) == true, failed);
315 TDM_UT_GOTO_IF_FAIL(_tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_SERVER_READY) == true, done);
317 TDM_INFO("*** server ready ***");
319 ret = tdm_display_get_fd(dpy, &tdm_fd);
320 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, done);
322 fds[0].events = POLLIN;
326 fds[1].events = POLLIN;
327 fds[1].fd = pipe_child[0];
331 /* make sure all events are flushed to clients before falling in sleep */
332 tdm_display_flush(dpy);
334 err = poll(fds, 2, -1);
336 if (errno == EINTR || errno == EAGAIN) {
339 TDM_ERR("server-process: poll failed: %m\n");
344 if (fds[0].revents & POLLIN)
345 ret = tc_tdm_display_handle_events(dpy);
347 if (fds[1].revents & POLLIN) {
348 int msg = _tc_tdm_pipe_read_msg(pipe_child[0]);
349 _tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_REPLY);
352 case TDM_UT_PIPE_MSG_DPMS_ON:
353 case TDM_UT_PIPE_MSG_DPMS_OFF:
354 _tc_tdm_server_set_output_dpms(dpy, msg);
356 case TDM_UT_PIPE_MSG_TERMINATE_SERVER:
366 tdm_display_deinit(dpy);
370 TDM_UT_GOTO_IF_FAIL(_tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_SERVER_FAILED) == true, done);
371 TDM_INFO("*** server failed ***");
374 tdm_display_deinit(dpy);
379 static void _tc_tdm_client_sig_handler(int sig)
381 TDM_UT_ERR("got signal: %d", sig);
382 kill(TDMClient::server_pid, 9);
387 _tc_tdm_client_server_fork(int *pipe_parent, int *pipe_child)
392 TDM_UT_GOTO_IF_FAIL(pipe(pipe_parent) == 0, failed);
393 TDM_UT_GOTO_IF_FAIL(pipe(pipe_child) == 0, failed);
395 signal(SIGCHLD, SIG_IGN);
396 signal(SIGSEGV, _tc_tdm_client_sig_handler);
398 prctl(PR_SET_PDEATHSIG, SIGHUP);
401 TDM_UT_GOTO_IF_FAIL(pid >= 0, failed);
404 _tc_tdm_server_run(pipe_parent, pipe_child);
405 close(pipe_child[0]);
406 close(pipe_child[1]);
407 close(pipe_parent[0]);
408 close(pipe_parent[1]);
410 #ifdef TIZEN_TEST_GCOV
417 msg = _tc_tdm_pipe_read_msg(pipe_parent[0]);
418 TDM_UT_GOTO_IF_FAIL(msg == TDM_UT_PIPE_MSG_SERVER_READY, failed);
420 TDM_INFO("*** server fork done ***");
428 TEST_P(TDMClient, ClientCreate)
432 client = tdm_client_create(&ret);
433 ASSERT_EQ(ret, TDM_ERROR_NONE);
434 ASSERT_NE(client, NULL);
437 TEST_P(TDMClient, ClientCreateNullOther)
439 client = tdm_client_create(NULL);
440 ASSERT_NE(client, NULL);
443 TEST_P(TDMClient, ClientDestroy)
447 client = tdm_client_create(&ret);
448 ASSERT_EQ(ret, TDM_ERROR_NONE);
449 ASSERT_NE(client, NULL);
451 tdm_client_destroy(client);
455 TEST_P(TDMClient, ClientNullObject)
457 tdm_client_destroy(NULL);
460 /* tdm_client_get_fd */
461 TEST_P(TDMClient, ClientGetFd)
463 int fd = TDM_UT_INVALID_VALUE;
465 ASSERT_EQ(PrepareClient(), true);
467 ASSERT_EQ(tdm_client_get_fd(client, &fd), TDM_ERROR_NONE);
471 TEST_P(TDMClient, ClientGetFdNullObject)
473 int fd = TDM_UT_INVALID_VALUE;
474 ASSERT_EQ(tdm_client_get_fd(NULL, &fd), TDM_ERROR_INVALID_PARAMETER);
475 ASSERT_EQ(fd, TDM_UT_INVALID_VALUE);
478 TEST_P(TDMClient, ClientGetFdNullOther)
480 ASSERT_EQ(PrepareClient(), true);
482 ASSERT_EQ(tdm_client_get_fd(client, NULL), TDM_ERROR_INVALID_PARAMETER);
486 _tc_tdm_client_vblank_cb(unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
488 bool *done = (bool *)user_data;
493 /* tdm_client_handle_events_timeout */
494 TEST_P(TDMClient, ClientHandleEvent)
498 ASSERT_EQ(PrepareClient(), true);
500 ASSERT_EQ(tdm_client_wait_vblank(client, NULL, 1, 1, 0, _tc_tdm_client_vblank_cb, &done), TDM_ERROR_NONE);
501 ASSERT_EQ(done, false);
504 ASSERT_EQ(tdm_client_handle_events(client), TDM_ERROR_NONE);
507 TEST_P(TDMClient, ClientHandleEventNullObject)
509 ASSERT_EQ(tdm_client_handle_events(NULL), TDM_ERROR_INVALID_PARAMETER);
512 /* tdm_client_wait_vblank, deprecated */
513 TEST_P(TDMClient, ClientWaitVblank)
517 ASSERT_EQ(PrepareClient(), true);
519 ASSERT_EQ(tdm_client_wait_vblank(client, NULL, 1, 1, 0, _tc_tdm_client_vblank_cb, &done), TDM_ERROR_NONE);
520 ASSERT_EQ(done, false);
523 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
526 /* tdm_client_get_output */
527 TEST_P(TDMClient, ClientGetOutput)
531 ASSERT_EQ(PrepareClient(), true);
533 output = tdm_client_get_output(client, NULL, &ret);
534 ASSERT_EQ(ret, TDM_ERROR_NONE);
535 ASSERT_NE(output, NULL);
538 TEST_P(TDMClient, ClientGetOutputPrimary)
542 ASSERT_EQ(PrepareClient(), true);
544 output = tdm_client_get_output(client, (char*)"primary", &ret);
545 ASSERT_EQ(ret, TDM_ERROR_NONE);
546 ASSERT_NE(output, NULL);
549 TEST_P(TDMClient, ClientGetOutputDefault)
553 ASSERT_EQ(PrepareClient(), true);
555 output = tdm_client_get_output(client, (char*)"default", &ret);
556 ASSERT_EQ(ret, TDM_ERROR_NONE);
557 ASSERT_NE(output, NULL);
560 TEST_P(TDMClient, ClientGetOutputInvalidName)
564 ASSERT_EQ(PrepareClient(), true);
566 output = tdm_client_get_output(client, (char*)"invalid", &ret);
567 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
568 ASSERT_EQ(output, NULL);
571 TEST_P(TDMClient, ClientGetOutputNullObject)
575 output = tdm_client_get_output(NULL, NULL, &ret);
576 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
577 ASSERT_EQ(output, NULL);
580 TEST_P(TDMClient, ClientGetOutputNullOther)
582 ASSERT_EQ(PrepareClient(), true);
584 output = tdm_client_get_output(client, NULL, NULL);
585 ASSERT_NE(output, NULL);
589 _tc_tdm_client_output_change_dpms_cb(tdm_client_output *output,
590 tdm_output_change_type type,
594 bool *done = (bool *)user_data;
597 case TDM_OUTPUT_CHANGE_DPMS:
606 /* tdm_client_output_add_change_handler */
607 TEST_P(TDMClient, ClientOutputAddChangeHandler)
610 tdm_output_dpms dpms;
612 ASSERT_EQ(PrepareClient(), true);
613 ASSERT_EQ(PrepareOutput(), true);
615 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, &done), TDM_ERROR_NONE);
616 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
619 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
621 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
622 ASSERT_EQ(dpms, TDM_OUTPUT_DPMS_OFF);
624 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
625 while (dpms != TDM_OUTPUT_DPMS_ON) {
626 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
627 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
631 TEST_P(TDMClient, ClientOutputAddChangeHandlerTwice)
633 ASSERT_EQ(PrepareClient(), true);
634 ASSERT_EQ(PrepareOutput(), true);
636 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_NONE);
637 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_BAD_REQUEST);
640 TEST_P(TDMClient, ClientOutputAddChangeHandlerNullObject)
642 ASSERT_EQ(tdm_client_output_add_change_handler(NULL, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
645 TEST_P(TDMClient, ClientOutputAddChangeHandlerNullOther)
647 ASSERT_EQ(PrepareClient(), true);
648 ASSERT_EQ(PrepareOutput(), true);
650 ASSERT_EQ(tdm_client_output_add_change_handler(output, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
653 /* tdm_client_output_remove_change_handler */
654 TEST_P(TDMClient, ClientOutputRemoveChangeHandler)
656 ASSERT_EQ(PrepareClient(), true);
657 ASSERT_EQ(PrepareOutput(), true);
659 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_NONE);
660 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL);
663 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerDifferentData)
665 bool done = (bool)TDM_UT_INVALID_VALUE;
667 ASSERT_EQ(PrepareClient(), true);
668 ASSERT_EQ(PrepareOutput(), true);
670 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, &done), TDM_ERROR_NONE);
671 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL);
675 _tc_tdm_client_output_change_dpms_cb2(tdm_client_output *output,
676 tdm_output_change_type type,
681 case TDM_OUTPUT_CHANGE_DPMS:
682 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb2, user_data);
689 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerInHandler)
691 tdm_output_dpms dpms = TDM_OUTPUT_DPMS_ON;
693 ASSERT_EQ(PrepareClient(), true);
694 ASSERT_EQ(PrepareOutput(), true);
696 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb2, NULL), TDM_ERROR_NONE);
697 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
698 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
699 while (dpms != TDM_OUTPUT_DPMS_OFF) {
700 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
701 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
704 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
705 while (dpms != TDM_OUTPUT_DPMS_ON)
706 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
709 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerNullObject)
711 tdm_client_output_remove_change_handler(NULL, _tc_tdm_client_output_change_dpms_cb, NULL);
714 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerNullOther)
716 ASSERT_EQ(PrepareClient(), true);
717 ASSERT_EQ(PrepareOutput(), true);
719 tdm_client_output_remove_change_handler(output, NULL, NULL);
722 /* tdm_client_output_get_refresh_rate */
723 TEST_P(TDMClient, ClientOutputGetRefreshRate)
725 unsigned int refresh = 0;
727 ASSERT_EQ(PrepareClient(), true);
728 ASSERT_EQ(PrepareOutput(), true);
730 ASSERT_EQ(tdm_client_output_get_refresh_rate(output, &refresh), TDM_ERROR_NONE);
731 ASSERT_GT(refresh, 0);
734 TEST_P(TDMClient, ClientOutputGetRefreshRateNullObject)
736 unsigned int refresh = (unsigned int)TDM_UT_INVALID_VALUE;
738 ASSERT_EQ(tdm_client_output_get_refresh_rate(NULL, &refresh), TDM_ERROR_INVALID_PARAMETER);
739 ASSERT_EQ(refresh, (unsigned int)TDM_UT_INVALID_VALUE);
742 TEST_P(TDMClient, ClientOutputGetRefreshRateNullOther)
744 ASSERT_EQ(PrepareClient(), true);
745 ASSERT_EQ(PrepareOutput(), true);
747 ASSERT_EQ(tdm_client_output_get_refresh_rate(output, NULL), TDM_ERROR_INVALID_PARAMETER);
750 /* tdm_client_output_get_mode */
751 TEST_P(TDMClient, ClientOutputGetMode)
753 unsigned int width = 0, height = 0;
755 ASSERT_EQ(PrepareClient(), true);
756 ASSERT_EQ(PrepareOutput(), true);
758 ASSERT_EQ(tdm_client_output_get_mode(output, &width, &height), TDM_ERROR_NONE);
760 ASSERT_GT(height, 0);
763 TEST_P(TDMClient, ClientOutputGetModeNullObject)
765 unsigned int width = (unsigned int)TDM_UT_INVALID_VALUE;
766 unsigned int height = (unsigned int)TDM_UT_INVALID_VALUE;
768 ASSERT_EQ(tdm_client_output_get_mode(NULL, &width, &height), TDM_ERROR_INVALID_PARAMETER);
769 ASSERT_EQ(width, (unsigned int)TDM_UT_INVALID_VALUE);
770 ASSERT_EQ(height, (unsigned int)TDM_UT_INVALID_VALUE);
773 TEST_P(TDMClient, ClientOutputGetModeNullOther)
775 ASSERT_EQ(PrepareClient(), true);
776 ASSERT_EQ(PrepareOutput(), true);
778 ASSERT_EQ(tdm_client_output_get_mode(output, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
781 /* tdm_client_output_get_conn_status */
782 TEST_P(TDMClient, ClientOutputGetConnStatus)
784 tdm_output_conn_status status = (tdm_output_conn_status)TDM_UT_INVALID_VALUE;
786 ASSERT_EQ(PrepareClient(), true);
787 ASSERT_EQ(PrepareOutput(), true);
789 ASSERT_EQ(tdm_client_output_get_conn_status(output, &status), TDM_ERROR_NONE);
790 ASSERT_NE(status, (tdm_output_conn_status)TDM_UT_INVALID_VALUE);
793 TEST_P(TDMClient, ClientOutputGetConnStatusNullObject)
795 tdm_output_conn_status status = (tdm_output_conn_status)TDM_UT_INVALID_VALUE;
797 ASSERT_EQ(tdm_client_output_get_conn_status(NULL, &status), TDM_ERROR_INVALID_PARAMETER);
798 ASSERT_EQ(status, (tdm_output_conn_status)TDM_UT_INVALID_VALUE);
801 TEST_P(TDMClient, ClientOutputGetConnStatusNullOther)
803 ASSERT_EQ(PrepareClient(), true);
804 ASSERT_EQ(PrepareOutput(), true);
806 ASSERT_EQ(tdm_client_output_get_conn_status(output, NULL), TDM_ERROR_INVALID_PARAMETER);
809 /* tdm_client_output_get_dpms */
810 TEST_P(TDMClient, ClientOutputGetDpms)
812 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
814 ASSERT_EQ(PrepareClient(), true);
815 ASSERT_EQ(PrepareOutput(), true);
817 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
818 ASSERT_NE(dpms, (tdm_output_dpms)TDM_UT_INVALID_VALUE);
821 TEST_P(TDMClient, ClientOutputGetDpmsNullObject)
823 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
825 ASSERT_EQ(tdm_client_output_get_dpms(NULL, &dpms), TDM_ERROR_INVALID_PARAMETER);
826 ASSERT_EQ(dpms, (tdm_output_dpms)TDM_UT_INVALID_VALUE);
829 TEST_P(TDMClient, ClientOutputGetDpmsNullOther)
831 ASSERT_EQ(PrepareClient(), true);
832 ASSERT_EQ(PrepareOutput(), true);
834 ASSERT_EQ(tdm_client_output_get_dpms(output, NULL), TDM_ERROR_INVALID_PARAMETER);
837 /* tdm_client_output_create_vblank */
838 TEST_P(TDMClient, ClientOutputCreateVblank)
842 ASSERT_EQ(PrepareClient(), true);
843 ASSERT_EQ(PrepareOutput(), true);
845 vblank = tdm_client_output_create_vblank(output, &ret);
846 ASSERT_EQ(ret, TDM_ERROR_NONE);
847 ASSERT_NE(vblank, NULL);
850 TEST_P(TDMClient, ClientOutputCreateVblankNullObject)
854 vblank = tdm_client_output_create_vblank(NULL, &ret);
855 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
856 ASSERT_EQ(vblank, NULL);
859 TEST_P(TDMClient, ClientOutputCreateVblankNullOther)
861 ASSERT_EQ(PrepareClient(), true);
862 ASSERT_EQ(PrepareOutput(), true);
864 vblank = tdm_client_output_create_vblank(output, NULL);
865 ASSERT_NE(vblank, NULL);
868 /* tdm_client_vblank_destroy */
869 TEST_P(TDMClient, ClientVblankDestroy)
873 ASSERT_EQ(PrepareClient(), true);
874 ASSERT_EQ(PrepareOutput(), true);
876 vblank = tdm_client_output_create_vblank(output, &ret);
877 ASSERT_EQ(ret, TDM_ERROR_NONE);
878 ASSERT_NE(vblank, NULL);
880 tdm_client_vblank_destroy(vblank);
884 TEST_P(TDMClient, ClientVblankDestroyNullObject)
886 tdm_client_vblank_destroy(NULL);
889 /* tdm_client_vblank_set_name */
890 TEST_P(TDMClient, ClientVblankSetName)
892 ASSERT_EQ(PrepareClient(), true);
893 ASSERT_EQ(PrepareOutput(), true);
894 ASSERT_EQ(PrepareVblank(), true);
896 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
899 TEST_P(TDMClient, ClientVblankSetNameTwice)
901 ASSERT_EQ(PrepareClient(), true);
902 ASSERT_EQ(PrepareOutput(), true);
903 ASSERT_EQ(PrepareVblank(), true);
905 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
906 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
909 TEST_P(TDMClient, ClientVblankSetNameNullObject)
911 ASSERT_EQ(tdm_client_vblank_set_name(NULL, TDM_UT_VBLANK_NAME), TDM_ERROR_INVALID_PARAMETER);
914 /* tdm_client_vblank_set_sync */
915 TEST_P(TDMClient, ClientVblankSetSync)
917 ASSERT_EQ(PrepareClient(), true);
918 ASSERT_EQ(PrepareOutput(), true);
919 ASSERT_EQ(PrepareVblank(), true);
921 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
924 TEST_P(TDMClient, ClientVblankSetSyncTwice)
926 ASSERT_EQ(PrepareClient(), true);
927 ASSERT_EQ(PrepareOutput(), true);
928 ASSERT_EQ(PrepareVblank(), true);
930 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
931 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
934 TEST_P(TDMClient, ClientVblankSetSyncNullObject)
936 ASSERT_EQ(tdm_client_vblank_set_sync(NULL, 1), TDM_ERROR_INVALID_PARAMETER);
939 /* tdm_client_vblank_set_fps */
940 TEST_P(TDMClient, ClientVblankSetFps)
942 ASSERT_EQ(PrepareClient(), true);
943 ASSERT_EQ(PrepareOutput(), true);
944 ASSERT_EQ(PrepareVblank(), true);
946 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
949 TEST_P(TDMClient, ClientVblankSetFpsTwice)
951 ASSERT_EQ(PrepareClient(), true);
952 ASSERT_EQ(PrepareOutput(), true);
953 ASSERT_EQ(PrepareVblank(), true);
955 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
956 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
959 TEST_P(TDMClient, ClientVblankSetFpsNullObject)
961 ASSERT_EQ(tdm_client_vblank_set_fps(NULL, 30), TDM_ERROR_INVALID_PARAMETER);
964 /* tdm_client_vblank_set_offset */
965 TEST_P(TDMClient, ClientVblankSetOffset)
967 ASSERT_EQ(PrepareClient(), true);
968 ASSERT_EQ(PrepareOutput(), true);
969 ASSERT_EQ(PrepareVblank(), true);
971 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
974 TEST_P(TDMClient, ClientVblankSetOffsetTwice)
976 ASSERT_EQ(PrepareClient(), true);
977 ASSERT_EQ(PrepareOutput(), true);
978 ASSERT_EQ(PrepareVblank(), true);
980 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
981 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
984 TEST_P(TDMClient, ClientVblankSetOffsetNullObject)
986 ASSERT_EQ(tdm_client_vblank_set_offset(NULL, 10), TDM_ERROR_INVALID_PARAMETER);
989 /* tdm_client_vblank_set_enable_fake */
990 TEST_P(TDMClient, ClientVblankSetEnableFake)
992 ASSERT_EQ(PrepareClient(), true);
993 ASSERT_EQ(PrepareOutput(), true);
994 ASSERT_EQ(PrepareVblank(), true);
996 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
999 TEST_P(TDMClient, ClientVblankSetEnableFakeTwice)
1001 ASSERT_EQ(PrepareClient(), true);
1002 ASSERT_EQ(PrepareOutput(), true);
1003 ASSERT_EQ(PrepareVblank(), true);
1005 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1006 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1009 TEST_P(TDMClient, ClientVblankSetEnableFakeNullObject)
1011 ASSERT_EQ(tdm_client_vblank_set_enable_fake(NULL, 1), TDM_ERROR_INVALID_PARAMETER);
1015 _tc_tdm_client_vblank_cb2(tdm_client_vblank *vblank,
1017 unsigned int sequence,
1018 unsigned int tv_sec,
1019 unsigned int tv_usec,
1022 bool *done = (bool *)user_data;
1027 /* tdm_client_vblank_wait */
1028 TEST_P(TDMClient, ClientVblankWait)
1032 ASSERT_EQ(PrepareClient(), true);
1033 ASSERT_EQ(PrepareOutput(), true);
1034 ASSERT_EQ(PrepareVblank(), true);
1037 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1039 start = tdm_helper_get_time();
1041 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1042 end = tdm_helper_get_time();
1044 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1045 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1048 TEST_P(TDMClient, ClientVblankWaitFewTime)
1050 bool done1, done2, done3;
1052 ASSERT_EQ(PrepareClient(), true);
1053 ASSERT_EQ(PrepareOutput(), true);
1054 ASSERT_EQ(PrepareVblank(), true);
1056 done1 = done2 = done3 = false;
1057 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done1), TDM_ERROR_NONE);
1058 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done2), TDM_ERROR_NONE);
1059 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done3), TDM_ERROR_NONE);
1061 start = tdm_helper_get_time();
1062 while (!done1 || !done2 || !done3)
1063 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1064 end = tdm_helper_get_time();
1066 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1067 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1071 TEST_P(TDMClient, ClientVblankWaitInterval0)
1073 ASSERT_EQ(PrepareClient(), true);
1074 ASSERT_EQ(PrepareOutput(), true);
1075 ASSERT_EQ(PrepareVblank(), true);
1077 ASSERT_EQ(tdm_client_vblank_wait(vblank, 0, _tc_tdm_client_vblank_cb2, NULL), TDM_ERROR_INVALID_PARAMETER);
1080 TEST_P(TDMClient, ClientVblankWaitInterval)
1084 ASSERT_EQ(PrepareClient(), true);
1085 ASSERT_EQ(PrepareOutput(), true);
1086 ASSERT_EQ(PrepareVblank(), true);
1089 for (int t = 1; t < 10; t++) {
1091 ASSERT_EQ(tdm_client_vblank_wait(vblank, t, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1093 start = tdm_helper_get_time();
1095 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1096 end = tdm_helper_get_time();
1098 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1099 ASSERT_GT((end - start), (vrefresh_interval * (t - 1)));
1100 ASSERT_LT((end - start), (vrefresh_interval * t + vrefresh_interval));
1105 _tc_tdm_client_vblank_cb3(tdm_client_vblank *vblank,
1107 unsigned int sequence,
1108 unsigned int tv_sec,
1109 unsigned int tv_usec,
1112 unsigned int *cur_seq = (unsigned int *)user_data;
1114 *cur_seq = sequence;
1117 TEST_P(TDMClient, ClientVblankWaitSeq)
1119 ASSERT_EQ(PrepareClient(), true);
1120 ASSERT_EQ(PrepareOutput(), true);
1121 ASSERT_EQ(PrepareVblank(), true);
1123 for (int t = 0; t < 10; t++) {
1124 unsigned int cur_seq = 0, temp = 0;
1126 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_NONE);
1127 while (cur_seq == 0)
1128 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1130 start = tdm_helper_get_time();
1131 ASSERT_EQ(tdm_client_vblank_wait_seq(vblank, cur_seq + 1, _tc_tdm_client_vblank_cb3, &temp), TDM_ERROR_NONE);
1133 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1134 end = tdm_helper_get_time();
1136 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1137 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1141 TEST_P(TDMClient, ClientVblankWaitSeqInterval)
1143 ASSERT_EQ(PrepareClient(), true);
1144 ASSERT_EQ(PrepareOutput(), true);
1145 ASSERT_EQ(PrepareVblank(), true);
1148 for (int t = 1; t < 10; t++) {
1149 unsigned int cur_seq = 0, temp = 0;
1151 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_NONE);
1152 while (cur_seq == 0)
1153 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1155 start = tdm_helper_get_time();
1156 ASSERT_EQ(tdm_client_vblank_wait_seq(vblank, cur_seq + t, _tc_tdm_client_vblank_cb3, &temp), TDM_ERROR_NONE);
1158 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1159 end = tdm_helper_get_time();
1161 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1162 ASSERT_GT((end - start), (vrefresh_interval * (t - 1)));
1163 ASSERT_LT((end - start), (vrefresh_interval * t + vrefresh_interval));
1167 TEST_P(TDMClient, ClientVblankWaitSetOffset)
1171 ASSERT_EQ(PrepareClient(), true);
1172 ASSERT_EQ(PrepareOutput(), true);
1173 ASSERT_EQ(PrepareVblank(), true);
1175 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 100), TDM_ERROR_NONE);
1178 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1180 start = tdm_helper_get_time();
1182 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1183 end = tdm_helper_get_time();
1185 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1186 ASSERT_GT((end - start), (0.1));
1187 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval + 0.1));
1190 TEST_P(TDMClient, ClientVblankWaitSetFps)
1194 unsigned int fps = 10;
1196 ASSERT_EQ(PrepareClient(), true);
1197 ASSERT_EQ(PrepareOutput(), true);
1198 ASSERT_EQ(PrepareVblank(), true);
1200 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, fps), TDM_ERROR_NONE);
1201 interval = 1.0 / (double)fps;
1204 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1206 start = tdm_helper_get_time();
1208 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1209 end = tdm_helper_get_time();
1211 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1212 ASSERT_GT((end - start), (interval - vrefresh_interval * 2));
1213 ASSERT_LT((end - start), (interval + vrefresh_interval));
1218 TEST_P(TDMVblank, VblankWaitEnableDisableGlobalFps)
1220 TDM_UT_SKIP_FLAG(has_outputs);
1222 unsigned int fps = (unsigned int)TDM_UT_INVALID_VALUE;
1223 double vrefresh_interval;
1224 unsigned int cur_seq[3];
1225 unsigned int global_fps = 5;
1226 double start, end, interval;
1228 ASSERT_EQ(TestPrepareOutput(), true);
1229 ASSERT_EQ(TestCreateVblanks3(), true);
1230 ASSERT_EQ(vblank_count, 3);
1232 ASSERT_EQ(tdm_vblank_get_fps(vblanks[0], &fps), TDM_ERROR_NONE);
1233 ASSERT_TRUE(fps >= 30 && fps != (unsigned int)TDM_UT_INVALID_VALUE);
1234 vrefresh_interval = 1.0 / (double)fps;
1236 for (int v = 0; v < 3; v++)
1237 ASSERT_EQ(tdm_vblank_set_fixed_fps(vblanks[v], 10 * (v + 1)), TDM_ERROR_NONE);
1240 tdm_vblank_enable_global_fps(1, global_fps);
1241 interval = 1.0 / (double)global_fps;
1243 for (int v = 0; v < 3; v++) {
1245 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1248 start = tdm_helper_get_time();
1249 while (cur_seq[0] == 0)
1250 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1251 end = tdm_helper_get_time();
1253 ASSERT_NE(cur_seq[1], 0);
1254 ASSERT_NE(cur_seq[2], 0);
1256 /* "+- vrefresh_interval" consider the delay of socket communication between kernel and platform */
1257 ASSERT_GT((end - start), (interval - vrefresh_interval));
1258 ASSERT_LT((end - start), (interval + vrefresh_interval));
1261 tdm_vblank_enable_global_fps(0, 0);
1263 for (int v = 0; v < 3; v++) {
1265 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1268 while (cur_seq[0] == 0)
1269 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1270 ASSERT_EQ(cur_seq[1], 0);
1271 ASSERT_EQ(cur_seq[2], 0);
1273 while (cur_seq[1] == 0)
1274 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1275 ASSERT_EQ(cur_seq[2], 0);
1278 TEST_P(TDMVblank, VblankWaitIgnoreGlobalFps)
1280 TDM_UT_SKIP_FLAG(has_outputs);
1282 unsigned int fps = (unsigned int)TDM_UT_INVALID_VALUE;
1283 unsigned int cur_seq[3];
1284 unsigned int global_fps = 5;
1285 double start, end, interval;
1287 ASSERT_EQ(TestPrepareOutput(), true);
1288 ASSERT_EQ(TestCreateVblanks3(), true);
1289 ASSERT_EQ(vblank_count, 3);
1291 ASSERT_EQ(tdm_vblank_get_fps(vblanks[0], &fps), TDM_ERROR_NONE);
1292 ASSERT_TRUE(fps >= 30 && fps != (unsigned int)TDM_UT_INVALID_VALUE);
1293 interval = 1.0 / (double)fps;
1295 /* 2nd vblank will ignore the global fps. */
1296 ASSERT_EQ(tdm_vblank_ignore_global_fps(vblanks[1], 1), TDM_ERROR_NONE);
1298 tdm_vblank_enable_global_fps(1, global_fps);
1300 for (int v = 0; v < 3; v++) {
1302 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1305 start = tdm_helper_get_time();
1306 while (cur_seq[1] == 0)
1307 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1308 end = tdm_helper_get_time();
1310 ASSERT_EQ(cur_seq[0], 0);
1311 ASSERT_EQ(cur_seq[2], 0);
1313 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1314 ASSERT_LT((end - start), (interval + interval));
1316 while (cur_seq[0] == 0)
1317 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1318 ASSERT_NE(cur_seq[2], 0);
1323 TEST_P(TDMClient, ClientVblankWaitNullObject)
1325 unsigned int cur_seq = 0;
1327 ASSERT_EQ(tdm_client_vblank_wait(NULL, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_INVALID_PARAMETER);
1330 TEST_P(TDMClient, ClientVblankWaitNullOther)
1332 ASSERT_EQ(PrepareClient(), true);
1333 ASSERT_EQ(PrepareOutput(), true);
1334 ASSERT_EQ(PrepareVblank(), true);
1336 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
1339 TEST_P(TDMClient, ClientVblankWaitDpmsOff)
1341 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
1343 ASSERT_EQ(PrepareClient(), true);
1344 ASSERT_EQ(PrepareOutput(), true);
1345 ASSERT_EQ(PrepareVblank(), true);
1347 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
1348 while (dpms != TDM_OUTPUT_DPMS_OFF)
1349 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1350 ASSERT_EQ(dpms, TDM_OUTPUT_DPMS_OFF);
1352 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, NULL), TDM_ERROR_DPMS_OFF);
1354 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
1355 while (dpms != TDM_OUTPUT_DPMS_ON)
1356 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1359 TEST_P(TDMClient, ClientVblankWaitSetEnableFakeDpmsOff)
1361 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
1364 ASSERT_EQ(PrepareClient(), true);
1365 ASSERT_EQ(PrepareOutput(), true);
1366 ASSERT_EQ(PrepareVblank(), true);
1368 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
1369 while (dpms != TDM_OUTPUT_DPMS_OFF)
1370 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1372 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1375 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1378 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1380 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
1381 while (dpms != TDM_OUTPUT_DPMS_ON)
1382 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1385 /* tdm_client_vblank_wait */
1386 TEST_P(TDMClient, ClientVblankIsWaiting)
1389 unsigned int waiting;
1391 ASSERT_EQ(PrepareClient(), true);
1392 ASSERT_EQ(PrepareOutput(), true);
1393 ASSERT_EQ(PrepareVblank(), true);
1396 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1398 waiting = tdm_client_vblank_is_waiting(vblank);
1399 ASSERT_EQ(waiting, 1);
1401 start = tdm_helper_get_time();
1403 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1404 end = tdm_helper_get_time();
1406 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1407 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1409 waiting = tdm_client_vblank_is_waiting(vblank);
1410 ASSERT_EQ(waiting, 0);
1413 /* tdm_client_vblank_wait */
1414 TEST_P(TDMClient, ClientVblankIsWaitingNullObject)
1416 unsigned int waiting = tdm_client_vblank_is_waiting(NULL);
1417 ASSERT_EQ(waiting, 0);
1420 TEST_P(TDMClient, ClientCreateVOutput)
1423 int virtual_conf = 0;
1424 const char name[TDM_NAME_LEN] = "Virtual Output";
1426 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1427 if (virtual_conf == 0) {
1428 ASSERT_EQ(virtual_conf, 0);
1432 ASSERT_EQ(PrepareClient(), true);
1434 voutput = tdm_client_create_voutput(client, name, &ret);
1435 ASSERT_EQ(ret, TDM_ERROR_NONE);
1436 ASSERT_NE(voutput, NULL);
1438 tdm_client_voutput_destroy(voutput);
1441 class TDMVirtualOutput : public ::testing::Test
1444 TDMVirtualOutput() {};
1445 ~TDMVirtualOutput() {};
1447 static void SetUpTestCase();
1448 static void TearDownTestCase();
1449 static bool PrepareVOutput(void);
1452 static tdm_client *client;
1453 static tdm_client_voutput *voutput;
1454 const int MODE_COUNT = 2;
1457 static pid_t server_pid;
1459 /* 0: read, 1: write */
1460 static int pipe_parent[2];
1461 static int pipe_child[2];
1463 static void ServerFork(void);
1464 static void ServerKill(void);
1467 pid_t TDMVirtualOutput::server_pid = -1;
1468 int TDMVirtualOutput::pipe_parent[2] = {-1, -1};
1469 int TDMVirtualOutput::pipe_child[2] = {-1, -1};
1470 tdm_client* TDMVirtualOutput::client = nullptr;
1471 tdm_client_voutput* TDMVirtualOutput::voutput = nullptr;
1473 void TDMVirtualOutput::ServerKill(void)
1475 if (pipe_child[0] >= 0)
1476 close(pipe_child[0]);
1477 if (pipe_child[1] >= 0) {
1478 if (server_pid > 0) {
1479 bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER);
1481 if (waitpid(server_pid, NULL, 0) == server_pid)
1482 TDM_INFO("*** server terminated ***");
1484 TDM_ERR("*** failed to terminate server ***");
1486 if (kill(server_pid, 9) < 0)
1487 TDM_ERR("*** failed to kill server ***");
1490 close(pipe_child[1]);
1493 if (pipe_parent[0] >= 0)
1494 close(pipe_parent[0]);
1495 if (pipe_parent[1] >= 0)
1496 close(pipe_parent[1]);
1499 pipe_parent[0] = pipe_parent[1] = -1;
1500 pipe_child[0] = pipe_child[1] = -1;
1503 void TDMVirtualOutput::ServerFork(void)
1508 server_pid = _tc_tdm_client_server_fork(pipe_parent, pipe_child);
1509 ASSERT_GT(server_pid, 0);
1512 void TDMVirtualOutput::SetUpTestCase(void)
1514 setenv("XDG_RUNTIME_DIR", "/run", 1);
1515 setenv("TBM_DISPLAY_SERVER", "1", 1);
1517 if (server_pid == -1)
1520 ASSERT_EQ(PrepareVOutput(), true);
1523 void TDMVirtualOutput::TearDownTestCase(void)
1525 // TDM_UT_WAIT("check & press");
1528 tdm_client_voutput_destroy(voutput);
1531 tdm_client_destroy(client);
1535 unsetenv("XDG_RUNTIME_DIR");
1536 unsetenv("TBM_DISPLAY_SERVER");
1539 bool TDMVirtualOutput::PrepareVOutput(void)
1542 int virtual_conf = 0;
1543 const char name[TDM_NAME_LEN] = "Virtual Output";
1545 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1546 if (virtual_conf == 0) return true;
1548 client = tdm_client_create(&ret);
1549 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
1550 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
1552 voutput = tdm_client_create_voutput(client, name, &ret);
1553 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
1554 TDM_UT_RETURN_FALSE_IF_FAIL(voutput != NULL);
1556 // TDM_UT_WAIT("check & press");
1562 _tc_tdm_client_virutual_make_available_mode(tdm_client_output_mode *modes, int count)
1566 for (i = 0; i < count; i++) {
1567 modes[i].clock = 25200;
1568 modes[i].hdisplay = 640;
1569 modes[i].hsync_start = 656;
1570 modes[i].hsync_end = 752;
1571 modes[i].htotal = 800;
1573 modes[i].vdisplay = 480;
1574 modes[i].vsync_start = 490;
1575 modes[i].vsync_end = 492;
1576 modes[i].vtotal = 525;
1578 modes[i].vrefresh = 30;
1581 snprintf(modes[i].name, TDM_NAME_LEN, "%dx%d_%d", modes[i].hdisplay, modes[i].vdisplay, i);
1585 TEST_F(TDMVirtualOutput, SetAvailableModes)
1588 tdm_client_output_mode modes[this->MODE_COUNT];
1589 int count = this->MODE_COUNT;
1592 if (this->voutput == NULL) {
1593 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1594 ASSERT_EQ(virtual_conf, 0);
1597 _tc_tdm_client_virutual_make_available_mode(modes, count);
1599 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1600 ASSERT_EQ(ret, TDM_ERROR_NONE);
1603 TEST_F(TDMVirtualOutput, FailTestSetAvailableModes)
1606 tdm_client_output_mode modes[this->MODE_COUNT];
1607 int count = this->MODE_COUNT;
1610 if (this->voutput == NULL) {
1611 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1612 ASSERT_EQ(virtual_conf, 0);
1616 ret = tdm_client_voutput_set_available_modes(NULL, modes, count);
1617 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1619 ret = tdm_client_voutput_set_available_modes(this->voutput, NULL, count);
1620 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1623 TEST_F(TDMVirtualOutput, SetPhysicalSize)
1626 unsigned int mmWidth = 1234, mmHeight = 1234;
1629 if (this->voutput == NULL) {
1630 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1631 ASSERT_EQ(virtual_conf, 0);
1635 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1636 ASSERT_EQ(ret, TDM_ERROR_NONE);
1639 TEST_F(TDMVirtualOutput, FailTestSetPhysicalSize)
1642 unsigned int invalid_mmWidth = 0, invalid_mmHeight = 0;
1645 if (this->voutput == NULL) {
1646 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1647 ASSERT_EQ(virtual_conf, 0);
1651 ret = tdm_client_voutput_set_physical_size(this->voutput, invalid_mmWidth, invalid_mmHeight);
1652 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1656 _tc_tdm_client_voutput_commit_handler(tdm_client_voutput *voutput, tbm_surface_h buffer, void *user_data)
1659 flag = (int *)user_data;
1663 TEST_F(TDMVirtualOutput, AddCommitHandler)
1666 int flag_callback_called = 0;
1669 if (this->voutput == NULL) {
1670 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1671 ASSERT_EQ(virtual_conf, 0);
1675 ret = tdm_client_voutput_add_commit_handler(this->voutput,
1676 _tc_tdm_client_voutput_commit_handler,
1677 &flag_callback_called);
1678 ASSERT_EQ(ret, TDM_ERROR_NONE);
1679 // ASSERT_EQ(flag_callback_called, 1);
1681 tdm_client_voutput_remove_commit_handler(this->voutput,
1682 _tc_tdm_client_voutput_commit_handler,
1683 &flag_callback_called);
1686 TEST_F(TDMVirtualOutput, CommitDone)
1691 if (this->voutput == NULL) {
1692 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1693 ASSERT_EQ(virtual_conf, 0);
1697 ret = tdm_client_voutput_commit_done(this->voutput);
1698 ASSERT_EQ(ret, TDM_ERROR_NONE);
1701 TEST_F(TDMVirtualOutput, GetClientOutput)
1704 tdm_client_output *output;
1707 if (this->voutput == NULL) {
1708 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1709 ASSERT_EQ(virtual_conf, 0);
1713 output = tdm_client_voutput_get_client_output(this->voutput, &ret);
1714 ASSERT_EQ(ret, TDM_ERROR_NONE);
1715 ASSERT_NE(output, NULL);
1718 TEST_F(TDMVirtualOutput, Connect)
1721 unsigned int mmWidth = 300, mmHeight = 150;
1722 tdm_client_output_mode modes[this->MODE_COUNT];
1723 int count = this->MODE_COUNT;
1726 if (this->voutput == NULL) {
1727 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1728 ASSERT_EQ(virtual_conf, 0);
1732 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1733 ASSERT_EQ(ret, TDM_ERROR_NONE);
1735 _tc_tdm_client_virutual_make_available_mode(modes, count);
1736 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1737 ASSERT_EQ(ret, TDM_ERROR_NONE);
1739 ret = tdm_client_voutput_connect(this->voutput);
1740 ASSERT_EQ(ret, TDM_ERROR_NONE);
1742 tdm_client_handle_events_timeout(this->client, 0);
1745 TEST_F(TDMVirtualOutput, Disconnect)
1750 if (this->voutput == NULL) {
1751 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1752 ASSERT_EQ(virtual_conf, 0);
1756 // TDM_UT_WAIT("check & press");
1758 ret = tdm_client_voutput_disconnect(this->voutput);
1759 ASSERT_EQ(ret, TDM_ERROR_NONE);
1761 tdm_client_handle_events_timeout(this->client, 0);
1765 TEST_F(TDMVirtualOutput, SetMode)
1768 unsigned int mmWidth = 300, mmHeight = 150;
1769 tdm_client_output_mode modes[this->MODE_COUNT];
1770 int count = this->MODE_COUNT;
1773 if (this->voutput == NULL) {
1774 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1775 ASSERT_EQ(virtual_conf, 0);
1779 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1780 ASSERT_EQ(ret, TDM_ERROR_NONE);
1782 _tc_tdm_client_virutual_make_available_mode(modes, count);
1783 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1784 ASSERT_EQ(ret, TDM_ERROR_NONE);
1786 ret = tdm_client_voutput_connect(this->voutput);
1787 ASSERT_EQ(ret, TDM_ERROR_NONE);
1789 tdm_client_handle_events_timeout(this->client, 100);
1791 ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, count - 1), TDM_ERROR_NONE);
1793 tdm_client_handle_events_timeout(this->client, 100);
1795 ret = tdm_client_voutput_disconnect(this->voutput);
1796 ASSERT_EQ(ret, TDM_ERROR_NONE);
1798 tdm_client_handle_events_timeout(this->client, 0);
1801 TEST_F(TDMVirtualOutput, SetModeNullObject)
1804 unsigned int mmWidth = 300, mmHeight = 150;
1805 tdm_client_output_mode modes[this->MODE_COUNT];
1806 int count = this->MODE_COUNT;
1809 if (this->voutput == NULL) {
1810 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1811 ASSERT_EQ(virtual_conf, 0);
1815 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1816 ASSERT_EQ(ret, TDM_ERROR_NONE);
1818 _tc_tdm_client_virutual_make_available_mode(modes, count);
1819 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1820 ASSERT_EQ(ret, TDM_ERROR_NONE);
1822 ret = tdm_client_voutput_connect(this->voutput);
1823 ASSERT_EQ(ret, TDM_ERROR_NONE);
1825 tdm_client_handle_events_timeout(this->client, 100);
1827 ASSERT_EQ(tdm_client_voutput_set_mode(NULL, 0), TDM_ERROR_INVALID_PARAMETER);
1829 ret = tdm_client_voutput_disconnect(this->voutput);
1830 ASSERT_EQ(ret, TDM_ERROR_NONE);
1832 tdm_client_handle_events_timeout(this->client, 0);
1835 TEST_F(TDMVirtualOutput, SetModeInvalidIndex)
1838 unsigned int mmWidth = 300, mmHeight = 150;
1839 tdm_client_output_mode modes[this->MODE_COUNT];
1840 int count = this->MODE_COUNT;
1843 if (this->voutput == NULL) {
1844 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1845 ASSERT_EQ(virtual_conf, 0);
1849 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1850 ASSERT_EQ(ret, TDM_ERROR_NONE);
1852 _tc_tdm_client_virutual_make_available_mode(modes, count);
1853 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1854 ASSERT_EQ(ret, TDM_ERROR_NONE);
1856 ret = tdm_client_voutput_connect(this->voutput);
1857 ASSERT_EQ(ret, TDM_ERROR_NONE);
1859 tdm_client_handle_events_timeout(this->client, 100);
1861 ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, -1), TDM_ERROR_INVALID_PARAMETER);
1863 ret = tdm_client_voutput_disconnect(this->voutput);
1864 ASSERT_EQ(ret, TDM_ERROR_NONE);
1866 tdm_client_handle_events_timeout(this->client, 0);
1869 #ifdef TDM_UT_TEST_WITH_PARAMS
1870 INSTANTIATE_TEST_CASE_P(TDMClientParams,
1872 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
1874 INSTANTIATE_TEST_CASE_P(TDMClientParams,
1876 Values(TDM_DEFAULT_MODULE));