From deb465e44272f873df52f7018804b60d03591209 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 21 Nov 2012 20:02:22 +0100 Subject: [PATCH] Improve robustness of chroot-related tests --- base-linux/run/env | 24 ++++++++++++++++++++++++ os/run/chroot.run | 7 +++---- os/run/chroot_loader.run | 11 +++++------ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/base-linux/run/env b/base-linux/run/env index ab4ca95af8..675a451323 100644 --- a/base-linux/run/env +++ b/base-linux/run/env @@ -41,3 +41,27 @@ proc run_genode_until {{wait_for_re forever} {timeout_value 0}} { set output $expect_out(buffer) } + +## +# Umount a directory that was bind-mounted beforehand +# +# This function is used by chroot-related tests, e.g., 'os/run/chroot.run', +# 'os/run/chroot_loader.run'. +# +proc umount_and_rmdir { path } { + + puts "umounting $path" + + # + # Invoke umount until it returns an error. Apparently, the unmounting + # of bind-mounted mount points does not always take immediate effect + # (regardless of the -l option). + # + while {1} { + if {[catch { exec sudo umount -l $path }]} { break; } + sleep 0.25 + } + + catch { exec rmdir -p $path } +} + diff --git a/os/run/chroot.run b/os/run/chroot.run index cbb8fc5dbe..890b0974b9 100644 --- a/os/run/chroot.run +++ b/os/run/chroot.run @@ -53,10 +53,9 @@ proc chroot_cwd_path { } { return "[chroot_path][pwd]/[run_dir]" } proc chroot_genode_tmp_path { } { return "[chroot_path]/tmp/genode-[exec id -u]" } proc cleanup_chroot { } { - catch { exec sudo umount -l [chroot_cwd_path] } - catch { exec sudo umount -l [chroot_genode_tmp_path] } - catch { exec sudo umount -l [chroot_path]/lib } - exec rm -rf [chroot_path] + umount_and_rmdir [chroot_cwd_path] + umount_and_rmdir [chroot_path]/lib + umount_and_rmdir [chroot_path]/lib64 } # replace 'chroot_path' marker in config with actual path diff --git a/os/run/chroot_loader.run b/os/run/chroot_loader.run index 9c120ebd3e..a27747278a 100644 --- a/os/run/chroot_loader.run +++ b/os/run/chroot_loader.run @@ -58,16 +58,15 @@ set config { } -proc chroot_path { id } { return "/tmp/chroot-test-$id" } - +proc chroot_path { id } { return "/tmp/chroot-test-$id" } proc chroot_cwd_path { id } { return "[chroot_path $id][pwd]/[run_dir]" } proc cleanup_chroot { } { + foreach id { 1 2 } { - catch { exec sudo umount -l [chroot_cwd_path $id] } - catch { exec sudo umount -l [chroot_path $id]/lib } - catch { exec sudo umount -l [chroot_path $id]/lib64 } - catch { exec rm -rf [chroot_path $id] } + umount_and_rmdir [chroot_cwd_path $id] + umount_and_rmdir [chroot_path $id]/lib + umount_and_rmdir [chroot_path $id]/lib64 } }