1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
44 #include <tdm_client.h>
45 #include "tdm_macro.h"
47 typedef struct _tdm_test_client_arg {
48 char output_name[512];
54 } tdm_test_client_arg;
56 typedef struct _tdm_test_client {
57 tdm_test_client_arg args;
85 static struct typestrings typestrs[] = {
91 static struct optstrings optstrs[] = {
92 {OPT_QRY, "qo", "output objects info", "<output_name>", "primary"},
93 {OPT_TST, "v", "vblank test", "<output_name>[,<sync>][@<fps>][~<interval>][+<offset>][*fake]", "primary,0@60~1+0*1"},
99 int type_size = sizeof(typestrs) / sizeof(struct typestrings);
100 int opt_size = sizeof(optstrs) / sizeof(struct optstrings);
103 printf("usage: %s \n\n", app_name);
105 for (t = 0; t < type_size; t++) {
108 for (o = 0; o < opt_size; o++)
109 if (optstrs[o].type == typestrs[t].type) {
111 printf(" %s options:\n\n", typestrs[t].string);
112 printf("\t-%s\t%s\n", optstrs[o].opt, optstrs[o].desc);
114 printf("\t\t %s\n", optstrs[o].arg);
116 printf("\t\t ex) %s\n", optstrs[o].ex);
127 parse_arg_qo(tdm_test_client *data, char *arg)
129 strtostr(data->args.output_name, 512, arg, TDM_DELIM);
132 //"<output_name>[,<sync>][@<fps>][~<interval>][+<offset>][*fake]"
134 parse_arg_v(tdm_test_client *data, char *arg)
138 end = strtostr(data->args.output_name, 512, arg, TDM_DELIM);
142 data->args.sync = strtol(arg, &end, 10);
147 data->args.fps = strtol(arg, &end, 10);
152 data->args.interval = strtol(arg, &end, 10);
155 if (*end == '+' || *end == '-') {
157 data->args.offset = strtol(arg, &end, 10);
162 data->args.enable_fake = strtol(arg, &end, 10);
167 parse_args(tdm_test_client *data, int argc, char *argv[])
176 memset(data, 0, sizeof *data);
177 data->args.interval = 1;
179 for (i = 1; i < argc; i++) {
180 if (!strncmp(argv[i]+1, "qo", 2)) {
182 parse_arg_qo(data, argv[++i]);
183 } else if (!strncmp(argv[i]+1, "v", 1)) {
185 parse_arg_v(data, argv[++i]);
198 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
199 return (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0;
205 _client_vblank_handler(tdm_client_vblank *vblank, tdm_error error, unsigned int sequence,
206 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
208 tdm_test_client *data = user_data;
210 static double p_vbl = 0;
214 if (error == TDM_ERROR_DPMS_OFF) {
215 printf("exit: dpms off\n");
219 if (error != TDM_ERROR_NONE) {
220 printf("exit: error(%d)\n", error);
225 vbl = (double)tv_sec + ((double)tv_usec) / 1000000.0;
227 printf("vblank : %.6f us vbl(%.6f)\n", vbl - p_vbl, vbl);
229 if (cur - vbl > 0.002) /* 2ms */
230 printf("kernel -> tdm-client: %.0f us\n", (cur - vbl) * 1000000.0);
235 static char *conn_str[3] = {"disconnected", "connected", "mode_setted"};
236 static char *dpms_str[4] = {"on", "standy", "suspend", "off"};
239 _client_output_handler(tdm_client_output *output, tdm_output_change_type type,
240 tdm_value value, void *user_data)
242 if (type == TDM_OUTPUT_CHANGE_CONNECTION)
243 printf("output %s.\n", conn_str[value.u32]);
244 else if (type == TDM_OUTPUT_CHANGE_DPMS)
245 printf("dpms %s.\n", dpms_str[value.u32]);
249 do_query(tdm_test_client *data)
251 tdm_client_output *output;
252 tdm_output_conn_status status;
253 tdm_output_dpms dpms;
254 unsigned int refresh;
257 output = tdm_client_get_output(data->client, NULL, &error);
258 if (error != TDM_ERROR_NONE) {
259 printf("tdm_client_get_output failed\n");
263 tdm_client_output_get_conn_status(output, &status);
264 tdm_client_output_get_dpms(output, &dpms);
265 tdm_client_output_get_refresh_rate(output, &refresh);
267 printf("tdm_output \"%s\"\n", data->args.output_name);
268 printf("\tstatus : %s\n", conn_str[status]);
269 printf("\tdpms : %s\n", dpms_str[dpms]);
270 printf("\trefresh : %d\n", refresh);
274 do_vblank(tdm_test_client *data)
276 tdm_client_output *output;
277 tdm_client_vblank *vblank = NULL;
282 output = tdm_client_get_output(data->client, data->args.output_name, &error);
283 if (error != TDM_ERROR_NONE) {
284 printf("tdm_client_get_output failed\n");
288 tdm_client_output_add_change_handler(output, _client_output_handler, NULL);
290 vblank = tdm_client_output_create_vblank(output, &error);
291 if (error != TDM_ERROR_NONE) {
292 printf("tdm_client_output_create_vblank failed\n");
296 tdm_client_vblank_set_enable_fake(vblank, data->args.enable_fake);
297 tdm_client_vblank_set_sync(vblank, data->args.sync);
298 if (data->args.fps > 0)
299 tdm_client_vblank_set_fps(vblank, data->args.fps);
300 tdm_client_vblank_set_offset(vblank, data->args.offset);
302 error = tdm_client_get_fd(data->client, &fd);
303 if (error != TDM_ERROR_NONE || fd < 0) {
304 printf("tdm_client_get_fd failed\n");
315 if (!data->waiting) {
316 error = tdm_client_vblank_wait(vblank, data->args.interval,
317 _client_vblank_handler, data);
318 if (error == TDM_ERROR_DPMS_OFF) {
319 printf("tdm_client_vblank_wait failed (dpms off)\n");
322 if (error != TDM_ERROR_NONE) {
323 printf("tdm_client_vblank_wait failed (error: %d)\n", error);
329 if (!data->args.sync) {
330 ret = poll(&fds, 1, -1);
332 if (errno == EINTR || errno == EAGAIN) /* normal case */
335 printf("poll failed: %m\n");
340 error = tdm_client_handle_events(data->client);
341 if (error != TDM_ERROR_NONE) {
342 printf("tdm_client_handle_events failed\n");
350 tdm_client_vblank_destroy(vblank);
353 static tdm_test_client ttc_data;
356 main(int argc, char *argv[])
358 tdm_test_client *data = &ttc_data;
361 #if 1 /* for testing */
362 const char *xdg = (const char*)getenv("XDG_RUNTIME_DIR");
365 snprintf(buf, sizeof(buf), "/run");
366 int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
372 parse_args(data, argc, argv);
374 printf("sync(%d) fps(%d) interval(%d) offset(%d) enable_fake(%d)\n",
375 data->args.sync, data->args.fps, data->args.interval,
376 data->args.offset, data->args.enable_fake);
378 data->client = tdm_client_create(&error);
379 if (error != TDM_ERROR_NONE) {
380 printf("tdm_client_create failed\n");
391 tdm_client_destroy(data->client);