sleep-util: split battery-capacity into sleep/

This is only used by sleep.c. Let's start shrinking down
the "mixed" sleep-util.
This commit is contained in:
Mike Yuan
2023-09-27 21:48:39 +08:00
parent 43309f14d9
commit 7d769198e0
7 changed files with 447 additions and 38 deletions
-27
View File
@@ -117,33 +117,6 @@ TEST(sleep) {
log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : STRERROR(r));
}
TEST(fetch_batteries_capacity_by_name) {
_cleanup_hashmap_free_ Hashmap *capacity = NULL;
int r;
assert_se(fetch_batteries_capacity_by_name(&capacity) >= 0);
log_debug("fetch_batteries_capacity_by_name: %u entries", hashmap_size(capacity));
const char *name;
void *cap;
HASHMAP_FOREACH_KEY(cap, name, capacity) {
assert(cap); /* Anything non-null is fine. */
log_info("Battery %s: capacity = %i", name, get_capacity_by_name(capacity, name));
}
for (int i = 0; i < 2; i++) {
usec_t interval;
if (i > 0)
sleep(1);
r = get_total_suspend_interval(capacity, &interval);
assert_se(r >= 0 || r == -ENOENT);
log_info("%d: get_total_suspend_interval: %s", i,
r < 0 ? STRERROR(r) : FORMAT_TIMESPAN(interval, USEC_PER_SEC));
}
}
static int intro(void) {
if (getuid() != 0)
log_warning("This program is unlikely to work for unprivileged users");