Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / tests / test_vt.c
1 /*
2  * test_console - Test VT Layer
3  *
4  * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
5  * Copyright (c) 2011 University of Tuebingen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files
9  * (the "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 /*
28  * Test VT Layer
29  * This opens a new VT and prints some text on it. You can then change the VT
30  * and change back. This is only to test the VT subsystem and event engine.
31  * This automatically switches to the new VT. Currently, the display gets
32  * frozen because we aren't painting to the framebuffer yet. Use
33  * ctrl+alt+FX (or some equivalent) to switch back to X/VT.
34  */
35
36 static void print_help();
37
38 #include <errno.h>
39 #include <signal.h>
40 #include <stdbool.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <unistd.h>
45 #include "eloop.h"
46 #include "shl_log.h"
47 #include "uterm_input.h"
48 #include "uterm_vt.h"
49 #include "test_include.h"
50
51 static void print_help()
52 {
53         /*
54          * Usage/Help information
55          * This should be scaled to a maximum of 80 characters per line:
56          *
57          * 80 char line:
58          *       |   10   |    20   |    30   |    40   |    50   |    60   |    70   |    80   |
59          *      "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
60          * 80 char line starting with tab:
61          *       |10|    20   |    30   |    40   |    50   |    60   |    70   |    80   |
62          *      "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
63          */
64         fprintf(stderr,
65                 "Usage:\n"
66                 "\t%1$s [options]\n"
67                 "\t%1$s -h [options]\n"
68                 "\n"
69                 "You can prefix boolean options with \"no-\" to negate it. If an argument is\n"
70                 "given multiple times, only the last argument matters if not otherwise stated.\n"
71                 "\n"
72                 "General Options:\n"
73                 TEST_HELP
74                 "\n"
75                 "VT Options:\n"
76                 "\t    --vt <vt>               [-]     Path to VT to use\n"
77                 "\t-s, --switchvt              [off]   Switch automatically to the new VT\n",
78                 "test_vt");
79         /*
80          * 80 char line:
81          *       |   10   |    20   |    30   |    40   |    50   |    60   |    70   |    80   |
82          *      "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
83          * 80 char line starting with tab:
84          *       |10|    20   |    30   |    40   |    50   |    60   |    70   |    80   |
85          *      "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
86          */
87 }
88
89 static const char *vtpath = NULL;
90 static bool switchvt = false;
91
92 struct conf_option options[] = {
93         TEST_OPTIONS,
94         CONF_OPTION_STRING(0, "vt", &vtpath, NULL),
95         CONF_OPTION_BOOL('s', "switchvt", &switchvt, false),
96 };
97
98 int main(int argc, char **argv)
99 {
100         int ret;
101         struct ev_eloop *eloop;
102         struct uterm_vt_master *vtm;
103         struct uterm_input *input;
104         struct uterm_vt *vt;
105         size_t onum;
106
107         onum = sizeof(options) / sizeof(*options);
108         ret = test_prepare(options, onum, argc, argv, &eloop);
109         if (ret)
110                 goto err_fail;
111
112         ret = uterm_vt_master_new(&vtm, eloop);
113         if (ret)
114                 goto err_exit;
115
116         ret = uterm_input_new(&input, eloop, "", "", "", "", "", 0, 0,
117                               log_llog, NULL);
118         if (ret)
119                 goto err_vtm;
120
121         ret = uterm_vt_allocate(vtm, &vt, UTERM_VT_FAKE | UTERM_VT_REAL,
122                                 "seat0", input, vtpath, NULL, NULL);
123         if (ret)
124                 goto err_input;
125
126         if (switchvt) {
127                 ret = uterm_vt_activate(vt);
128                 if (ret == -EINPROGRESS)
129                         log_debug("VT switch in progress");
130                 else if (ret)
131                         log_warn("cannot switch to VT: %d", ret);
132         }
133
134         ev_eloop_run(eloop, -1);
135
136         log_debug("Terminating");
137
138         /* switch back to previous VT but wait for eloop to process SIGUSR0 */
139         if (switchvt) {
140                 ret = uterm_vt_deactivate(vt);
141                 if (ret == -EINPROGRESS)
142                         ev_eloop_run(eloop, 50);
143         }
144
145         uterm_vt_unref(vt);
146 err_input:
147         uterm_input_unref(input);
148 err_vtm:
149         uterm_vt_master_unref(vtm);
150 err_exit:
151         test_exit(options, onum, eloop);
152 err_fail:
153         if (ret != -ECANCELED)
154                 test_fail(ret);
155         return abs(ret);
156 }