summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2018-05-31 15:29:05 +0100
committer Roland Levillain <rpl@google.com> 2018-05-31 15:45:40 +0100
commite2e5e66a9cec84f83c2a47a815bae28f9c849d8d (patch)
tree3bb47bed7cd0f4820d66c94a1fa7669e5d775d39
parent21bd011c4d5364161baabd4dabc06c1eaed2ef7e (diff)
Improve diagnostics in ART script tools/teardown-buildbot-device.sh.
In case of unmounting failure, show the list of open files in the directory that we tried to unmount. Also refactor the logic of unmounting and removing directories under the chroot dir. Test: art/tools/setup-buildbot-device.sh; sh -x art/tools/teardown-buildbot-device.sh Bug: 34729697 Change-Id: I22f9414c3a6e2ae37f90a7eeff058e2c4252dbbf
-rwxr-xr-xtools/teardown-buildbot-device.sh38
1 files changed, 27 insertions, 11 deletions
diff --git a/tools/teardown-buildbot-device.sh b/tools/teardown-buildbot-device.sh
index be2cb274fc..bf14ca4f9f 100755
--- a/tools/teardown-buildbot-device.sh
+++ b/tools/teardown-buildbot-device.sh
@@ -25,6 +25,27 @@ adb root
adb wait-for-device
if [[ -n "$ART_TEST_CHROOT" ]]; then
+
+ # remove_filesystem_from_chroot DIR-IN-CHROOT FSTYPE REMOVE-DIR-IN-CHROOT
+ # -----------------------------------------------------------------------
+ # Unmount filesystem with type FSTYPE mounted in directory DIR-IN-CHROOT
+ # under the chroot directory.
+ # Remove DIR-IN-CHROOT under the chroot if REMOVE-DIR-IN-CHROOT is
+ # true.
+ remove_filesystem_from_chroot() {
+ local dir_in_chroot=$1
+ local fstype=$2
+ local remove_dir=$3
+ local dir="$ART_TEST_CHROOT/$dir_in_chroot"
+ adb shell test -d "$dir" \
+ && adb shell mount | grep -q "^$fstype on $dir type $fstype " \
+ && if adb shell umount "$dir"; then
+ $remove_dir && adb shell rmdir "$dir"
+ else
+ adb shell lsof "$dir"
+ fi
+ }
+
# Tear down the chroot dir.
echo -e "${green}Tear down the chroot dir in $ART_TEST_CHROOT${nc}"
@@ -32,22 +53,17 @@ if [[ -n "$ART_TEST_CHROOT" ]]; then
[[ "x$ART_TEST_CHROOT" = x/* ]] || { echo "$ART_TEST_CHROOT is not an absolute path"; exit 1; }
# Remove /dev from chroot.
- adb shell mount | grep -q "^tmpfs on $ART_TEST_CHROOT/dev type tmpfs " \
- && adb shell umount "$ART_TEST_CHROOT/dev" \
- && adb shell rmdir "$ART_TEST_CHROOT/dev"
+ remove_filesystem_from_chroot dev tmpfs true
# Remove /sys/kernel/debug from chroot.
- adb shell mount | grep -q "^debugfs on $ART_TEST_CHROOT/sys/kernel/debug type debugfs " \
- && adb shell umount "$ART_TEST_CHROOT/sys/kernel/debug"
+ # The /sys/kernel/debug directory under the chroot dir cannot be
+ # deleted, as it is part of the host device's /sys filesystem.
+ remove_filesystem_from_chroot sys/kernel/debug debugfs false
# Remove /sys from chroot.
- adb shell mount | grep -q "^sysfs on $ART_TEST_CHROOT/sys type sysfs " \
- && adb shell umount "$ART_TEST_CHROOT/sys" \
- && adb shell rmdir "$ART_TEST_CHROOT/sys"
+ remove_filesystem_from_chroot sys sysfs true
# Remove /proc from chroot.
- adb shell mount | grep -q "^proc on $ART_TEST_CHROOT/proc type proc " \
- && adb shell umount "$ART_TEST_CHROOT/proc" \
- && adb shell rmdir "$ART_TEST_CHROOT/proc"
+ remove_filesystem_from_chroot proc proc true
# Remove /etc from chroot.
adb shell rm -f "$ART_TEST_CHROOT/etc"