From cfb13f6b5a2a6e3fff84f664ce2396e411249b51 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa
Date: Mon, 3 Apr 2017 15:00:43 +0530
Subject: [PATCH 3/6] tests: t1101-busy-partition.sh: Update tests for script
operations
* Add tests for 'resizepart' operations.
* Don't expect 'rm' and 'resizepart' operations to fail when run in
script mode.
Signed-off-by: Sunil Mohan Adapa
---
tests/t1101-busy-partition.sh | 40 ++++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/tests/t1101-busy-partition.sh b/tests/t1101-busy-partition.sh
index ad091f7..7ed480c 100755
--- a/tests/t1101-busy-partition.sh
+++ b/tests/t1101-busy-partition.sh
@@ -24,14 +24,10 @@ require_root_
require_scsi_debug_module_
# create memory-backed device
-scsi_debug_setup_ dev_size_mb=80 > dev-name ||
+scsi_debug_setup_ dev_size_mb=100 > dev-name ||
skip_ 'failed to create scsi_debug device'
dev=$(cat dev-name)
-cat < exp-error || framework_failure
-Warning: Partition ${dev}2 is being used. Are you sure you want to continue?
-EOF
-
parted -s "$dev" mklabel msdos > out 2>&1 || fail=1
# expect no output
@@ -40,7 +36,7 @@ compare /dev/null out || fail=1
parted -s "$dev" mkpart primary fat32 1 40 > out 2>&1 || fail=1
compare /dev/null out || fail=1
-parted -s "$dev" mkpart primary fat32 40 80 > out 2>&1 || fail=1
+parted -s "$dev" mkpart primary fat32 50 90 > out 2>&1 || fail=1
compare /dev/null out || fail=1
# wait for new partition device to appear
@@ -49,20 +45,44 @@ wait_for_dev_to_appear_ ${dev}2 || fail_ ${dev}2 did not appear
mkfs.vfat -F 32 ${dev}2 || skip_ mkfs.vfat failed
# be sure to unmount upon interrupt, failure, etc.
-cleanup_fn_() { umount "${dev}2" > /dev/null 2>&1; }
+cleanup_fn_() { umount "$mount_point" > /dev/null 2>&1; }
mount_point=$(pwd)/mnt
mkdir $mount_point || fail=1
mount "${dev}2" "$mount_point" || fail=1
+# Resize of unmounted partition must succeed.
+parted -s "$dev" resizepart 1 50 > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
# Removal of unmounted partition must succeed.
parted -s "$dev" rm 1 > out 2>&1 || fail=1
+compare /dev/null out || fail=1
-# Removal of mounted partition must fail.
-parted -s "$dev" rm 2 > out 2>&1 && fail=1
+# Resize of mounted partition must fail in non-script mode.
+parted "$dev" resizepart 2 100 < /dev/null > out 2>&1 && fail=1
+echo -n "Warning: Partition ${dev}2 is being used. Are you sure you want to continue?
+
" \
+ > exp-error || framework_failure
+compare exp-error out || fail=1
-# expect error
+# Resize of mounted partition must succeed in script mode.
+parted -s "$dev" resizepart 2 100 > out 2>&1 || fail=1
+compare /dev/null out || fail=1
+
+# Removal of mounted partition must fail in non-script mode.
+parted "$dev" rm 2 < /dev/null > out 2>&1 && fail=1
+echo -n "Warning: Partition ${dev}2 is being used. Are you sure you want to continue?
+
" \
+ > exp-error || framework_failure
+compare exp-error out || fail=1
+
+# Removal of mounted partition must succeed in script mode.
+parted -s "$dev" rm 2 > out 2>&1 || fail=1
+cat < exp-error || framework_failure
+Error: Partition(s) 2 on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
+EOF
compare exp-error out || fail=1
Exit $fail
--
2.11.0