]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sleep.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2012 Lennart Poettering
8 #include <linux/fiemap.h>
13 #include "sleep-config.h"
17 static int test_fiemap(const char *path
) {
18 _cleanup_free_
struct fiemap
*fiemap
= NULL
;
19 _cleanup_close_
int fd
= -1;
22 fd
= open(path
, O_RDONLY
| O_CLOEXEC
| O_NONBLOCK
);
24 return log_error_errno(errno
, "failed to open %s: %m", path
);
25 r
= read_fiemap(fd
, &fiemap
);
27 log_info("Skipping test, not supported");
31 return log_error_errno(r
, "Unable to read extent map for '%s': %m", path
);
32 log_info("extent map information for %s:", path
);
33 log_info("\t start: %llu", fiemap
->fm_start
);
34 log_info("\t length: %llu", fiemap
->fm_length
);
35 log_info("\t flags: %u", fiemap
->fm_flags
);
36 log_info("\t number of mapped extents: %u", fiemap
->fm_mapped_extents
);
37 log_info("\t extent count: %u", fiemap
->fm_extent_count
);
38 if (fiemap
->fm_extent_count
> 0)
39 log_info("\t first extent location: %llu",
40 fiemap
->fm_extents
[0].fe_physical
/ page_size());
45 static void test_sleep(void) {
46 _cleanup_strv_free_
char
47 **standby
= strv_new("standby", NULL
),
48 **mem
= strv_new("mem", NULL
),
49 **disk
= strv_new("disk", NULL
),
50 **suspend
= strv_new("suspend", NULL
),
51 **reboot
= strv_new("reboot", NULL
),
52 **platform
= strv_new("platform", NULL
),
53 **shutdown
= strv_new("shutdown", NULL
),
54 **freez
= strv_new("freeze", NULL
);
57 log_info("/* configuration */");
58 log_info("Standby configured: %s", yes_no(can_sleep_state(standby
) > 0));
59 log_info("Suspend configured: %s", yes_no(can_sleep_state(mem
) > 0));
60 log_info("Hibernate configured: %s", yes_no(can_sleep_state(disk
) > 0));
61 log_info("Hibernate+Suspend (Hybrid-Sleep) configured: %s", yes_no(can_sleep_disk(suspend
) > 0));
62 log_info("Hibernate+Reboot configured: %s", yes_no(can_sleep_disk(reboot
) > 0));
63 log_info("Hibernate+Platform configured: %s", yes_no(can_sleep_disk(platform
) > 0));
64 log_info("Hibernate+Shutdown configured: %s", yes_no(can_sleep_disk(shutdown
) > 0));
65 log_info("Freeze configured: %s", yes_no(can_sleep_state(freez
) > 0));
67 log_info("/* running system */");
68 r
= can_sleep("suspend");
69 log_info("Suspend configured and possible: %s", r
>= 0 ? yes_no(r
) : strerror(-r
));
70 r
= can_sleep("hibernate");
71 log_info("Hibernation configured and possible: %s", r
>= 0 ? yes_no(r
) : strerror(-r
));
72 r
= can_sleep("hybrid-sleep");
73 log_info("Hybrid-sleep configured and possible: %s", r
>= 0 ? yes_no(r
) : strerror(-r
));
74 r
= can_sleep("suspend-then-hibernate");
75 log_info("Suspend-then-Hibernate configured and possible: %s", r
>= 0 ? yes_no(r
) : strerror(-r
));
78 int main(int argc
, char* argv
[]) {
81 log_parse_environment();
85 log_warning("This program is unlikely to work for unprivileged users");
90 assert_se(test_fiemap(argv
[0]) == 0);
92 for (i
= 1; i
< argc
; i
++) {
93 k
= test_fiemap(argv
[i
]);