eloop: move prefix to "ev_" instead of "kmscon_"
[platform/upstream/kmscon.git] / tests / test_vt.c
1 /*
2  * test_console - Test VT Layer
3  *
4  * Copyright (c) 2011 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  * freezed then 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
47 static bool terminate;
48
49 static void sig_term(struct ev_signal *sig, int signum, void *data)
50 {
51         terminate = true;
52 }
53
54 int main(int argc, char **argv)
55 {
56         int ret;
57         struct ev_eloop *loop;
58         struct kmscon_vt *vt;
59         struct ev_signal *sig;
60
61         ret = ev_eloop_new(&loop);
62         if (ret) {
63                 log_err("Cannot create eloop\n");
64                 goto err_out;
65         }
66
67         ret = ev_eloop_new_signal(loop, &sig, SIGINT, sig_term, NULL);
68         if (ret) {
69                 log_err("Cannot add signal\n");
70                 goto err_loop;
71         }
72
73         ret = kmscon_vt_new(&vt, NULL, NULL);
74         if (ret) {
75                 log_err("Cannot create vt\n");
76                 goto err_sig;
77         }
78
79         ret = kmscon_vt_open(vt, KMSCON_VT_NEW, loop);
80         if (ret) {
81                 log_err("Cannot open VT\n");
82                 goto err_vt;
83         }
84
85         ret = kmscon_vt_enter(vt);
86         if (ret)
87                 log_warn("Cannot switch to VT\n");
88
89         while (!terminate) {
90                 ret = ev_eloop_dispatch(loop, -1);
91                 if (ret) {
92                         log_err("Dispatcher failed\n");
93                         break;
94                 }
95         }
96
97         log_debug("Terminating\n");
98
99         /* switch back to previous VT but wait for eloop to process SIGUSR0 */
100         ret = kmscon_vt_leave(vt);
101         if (ret == -EINPROGRESS)
102                 ev_eloop_dispatch(loop, 1000);
103
104 err_vt:
105         kmscon_vt_unref(vt);
106 err_sig:
107         ev_eloop_rm_signal(sig);
108 err_loop:
109         ev_eloop_unref(loop);
110 err_out:
111         return abs(ret);
112 }