From 933ab8199d51f25e7dafbaad54d73c80a4d15a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 27 Jul 2020 13:49:12 +0200 Subject: [PATCH 1/4] test-fs-util: do not assume /dev is always real When building in Fedora's koji, test-fs-util would fail: --- command --- 10:18:29 SYSTEMD_LANGUAGE_FALLBACK_MAP='/builddir/build/BUILD/systemd-246-rc2/src/locale/language-fallback-map' PATH='/builddir/build/BUILD/systemd-246-rc2/x86_64-redhat-linux-gnu:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin' SYSTEMD_KBD_MODEL_MAP='/builddir/build/BUILD/systemd-246-rc2/src/locale/kbd-model-map' /builddir/build/BUILD/systemd-246-rc2/x86_64-redhat-linux-gnu/test-fs-util --- stderr --- /* test_chase_symlinks */ /* test_unlink_noerrno */ /* test_readlink_and_make_absolute */ /* test_var_tmp */ /* test_dot_or_dot_dot */ /* test_access_fd */ /* test_touch_file */ /* test_unlinkat_deallocate */ /* test_fsync_directory_of_file */ /* test_rename_noreplace */ /* test_path_is_encrypted */ /home encrypted: yes /var encrypted: yes / encrypted: yes /proc encrypted: no /sys encrypted: no /dev encrypted: yes Assertion 'expect < 0 || ((r > 0) == (expect > 0))' failed at src/test/test-fs-util.c:863, function test_path_is_encrypted_one(). Aborting. ------- It seems / is encrypted, but /dev is just a normal directory. --- src/test/test-fs-util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 8d9a1974b2..dfea70ca27 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -864,14 +864,17 @@ static void test_path_is_encrypted_one(const char *p, int expect) { } static void test_path_is_encrypted(void) { - log_info("/* %s */", __func__); + int booted = sd_booted(); /* If this is run in build environments such as koji, /dev might be a + * reguar fs. Don't assume too much if not running under systemd. */ + + log_info("/* %s (sd_booted=%d)*/", __func__, booted); test_path_is_encrypted_one("/home", -1); test_path_is_encrypted_one("/var", -1); test_path_is_encrypted_one("/", -1); test_path_is_encrypted_one("/proc", false); test_path_is_encrypted_one("/sys", false); - test_path_is_encrypted_one("/dev", false); + test_path_is_encrypted_one("/dev", booted > 0 ? false : -1); } int main(int argc, char *argv[]) { From 500727c220354b81b68ed6667d9a6f0fafe3ba19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 27 Jul 2020 15:08:35 +0200 Subject: [PATCH 2/4] test-path: increase timeout The tests fail in Fedora's koji with a timeout. Let's just bump the timeout: --- stderr --- Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-exists.service: Failed to create cgroup /system.slice/kojid.service/path-exists.service: Permission denied path-exists.service: Succeeded. -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-exists.service: Failed to create cgroup /system.slice/kojid.service/path-exists.service: Permission denied path-exists.service: Succeeded. path-exists.path: Succeeded. Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-existsglob.service: Failed to create cgroup /system.slice/kojid.service/path-existsglob.service: Permission denied path-existsglob.service: Succeeded. -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-existsglob.service: Failed to create cgroup /system.slice/kojid.service/path-existsglob.service: Permission denied path-existsglob.service: Succeeded. path-existsglob.path: Succeeded. Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-changed.service: Failed to create cgroup /system.slice/kojid.service/path-changed.service: Permission denied path-changed.service: Succeeded. -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-changed.service: Failed to create cgroup /system.slice/kojid.service/path-changed.service: Permission denied path-changed.service: Succeeded. path-changed.path: Succeeded. Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-modified.service: Failed to create cgroup /system.slice/kojid.service/path-modified.service: Permission denied path-modified.service: Succeeded. -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-modified.service: Failed to create cgroup /system.slice/kojid.service/path-modified.service: Permission denied path-modified.service: Succeeded. path-modified.path: Succeeded. Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-mycustomunit.service: Failed to create cgroup /system.slice/kojid.service/path-mycustomunit.service: Permission denied path-mycustomunit.service: Succeeded. path-unit.path: Succeeded. Failed to connect to system bus: No such file or directory -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-directorynotempty.service: Failed to create cgroup /system.slice/kojid.service/path-directorynotempty.service: Permission denied path-directorynotempty.service: Succeeded. -.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied path-directorynotempty.service: Failed to create cgroup /system.slice/kojid.service/path-directorynotempty.service: Permission denied path-directorynotempty.service: Failed to attach to cgroup /system.slice/kojid.service/path-directorynotempty.service: No such file or directory path-directorynotempty.service: Failed at step CGROUP spawning /bin/true: No such file or directory path-directorynotempty.service: Main process exited, code=exited, status=219/CGROUP path-directorynotempty.service: Failed with result 'exit-code'. Test timeout when testing path-directorynotempty.path --- src/test/test-path.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/test/test-path.c b/src/test/test-path.c index e8844fd5ef..1075f31bc6 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -79,21 +79,15 @@ static Service *service_for_path(Manager *m, Path *path, const char *service_nam } static void check_states(Manager *m, Path *path, Service *service, PathState path_state, ServiceState service_state) { - usec_t ts; - usec_t timeout = 2 * USEC_PER_SEC; - assert_se(m); assert_se(service); - ts = now(CLOCK_MONOTONIC); + usec_t end = now(CLOCK_MONOTONIC) + 30 * USEC_PER_SEC; while (path->result != PATH_SUCCESS || service->result != SERVICE_SUCCESS || path->state != path_state || service->state != service_state) { - usec_t n; - int r; - r = sd_event_run(m->event, 100 * USEC_PER_MSEC); - assert_se(r >= 0); + assert_se(sd_event_run(m->event, 100 * USEC_PER_MSEC) >= 0); printf("%s: state = %s; result = %s \n", UNIT(path)->id, @@ -104,8 +98,7 @@ static void check_states(Manager *m, Path *path, Service *service, PathState pat service_state_to_string(service->state), service_result_to_string(service->result)); - n = now(CLOCK_MONOTONIC); - if (ts + timeout < n) { + if (now(CLOCK_MONOTONIC) >= end) { log_error("Test timeout when testing %s", UNIT(path)->id); exit(EXIT_FAILURE); } From c21ed6812e9894365e080b0ca9e917b79587f6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 27 Jul 2020 16:09:22 +0200 Subject: [PATCH 3/4] test-ndisc-rs: increase timeouts Timestamp: Mon 2020-07-27 13:50:50 UTC Monotonic: 985702942708 Hop limit: 64 Flags: <|MANAGED> Preference: medium Lifetime: 180 No MTU set >> Option 3 Valid Lifetime: 500 Preferred Lifetime: 440 Flags: Prefix Length: 64 Prefix: 2001:db8:dead:beef:: >> Option 25 DNS: 2001:db8:dead:beef::1 Lifetime: 60 >> Option 31 Domain: lab.intra Lifetime: 60 >> Option 1 Address: 782bcbb36d53 NDISC: Started IPv6 Router Solicitation client backoff timeout interval 1 3.600s <= 3.987s <= 4.400s NDISC: Sent Router Solicitation, next solicitation in 3s backoff timeout interval 2 7.576s <= 8.114s <= 8.374s NDISC: Sent Router Solicitation, next solicitation in 8s Assertion 'false' failed at src/libsystemd-network/test-ndisc-rs.c:172, function test_rs_hangcheck(). Aborting. --- src/libsystemd-network/test-ndisc-rs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c index 5d1e66fcdc..3f46c8d0c5 100644 --- a/src/libsystemd-network/test-ndisc-rs.c +++ b/src/libsystemd-network/test-ndisc-rs.c @@ -217,7 +217,7 @@ static int send_ra(uint8_t flags) { advertisement[5] = flags; assert_se(write(test_fd[1], advertisement, sizeof(advertisement)) == - sizeof(advertisement)); + sizeof(advertisement)); if (verbose) printf(" sent RA with flag 0x%02x\n", flags); @@ -291,8 +291,8 @@ static void test_rs(void) { assert_se(sd_ndisc_set_callback(nd, test_callback, e) >= 0); assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(), - time_now + 2 *USEC_PER_SEC, 0, - test_rs_hangcheck, NULL) >= 0); + time_now + 30 * USEC_PER_SEC, 0, + test_rs_hangcheck, NULL) >= 0); assert_se(sd_ndisc_stop(nd) >= 0); assert_se(sd_ndisc_start(nd) >= 0); @@ -393,8 +393,8 @@ static void test_timeout(void) { assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0); assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(), - time_now + 2U * USEC_PER_SEC, 0, - test_rs_hangcheck, NULL) >= 0); + time_now + 30 * USEC_PER_SEC, 0, + test_rs_hangcheck, NULL) >= 0); assert_se(sd_ndisc_start(nd) >= 0); From c550cb7f8cbd4727cb484e6ef30fc6b95d7e4d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 27 Jul 2020 17:36:56 +0200 Subject: [PATCH 4/4] test-sleep: add more logging, show secure boot mode In https://bugzilla.redhat.com/show_bug.cgi?id=1858219 a user reported that hibernation is not supported. This is probably caused by secure boot, but our current logging does not make this obvious. --- src/shared/sleep-config.c | 8 +++++++- src/test/test-sleep.c | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 6b9074ce2b..0dccc8f970 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -125,10 +125,16 @@ int can_sleep_state(char **types) { k = strlen(*type); FOREACH_WORD_SEPARATOR(word, l, p, WHITESPACE, state) - if (l == k && memcmp(word, *type, l) == 0) + if (l == k && memcmp(word, *type, l) == 0) { + log_debug("Sleep mode \"%s\" is supported by the kernel.", *type); return true; + } } + if (DEBUG_LOGGING) { + _cleanup_free_ char *t = strv_join(types, "/"); + log_debug("Sleep mode %s not supported by the kernel, sorry.", strnull(t)); + } return false; } diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 2e63aace02..8b4fa82640 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -7,6 +7,7 @@ #include #include +#include "efivars.h" #include "errno-util.h" #include "fd-util.h" #include "log.h" @@ -84,7 +85,9 @@ static void test_sleep(void) { log_info("/* %s */", __func__); - log_info("/= configuration =/"); + printf("Secure boot: %sd\n", enable_disable(is_efi_secure_boot())); + + log_info("/= individual sleep modes =/"); 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)); @@ -94,7 +97,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(freeze) > 0)); - log_info("/= running system =/"); + log_info("/= high-level sleep verbs =/"); r = can_sleep("suspend"); log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r)); r = can_sleep("hibernate");