add tdm-client to test tdm client API 34/65534/1
authorBoram Park <boram1288.park@samsung.com>
Mon, 4 Apr 2016 10:22:29 +0000 (19:22 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 11 Apr 2016 10:33:07 +0000 (19:33 +0900)
Change-Id: Ifa6219f85b35d1d9d119211c276062974967986d

Makefile.am
configure.ac
packaging/libtdm.spec
tools/Makefile.am [new file with mode: 0644]
tools/tdm_test_client.c [new file with mode: 0644]

index e8aa5d7..393ba5c 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = . include protocol client src
+SUBDIRS = . include protocol client src tools
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libtdm.pc
index db21b7e..84bdb79 100644 (file)
@@ -64,7 +64,8 @@ AC_OUTPUT([
        protocol/Makefile
        client/libtdm-client.pc
        client/Makefile
-       src/Makefile])
+       src/Makefile
+       tools/Makefile])
 
 echo ""
 echo "$PACKAGE_STRING will be compiled with:"
index 3f6e0b1..37f86c1 100644 (file)
@@ -41,6 +41,14 @@ Tizen Display Manager Client Library headers
 
 %global TZ_SYS_RO_SHARE  %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:/usr/share}
 
+%package tools
+Summary:        Tools for libtdm
+Group:          Development/Utilities
+#Provides:       libtdm = %version
+
+%description tools
+This contains libtdm tools for fundamental testing
+
 %prep
 %setup -q
 cp %{SOURCE1001} .
@@ -113,4 +121,8 @@ rm -f %{_unitdir_user}/default.target.wants/tdm-socket-user.path
 %{_libdir}/pkgconfig/libtdm-client.pc
 %{_libdir}/libtdm-client.so
 
+%files tools
+%manifest %{name}.manifest
+%{_bindir}/tdm-client
+
 %changelog
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644 (file)
index 0000000..1395786
--- /dev/null
@@ -0,0 +1,14 @@
+bin_PROGRAMS = \
+       tdm-client
+
+tdm_client_SOURCES = \
+       tdm_test_client.c
+
+tdm_client_LDFLAGS = ${LDFLAGS}
+tdm_client_CFLAGS = \
+       $(TDM_CFLAGS) \
+       -I$(top_srcdir)/include \
+       -I$(top_srcdir)/client
+tdm_client_LDADD = \
+       $(TDM_LIBS) \
+       $(top_builddir)/client/libtdm-client.la
diff --git a/tools/tdm_test_client.c b/tools/tdm_test_client.c
new file mode 100644 (file)
index 0000000..ed88d8a
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+      Changyeon Lee <cyeon.lee@samsung.com>,
+      JunKyeong Kim <jk0430.kim@samsung.com>,
+      Boram Park <boram1288.park@samsung.com>,
+      SooChan Lim <sc1.lim@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <errno.h>
+#include <time.h>
+
+#include <tdm_client.h>
+#include <tdm_helper.h>
+
+static int
+get_time_in_millis(void)
+{
+       struct timespec tp;
+
+       if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+               return (int)(tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
+
+       return 0;
+}
+
+static void
+_client_vblank_handler(unsigned int sequence, unsigned int tv_sec,
+                       unsigned int tv_usec, void *user_data)
+{
+       int temp1, temp2;
+
+       temp1 = (int)user_data;
+       temp2 = get_time_in_millis();
+
+       printf("%d ms\n", temp2 - temp1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+       tdm_client *client;
+       tdm_client_error error;
+       int fd = -1;
+       struct pollfd fds;
+
+       client = tdm_client_create(&error);
+       if (error != TDM_CLIENT_ERROR_NONE) {
+               printf("tdm_client_create failed\n");
+               exit(1);
+       }
+
+       error = tdm_client_get_fd(client, &fd);
+       if (error != TDM_CLIENT_ERROR_NONE || fd < 0) {
+               printf("tdm_client_get_fd failed\n");
+               goto done;
+       }
+
+       fds.events = POLLIN;
+       fds.fd = fd;
+       fds.revents = 0;
+
+       while (1) {
+               int ret;
+
+               error = tdm_client_wait_vblank(client, "unknown-0", 1, 0,
+                                              _client_vblank_handler,
+                                              (void*)get_time_in_millis());
+               if (error != TDM_CLIENT_ERROR_NONE) {
+                       printf("tdm_client_wait_vblank failed\n");
+                       goto done;
+               }
+
+               ret = poll(&fds, 1, -1);
+               if (ret < 0) {
+                       if (errno == EBUSY)  /* normal case */
+                               continue;
+                       else {
+                               printf("poll failed: %m\n");
+                               goto done;
+                       }
+               }
+
+               error = tdm_client_handle_events(client);
+               if (error != TDM_CLIENT_ERROR_NONE)
+                       printf("tdm_client_handle_events failed\n");
+       }
+
+done:
+       tdm_client_destroy(client);
+       return 0;
+}