Merge pull request #27534 from keszybz/deperlify

Rewrite udev-test.pl in Python
This commit is contained in:
Yu Watanabe
2023-05-09 18:06:51 +09:00
committed by GitHub
21 changed files with 2556 additions and 3008 deletions
-2
View File
@@ -99,8 +99,6 @@ enum JobResult {
_JOB_RESULT_INVALID = -EINVAL,
};
#include "unit.h"
struct JobDependency {
/* Encodes that the 'subject' job needs the 'object' job in
* some way. This structure is used only while building a transaction. */
+1 -1
View File
@@ -409,7 +409,7 @@ tests += [
'timeout' : 120,
},
{
'sources' : files('test-udev.c'),
'sources' : files('udev-rule-runner.c'),
'link_with' : [
libshared,
libudevd_core,
@@ -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);
+4 -2
View File
@@ -18,13 +18,15 @@ import textwrap
try:
import pytest
except ImportError:
except ImportError as e:
print(str(e), file=sys.stderr)
sys.exit(77)
try:
# pyflakes: noqa
import pefile # noqa
except ImportError:
except ImportError as e:
print(str(e), file=sys.stderr)
sys.exit(77)
# We import ukify.py, which is a template file. But only __version__ is