[parted-devel] [PATCH 5/5] tests: Add tests for --readonly flag

Brian C. Lane bcl at redhat.com
Fri Feb 10 01:19:01 GMT 2023


---
 tests/Makefile.am               |  2 ++
 tests/t0102-print-readonly.sh   | 30 ++++++++++++++++++++++++++++++
 tests/t1105-mklabel-readonly.sh | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 tests/t0102-print-readonly.sh
 create mode 100644 tests/t1105-mklabel-readonly.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index fa27b44..e747155 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,6 +8,7 @@ TESTS = \
   t0010-script-no-ctrl-chars.sh \
   t0100-print.sh \
   t0101-print-empty.sh \
+  t0102-print-readonly.sh \
   t0200-gpt.sh \
   t0201-gpt.sh \
   t0202-gpt-pmbr.sh \
@@ -48,6 +49,7 @@ TESTS = \
   t1101-busy-partition.sh \
   t1102-loop-label.sh \
   t1104-remove-and-add-partition.sh \
+  t1105-mklabel-readonly.sh \
   t1700-probe-fs.sh \
   t1701-rescue-fs.sh \
   t2200-dos-label-recog.sh \
diff --git a/tests/t0102-print-readonly.sh b/tests/t0102-print-readonly.sh
new file mode 100644
index 0000000..5dd30b6
--- /dev/null
+++ b/tests/t0102-print-readonly.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Test printing the partition table in readonly mode
+
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+dev=loop-file
+
+# create device
+truncate --size 10MiB "$dev" || fail=1
+
+parted --script "$dev" mklabel msdos > out 2>&1 || fail=1
+parted --script "$dev" mkpart primary ext4 64s 128s > out 2>&1 || fail=1
+parted --readonly --script "$dev" u s p free > out 2>&1 || fail=1
+
+Exit $fail
diff --git a/tests/t1105-mklabel-readonly.sh b/tests/t1105-mklabel-readonly.sh
new file mode 100644
index 0000000..48d8f93
--- /dev/null
+++ b/tests/t1105-mklabel-readonly.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Test printing the partition table in readonly mode
+
+# Copyright (C) 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+dev=loop-file
+
+# create device
+truncate --size 10MiB "$dev" || fail=1
+
+parted --readonly --script "$dev" mklabel msdos > out 2>&1; test $? = 1 || fail=1
+
+# create expected output file
+echo "Error: Can't write to $PWD/$dev, because it is opened read-only." > exp
+compare exp out || fail=1
+
+
+Exit $fail
-- 
2.39.1




More information about the parted-devel mailing list