test_input: use new test_include.h infrastructure
[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 "vt.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 kmscon_vt *vt;
53
54         ret = test_prepare(argc, argv, &eloop);
55         if (ret)
56                 goto err_fail;
57
58         ret = kmscon_vt_new(&vt, NULL, NULL);
59         if (ret)
60                 goto err_exit;
61
62         ret = kmscon_vt_open(vt, KMSCON_VT_NEW, eloop);
63         if (ret)
64                 goto err_vt;
65
66         ret = kmscon_vt_enter(vt);
67         if (ret)
68                 log_warn("Cannot switch to VT");
69
70         ev_eloop_run(eloop, -1);
71
72         log_debug("Terminating\n");
73
74         /* switch back to previous VT but wait for eloop to process SIGUSR0 */
75         ret = kmscon_vt_leave(vt);
76         if (ret == -EINPROGRESS)
77                 ev_eloop_run(eloop, 50);
78
79 err_vt:
80         kmscon_vt_unref(vt);
81 err_exit:
82         test_exit(eloop);
83 err_fail:
84         test_fail(ret);
85         return abs(ret);
86 }