2 * kmscon - Common test functions
4 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include <sys/signalfd.h>
36 static void sig_generic(struct ev_eloop *p, struct signalfd_siginfo *info,
39 struct ev_eloop *eloop = data;
42 log_info("terminating due to caught signal %d", info->ssi_signo);
45 static int test_prepare(int argc, char **argv, struct ev_eloop **out)
48 struct ev_eloop *eloop;
50 ret = conf_parse_argv(argc, argv);
57 if (!conf_global.debug && !conf_global.verbose && conf_global.silent)
58 log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0));
60 log_set_config(&LOG_CONFIG_INFO(conf_global.debug,
61 conf_global.verbose));
63 log_print_init(argv[0]);
65 ret = ev_eloop_new(&eloop);
69 ret = ev_eloop_register_signal_cb(eloop, SIGTERM, sig_generic, eloop);
71 ev_eloop_unref(eloop);
75 ret = ev_eloop_register_signal_cb(eloop, SIGINT, sig_generic, eloop);
77 ev_eloop_unregister_signal_cb(eloop, SIGTERM,
79 ev_eloop_unref(eloop);
87 static void test_fail(int ret)
90 log_err("init failed, errno %d: %s", ret, strerror(-ret));
93 static void test_exit(struct ev_eloop *eloop)
95 ev_eloop_unregister_signal_cb(eloop, SIGINT, sig_generic, eloop);
96 ev_eloop_unregister_signal_cb(eloop, SIGTERM, sig_generic, eloop);
97 ev_eloop_unref(eloop);