diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-08 21:39:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-08 21:39:54 +0200 |
commit | 1634ebb54a8955ab01dac9a59fc16f02f16cf007 (patch) | |
tree | 6ec49af7c236c2d5d210744dc7403da9a06d5f45 /src/test | |
parent | 3ccf61268fc500ec0fbc28c432f279c4b4aa8642 (diff) | |
parent | 9259d0e23ed09d1f9ea6b04e916df191181eadcb (diff) | |
download | systemd-1634ebb54a8955ab01dac9a59fc16f02f16cf007.tar.gz systemd-1634ebb54a8955ab01dac9a59fc16f02f16cf007.tar.bz2 systemd-1634ebb54a8955ab01dac9a59fc16f02f16cf007.zip |
Merge pull request #10262 from keszybz/hibres-disable
Switches to disable hibernation and/or resuming
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-proc-cmdline.c | 94 | ||||
-rw-r--r-- | src/test/test-sleep.c | 12 |
2 files changed, 89 insertions, 17 deletions
diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 8f77e084b6..5db103bd22 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "alloc-util.h" +#include "env-util.h" #include "log.h" #include "macro.h" #include "proc-cmdline.h" @@ -19,28 +20,68 @@ static int parse_item(const char *key, const char *value, void *data) { } static void test_proc_cmdline_parse(void) { - assert_se(proc_cmdline_parse(parse_item, &obj, true) >= 0); + log_info("/* %s */", __func__); + + assert_se(proc_cmdline_parse(parse_item, &obj, PROC_CMDLINE_STRIP_RD_PREFIX) >= 0); } -static void test_runlevel_to_target(void) { - in_initrd_force(false); - assert_se(streq_ptr(runlevel_to_target(NULL), NULL)); - assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET)); - assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL)); +static void test_proc_cmdline_override(void) { + log_info("/* %s */", __func__); - in_initrd_force(true); - assert_se(streq_ptr(runlevel_to_target(NULL), NULL)); - assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL)); - assert_se(streq_ptr(runlevel_to_target("3"), NULL)); - assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET)); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm") == 0); + + /* Test if the override works */ + _cleanup_free_ char *line = NULL, *value = NULL; + assert_se(proc_cmdline(&line) >= 0); + + /* Test if parsing makes uses of the override */ + assert_se(streq(line, "foo_bar=quux wuff-piep=tuet zumm")); + assert_se(proc_cmdline_get_key("foo_bar", 0, &value) > 0 && streq_ptr(value, "quux")); +} + +static int parse_item_given(const char *key, const char *value, void *data) { + assert_se(key); + assert_se(data); + + bool *strip = data; + + log_info("%s: option <%s> = <%s>", __func__, key, strna(value)); + if (streq(key, "foo_bar")) + assert_se(streq(value, "quux")); + else if (streq(key, "wuff-piep")) + assert_se(streq(value, "tuet ")); + else if (in_initrd() && *strip && streq(key, "zumm")) + assert_se(!value); + else if (in_initrd() && !*strip && streq(key, "rd.zumm")) + assert_se(!value); + else + assert_not_reached("Bad key!"); + + return 0; +} + +static void test_proc_cmdline_given(bool flip_initrd) { + log_info("/* %s (flip: %s) */", __func__, yes_no(flip_initrd)); + + if (flip_initrd) + in_initrd_force(!in_initrd()); + + bool t = true, f = false; + assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm", + parse_item_given, &t, PROC_CMDLINE_STRIP_RD_PREFIX) >= 0); + + assert_se(proc_cmdline_parse_given("foo_bar=quux wuff-piep=\"tuet \" rd.zumm", + parse_item_given, &f, 0) >= 0); + + + if (flip_initrd) + in_initrd_force(!in_initrd()); } static void test_proc_cmdline_get_key(void) { _cleanup_free_ char *value = NULL; + log_info("/* %s */", __func__); putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm"); assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL); @@ -78,6 +119,7 @@ static void test_proc_cmdline_get_key(void) { static void test_proc_cmdline_get_bool(void) { bool value = false; + log_info("/* %s */", __func__); putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep"); assert_se(proc_cmdline_get_bool("", &value) == -EINVAL); @@ -94,6 +136,7 @@ static void test_proc_cmdline_get_bool(void) { } static void test_proc_cmdline_key_streq(void) { + log_info("/* %s */", __func__); assert_se(proc_cmdline_key_streq("", "")); assert_se(proc_cmdline_key_streq("a", "a")); @@ -110,6 +153,7 @@ static void test_proc_cmdline_key_streq(void) { } static void test_proc_cmdline_key_startswith(void) { + log_info("/* %s */", __func__); assert_se(proc_cmdline_key_startswith("", "")); assert_se(proc_cmdline_key_startswith("x", "")); @@ -124,11 +168,33 @@ static void test_proc_cmdline_key_startswith(void) { assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx")); } +static void test_runlevel_to_target(void) { + log_info("/* %s */", __func__); + + in_initrd_force(false); + assert_se(streq_ptr(runlevel_to_target(NULL), NULL)); + assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("3"), SPECIAL_MULTI_USER_TARGET)); + assert_se(streq_ptr(runlevel_to_target("rd.rescue"), NULL)); + + in_initrd_force(true); + assert_se(streq_ptr(runlevel_to_target(NULL), NULL)); + assert_se(streq_ptr(runlevel_to_target("unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("rd.unknown-runlevel"), NULL)); + assert_se(streq_ptr(runlevel_to_target("3"), NULL)); + assert_se(streq_ptr(runlevel_to_target("rd.rescue"), SPECIAL_RESCUE_TARGET)); +} + int main(void) { log_parse_environment(); log_open(); test_proc_cmdline_parse(); + test_proc_cmdline_override(); + test_proc_cmdline_given(false); + /* Repeat the same thing, but now flip our ininitrdness */ + test_proc_cmdline_given(true); test_proc_cmdline_key_streq(); test_proc_cmdline_key_startswith(); test_proc_cmdline_get_key(); diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 2ce79f8345..442541a298 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -14,8 +14,10 @@ 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) { @@ -23,6 +25,8 @@ 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); @@ -56,7 +60,9 @@ static void test_sleep(void) { **freez = strv_new("freeze", NULL); 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"); |