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"},
96 #define DELIM "!@#^&*+-|,"
99 strtostr(char *buf, int len, char *str, char *delim)
102 end = strpbrk(str, delim);
104 len = ((end - str + 1) < len) ? (end - str + 1) : len;
107 len = ((l + 1) < len) ? (l + 1) : len;
109 snprintf(buf, len, "%s", str);
110 return str + len - 1;
114 usage(char *app_name)
116 int type_size = sizeof(typestrs) / sizeof(struct typestrings);
117 int opt_size = sizeof(optstrs) / sizeof(struct optstrings);
120 printf("usage: %s \n\n", app_name);
122 for (t = 0; t < type_size; t++) {
125 for (o = 0; o < opt_size; o++)
126 if (optstrs[o].type == typestrs[t].type) {
128 printf(" %s options:\n\n", typestrs[t].string);
129 printf("\t-%s\t%s\n", optstrs[o].opt, optstrs[o].desc);
130 printf("\t\t%s\n", optstrs[o].arg);
131 printf("\t\tex) %s\n", optstrs[o].ex);
141 parse_arg_qo(tdm_test_client *data, char *p)
143 strtostr(data->args.output_name, 512, p, DELIM);
146 //"<output_name>[,<sync>][@<fps>][#<interval>][+<offset>][*fake]"
148 parse_arg_v(tdm_test_client *data, char *p)
152 end = strtostr(data->args.output_name, 512, p, DELIM);
156 data->args.sync = strtol(p, &end, 10);
161 data->args.fps = strtol(p, &end, 10);
166 data->args.interval = strtol(p, &end, 10);
169 if (*end == '+' || *end == '-') {
171 data->args.offset = strtol(p, &end, 10);
176 data->args.enable_fake= strtol(p, &end, 10);
181 parse_args(tdm_test_client *data, int argc, char *argv[])
183 int size = sizeof(optstrs) / sizeof(struct optstrings);
191 memset(data, 0, sizeof *data);
192 data->args.interval = 1;
194 for (i = 1; i < argc; i++) {
195 for (j = 0; j < size; j++) {
196 if (!strncmp(argv[i]+1, "qo", 512)) {
198 parse_arg_qo(data, argv[++i]);
200 } else if (!strncmp(argv[i]+1, "v", 512)) {
202 parse_arg_v(data, argv[++i]);
213 get_time_in_micros(void)
217 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
218 return (unsigned long)(tp.tv_sec * 1000000) + (tp.tv_nsec / 1000L);
224 _client_vblank_handler(tdm_client_vblank *vblank, tdm_error error, unsigned int sequence,
225 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
227 tdm_test_client *data = user_data;
228 unsigned long cur, vbl;
229 static unsigned long p_vbl = 0;
233 if (error == TDM_ERROR_DPMS_OFF) {
234 printf("exit: dpms off\n");
238 if (error != TDM_ERROR_NONE) {
239 printf("exit: error(%d)\n", error);
243 cur = get_time_in_micros();
244 vbl = (unsigned long)tv_sec * (unsigned long)1000000 + (unsigned long)tv_usec;
246 printf("vblank : %ld us vbl(%lu)\n", vbl - p_vbl, vbl);
248 if (cur - vbl > 2000) /* 2ms */
249 printf("kernel -> tdm-client: %ld us\n", cur - vbl);
254 static char *conn_str[3] = {"disconnected", "connected", "mode_setted"};
255 static char *dpms_str[4] = {"on", "standy", "suspend", "off"};
258 _client_output_handler(tdm_client_output *output, tdm_output_change_type type,
259 tdm_value value, void *user_data)
261 if (type == TDM_OUTPUT_CHANGE_CONNECTION)
262 printf("output %s.\n", conn_str[value.u32]);
263 else if (type == TDM_OUTPUT_CHANGE_DPMS)
264 printf("dpms %s.\n", dpms_str[value.u32]);
268 do_query(tdm_test_client *data)
270 tdm_client_output *output;
271 tdm_output_conn_status status;
272 tdm_output_dpms dpms;
273 unsigned int refresh;
276 output = tdm_client_get_output(data->client, NULL, &error);
277 if (error != TDM_ERROR_NONE) {
278 printf("tdm_client_get_output failed\n");
282 tdm_client_output_get_conn_status(output, &status);
283 tdm_client_output_get_dpms(output, &dpms);
284 tdm_client_output_get_refresh_rate(output, &refresh);
286 printf("tdm_output \"%s\"\n", data->args.output_name);
287 printf("\tstatus : %s\n", conn_str[status]);
288 printf("\tdpms : %s\n", dpms_str[dpms]);
289 printf("\trefresh : %d\n", refresh);
293 do_vblank(tdm_test_client *data)
295 tdm_client_output *output;
296 tdm_client_vblank *vblank = NULL;
301 output = tdm_client_get_output(data->client, data->args.output_name, &error);
302 if (error != TDM_ERROR_NONE) {
303 printf("tdm_client_get_output failed\n");
307 tdm_client_output_add_change_handler(output, _client_output_handler, NULL);
309 vblank = tdm_client_output_create_vblank(output, &error);
310 if (error != TDM_ERROR_NONE) {
311 printf("tdm_client_output_create_vblank failed\n");
315 tdm_client_vblank_set_enable_fake(vblank, data->args.enable_fake);
316 tdm_client_vblank_set_sync(vblank, data->args.sync);
317 if (data->args.fps > 0)
318 tdm_client_vblank_set_fps(vblank, data->args.fps);
319 tdm_client_vblank_set_offset(vblank, data->args.offset);
321 error = tdm_client_get_fd(data->client, &fd);
322 if (error != TDM_ERROR_NONE || fd < 0) {
323 printf("tdm_client_get_fd failed\n");
334 if (!data->waiting) {
335 error = tdm_client_vblank_wait(vblank, data->args.interval,
336 _client_vblank_handler, data);
337 if (error == TDM_ERROR_DPMS_OFF) {
338 printf("tdm_client_vblank_wait failed (dpms off)\n");
341 if (error != TDM_ERROR_NONE) {
342 printf("tdm_client_vblank_wait failed (error: %d)\n", error);
348 if (!data->args.sync) {
349 ret = poll(&fds, 1, -1);
351 if (errno == EINTR || errno == EAGAIN) /* normal case */
354 printf("poll failed: %m\n");
359 error = tdm_client_handle_events(data->client);
360 if (error != TDM_ERROR_NONE) {
361 printf("tdm_client_handle_events failed\n");
369 tdm_client_vblank_destroy(vblank);
372 static tdm_test_client ttc_data;
375 main(int argc, char *argv[])
377 tdm_test_client *data = &ttc_data;
380 parse_args(data, argc, argv);
382 printf("sync(%d) fps(%d) interval(%d) offset(%d) enable_fake(%d)\n",
383 data->args.sync, data->args.fps, data->args.interval,
384 data->args.offset, data->args.enable_fake);
386 data->client = tdm_client_create(&error);
387 if (error != TDM_ERROR_NONE) {
388 printf("tdm_client_create failed\n");
399 tdm_client_destroy(data->client);