1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

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.
This commit is contained in:
Martin Wilck 2018-04-25 09:54:26 +02:00 committed by Michal Sekletár
parent 2ab0a8d00b
commit eb44d715eb

View File

@ -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});