chiark / gitweb /
journalctl: Unify boot id lookup into common function get_boots
[elogind.git] / src / test / test-sleep.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2012 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <fcntl.h>
26
27 #include "util.h"
28 #include "log.h"
29 #include "sleep-config.h"
30 #include "strv.h"
31
32 static void test_sleep(void) {
33         _cleanup_strv_free_ char
34                 **standby = strv_new("standby", NULL),
35                 **mem = strv_new("mem", NULL),
36                 **disk = strv_new("disk", NULL),
37                 **suspend = strv_new("suspend", NULL),
38                 **reboot = strv_new("reboot", NULL),
39                 **platform = strv_new("platform", NULL),
40                 **shutdown = strv_new("shutdown", NULL),
41                 **freez = strv_new("freeze", NULL);
42
43         log_info("Standby configured: %s", yes_no(can_sleep_state(standby) > 0));
44         log_info("Suspend configured: %s", yes_no(can_sleep_state(mem) > 0));
45         log_info("Hibernate configured: %s", yes_no(can_sleep_state(disk) > 0));
46         log_info("Hibernate+Suspend (Hybrid-Sleep) configured: %s", yes_no(can_sleep_disk(suspend) > 0));
47         log_info("Hibernate+Reboot configured: %s", yes_no(can_sleep_disk(reboot) > 0));
48         log_info("Hibernate+Platform configured: %s", yes_no(can_sleep_disk(platform) > 0));
49         log_info("Hibernate+Shutdown configured: %s", yes_no(can_sleep_disk(shutdown) > 0));
50         log_info("Freeze configured: %s", yes_no(can_sleep_state(freez) > 0));
51
52         log_info("Suspend configured and possible: %s", yes_no(can_sleep("suspend") > 0));
53         log_info("Hibernation configured and possible: %s", yes_no(can_sleep("hibernate") > 0));
54         log_info("Hybrid-sleep configured and possible: %s", yes_no(can_sleep("hybrid-sleep") > 0));
55 }
56
57 int main(int argc, char* argv[]) {
58         log_parse_environment();
59         log_open();
60
61         if (getuid() != 0)
62                 log_warning("This program is unlikely to work for unpriviledged users");
63
64         test_sleep();
65
66         return 0;
67 }