test_input: always print keysym
[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 #include <errno.h>
37 #include <signal.h>
38 #include <stdbool.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42
43 #include "eloop.h"
44 #include "log.h"
45 #include "uterm.h"
46 #include "test_include.h"
47
48 int main(int argc, char **argv)
49 {
50         int ret;
51         struct ev_eloop *eloop;
52         struct uterm_vt_master *vtm;
53         struct uterm_vt *vt;
54
55         ret = test_prepare(argc, argv, &eloop);
56         if (ret)
57                 goto err_fail;
58
59         ret = uterm_vt_master_new(&vtm, eloop);
60         if (ret)
61                 goto err_exit;
62
63         ret = uterm_vt_allocate(vtm, &vt, NULL, NULL, NULL);
64         if (ret)
65                 goto err_vtm;
66
67         ret = uterm_vt_activate(vt);
68         if (ret)
69                 log_warn("Cannot switch to VT");
70
71         ev_eloop_run(eloop, -1);
72
73         log_debug("Terminating\n");
74
75         /* switch back to previous VT but wait for eloop to process SIGUSR0 */
76         ret = uterm_vt_deactivate(vt);
77         if (ret == -EINPROGRESS)
78                 ev_eloop_run(eloop, 50);
79
80         uterm_vt_unref(vt);
81 err_vtm:
82         uterm_vt_master_unref(vtm);
83 err_exit:
84         test_exit(eloop);
85 err_fail:
86         test_fail(ret);
87         return abs(ret);
88 }