diff options
Diffstat (limited to 'src/test/test-sleep.c')
-rw-r--r-- | src/test/test-sleep.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 5286442e26..2a6d5e765a 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ +#include <inttypes.h> #include <linux/fiemap.h> #include <stdio.h> @@ -7,13 +8,16 @@ #include "log.h" #include "sleep-config.h" #include "strv.h" +#include "tests.h" #include "util.h" static void test_parse_sleep_config(void) { const char *verb; + log_info("/* %s */", __func__); + FOREACH_STRING(verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate") - assert_se(parse_sleep_config(verb, NULL, NULL, NULL) == 0); + assert_se(parse_sleep_config(verb, NULL, NULL, NULL, NULL) == 0); } static int test_fiemap(const char *path) { @@ -21,42 +25,44 @@ static int test_fiemap(const char *path) { _cleanup_close_ int fd = -1; int r; + log_info("/* %s */", __func__); + fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK); if (fd < 0) return log_error_errno(errno, "failed to open %s: %m", path); r = read_fiemap(fd, &fiemap); - if (r == -EOPNOTSUPP) { - log_info("Skipping test, not supported"); - exit(EXIT_TEST_SKIP); - } + if (r == -EOPNOTSUPP) + exit(log_tests_skipped("Not supported")); if (r < 0) return log_error_errno(r, "Unable to read extent map for '%s': %m", path); log_info("extent map information for %s:", path); - log_info("\t start: %llu", fiemap->fm_start); - log_info("\t length: %llu", fiemap->fm_length); - log_info("\t flags: %u", fiemap->fm_flags); - log_info("\t number of mapped extents: %u", fiemap->fm_mapped_extents); - log_info("\t extent count: %u", fiemap->fm_extent_count); + log_info("\t start: %" PRIu64, (uint64_t) fiemap->fm_start); + log_info("\t length: %" PRIu64, (uint64_t) fiemap->fm_length); + log_info("\t flags: %" PRIu32, fiemap->fm_flags); + log_info("\t number of mapped extents: %" PRIu32, fiemap->fm_mapped_extents); + log_info("\t extent count: %" PRIu32, fiemap->fm_extent_count); if (fiemap->fm_extent_count > 0) - log_info("\t first extent location: %llu", - fiemap->fm_extents[0].fe_physical / page_size()); + log_info("\t first extent location: %" PRIu64, + (uint64_t) (fiemap->fm_extents[0].fe_physical / page_size())); return 0; } static void test_sleep(void) { _cleanup_strv_free_ char - **standby = strv_new("standby", NULL), - **mem = strv_new("mem", NULL), - **disk = strv_new("disk", NULL), - **suspend = strv_new("suspend", NULL), - **reboot = strv_new("reboot", NULL), - **platform = strv_new("platform", NULL), - **shutdown = strv_new("shutdown", NULL), - **freez = strv_new("freeze", NULL); + **standby = strv_new("standby"), + **mem = strv_new("mem"), + **disk = strv_new("disk"), + **suspend = strv_new("suspend"), + **reboot = strv_new("reboot"), + **platform = strv_new("platform"), + **shutdown = strv_new("shutdown"), + **freez = strv_new("freeze"); int r; - log_info("/* configuration */"); + log_info("/* %s */", __func__); + + log_info("/= configuration =/"); log_info("Standby configured: %s", yes_no(can_sleep_state(standby) > 0)); log_info("Suspend configured: %s", yes_no(can_sleep_state(mem) > 0)); log_info("Hibernate configured: %s", yes_no(can_sleep_state(disk) > 0)); @@ -66,7 +72,7 @@ static void test_sleep(void) { log_info("Hibernate+Shutdown configured: %s", yes_no(can_sleep_disk(shutdown) > 0)); log_info("Freeze configured: %s", yes_no(can_sleep_state(freez) > 0)); - log_info("/* running system */"); + log_info("/= running system =/"); r = can_sleep("suspend"); log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r)); r = can_sleep("hibernate"); @@ -80,8 +86,7 @@ static void test_sleep(void) { int main(int argc, char* argv[]) { int i, r = 0, k; - log_parse_environment(); - log_open(); + test_setup_logging(LOG_INFO); if (getuid() != 0) log_warning("This program is unlikely to work for unprivileged users"); |