21255d
From 9aa12f2f564c208c4c1eaef613d18d1c0b481a16 Mon Sep 17 00:00:00 2001
21255d
From: Martin Wilck <mwilck@suse.com>
21255d
Date: Mon, 23 Apr 2018 21:58:12 +0200
21255d
Subject: [PATCH] test/udev-test.pl: create rules only once
21255d
21255d
It's not necessary to write the rules for every udev run, as we
21255d
now may have many (rather than just 2) per test.
21255d
21255d
(cherry picked from commit af7ee3eae689f9c31b49ea13758ad9c901918ce3)
21255d
21255d
Related: #1642728
21255d
---
21255d
 test/udev-test.pl | 13 +++++++++----
21255d
 1 file changed, 9 insertions(+), 4 deletions(-)
21255d
21255d
diff --git a/test/udev-test.pl b/test/udev-test.pl
21255d
index bd5401da75..8b5a97ad61 100755
21255d
--- a/test/udev-test.pl
21255d
+++ b/test/udev-test.pl
21255d
@@ -2069,14 +2069,18 @@ EOF
21255d
         },
21255d
 );
21255d
 
21255d
-sub udev {
21255d
-        my ($action, $devpath, $rules) = @_;
21255d
+sub create_rules {
21255d
+        my ($rules) = @_;
21255d
 
21255d
         # create temporary rules
21255d
         system("mkdir", "-p", "$udev_rules_dir");
21255d
         open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
21255d
         print CONF $$rules;
21255d
         close CONF;
21255d
+}
21255d
+
21255d
+sub udev {
21255d
+        my ($action, $devpath) = @_;
21255d
 
21255d
         if ($valgrind > 0) {
21255d
                 return system("$udev_bin_valgrind $action $devpath");
21255d
@@ -2259,9 +2263,10 @@ sub run_test {
21255d
         my @devices = @{$rules->{devices}};
21255d
 
21255d
         print "TEST $number: $rules->{desc}\n";
21255d
+        create_rules(\$rules->{rules});
21255d
         foreach my $dev (@devices) {
21255d
                 print "device \'$dev->{devpath}\' expecting node/link \'$dev->{exp_name}\'\n";
21255d
-                $rc = udev("add", $dev->{devpath}, \$rules->{rules});
21255d
+                $rc = udev("add", $dev->{devpath});
21255d
                 if ($rc != 0) {
21255d
                         print "$udev_bin add failed with code $rc\n";
21255d
                         $error++;
21255d
@@ -2278,7 +2283,7 @@ sub run_test {
21255d
         }
21255d
 
21255d
         foreach my $dev (@devices) {
21255d
-                $rc = udev("remove", $dev->{devpath}, \$rules->{rules});
21255d
+                $rc = udev("remove", $dev->{devpath});
21255d
                 if ($rc != 0) {
21255d
                         print "$udev_bin remove failed with code $rc\n";
21255d
                         $error++;