1 Star 0 Fork 50

杨枝甘露瑞纳冰/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0540-test-udev-test.pl-generator-for-large-list-of-block-.patch 3.31 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2021-06-16 16:46 . update to systemd-239-45.el8.src.rpm
From 6c3191e979165700f98903b76621c214186a110c Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Wed, 25 Apr 2018 09:54:26 +0200
Subject: [PATCH] test/udev-test.pl: generator for large list of block devices
Manually listing all devices in the test definition becomes cumbersome with
lots of devices. Add a function that scans on all block devices in
the test sysfs and generates a list of devices to test.
(cherry picked from commit eb44d715ebee2fe11288433b99f8e1dc5fdac84a)
Related: #1642728
---
test/udev-test.pl | 60 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 59 insertions(+), 1 deletion(-)
diff --git a/test/udev-test.pl b/test/udev-test.pl
index 8b1ab3c06c..2866fdb77a 100755
--- a/test/udev-test.pl
+++ b/test/udev-test.pl
@@ -50,6 +50,50 @@ for (my $i = 1; $i < 10000; ++$i) {
}
$rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n";
+# Create a device list with all block devices under /sys
+# (except virtual devices and cd-roms)
+# the optional argument exp_func returns expected and non-expected
+# symlinks for the device.
+sub all_block_devs {
+ my ($exp_func) = @_;
+ my @devices;
+
+ foreach my $bd (glob "$udev_sys/dev/block/*") {
+ my $tgt = readlink($bd);
+ my ($exp, $notexp) = (undef, undef);
+
+ next if ($tgt =~ m!/virtual/! || $tgt =~ m!/sr[0-9]*$!);
+
+ $tgt =~ s!^\.\./\.\.!!;
+ ($exp, $notexp) = $exp_func->($tgt) if defined($exp_func);
+ my $device = {
+ devpath => $tgt,
+ exp_links => $exp,
+ not_exp_links => $notexp,
+ };
+ push(@devices, $device);
+ }
+ return \@devices;
+}
+
+# This generator returns a suitable exp_func for use with
+# all_block_devs().
+sub expect_for_some {
+ my ($pattern, $links, $donot) = @_;
+ my $_expect = sub {
+ my ($name) = @_;
+
+ if ($name =~ /$pattern/) {
+ return ($links, undef);
+ } elsif ($donot) {
+ return (undef, $links);
+ } else {
+ return (undef, undef);
+ }
+ };
+ return $_expect;
+}
+
my @tests = (
{
desc => "no rules",
@@ -2257,6 +2301,15 @@ SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partitio
KERNEL=="*7", OPTIONS+="link_priority=10"
EOF
},
+ {
+ desc => 'all_block_devs',
+ generator => expect_for_some("\\/sda6\$", ["blockdev"]),
+ repeat => 10,
+ rules => <<EOF
+SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sd*", SYMLINK+="blockdev"
+KERNEL=="sda6", OPTIONS+="link_priority=10"
+EOF
+ }
);
sub create_rules {
@@ -2631,7 +2684,12 @@ sub fork_and_run_udev {
sub run_test {
my ($rules, $number, $sema) = @_;
my $rc;
- my @devices = @{$rules->{devices}};
+ my @devices;
+
+ if (!defined $rules->{devices}) {
+ $rules->{devices} = all_block_devs($rules->{generator});
+ }
+ @devices = @{$rules->{devices}};
print "TEST $number: $rules->{desc}\n";
create_rules(\$rules->{rules});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yummypeng/systemd.git
git@gitee.com:yummypeng/systemd.git
yummypeng
systemd
systemd
a8

搜索帮助