test: introduce our own sleep command for testing

This commit is contained in:
Yu Watanabe
2025-12-15 18:09:21 +09:00
parent 78385b8e94
commit 4c98063d6e
2 changed files with 28 additions and 0 deletions
+4
View 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,
+24
View File
@@ -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);