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()
148 vrefresh_interval = start = end = 0.0;
151 void TDMClient::SetUp(void)
155 if (server_pid == -1)
159 void TDMClient::TearDown(void)
162 tdm_client_vblank_destroy(vblank);
164 tdm_client_destroy(client);
169 bool TDMClient::PrepareClient(void)
172 client = tdm_client_create(&ret);
173 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
174 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
179 bool TDMClient::PrepareOutput(void)
183 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
185 output = tdm_client_get_output(client, NULL, &ret);
186 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
187 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
192 bool TDMClient::PrepareVblank(void)
195 unsigned int refresh;
197 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
199 vblank = tdm_client_output_create_vblank(output, &ret);
200 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
201 TDM_UT_RETURN_FALSE_IF_FAIL(vblank != NULL);
203 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_client_output_get_refresh_rate(output, &refresh) == TDM_ERROR_NONE);
204 TDM_UT_RETURN_FALSE_IF_FAIL(refresh > 0);
206 vrefresh_interval = 1.0 / (double)refresh;
207 TDM_UT_RETURN_FALSE_IF_FAIL(vrefresh_interval > 0);
218 if (ch == '\n' || ch == '\r')
223 while (c != '\n' && c != EOF)
230 _tc_tdm_pipe_read_msg(int fd)
236 len = read(fd, &msg, sizeof msg);
237 } while (len < 0 && errno == EINTR);
240 msg = TDM_UT_PIPE_MSG_NONE;
246 _tc_tdm_pipe_write_msg(int fd, int reply_fd, int msg)
248 ssize_t len = write(fd, &msg, sizeof msg);
249 TDM_UT_RETURN_FALSE_IF_FAIL(len == sizeof msg);
252 int reply = _tc_tdm_pipe_read_msg(reply_fd);
253 TDM_UT_RETURN_FALSE_IF_FAIL(reply == TDM_UT_PIPE_MSG_REPLY);
260 _tc_tdm_server_set_output_dpms(tdm_display *dpy, int msg)
264 tdm_output_dpms dpms;
266 output = tdm_display_find_output(dpy, "primary", &ret);
267 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
268 TDM_UT_RETURN_FALSE_IF_FAIL(output != NULL);
270 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_dpms(output, &dpms) == TDM_ERROR_NONE);
273 case TDM_UT_PIPE_MSG_DPMS_ON:
274 if (dpms != TDM_OUTPUT_DPMS_ON)
275 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON) == TDM_ERROR_NONE);
277 case TDM_UT_PIPE_MSG_DPMS_OFF:
278 if (dpms != TDM_OUTPUT_DPMS_OFF)
279 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF) == TDM_ERROR_NONE);
289 _tc_tdm_server_run(int *pipe_parent, int *pipe_child)
291 tdm_display *dpy = NULL;
293 struct pollfd fds[2];
295 int output_count = 0;
297 dpy = tdm_display_init(&ret);
298 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
299 TDM_UT_GOTO_IF_FAIL(dpy != NULL, failed);
301 TDM_UT_GOTO_IF_FAIL(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE, failed);
303 for (int o = 0; o < output_count; o++) {
304 tdm_output *output = tdm_display_get_output(dpy, o, &ret);
305 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, failed);
306 TDM_UT_GOTO_IF_FAIL(output != NULL, failed);
308 if (!tc_tdm_output_is_connected(output))
311 TDM_UT_GOTO_IF_FAIL(tc_tdm_output_prepare(dpy, output, true) == true, failed);
314 TDM_UT_GOTO_IF_FAIL(_tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_SERVER_READY) == true, done);
316 TDM_INFO("*** server ready ***");
318 ret = tdm_display_get_fd(dpy, &tdm_fd);
319 TDM_UT_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, done);
321 fds[0].events = POLLIN;
325 fds[1].events = POLLIN;
326 fds[1].fd = pipe_child[0];
330 /* make sure all events are flushed to clients before falling in sleep */
331 tdm_display_flush(dpy);
333 err = poll(fds, 2, -1);
335 if (errno == EINTR || errno == EAGAIN) {
338 TDM_ERR("server-process: poll failed: %m\n");
343 if (fds[0].revents & POLLIN)
344 ret = tc_tdm_display_handle_events(dpy);
346 if (fds[1].revents & POLLIN) {
347 int msg = _tc_tdm_pipe_read_msg(pipe_child[0]);
348 _tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_REPLY);
351 case TDM_UT_PIPE_MSG_DPMS_ON:
352 case TDM_UT_PIPE_MSG_DPMS_OFF:
353 _tc_tdm_server_set_output_dpms(dpy, msg);
355 case TDM_UT_PIPE_MSG_TERMINATE_SERVER:
365 tdm_display_deinit(dpy);
369 TDM_UT_GOTO_IF_FAIL(_tc_tdm_pipe_write_msg(pipe_parent[1], -1, TDM_UT_PIPE_MSG_SERVER_FAILED) == true, done);
370 TDM_INFO("*** server failed ***");
373 tdm_display_deinit(dpy);
378 static void _tc_tdm_client_sig_handler(int sig)
380 TDM_UT_ERR("got signal: %d", sig);
381 kill(TDMClient::server_pid, 9);
386 _tc_tdm_client_server_fork(int *pipe_parent, int *pipe_child)
391 TDM_UT_GOTO_IF_FAIL(pipe(pipe_parent) == 0, failed);
392 TDM_UT_GOTO_IF_FAIL(pipe(pipe_child) == 0, failed);
394 signal(SIGCHLD, SIG_IGN);
395 signal(SIGSEGV, _tc_tdm_client_sig_handler);
397 prctl(PR_SET_PDEATHSIG, SIGHUP);
400 TDM_UT_GOTO_IF_FAIL(pid >= 0, failed);
403 _tc_tdm_server_run(pipe_parent, pipe_child);
404 close(pipe_child[0]);
405 close(pipe_child[1]);
406 close(pipe_parent[0]);
407 close(pipe_parent[1]);
409 #ifdef TIZEN_TEST_GCOV
416 msg = _tc_tdm_pipe_read_msg(pipe_parent[0]);
417 TDM_UT_GOTO_IF_FAIL(msg == TDM_UT_PIPE_MSG_SERVER_READY, failed);
419 TDM_INFO("*** server fork done ***");
427 TEST_P(TDMClient, ClientCreate)
431 client = tdm_client_create(&ret);
432 ASSERT_EQ(ret, TDM_ERROR_NONE);
433 ASSERT_NE(client, NULL);
436 TEST_P(TDMClient, ClientCreateNullOther)
438 client = tdm_client_create(NULL);
439 ASSERT_NE(client, NULL);
442 TEST_P(TDMClient, ClientDestroy)
446 client = tdm_client_create(&ret);
447 ASSERT_EQ(ret, TDM_ERROR_NONE);
448 ASSERT_NE(client, NULL);
450 tdm_client_destroy(client);
454 TEST_P(TDMClient, ClientNullObject)
456 tdm_client_destroy(NULL);
459 /* tdm_client_get_fd */
460 TEST_P(TDMClient, ClientGetFd)
462 int fd = TDM_UT_INVALID_VALUE;
464 ASSERT_EQ(PrepareClient(), true);
466 ASSERT_EQ(tdm_client_get_fd(client, &fd), TDM_ERROR_NONE);
470 TEST_P(TDMClient, ClientGetFdNullObject)
472 int fd = TDM_UT_INVALID_VALUE;
473 ASSERT_EQ(tdm_client_get_fd(NULL, &fd), TDM_ERROR_INVALID_PARAMETER);
474 ASSERT_EQ(fd, TDM_UT_INVALID_VALUE);
477 TEST_P(TDMClient, ClientGetFdNullOther)
479 ASSERT_EQ(PrepareClient(), true);
481 ASSERT_EQ(tdm_client_get_fd(client, NULL), TDM_ERROR_INVALID_PARAMETER);
485 _tc_tdm_client_vblank_cb(unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
487 bool *done = (bool *)user_data;
492 /* tdm_client_handle_events_timeout */
493 TEST_P(TDMClient, ClientHandleEvent)
497 ASSERT_EQ(PrepareClient(), true);
499 ASSERT_EQ(tdm_client_wait_vblank(client, NULL, 1, 1, 0, _tc_tdm_client_vblank_cb, &done), TDM_ERROR_NONE);
500 ASSERT_EQ(done, false);
503 ASSERT_EQ(tdm_client_handle_events(client), TDM_ERROR_NONE);
506 TEST_P(TDMClient, ClientHandleEventNullObject)
508 ASSERT_EQ(tdm_client_handle_events(NULL), TDM_ERROR_INVALID_PARAMETER);
511 /* tdm_client_wait_vblank, deprecated */
512 TEST_P(TDMClient, ClientWaitVblank)
516 ASSERT_EQ(PrepareClient(), true);
518 ASSERT_EQ(tdm_client_wait_vblank(client, NULL, 1, 1, 0, _tc_tdm_client_vblank_cb, &done), TDM_ERROR_NONE);
519 ASSERT_EQ(done, false);
522 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
525 /* tdm_client_get_output */
526 TEST_P(TDMClient, ClientGetOutput)
530 ASSERT_EQ(PrepareClient(), true);
532 output = tdm_client_get_output(client, NULL, &ret);
533 ASSERT_EQ(ret, TDM_ERROR_NONE);
534 ASSERT_NE(output, NULL);
537 TEST_P(TDMClient, ClientGetOutputPrimary)
541 ASSERT_EQ(PrepareClient(), true);
543 output = tdm_client_get_output(client, (char*)"primary", &ret);
544 ASSERT_EQ(ret, TDM_ERROR_NONE);
545 ASSERT_NE(output, NULL);
548 TEST_P(TDMClient, ClientGetOutputDefault)
552 ASSERT_EQ(PrepareClient(), true);
554 output = tdm_client_get_output(client, (char*)"default", &ret);
555 ASSERT_EQ(ret, TDM_ERROR_NONE);
556 ASSERT_NE(output, NULL);
559 TEST_P(TDMClient, ClientGetOutputInvalidName)
563 ASSERT_EQ(PrepareClient(), true);
565 output = tdm_client_get_output(client, (char*)"invalid", &ret);
566 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
567 ASSERT_EQ(output, NULL);
570 TEST_P(TDMClient, ClientGetOutputNullObject)
574 output = tdm_client_get_output(NULL, NULL, &ret);
575 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
576 ASSERT_EQ(output, NULL);
579 TEST_P(TDMClient, ClientGetOutputNullOther)
581 ASSERT_EQ(PrepareClient(), true);
583 output = tdm_client_get_output(client, NULL, NULL);
584 ASSERT_NE(output, NULL);
588 _tc_tdm_client_output_change_dpms_cb(tdm_client_output *output,
589 tdm_output_change_type type,
593 bool *done = (bool *)user_data;
596 case TDM_OUTPUT_CHANGE_DPMS:
605 /* tdm_client_output_add_change_handler */
606 TEST_P(TDMClient, ClientOutputAddChangeHandler)
609 tdm_output_dpms dpms;
611 ASSERT_EQ(PrepareClient(), true);
612 ASSERT_EQ(PrepareOutput(), true);
614 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, &done), TDM_ERROR_NONE);
615 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
618 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
620 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
621 ASSERT_EQ(dpms, TDM_OUTPUT_DPMS_OFF);
623 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
624 while (dpms != TDM_OUTPUT_DPMS_ON) {
625 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
626 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
630 TEST_P(TDMClient, ClientOutputAddChangeHandlerTwice)
632 ASSERT_EQ(PrepareClient(), true);
633 ASSERT_EQ(PrepareOutput(), true);
635 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_NONE);
636 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_BAD_REQUEST);
639 TEST_P(TDMClient, ClientOutputAddChangeHandlerNullObject)
641 ASSERT_EQ(tdm_client_output_add_change_handler(NULL, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
644 TEST_P(TDMClient, ClientOutputAddChangeHandlerNullOther)
646 ASSERT_EQ(PrepareClient(), true);
647 ASSERT_EQ(PrepareOutput(), true);
649 ASSERT_EQ(tdm_client_output_add_change_handler(output, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
652 /* tdm_client_output_remove_change_handler */
653 TEST_P(TDMClient, ClientOutputRemoveChangeHandler)
655 ASSERT_EQ(PrepareClient(), true);
656 ASSERT_EQ(PrepareOutput(), true);
658 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL), TDM_ERROR_NONE);
659 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL);
662 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerDifferentData)
664 bool done = (bool)TDM_UT_INVALID_VALUE;
666 ASSERT_EQ(PrepareClient(), true);
667 ASSERT_EQ(PrepareOutput(), true);
669 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb, &done), TDM_ERROR_NONE);
670 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb, NULL);
674 _tc_tdm_client_output_change_dpms_cb2(tdm_client_output *output,
675 tdm_output_change_type type,
680 case TDM_OUTPUT_CHANGE_DPMS:
681 tdm_client_output_remove_change_handler(output, _tc_tdm_client_output_change_dpms_cb2, user_data);
688 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerInHandler)
690 tdm_output_dpms dpms = TDM_OUTPUT_DPMS_ON;
692 ASSERT_EQ(PrepareClient(), true);
693 ASSERT_EQ(PrepareOutput(), true);
695 ASSERT_EQ(tdm_client_output_add_change_handler(output, _tc_tdm_client_output_change_dpms_cb2, NULL), TDM_ERROR_NONE);
696 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
697 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
698 while (dpms != TDM_OUTPUT_DPMS_OFF) {
699 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
700 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
703 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
704 while (dpms != TDM_OUTPUT_DPMS_ON)
705 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
708 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerNullObject)
710 tdm_client_output_remove_change_handler(NULL, _tc_tdm_client_output_change_dpms_cb, NULL);
713 TEST_P(TDMClient, ClientOutputRemoveChangeHandlerNullOther)
715 ASSERT_EQ(PrepareClient(), true);
716 ASSERT_EQ(PrepareOutput(), true);
718 tdm_client_output_remove_change_handler(output, NULL, NULL);
721 /* tdm_client_output_get_refresh_rate */
722 TEST_P(TDMClient, ClientOutputGetRefreshRate)
724 unsigned int refresh = 0;
726 ASSERT_EQ(PrepareClient(), true);
727 ASSERT_EQ(PrepareOutput(), true);
729 ASSERT_EQ(tdm_client_output_get_refresh_rate(output, &refresh), TDM_ERROR_NONE);
730 ASSERT_GT(refresh, 0);
733 TEST_P(TDMClient, ClientOutputGetRefreshRateNullObject)
735 unsigned int refresh = (unsigned int)TDM_UT_INVALID_VALUE;
737 ASSERT_EQ(tdm_client_output_get_refresh_rate(NULL, &refresh), TDM_ERROR_INVALID_PARAMETER);
738 ASSERT_EQ(refresh, (unsigned int)TDM_UT_INVALID_VALUE);
741 TEST_P(TDMClient, ClientOutputGetRefreshRateNullOther)
743 ASSERT_EQ(PrepareClient(), true);
744 ASSERT_EQ(PrepareOutput(), true);
746 ASSERT_EQ(tdm_client_output_get_refresh_rate(output, NULL), TDM_ERROR_INVALID_PARAMETER);
749 /* tdm_client_output_get_mode */
750 TEST_P(TDMClient, ClientOutputGetMode)
752 unsigned int width = 0, height = 0;
754 ASSERT_EQ(PrepareClient(), true);
755 ASSERT_EQ(PrepareOutput(), true);
757 ASSERT_EQ(tdm_client_output_get_mode(output, &width, &height), TDM_ERROR_NONE);
759 ASSERT_GT(height, 0);
762 TEST_P(TDMClient, ClientOutputGetModeNullObject)
764 unsigned int width = (unsigned int)TDM_UT_INVALID_VALUE;
765 unsigned int height = (unsigned int)TDM_UT_INVALID_VALUE;
767 ASSERT_EQ(tdm_client_output_get_mode(NULL, &width, &height), TDM_ERROR_INVALID_PARAMETER);
768 ASSERT_EQ(width, (unsigned int)TDM_UT_INVALID_VALUE);
769 ASSERT_EQ(height, (unsigned int)TDM_UT_INVALID_VALUE);
772 TEST_P(TDMClient, ClientOutputGetModeNullOther)
774 ASSERT_EQ(PrepareClient(), true);
775 ASSERT_EQ(PrepareOutput(), true);
777 ASSERT_EQ(tdm_client_output_get_mode(output, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
780 /* tdm_client_output_get_conn_status */
781 TEST_P(TDMClient, ClientOutputGetConnStatus)
783 tdm_output_conn_status status = (tdm_output_conn_status)TDM_UT_INVALID_VALUE;
785 ASSERT_EQ(PrepareClient(), true);
786 ASSERT_EQ(PrepareOutput(), true);
788 ASSERT_EQ(tdm_client_output_get_conn_status(output, &status), TDM_ERROR_NONE);
789 ASSERT_NE(status, (tdm_output_conn_status)TDM_UT_INVALID_VALUE);
792 TEST_P(TDMClient, ClientOutputGetConnStatusNullObject)
794 tdm_output_conn_status status = (tdm_output_conn_status)TDM_UT_INVALID_VALUE;
796 ASSERT_EQ(tdm_client_output_get_conn_status(NULL, &status), TDM_ERROR_INVALID_PARAMETER);
797 ASSERT_EQ(status, (tdm_output_conn_status)TDM_UT_INVALID_VALUE);
800 TEST_P(TDMClient, ClientOutputGetConnStatusNullOther)
802 ASSERT_EQ(PrepareClient(), true);
803 ASSERT_EQ(PrepareOutput(), true);
805 ASSERT_EQ(tdm_client_output_get_conn_status(output, NULL), TDM_ERROR_INVALID_PARAMETER);
808 /* tdm_client_output_get_dpms */
809 TEST_P(TDMClient, ClientOutputGetDpms)
811 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
813 ASSERT_EQ(PrepareClient(), true);
814 ASSERT_EQ(PrepareOutput(), true);
816 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
817 ASSERT_NE(dpms, (tdm_output_dpms)TDM_UT_INVALID_VALUE);
820 TEST_P(TDMClient, ClientOutputGetDpmsNullObject)
822 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
824 ASSERT_EQ(tdm_client_output_get_dpms(NULL, &dpms), TDM_ERROR_INVALID_PARAMETER);
825 ASSERT_EQ(dpms, (tdm_output_dpms)TDM_UT_INVALID_VALUE);
828 TEST_P(TDMClient, ClientOutputGetDpmsNullOther)
830 ASSERT_EQ(PrepareClient(), true);
831 ASSERT_EQ(PrepareOutput(), true);
833 ASSERT_EQ(tdm_client_output_get_dpms(output, NULL), TDM_ERROR_INVALID_PARAMETER);
836 /* tdm_client_output_create_vblank */
837 TEST_P(TDMClient, ClientOutputCreateVblank)
841 ASSERT_EQ(PrepareClient(), true);
842 ASSERT_EQ(PrepareOutput(), true);
844 vblank = tdm_client_output_create_vblank(output, &ret);
845 ASSERT_EQ(ret, TDM_ERROR_NONE);
846 ASSERT_NE(vblank, NULL);
849 TEST_P(TDMClient, ClientOutputCreateVblankNullObject)
853 vblank = tdm_client_output_create_vblank(NULL, &ret);
854 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
855 ASSERT_EQ(vblank, NULL);
858 TEST_P(TDMClient, ClientOutputCreateVblankNullOther)
860 ASSERT_EQ(PrepareClient(), true);
861 ASSERT_EQ(PrepareOutput(), true);
863 vblank = tdm_client_output_create_vblank(output, NULL);
864 ASSERT_NE(vblank, NULL);
867 /* tdm_client_vblank_destroy */
868 TEST_P(TDMClient, ClientVblankDestroy)
872 ASSERT_EQ(PrepareClient(), true);
873 ASSERT_EQ(PrepareOutput(), true);
875 vblank = tdm_client_output_create_vblank(output, &ret);
876 ASSERT_EQ(ret, TDM_ERROR_NONE);
877 ASSERT_NE(vblank, NULL);
879 tdm_client_vblank_destroy(vblank);
883 TEST_P(TDMClient, ClientVblankDestroyNullObject)
885 tdm_client_vblank_destroy(NULL);
888 /* tdm_client_vblank_set_name */
889 TEST_P(TDMClient, ClientVblankSetName)
891 ASSERT_EQ(PrepareClient(), true);
892 ASSERT_EQ(PrepareOutput(), true);
893 ASSERT_EQ(PrepareVblank(), true);
895 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
898 TEST_P(TDMClient, ClientVblankSetNameTwice)
900 ASSERT_EQ(PrepareClient(), true);
901 ASSERT_EQ(PrepareOutput(), true);
902 ASSERT_EQ(PrepareVblank(), true);
904 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
905 ASSERT_EQ(tdm_client_vblank_set_name(vblank, TDM_UT_VBLANK_NAME), TDM_ERROR_NONE);
908 TEST_P(TDMClient, ClientVblankSetNameNullObject)
910 ASSERT_EQ(tdm_client_vblank_set_name(NULL, TDM_UT_VBLANK_NAME), TDM_ERROR_INVALID_PARAMETER);
913 /* tdm_client_vblank_set_sync */
914 TEST_P(TDMClient, ClientVblankSetSync)
916 ASSERT_EQ(PrepareClient(), true);
917 ASSERT_EQ(PrepareOutput(), true);
918 ASSERT_EQ(PrepareVblank(), true);
920 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
923 TEST_P(TDMClient, ClientVblankSetSyncTwice)
925 ASSERT_EQ(PrepareClient(), true);
926 ASSERT_EQ(PrepareOutput(), true);
927 ASSERT_EQ(PrepareVblank(), true);
929 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
930 ASSERT_EQ(tdm_client_vblank_set_sync(vblank, 1), TDM_ERROR_NONE);
933 TEST_P(TDMClient, ClientVblankSetSyncNullObject)
935 ASSERT_EQ(tdm_client_vblank_set_sync(NULL, 1), TDM_ERROR_INVALID_PARAMETER);
938 /* tdm_client_vblank_set_fps */
939 TEST_P(TDMClient, ClientVblankSetFps)
941 ASSERT_EQ(PrepareClient(), true);
942 ASSERT_EQ(PrepareOutput(), true);
943 ASSERT_EQ(PrepareVblank(), true);
945 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
948 TEST_P(TDMClient, ClientVblankSetFpsTwice)
950 ASSERT_EQ(PrepareClient(), true);
951 ASSERT_EQ(PrepareOutput(), true);
952 ASSERT_EQ(PrepareVblank(), true);
954 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
955 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, 30), TDM_ERROR_NONE);
958 TEST_P(TDMClient, ClientVblankSetFpsNullObject)
960 ASSERT_EQ(tdm_client_vblank_set_fps(NULL, 30), TDM_ERROR_INVALID_PARAMETER);
963 /* tdm_client_vblank_set_offset */
964 TEST_P(TDMClient, ClientVblankSetOffset)
966 ASSERT_EQ(PrepareClient(), true);
967 ASSERT_EQ(PrepareOutput(), true);
968 ASSERT_EQ(PrepareVblank(), true);
970 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
973 TEST_P(TDMClient, ClientVblankSetOffsetTwice)
975 ASSERT_EQ(PrepareClient(), true);
976 ASSERT_EQ(PrepareOutput(), true);
977 ASSERT_EQ(PrepareVblank(), true);
979 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
980 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 10), TDM_ERROR_NONE);
983 TEST_P(TDMClient, ClientVblankSetOffsetNullObject)
985 ASSERT_EQ(tdm_client_vblank_set_offset(NULL, 10), TDM_ERROR_INVALID_PARAMETER);
988 /* tdm_client_vblank_set_enable_fake */
989 TEST_P(TDMClient, ClientVblankSetEnableFake)
991 ASSERT_EQ(PrepareClient(), true);
992 ASSERT_EQ(PrepareOutput(), true);
993 ASSERT_EQ(PrepareVblank(), true);
995 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
998 TEST_P(TDMClient, ClientVblankSetEnableFakeTwice)
1000 ASSERT_EQ(PrepareClient(), true);
1001 ASSERT_EQ(PrepareOutput(), true);
1002 ASSERT_EQ(PrepareVblank(), true);
1004 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1005 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1008 TEST_P(TDMClient, ClientVblankSetEnableFakeNullObject)
1010 ASSERT_EQ(tdm_client_vblank_set_enable_fake(NULL, 1), TDM_ERROR_INVALID_PARAMETER);
1014 _tc_tdm_client_vblank_cb2(tdm_client_vblank *vblank,
1016 unsigned int sequence,
1017 unsigned int tv_sec,
1018 unsigned int tv_usec,
1021 bool *done = (bool *)user_data;
1026 /* tdm_client_vblank_wait */
1027 TEST_P(TDMClient, ClientVblankWait)
1031 ASSERT_EQ(PrepareClient(), true);
1032 ASSERT_EQ(PrepareOutput(), true);
1033 ASSERT_EQ(PrepareVblank(), true);
1036 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1038 start = tdm_helper_get_time();
1040 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1041 end = tdm_helper_get_time();
1043 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1044 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1047 TEST_P(TDMClient, ClientVblankWaitFewTime)
1049 bool done1, done2, done3;
1051 ASSERT_EQ(PrepareClient(), true);
1052 ASSERT_EQ(PrepareOutput(), true);
1053 ASSERT_EQ(PrepareVblank(), true);
1055 done1 = done2 = done3 = false;
1056 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done1), TDM_ERROR_NONE);
1057 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done2), TDM_ERROR_NONE);
1058 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done3), TDM_ERROR_NONE);
1060 start = tdm_helper_get_time();
1061 while (!done1 || !done2 || !done3)
1062 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1063 end = tdm_helper_get_time();
1065 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1066 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1070 TEST_P(TDMClient, ClientVblankWaitInterval0)
1072 ASSERT_EQ(PrepareClient(), true);
1073 ASSERT_EQ(PrepareOutput(), true);
1074 ASSERT_EQ(PrepareVblank(), true);
1076 ASSERT_EQ(tdm_client_vblank_wait(vblank, 0, _tc_tdm_client_vblank_cb2, NULL), TDM_ERROR_INVALID_PARAMETER);
1079 TEST_P(TDMClient, ClientVblankWaitInterval)
1083 ASSERT_EQ(PrepareClient(), true);
1084 ASSERT_EQ(PrepareOutput(), true);
1085 ASSERT_EQ(PrepareVblank(), true);
1088 for (int t = 1; t < 10; t++) {
1090 ASSERT_EQ(tdm_client_vblank_wait(vblank, t, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1092 start = tdm_helper_get_time();
1094 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1095 end = tdm_helper_get_time();
1097 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1098 ASSERT_GT((end - start), (vrefresh_interval * (t - 1)));
1099 ASSERT_LT((end - start), (vrefresh_interval * t + vrefresh_interval));
1104 _tc_tdm_client_vblank_cb3(tdm_client_vblank *vblank,
1106 unsigned int sequence,
1107 unsigned int tv_sec,
1108 unsigned int tv_usec,
1111 unsigned int *cur_seq = (unsigned int *)user_data;
1113 *cur_seq = sequence;
1116 TEST_P(TDMClient, ClientVblankWaitSeq)
1118 ASSERT_EQ(PrepareClient(), true);
1119 ASSERT_EQ(PrepareOutput(), true);
1120 ASSERT_EQ(PrepareVblank(), true);
1122 for (int t = 0; t < 10; t++) {
1123 unsigned int cur_seq = 0, temp = 0;
1125 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_NONE);
1126 while (cur_seq == 0)
1127 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1129 start = tdm_helper_get_time();
1130 ASSERT_EQ(tdm_client_vblank_wait_seq(vblank, cur_seq + 1, _tc_tdm_client_vblank_cb3, &temp), TDM_ERROR_NONE);
1132 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1133 end = tdm_helper_get_time();
1135 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1136 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1140 TEST_P(TDMClient, ClientVblankWaitSeqInterval)
1142 ASSERT_EQ(PrepareClient(), true);
1143 ASSERT_EQ(PrepareOutput(), true);
1144 ASSERT_EQ(PrepareVblank(), true);
1147 for (int t = 1; t < 10; t++) {
1148 unsigned int cur_seq = 0, temp = 0;
1150 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_NONE);
1151 while (cur_seq == 0)
1152 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1154 start = tdm_helper_get_time();
1155 ASSERT_EQ(tdm_client_vblank_wait_seq(vblank, cur_seq + t, _tc_tdm_client_vblank_cb3, &temp), TDM_ERROR_NONE);
1157 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1158 end = tdm_helper_get_time();
1160 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1161 ASSERT_GT((end - start), (vrefresh_interval * (t - 1)));
1162 ASSERT_LT((end - start), (vrefresh_interval * t + vrefresh_interval));
1166 TEST_P(TDMClient, ClientVblankWaitSetOffset)
1170 ASSERT_EQ(PrepareClient(), true);
1171 ASSERT_EQ(PrepareOutput(), true);
1172 ASSERT_EQ(PrepareVblank(), true);
1174 ASSERT_EQ(tdm_client_vblank_set_offset(vblank, 100), TDM_ERROR_NONE);
1177 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1179 start = tdm_helper_get_time();
1181 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1182 end = tdm_helper_get_time();
1184 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1185 ASSERT_GT((end - start), (0.1));
1186 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval + 0.1));
1189 TEST_P(TDMClient, ClientVblankWaitSetFps)
1193 unsigned int fps = 10;
1195 ASSERT_EQ(PrepareClient(), true);
1196 ASSERT_EQ(PrepareOutput(), true);
1197 ASSERT_EQ(PrepareVblank(), true);
1199 ASSERT_EQ(tdm_client_vblank_set_fps(vblank, fps), TDM_ERROR_NONE);
1200 interval = 1.0 / (double)fps;
1203 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1205 start = tdm_helper_get_time();
1207 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1208 end = tdm_helper_get_time();
1210 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1211 ASSERT_GT((end - start), (interval - vrefresh_interval * 2));
1212 ASSERT_LT((end - start), (interval + vrefresh_interval));
1217 TEST_P(TDMVblank, VblankWaitEnableDisableGlobalFps)
1219 TDM_UT_SKIP_FLAG(has_outputs);
1221 unsigned int fps = (unsigned int)TDM_UT_INVALID_VALUE;
1222 double vrefresh_interval;
1223 unsigned int cur_seq[3];
1224 unsigned int global_fps = 5;
1225 double start, end, interval;
1227 ASSERT_EQ(TestPrepareOutput(), true);
1228 ASSERT_EQ(TestCreateVblanks3(), true);
1229 ASSERT_EQ(vblank_count, 3);
1231 ASSERT_EQ(tdm_vblank_get_fps(vblanks[0], &fps), TDM_ERROR_NONE);
1232 ASSERT_TRUE(fps >= 30 && fps != (unsigned int)TDM_UT_INVALID_VALUE);
1233 vrefresh_interval = 1.0 / (double)fps;
1235 for (int v = 0; v < 3; v++)
1236 ASSERT_EQ(tdm_vblank_set_fixed_fps(vblanks[v], 10 * (v + 1)), TDM_ERROR_NONE);
1239 tdm_vblank_enable_global_fps(1, global_fps);
1240 interval = 1.0 / (double)global_fps;
1242 for (int v = 0; v < 3; v++) {
1244 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1247 start = tdm_helper_get_time();
1248 while (cur_seq[0] == 0)
1249 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1250 end = tdm_helper_get_time();
1252 ASSERT_NE(cur_seq[1], 0);
1253 ASSERT_NE(cur_seq[2], 0);
1255 /* "+- vrefresh_interval" consider the delay of socket communication between kernel and platform */
1256 ASSERT_GT((end - start), (interval - vrefresh_interval));
1257 ASSERT_LT((end - start), (interval + vrefresh_interval));
1260 tdm_vblank_enable_global_fps(0, 0);
1262 for (int v = 0; v < 3; v++) {
1264 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1267 while (cur_seq[0] == 0)
1268 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1269 ASSERT_EQ(cur_seq[1], 0);
1270 ASSERT_EQ(cur_seq[2], 0);
1272 while (cur_seq[1] == 0)
1273 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1274 ASSERT_EQ(cur_seq[2], 0);
1277 TEST_P(TDMVblank, VblankWaitIgnoreGlobalFps)
1279 TDM_UT_SKIP_FLAG(has_outputs);
1281 unsigned int fps = (unsigned int)TDM_UT_INVALID_VALUE;
1282 unsigned int cur_seq[3];
1283 unsigned int global_fps = 5;
1284 double start, end, interval;
1286 ASSERT_EQ(TestPrepareOutput(), true);
1287 ASSERT_EQ(TestCreateVblanks3(), true);
1288 ASSERT_EQ(vblank_count, 3);
1290 ASSERT_EQ(tdm_vblank_get_fps(vblanks[0], &fps), TDM_ERROR_NONE);
1291 ASSERT_TRUE(fps >= 30 && fps != (unsigned int)TDM_UT_INVALID_VALUE);
1292 interval = 1.0 / (double)fps;
1294 /* 2nd vblank will ignore the global fps. */
1295 ASSERT_EQ(tdm_vblank_ignore_global_fps(vblanks[1], 1), TDM_ERROR_NONE);
1297 tdm_vblank_enable_global_fps(1, global_fps);
1299 for (int v = 0; v < 3; v++) {
1301 ASSERT_EQ(tdm_vblank_wait(vblanks[v], 0, 0, 1, _tc_tdm_vblank_cb, &cur_seq[v]), TDM_ERROR_NONE);
1304 start = tdm_helper_get_time();
1305 while (cur_seq[1] == 0)
1306 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1307 end = tdm_helper_get_time();
1309 ASSERT_EQ(cur_seq[0], 0);
1310 ASSERT_EQ(cur_seq[2], 0);
1312 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1313 ASSERT_LT((end - start), (interval + interval));
1315 while (cur_seq[0] == 0)
1316 ASSERT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1317 ASSERT_NE(cur_seq[2], 0);
1322 TEST_P(TDMClient, ClientVblankWaitNullObject)
1324 unsigned int cur_seq = 0;
1326 ASSERT_EQ(tdm_client_vblank_wait(NULL, 1, _tc_tdm_client_vblank_cb3, &cur_seq), TDM_ERROR_INVALID_PARAMETER);
1329 TEST_P(TDMClient, ClientVblankWaitNullOther)
1331 ASSERT_EQ(PrepareClient(), true);
1332 ASSERT_EQ(PrepareOutput(), true);
1333 ASSERT_EQ(PrepareVblank(), true);
1335 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
1338 TEST_P(TDMClient, ClientVblankWaitDpmsOff)
1340 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
1342 ASSERT_EQ(PrepareClient(), true);
1343 ASSERT_EQ(PrepareOutput(), true);
1344 ASSERT_EQ(PrepareVblank(), true);
1346 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
1347 while (dpms != TDM_OUTPUT_DPMS_OFF)
1348 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1349 ASSERT_EQ(dpms, TDM_OUTPUT_DPMS_OFF);
1351 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, NULL), TDM_ERROR_DPMS_OFF);
1353 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
1354 while (dpms != TDM_OUTPUT_DPMS_ON)
1355 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1358 TEST_P(TDMClient, ClientVblankWaitSetEnableFakeDpmsOff)
1360 tdm_output_dpms dpms = (tdm_output_dpms)TDM_UT_INVALID_VALUE;
1363 ASSERT_EQ(PrepareClient(), true);
1364 ASSERT_EQ(PrepareOutput(), true);
1365 ASSERT_EQ(PrepareVblank(), true);
1367 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_OFF), true);
1368 while (dpms != TDM_OUTPUT_DPMS_OFF)
1369 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1371 ASSERT_EQ(tdm_client_vblank_set_enable_fake(vblank, 1), TDM_ERROR_NONE);
1374 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1377 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1379 ASSERT_EQ(_tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_DPMS_ON), true);
1380 while (dpms != TDM_OUTPUT_DPMS_ON)
1381 ASSERT_EQ(tdm_client_output_get_dpms(output, &dpms), TDM_ERROR_NONE);
1384 /* tdm_client_vblank_wait */
1385 TEST_P(TDMClient, ClientVblankIsWaiting)
1388 unsigned int waiting;
1390 ASSERT_EQ(PrepareClient(), true);
1391 ASSERT_EQ(PrepareOutput(), true);
1392 ASSERT_EQ(PrepareVblank(), true);
1395 ASSERT_EQ(tdm_client_vblank_wait(vblank, 1, _tc_tdm_client_vblank_cb2, &done), TDM_ERROR_NONE);
1397 waiting = tdm_client_vblank_is_waiting(vblank);
1398 ASSERT_EQ(waiting, 1);
1400 start = tdm_helper_get_time();
1402 ASSERT_EQ(tdm_client_handle_events_timeout(client, 3000), TDM_ERROR_NONE);
1403 end = tdm_helper_get_time();
1405 /* "+ vrefresh_interval" consider the delay of socket communication between kernel and platform */
1406 ASSERT_LT((end - start), (vrefresh_interval + vrefresh_interval));
1408 waiting = tdm_client_vblank_is_waiting(vblank);
1409 ASSERT_EQ(waiting, 0);
1412 /* tdm_client_vblank_wait */
1413 TEST_P(TDMClient, ClientVblankIsWaitingNullObject)
1415 unsigned int waiting = tdm_client_vblank_is_waiting(NULL);
1416 ASSERT_EQ(waiting, 0);
1419 TEST_P(TDMClient, ClientCreateVOutput)
1422 int virtual_conf = 0;
1423 const char name[TDM_NAME_LEN] = "Virtual Output";
1425 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1426 if (virtual_conf == 0) {
1427 ASSERT_EQ(virtual_conf, 0);
1431 ASSERT_EQ(PrepareClient(), true);
1433 voutput = tdm_client_create_voutput(client, name, &ret);
1434 ASSERT_EQ(ret, TDM_ERROR_NONE);
1435 ASSERT_NE(voutput, NULL);
1437 tdm_client_voutput_destroy(voutput);
1440 class TDMVirtualOutput : public ::testing::Test
1443 TDMVirtualOutput() {};
1444 ~TDMVirtualOutput() {};
1446 static void SetUpTestCase();
1447 static void TearDownTestCase();
1448 static bool PrepareVOutput(void);
1451 static tdm_client *client;
1452 static tdm_client_voutput *voutput;
1453 const int MODE_COUNT = 2;
1456 static pid_t server_pid;
1458 /* 0: read, 1: write */
1459 static int pipe_parent[2];
1460 static int pipe_child[2];
1462 static void ServerFork(void);
1463 static void ServerKill(void);
1466 pid_t TDMVirtualOutput::server_pid = -1;
1467 int TDMVirtualOutput::pipe_parent[2] = {-1, -1};
1468 int TDMVirtualOutput::pipe_child[2] = {-1, -1};
1469 tdm_client* TDMVirtualOutput::client = nullptr;
1470 tdm_client_voutput* TDMVirtualOutput::voutput = nullptr;
1472 void TDMVirtualOutput::ServerKill(void)
1474 if (pipe_child[0] >= 0)
1475 close(pipe_child[0]);
1476 if (pipe_child[1] >= 0) {
1477 if (server_pid > 0) {
1478 bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER);
1480 if (waitpid(server_pid, NULL, 0) == server_pid)
1481 TDM_INFO("*** server terminated ***");
1483 TDM_ERR("*** failed to terminate server ***");
1485 if (kill(server_pid, 9) < 0)
1486 TDM_ERR("*** failed to kill server ***");
1489 close(pipe_child[1]);
1492 if (pipe_parent[0] >= 0)
1493 close(pipe_parent[0]);
1494 if (pipe_parent[1] >= 0)
1495 close(pipe_parent[1]);
1498 pipe_parent[0] = pipe_parent[1] = -1;
1499 pipe_child[0] = pipe_child[1] = -1;
1502 void TDMVirtualOutput::ServerFork(void)
1507 server_pid = _tc_tdm_client_server_fork(pipe_parent, pipe_child);
1508 ASSERT_GT(server_pid, 0);
1511 void TDMVirtualOutput::SetUpTestCase(void)
1513 setenv("XDG_RUNTIME_DIR", "/run", 1);
1514 setenv("TBM_DISPLAY_SERVER", "1", 1);
1516 if (server_pid == -1)
1519 ASSERT_EQ(PrepareVOutput(), true);
1522 void TDMVirtualOutput::TearDownTestCase(void)
1524 // TDM_UT_WAIT("check & press");
1527 tdm_client_voutput_destroy(voutput);
1530 tdm_client_destroy(client);
1534 unsetenv("XDG_RUNTIME_DIR");
1535 unsetenv("TBM_DISPLAY_SERVER");
1538 bool TDMVirtualOutput::PrepareVOutput(void)
1541 int virtual_conf = 0;
1542 const char name[TDM_NAME_LEN] = "Virtual Output";
1544 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1545 if (virtual_conf == 0) return true;
1547 client = tdm_client_create(&ret);
1548 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
1549 TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
1551 voutput = tdm_client_create_voutput(client, name, &ret);
1552 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
1553 TDM_UT_RETURN_FALSE_IF_FAIL(voutput != NULL);
1555 // TDM_UT_WAIT("check & press");
1561 _tc_tdm_client_virutual_make_available_mode(tdm_client_output_mode *modes, int count)
1565 for (i = 0; i < count; i++) {
1566 modes[i].clock = 25200;
1567 modes[i].hdisplay = 640;
1568 modes[i].hsync_start = 656;
1569 modes[i].hsync_end = 752;
1570 modes[i].htotal = 800;
1572 modes[i].vdisplay = 480;
1573 modes[i].vsync_start = 490;
1574 modes[i].vsync_end = 492;
1575 modes[i].vtotal = 525;
1577 modes[i].vrefresh = 30;
1580 snprintf(modes[i].name, TDM_NAME_LEN, "%dx%d_%d", modes[i].hdisplay, modes[i].vdisplay, i);
1584 TEST_F(TDMVirtualOutput, SetAvailableModes)
1587 tdm_client_output_mode modes[this->MODE_COUNT];
1588 int count = this->MODE_COUNT;
1591 if (this->voutput == NULL) {
1592 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1593 ASSERT_EQ(virtual_conf, 0);
1596 _tc_tdm_client_virutual_make_available_mode(modes, count);
1598 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1599 ASSERT_EQ(ret, TDM_ERROR_NONE);
1602 TEST_F(TDMVirtualOutput, FailTestSetAvailableModes)
1605 tdm_client_output_mode modes[this->MODE_COUNT];
1606 int count = this->MODE_COUNT;
1609 if (this->voutput == NULL) {
1610 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1611 ASSERT_EQ(virtual_conf, 0);
1615 ret = tdm_client_voutput_set_available_modes(NULL, modes, count);
1616 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1618 ret = tdm_client_voutput_set_available_modes(this->voutput, NULL, count);
1619 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1622 TEST_F(TDMVirtualOutput, SetPhysicalSize)
1625 unsigned int mmWidth = 1234, mmHeight = 1234;
1628 if (this->voutput == NULL) {
1629 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1630 ASSERT_EQ(virtual_conf, 0);
1634 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1635 ASSERT_EQ(ret, TDM_ERROR_NONE);
1638 TEST_F(TDMVirtualOutput, FailTestSetPhysicalSize)
1641 unsigned int invalid_mmWidth = 0, invalid_mmHeight = 0;
1644 if (this->voutput == NULL) {
1645 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1646 ASSERT_EQ(virtual_conf, 0);
1650 ret = tdm_client_voutput_set_physical_size(this->voutput, invalid_mmWidth, invalid_mmHeight);
1651 ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
1655 _tc_tdm_client_voutput_commit_handler(tdm_client_voutput *voutput, tbm_surface_h buffer, void *user_data)
1658 flag = (int *)user_data;
1662 TEST_F(TDMVirtualOutput, AddCommitHandler)
1665 int flag_callback_called = 0;
1668 if (this->voutput == NULL) {
1669 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1670 ASSERT_EQ(virtual_conf, 0);
1674 ret = tdm_client_voutput_add_commit_handler(this->voutput,
1675 _tc_tdm_client_voutput_commit_handler,
1676 &flag_callback_called);
1677 ASSERT_EQ(ret, TDM_ERROR_NONE);
1678 // ASSERT_EQ(flag_callback_called, 1);
1680 tdm_client_voutput_remove_commit_handler(this->voutput,
1681 _tc_tdm_client_voutput_commit_handler,
1682 &flag_callback_called);
1685 TEST_F(TDMVirtualOutput, CommitDone)
1690 if (this->voutput == NULL) {
1691 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1692 ASSERT_EQ(virtual_conf, 0);
1696 ret = tdm_client_voutput_commit_done(this->voutput);
1697 ASSERT_EQ(ret, TDM_ERROR_NONE);
1700 TEST_F(TDMVirtualOutput, GetClientOutput)
1703 tdm_client_output *output;
1706 if (this->voutput == NULL) {
1707 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1708 ASSERT_EQ(virtual_conf, 0);
1712 output = tdm_client_voutput_get_client_output(this->voutput, &ret);
1713 ASSERT_EQ(ret, TDM_ERROR_NONE);
1714 ASSERT_NE(output, NULL);
1717 TEST_F(TDMVirtualOutput, Connect)
1720 unsigned int mmWidth = 300, mmHeight = 150;
1721 tdm_client_output_mode modes[this->MODE_COUNT];
1722 int count = this->MODE_COUNT;
1725 if (this->voutput == NULL) {
1726 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1727 ASSERT_EQ(virtual_conf, 0);
1731 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1732 ASSERT_EQ(ret, TDM_ERROR_NONE);
1734 _tc_tdm_client_virutual_make_available_mode(modes, count);
1735 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1736 ASSERT_EQ(ret, TDM_ERROR_NONE);
1738 ret = tdm_client_voutput_connect(this->voutput);
1739 ASSERT_EQ(ret, TDM_ERROR_NONE);
1741 tdm_client_handle_events_timeout(this->client, 0);
1744 TEST_F(TDMVirtualOutput, Disconnect)
1749 if (this->voutput == NULL) {
1750 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1751 ASSERT_EQ(virtual_conf, 0);
1755 // TDM_UT_WAIT("check & press");
1757 ret = tdm_client_voutput_disconnect(this->voutput);
1758 ASSERT_EQ(ret, TDM_ERROR_NONE);
1760 tdm_client_handle_events_timeout(this->client, 0);
1764 TEST_F(TDMVirtualOutput, SetMode)
1767 unsigned int mmWidth = 300, mmHeight = 150;
1768 tdm_client_output_mode modes[this->MODE_COUNT];
1769 int count = this->MODE_COUNT;
1772 if (this->voutput == NULL) {
1773 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1774 ASSERT_EQ(virtual_conf, 0);
1778 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1779 ASSERT_EQ(ret, TDM_ERROR_NONE);
1781 _tc_tdm_client_virutual_make_available_mode(modes, count);
1782 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1783 ASSERT_EQ(ret, TDM_ERROR_NONE);
1785 ret = tdm_client_voutput_connect(this->voutput);
1786 ASSERT_EQ(ret, TDM_ERROR_NONE);
1788 tdm_client_handle_events_timeout(this->client, 100);
1790 ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, count - 1), TDM_ERROR_NONE);
1792 tdm_client_handle_events_timeout(this->client, 100);
1794 ret = tdm_client_voutput_disconnect(this->voutput);
1795 ASSERT_EQ(ret, TDM_ERROR_NONE);
1797 tdm_client_handle_events_timeout(this->client, 0);
1800 TEST_F(TDMVirtualOutput, SetModeNullObject)
1803 unsigned int mmWidth = 300, mmHeight = 150;
1804 tdm_client_output_mode modes[this->MODE_COUNT];
1805 int count = this->MODE_COUNT;
1808 if (this->voutput == NULL) {
1809 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1810 ASSERT_EQ(virtual_conf, 0);
1814 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1815 ASSERT_EQ(ret, TDM_ERROR_NONE);
1817 _tc_tdm_client_virutual_make_available_mode(modes, count);
1818 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1819 ASSERT_EQ(ret, TDM_ERROR_NONE);
1821 ret = tdm_client_voutput_connect(this->voutput);
1822 ASSERT_EQ(ret, TDM_ERROR_NONE);
1824 tdm_client_handle_events_timeout(this->client, 100);
1826 ASSERT_EQ(tdm_client_voutput_set_mode(NULL, 0), TDM_ERROR_INVALID_PARAMETER);
1828 ret = tdm_client_voutput_disconnect(this->voutput);
1829 ASSERT_EQ(ret, TDM_ERROR_NONE);
1831 tdm_client_handle_events_timeout(this->client, 0);
1834 TEST_F(TDMVirtualOutput, SetModeInvalidIndex)
1837 unsigned int mmWidth = 300, mmHeight = 150;
1838 tdm_client_output_mode modes[this->MODE_COUNT];
1839 int count = this->MODE_COUNT;
1842 if (this->voutput == NULL) {
1843 virtual_conf = tdm_config_get_int(TDM_CONFIG_KEY_GENERAL_VIRTUAL_OUTPUT, 0);
1844 ASSERT_EQ(virtual_conf, 0);
1848 ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
1849 ASSERT_EQ(ret, TDM_ERROR_NONE);
1851 _tc_tdm_client_virutual_make_available_mode(modes, count);
1852 ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
1853 ASSERT_EQ(ret, TDM_ERROR_NONE);
1855 ret = tdm_client_voutput_connect(this->voutput);
1856 ASSERT_EQ(ret, TDM_ERROR_NONE);
1858 tdm_client_handle_events_timeout(this->client, 100);
1860 ASSERT_EQ(tdm_client_voutput_set_mode(this->voutput, -1), TDM_ERROR_INVALID_PARAMETER);
1862 ret = tdm_client_voutput_disconnect(this->voutput);
1863 ASSERT_EQ(ret, TDM_ERROR_NONE);
1865 tdm_client_handle_events_timeout(this->client, 0);
1868 #ifdef TDM_UT_TEST_WITH_PARAMS
1869 INSTANTIATE_TEST_CASE_P(TDMClientParams,
1871 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
1873 INSTANTIATE_TEST_CASE_P(TDMClientParams,
1875 Values(TDM_DEFAULT_MODULE));