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