naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
21255d
From dc50d1cc5bf445f1a26dbc646ff52421563e677f Mon Sep 17 00:00:00 2001
21255d
From: Dan Streetman <ddstreet@canonical.com>
21255d
Date: Fri, 5 Jul 2019 11:24:55 -0400
21255d
Subject: [PATCH] test/udev-test.pl: cleanup if skipping test
21255d
21255d
In Ubuntu CI, udev-test.pl is run from the debian/test/udev script,
21255d
in a test dir created for it; but udev-test.pl setup mounts a
21255d
dir, so if it doesn't cleanup/unmount before exiting, the test dir
21255d
autopkgtest created for it can't be removed, and autopkgtest
21255d
aborts the entire test suite, for example this output (from a
21255d
test run inside an armhf container):
21255d
21255d
autopkgtest [12:45:36]: test udev: [-----------------------
21255d
umount: test/tmpfs: no mount point specified.
21255d
mknod: test/tmpfs/dev/null: Operation not permitted
21255d
unable to create test/tmpfs/dev/null at ./udev-test.pl line 1611.
21255d
Failed to set up the environment, skipping the test at ./udev-test.pl line 1731.
21255d
autopkgtest [12:45:41]: test udev: -----------------------]
21255d
autopkgtest [12:45:44]: test udev:  - - - - - - - - - - results - - - - - - - - - -
21255d
udev                 FAIL non-zero exit status 77
21255d
rm: cannot remove '/tmp/autopkgtest.ocPFA6/autopkgtest_tmp/test/tmpfs': Device or resource busy
21255d
autopkgtest [12:46:22]: ERROR: "rm -rf /tmp/autopkgtest.ocPFA6/udev-artifacts /tmp/autopkgtest.ocPFA6/autopkgtest_tmp" failed with stderr "rm:
21255d
21255d
(cherry picked from commit abb9cc50afb3949c442849f43301fb33578f3888)
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 122359e377..2fea72875b 100755
21255d
--- a/test/udev-test.pl
21255d
+++ b/test/udev-test.pl
21255d
@@ -1713,6 +1713,12 @@ sub run_test {
21255d
 
21255d
 }
21255d
 
21255d
+sub cleanup {
21255d
+        system("rm", "-rf", "$udev_run");
21255d
+        system("umount", "$udev_tmpfs");
21255d
+        rmdir($udev_tmpfs);
21255d
+}
21255d
+
21255d
 # only run if we have root permissions
21255d
 # due to mknod restrictions
21255d
 if (!($<==0)) {
21255d
@@ -1729,11 +1735,13 @@ if ($? >> 8 == 0) {
21255d
 
21255d
 if (!udev_setup()) {
21255d
         warn "Failed to set up the environment, skipping the test";
21255d
+        cleanup();
21255d
         exit($EXIT_TEST_SKIP);
21255d
 }
21255d
 
21255d
 if (system($udev_bin, "check")) {
21255d
         warn "$udev_bin failed to set up the environment, skipping the test";
21255d
+        cleanup();
21255d
         exit($EXIT_TEST_SKIP);
21255d
 }
21255d
 
21255d
@@ -1776,10 +1784,7 @@ if ($list[0]) {
21255d
 
21255d
 print "$error errors occurred\n\n";
21255d
 
21255d
-# cleanup
21255d
-system("rm", "-rf", "$udev_run");
21255d
-system("umount", "$udev_tmpfs");
21255d
-rmdir($udev_tmpfs);
21255d
+cleanup();
21255d
 
21255d
 if ($error > 0) {
21255d
         exit(1);