Blame SOURCES/0003-tests-Add-tests-for-fix.patch

edefaa
From 6b2c8806b42a7214d726cc2b3dac6b96013a6cce Mon Sep 17 00:00:00 2001
edefaa
From: Cristian Klein <cristian.klein@elastisys.com>
edefaa
Date: Fri, 11 Dec 2020 22:19:24 +0100
edefaa
Subject: [PATCH 3/5] tests: Add tests for --fix
edefaa
edefaa
Signed-off-by: Brian C. Lane <bcl@redhat.com>
edefaa
---
edefaa
 tests/Makefile.am                  |   3 +-
edefaa
 tests/t9060-gpt-grow-script-fix.sh | 100 +++++++++++++++++++++++++++++
edefaa
 2 files changed, 102 insertions(+), 1 deletion(-)
edefaa
 create mode 100755 tests/t9060-gpt-grow-script-fix.sh
edefaa
edefaa
diff --git a/tests/Makefile.am b/tests/Makefile.am
edefaa
index 0d7c022..3473e6b 100644
edefaa
--- a/tests/Makefile.am
edefaa
+++ b/tests/Makefile.am
edefaa
@@ -89,7 +89,8 @@ TESTS = \
edefaa
   t9040-many-partitions.sh \
edefaa
   t9041-undetected-in-use-16th-partition.sh \
edefaa
   t9042-dos-partition-limit.sh \
edefaa
-  t9050-partition-table-types.sh
edefaa
+  t9050-partition-table-types.sh \
edefaa
+  t9060-gpt-grow-script-fix.sh
edefaa
 
edefaa
 EXTRA_DIST = \
edefaa
   $(TESTS) t-local.sh t-lvm.sh \
edefaa
diff --git a/tests/t9060-gpt-grow-script-fix.sh b/tests/t9060-gpt-grow-script-fix.sh
edefaa
new file mode 100755
edefaa
index 0000000..4a3a8a9
edefaa
--- /dev/null
edefaa
+++ b/tests/t9060-gpt-grow-script-fix.sh
edefaa
@@ -0,0 +1,100 @@
edefaa
+#!/bin/sh
edefaa
+# grow a gpt disk, ensure that parted offers to update the gpt size
edefaa
+# do this in script mode with fix
edefaa
+
edefaa
+# Copyright (C) 2009-2012, 2014, 2019 Free Software Foundation, Inc.
edefaa
+
edefaa
+# This program is free software; you can redistribute it and/or modify
edefaa
+# it under the terms of the GNU General Public License as published by
edefaa
+# the Free Software Foundation; either version 3 of the License, or
edefaa
+# (at your option) any later version.
edefaa
+
edefaa
+# This program is distributed in the hope that it will be useful,
edefaa
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
edefaa
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
edefaa
+# GNU General Public License for more details.
edefaa
+
edefaa
+# You should have received a copy of the GNU General Public License
edefaa
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
edefaa
+
edefaa
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
edefaa
+require_512_byte_sector_size_
edefaa
+dev=loop-file
edefaa
+
edefaa
+ss=$sector_size_
edefaa
+n_sectors=5000
edefaa
+
edefaa
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
edefaa
+
edefaa
+# create gpt label
edefaa
+parted -s $dev mklabel gpt > empty 2>&1 || fail=1
edefaa
+compare /dev/null empty || fail=1
edefaa
+
edefaa
+# print the empty table
edefaa
+parted -m -s $dev unit s print > t 2>&1 || fail=1
edefaa
+sed "s,.*/$dev:,$dev:," t > out || fail=1
edefaa
+
edefaa
+# check for expected output
edefaa
+printf "BYT;\n$dev:${n_sectors}s:file:$sector_size_:$sector_size_:gpt::;\n" \
edefaa
+  > exp || fail=1
edefaa
+compare exp out || fail=1
edefaa
+
edefaa
+# grow disk
edefaa
+n_sectors=5500
edefaa
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
edefaa
+
edefaa
+# printing must warn, but not fix in script mode
edefaa
+parted -s $dev print > out 2>&1 || fail=1
edefaa
+
edefaa
+# Transform the actual output, to avoid spurious differences when
edefaa
+# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
edefaa
+# normalize the actual output
edefaa
+mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s,
   *
,,g;s, $,," \
edefaa
+                      -e "s,^.*/lt-parted: ,parted: ," o2 > out
edefaa
+
edefaa
+# check for expected diagnostic
edefaa
+cat <<EOF > exp || fail=1
edefaa
+Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting?
edefaa
+Model:  (file)
edefaa
+Disk DEVICE: 2816kB
edefaa
+Sector size (logical/physical): 512B/512B
edefaa
+Partition Table: gpt
edefaa
+Disk Flags:
edefaa
+
edefaa
+Number  Start  End  Size  File system  Name  Flags
edefaa
+
edefaa
+EOF
edefaa
+compare exp out || fail=1
edefaa
+
edefaa
+# now we fix
edefaa
+parted --script --fix $dev print > out 2>&1 || fail=1
edefaa
+
edefaa
+# Transform the actual output, to avoid spurious differences when
edefaa
+# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
edefaa
+# normalize the actual output
edefaa
+mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s,
   *
,,g;s, $,," \
edefaa
+                      -e "s,^.*/lt-parted: ,parted: ," o2 > out
edefaa
+
edefaa
+# check for expected diagnostic
edefaa
+cat <<EOF > exp || fail=1
edefaa
+Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting?
edefaa
+Fixing, due to --fix
edefaa
+Model:  (file)
edefaa
+Disk DEVICE: 2816kB
edefaa
+Sector size (logical/physical): 512B/512B
edefaa
+Partition Table: gpt
edefaa
+Disk Flags:
edefaa
+
edefaa
+Number  Start  End  Size  File system  Name  Flags
edefaa
+
edefaa
+EOF
edefaa
+compare exp out || fail=1
edefaa
+
edefaa
+
edefaa
+# Now should not warn
edefaa
+
edefaa
+parted -s $dev print > err 2>&1 || fail=1
edefaa
+grep Warning: err > k ; mv k err
edefaa
+compare /dev/null err || fail=1
edefaa
+
edefaa
+Exit $fail
edefaa
-- 
edefaa
2.26.2
edefaa