]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: introduce our own sleep command for testing
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Dec 2025 08:57:53 +0000 (17:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Dec 2025 09:09:21 +0000 (18:09 +0900)
src/test/meson.build
src/test/test-sleep.c [new file with mode: 0644]

index 2366dbaf1c2d00f2b91149417ba0e75bc9b6015e..a21f85c2ecb27da6dc09afe39f73339f49b821b9 100644 (file)
@@ -460,6 +460,10 @@ executables += [
                         libbasic_static,
                 ],
         },
+        test_template + {
+                'sources' : files('test-sleep.c'),
+                'type' : 'manual',
+        },
         test_template + {
                 'sources' : files('test-time-util.c'),
                 'timeout' : 120,
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c
new file mode 100644 (file)
index 0000000..90b5cfe
--- /dev/null
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "log.h"
+#include "main-func.h"
+#include "time-util.h"
+
+static int run(int argc, char *argv[]) {
+        usec_t usec = USEC_INFINITY;
+        int r;
+
+        if (argc > 1) {
+                r = parse_sec(argv[1], &usec);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse timespan '%s': %m", argv[1]);
+        }
+
+        r = usleep_safe(usec);
+        if (r < 0)
+                return log_error_errno(r, "Failed to sleep: %m");
+
+        return 0;
+}
+
+DEFINE_MAIN_FUNCTION(run);