1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include <linux/fiemap.h>
11 #include "errno-util.h"
14 #include "memory-util.h"
15 #include "sleep-config.h"
19 TEST(parse_sleep_config
) {
20 _cleanup_(free_sleep_configp
) SleepConfig
*sleep_config
= NULL
;
22 assert_se(parse_sleep_config(&sleep_config
) == 0);
24 _cleanup_free_
char *sum
, *sus
, *him
, *his
, *hym
, *hys
;
26 sum
= strv_join(sleep_config
->modes
[SLEEP_SUSPEND
], ", ");
27 sus
= strv_join(sleep_config
->states
[SLEEP_SUSPEND
], ", ");
28 him
= strv_join(sleep_config
->modes
[SLEEP_HIBERNATE
], ", ");
29 his
= strv_join(sleep_config
->states
[SLEEP_HIBERNATE
], ", ");
30 hym
= strv_join(sleep_config
->modes
[SLEEP_HYBRID_SLEEP
], ", ");
31 hys
= strv_join(sleep_config
->states
[SLEEP_HYBRID_SLEEP
], ", ");
32 log_debug(" allow_suspend: %s", yes_no(sleep_config
->allow
[SLEEP_SUSPEND
]));
33 log_debug(" allow_hibernate: %s", yes_no(sleep_config
->allow
[SLEEP_HIBERNATE
]));
34 log_debug(" allow_s2h: %s", yes_no(sleep_config
->allow
[SLEEP_SUSPEND_THEN_HIBERNATE
]));
35 log_debug(" allow_hybrid_sleep: %s", yes_no(sleep_config
->allow
[SLEEP_HYBRID_SLEEP
]));
36 log_debug(" suspend modes: %s", sum
);
37 log_debug(" states: %s", sus
);
38 log_debug(" hibernate modes: %s", him
);
39 log_debug(" states: %s", his
);
40 log_debug(" hybrid modes: %s", hym
);
41 log_debug(" states: %s", hys
);
44 static int test_fiemap_one(const char *path
) {
45 _cleanup_free_
struct fiemap
*fiemap
= NULL
;
46 _cleanup_close_
int fd
= -1;
49 log_info("/* %s */", __func__
);
51 fd
= open(path
, O_RDONLY
| O_CLOEXEC
| O_NONBLOCK
);
53 return log_error_errno(errno
, "failed to open %s: %m", path
);
54 r
= read_fiemap(fd
, &fiemap
);
56 exit(log_tests_skipped("Not supported"));
58 return log_error_errno(r
, "Unable to read extent map for '%s': %m", path
);
59 log_info("extent map information for %s:", path
);
60 log_info("\t start: %" PRIu64
, (uint64_t) fiemap
->fm_start
);
61 log_info("\t length: %" PRIu64
, (uint64_t) fiemap
->fm_length
);
62 log_info("\t flags: %" PRIu32
, fiemap
->fm_flags
);
63 log_info("\t number of mapped extents: %" PRIu32
, fiemap
->fm_mapped_extents
);
64 log_info("\t extent count: %" PRIu32
, fiemap
->fm_extent_count
);
65 if (fiemap
->fm_extent_count
> 0)
66 log_info("\t first extent location: %" PRIu64
,
67 (uint64_t) (fiemap
->fm_extents
[0].fe_physical
/ page_size()));
75 assert_se(test_fiemap_one(saved_argv
[0]) == 0);
76 for (int i
= 1; i
< saved_argc
; i
++) {
77 int k
= test_fiemap_one(saved_argv
[i
]);
86 _cleanup_strv_free_
char
87 **standby
= strv_new("standby"),
88 **mem
= strv_new("mem"),
89 **disk
= strv_new("disk"),
90 **suspend
= strv_new("suspend"),
91 **reboot
= strv_new("reboot"),
92 **platform
= strv_new("platform"),
93 **shutdown
= strv_new("shutdown"),
94 **freeze
= strv_new("freeze");
97 printf("Secure boot: %sd\n", enable_disable(is_efi_secure_boot()));
99 log_info("/= individual sleep modes =/");
100 log_info("Standby configured: %s", yes_no(can_sleep_state(standby
) > 0));
101 log_info("Suspend configured: %s", yes_no(can_sleep_state(mem
) > 0));
102 log_info("Hibernate configured: %s", yes_no(can_sleep_state(disk
) > 0));
103 log_info("Hibernate+Suspend (Hybrid-Sleep) configured: %s", yes_no(can_sleep_disk(suspend
) > 0));
104 log_info("Hibernate+Reboot configured: %s", yes_no(can_sleep_disk(reboot
) > 0));
105 log_info("Hibernate+Platform configured: %s", yes_no(can_sleep_disk(platform
) > 0));
106 log_info("Hibernate+Shutdown configured: %s", yes_no(can_sleep_disk(shutdown
) > 0));
107 log_info("Freeze configured: %s", yes_no(can_sleep_state(freeze
) > 0));
109 log_info("/= high-level sleep verbs =/");
110 r
= can_sleep(SLEEP_SUSPEND
);
111 log_info("Suspend configured and possible: %s", r
>= 0 ? yes_no(r
) : STRERROR(r
));
112 r
= can_sleep(SLEEP_HIBERNATE
);
113 log_info("Hibernation configured and possible: %s", r
>= 0 ? yes_no(r
) : STRERROR(r
));
114 r
= can_sleep(SLEEP_HYBRID_SLEEP
);
115 log_info("Hybrid-sleep configured and possible: %s", r
>= 0 ? yes_no(r
) : STRERROR(r
));
116 r
= can_sleep(SLEEP_SUSPEND_THEN_HIBERNATE
);
117 log_info("Suspend-then-Hibernate configured and possible: %s", r
>= 0 ? yes_no(r
) : STRERROR(r
));
120 static int intro(void) {
122 log_warning("This program is unlikely to work for unprivileged users");
127 DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG
, intro
);