diff options
author | Martin Wilck <mwilck@suse.com> | 2018-04-25 09:54:26 +0200 |
---|---|---|
committer | Michal Sekletár <msekleta@redhat.com> | 2020-11-02 11:43:15 +0100 |
commit | eb44d715ebee2fe11288433b99f8e1dc5fdac84a (patch) | |
tree | 0c86228faabd15c81f0c3dc758f30ebeebc08989 /test/udev-test.pl | |
parent | test/udev-test.pl: add repeat count (diff) | |
download | systemd-eb44d715ebee2fe11288433b99f8e1dc5fdac84a.tar.xz systemd-eb44d715ebee2fe11288433b99f8e1dc5fdac84a.zip |
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.
Diffstat (limited to 'test/udev-test.pl')
-rwxr-xr-x | test/udev-test.pl | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/test/udev-test.pl b/test/udev-test.pl index a19cc9f23d..790387e680 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}); |