test_vt: use a dummy input-object
[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 "log.h"
47 #include "uterm.h"
48 #include "test_include.h"
49
50 static void print_help()
51 {
52         /*
53          * Usage/Help information
54          * This should be scaled to a maximum of 80 characters per line:
55          *
56          * 80 char line:
57          *       |   10   |    20   |    30   |    40   |    50   |    60   |    70   |    80   |
58          *      "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
59          * 80 char line starting with tab:
60          *       |10|    20   |    30   |    40   |    50   |    60   |    70   |    80   |
61          *      "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
62          */
63         fprintf(stderr,
64                 "Usage:\n"
65                 "\t%1$s [options]\n"
66                 "\t%1$s -h [options]\n"
67                 "\n"
68                 "You can prefix boolean options with \"no-\" to negate it. If an argument is\n"
69                 "given multiple times, only the last argument matters if not otherwise stated.\n"
70                 "\n"
71                 "General Options:\n"
72                 TEST_HELP,
73                 "test_vt");
74         /*
75          * 80 char line:
76          *       |   10   |    20   |    30   |    40   |    50   |    60   |    70   |    80   |
77          *      "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
78          * 80 char line starting with tab:
79          *       |10|    20   |    30   |    40   |    50   |    60   |    70   |    80   |
80          *      "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
81          */
82 }
83
84 struct conf_option options[] = {
85         TEST_OPTIONS
86 };
87
88 int main(int argc, char **argv)
89 {
90         int ret;
91         struct ev_eloop *eloop;
92         struct uterm_vt_master *vtm;
93         struct uterm_input *input;
94         struct uterm_vt *vt;
95         size_t onum;
96
97         onum = sizeof(options) / sizeof(*options);
98         ret = test_prepare(options, onum, argc, argv, &eloop);
99         if (ret)
100                 goto err_fail;
101
102         ret = uterm_vt_master_new(&vtm, eloop);
103         if (ret)
104                 goto err_exit;
105
106         ret = uterm_input_new(&input, eloop, "", "", "", "", 0, 0);
107         if (ret)
108                 goto err_vtm;
109
110         ret = uterm_vt_allocate(vtm, &vt, "seat0", input, NULL, NULL, NULL);
111         if (ret)
112                 goto err_input;
113
114         ret = uterm_vt_activate(vt);
115         if (ret == -EINPROGRESS)
116                 log_debug("VT switch in progress");
117         else if (ret)
118                 log_warn("cannot switch to VT: %d", ret);
119
120         ev_eloop_run(eloop, -1);
121
122         log_debug("Terminating\n");
123
124         /* switch back to previous VT but wait for eloop to process SIGUSR0 */
125         ret = uterm_vt_deactivate(vt);
126         if (ret == -EINPROGRESS)
127                 ev_eloop_run(eloop, 50);
128
129         uterm_vt_unref(vt);
130 err_input:
131         uterm_input_unref(input);
132 err_vtm:
133         uterm_vt_master_unref(vtm);
134 err_exit:
135         test_exit(options, onum, eloop);
136 err_fail:
137         if (ret != -ECANCELED)
138                 test_fail(ret);
139         return abs(ret);
140 }