summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-04 22:43:54 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-05-09 08:10:20 +0200
commitfb5578b3c3e3a9aed28d573e0a1e549a30b61264 (patch)
treebb9e2402d2a2dddc8bad79fc58699712b69e369c /src/test
parent210cb8d690cf585b7cd162efbdc563a5ae6921ff (diff)
downloadsystemd-fb5578b3c3e3a9aed28d573e0a1e549a30b61264.tar.gz
test-udev: add an optional timeout argument
The tests wants to call some workers with a delay. This implements the delay directly in test-udev so that the caller can be simplified. Note that the argument is to be used by the other test file, so this is purposefully implemented in a simple way.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-udev.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/test/test-udev.c b/src/test/test-udev.c
index 3ca132db3b..00ca79d0eb 100644
--- a/src/test/test-udev.c
+++ b/src/test/test-udev.c
@@ -18,6 +18,7 @@
#include "mkdir-label.h"
#include "mount-util.h"
#include "namespace-util.h"
+#include "parse-util.h"
#include "selinux-util.h"
#include "signal-util.h"
#include "string-util.h"
@@ -92,9 +93,9 @@ static int run(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
- if (!IN_SET(argc, 2, 3))
+ if (!IN_SET(argc, 2, 3, 4))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "This program needs one or two arguments, %d given", argc - 1);
+ "This program needs between one and three arguments, %d given", argc - 1);
r = fake_filesystems();
if (r < 0)
@@ -123,10 +124,18 @@ static int run(int argc, char *argv[]) {
action = argv[1];
devpath = argv[2];
+ if (argv[3]) {
+ unsigned us;
+
+ r = safe_atou(argv[3], &us);
+ if (r < 0)
+ return log_error_errno(r, "Invalid delay '%s': %m", argv[3]);
+ usleep(us);
+ }
+
assert_se(udev_rules_load(&rules, RESOLVE_NAME_EARLY) == 0);
- const char *syspath;
- syspath = strjoina("/sys", devpath);
+ const char *syspath = strjoina("/sys", devpath);
r = device_new_from_synthetic_event(&dev, syspath, action);
if (r < 0)
return log_debug_errno(r, "Failed to open device '%s'", devpath);