diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-05-09 11:06:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 11:06:51 +0200 |
commit | c093bfe0ad47bd441b5f66005d73b7b62af554a0 (patch) | |
tree | 716d3dca6375ff3cb2ef0113b4eb49e6f4c1d62c /src/test | |
parent | bus-util: drop unnecessary continue (diff) | |
parent | mkosi,ci: do not install perl (diff) | |
download | systemd-c093bfe0ad47bd441b5f66005d73b7b62af554a0.tar.xz systemd-c093bfe0ad47bd441b5f66005d73b7b62af554a0.zip |
Merge pull request #27534 from keszybz/deperlify
Rewrite udev-test.pl in Python
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/meson.build | 2 | ||||
-rw-r--r-- | src/test/udev-rule-runner.c (renamed from src/test/test-udev.c) | 27 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/test/meson.build b/src/test/meson.build index 8a5e47f004..8e76df624d 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -409,7 +409,7 @@ tests += [ 'timeout' : 120, }, { - 'sources' : files('test-udev.c'), + 'sources' : files('udev-rule-runner.c'), 'link_with' : [ libshared, libudevd_core, diff --git a/src/test/test-udev.c b/src/test/udev-rule-runner.c index 3ca132db3b..0b5938802a 100644 --- a/src/test/test-udev.c +++ b/src/test/udev-rule-runner.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" @@ -61,11 +62,11 @@ static int fake_filesystems(void) { const char *error; bool ignore_mount_error; } fakefss[] = { - { "test/tmpfs/sys", "/sys", "Failed to mount test /sys", false }, - { "test/tmpfs/dev", "/dev", "Failed to mount test /dev", false }, - { "test/run", "/run", "Failed to mount test /run", false }, - { "test/run", "/etc/udev/rules.d", "Failed to mount empty /etc/udev/rules.d", true }, - { "test/run", UDEVLIBEXECDIR "/rules.d", "Failed to mount empty " UDEVLIBEXECDIR "/rules.d", true }, + { "tmpfs/sys", "/sys", "Failed to mount test /sys", false }, + { "tmpfs/dev", "/dev", "Failed to mount test /dev", false }, + { "run", "/run", "Failed to mount test /run", false }, + { "run", "/etc/udev/rules.d", "Failed to mount empty /etc/udev/rules.d", true }, + { "run", UDEVLIBEXECDIR "/rules.d", "Failed to mount empty " UDEVLIBEXECDIR "/rules.d", true }, }; int r; @@ -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); |