]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-sleep.c
test-sleep: add more logging, show secure boot mode
[thirdparty/systemd.git] / src / test / test-sleep.c
index 2ce79f8345c460012bfdb0de0c91ebdda1ea63a1..8b4fa82640b443f660c149609fbd843c72f69828 100644 (file)
@@ -1,21 +1,46 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include <fcntl.h>
 #include <inttypes.h>
 #include <linux/fiemap.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
 
+#include "efivars.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "log.h"
+#include "memory-util.h"
 #include "sleep-config.h"
 #include "strv.h"
 #include "tests.h"
 #include "util.h"
 
 static void test_parse_sleep_config(void) {
-        const char *verb;
-
-        FOREACH_STRING(verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate")
-                assert_se(parse_sleep_config(verb, NULL, NULL, NULL) == 0);
+        _cleanup_(free_sleep_configp) SleepConfig *sleep_config = NULL;
+        log_info("/* %s */", __func__);
+
+        assert_se(parse_sleep_config(&sleep_config) == 0);
+
+        _cleanup_free_ char *sum, *sus, *him, *his, *hym, *hys;
+
+        sum = strv_join(sleep_config->suspend_modes, ", ");
+        sus = strv_join(sleep_config->suspend_states, ", ");
+        him = strv_join(sleep_config->hibernate_modes, ", ");
+        his = strv_join(sleep_config->hibernate_states, ", ");
+        hym = strv_join(sleep_config->hybrid_modes, ", ");
+        hys = strv_join(sleep_config->hybrid_states, ", ");
+        log_debug("  allow_suspend: %u", sleep_config->allow_suspend);
+        log_debug("  allow_hibernate: %u", sleep_config->allow_hibernate);
+        log_debug("  allow_s2h: %u", sleep_config->allow_s2h);
+        log_debug("  allow_hybrid_sleep: %u", sleep_config->allow_hybrid_sleep);
+        log_debug("  suspend modes: %s", sum);
+        log_debug("         states: %s", sus);
+        log_debug("  hibernate modes: %s", him);
+        log_debug("           states: %s", his);
+        log_debug("  hybrid modes: %s", hym);
+        log_debug("        states: %s", hys);
 }
 
 static int test_fiemap(const char *path) {
@@ -23,6 +48,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);
@@ -46,17 +73,21 @@ static int test_fiemap(const char *path) {
 
 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"),
+                **freeze = strv_new("freeze");
         int r;
 
-        log_info("/* configuration */");
+        log_info("/* %s */", __func__);
+
+        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));
@@ -64,23 +95,23 @@ static void test_sleep(void) {
         log_info("Hibernate+Reboot configured: %s", yes_no(can_sleep_disk(reboot) > 0));
         log_info("Hibernate+Platform configured: %s", yes_no(can_sleep_disk(platform) > 0));
         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("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(-r));
+        log_info("Suspend configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
         r = can_sleep("hibernate");
-        log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
+        log_info("Hibernation configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
         r = can_sleep("hybrid-sleep");
-        log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
+        log_info("Hybrid-sleep configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
         r = can_sleep("suspend-then-hibernate");
-        log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror(-r));
+        log_info("Suspend-then-Hibernate configured and possible: %s", r >= 0 ? yes_no(r) : strerror_safe(r));
 }
 
 int main(int argc, char* argv[]) {
         int i, r = 0, k;
 
-        test_setup_logging(LOG_INFO);
+        test_setup_logging(LOG_DEBUG);
 
         if (getuid() != 0)
                 log_warning("This program is unlikely to work for unprivileged users");