From: Karel Zak Date: Wed, 15 Feb 2017 11:48:06 +0000 (+0100) Subject: tests: add sfdisk --wipe and --wipe-partition tests X-Git-Tag: v2.30-rc1~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0c60dff1acae21b1729ed4963bd46be3bbaa83e;p=thirdparty%2Futil-linux.git tests: add sfdisk --wipe and --wipe-partition tests Addresses: https://github.com/karelzak/util-linux/issues/410 Addresses: https://github.com/karelzak/util-linux/issues/411 Signed-off-by: Karel Zak --- diff --git a/tests/expected/sfdisk/wipe-fs-to-dos b/tests/expected/sfdisk/wipe-fs-to-dos new file mode 100644 index 0000000000..ca1184ca84 --- /dev/null +++ b/tests/expected/sfdisk/wipe-fs-to-dos @@ -0,0 +1,31 @@ + +=====Create FS================================ + +=====Create DOS================================ + + +The old swap signature will be removed by a write command. +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes + +>>> Created a new . +The old swap signature will be removed by a write command. +1: Created a new . +2: Done. + +New situation: +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 2048 102399 100352 49M 83 Linux + +The partition table has been altered. + +=====Check content================================ +offset type +---------------------------------------------------------------- +0x1fe dos [partition table] + diff --git a/tests/expected/sfdisk/wipe-gpt-to-dos b/tests/expected/sfdisk/wipe-gpt-to-dos new file mode 100644 index 0000000000..3831671b3e --- /dev/null +++ b/tests/expected/sfdisk/wipe-gpt-to-dos @@ -0,0 +1,51 @@ + +=====Create GPT================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes + +>>> Created a new . +1: Created a new . +2: Done. + +New situation: +Disklabel type: gpt +Disk identifier: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +The partition table has been altered. + +=====Create DOS================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes +Disklabel type: gpt +Disk identifier: + +Old situation: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +>>> Created a new . +1: Created a new . +2: Done. + +New situation: +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 2048 102399 100352 49M 83 Linux + +The partition table has been altered. + +=====Check content================================ +offset type +---------------------------------------------------------------- +0x1fe dos [partition table] + diff --git a/tests/expected/sfdisk/wipe-gpt-to-dos-auto b/tests/expected/sfdisk/wipe-gpt-to-dos-auto new file mode 100644 index 0000000000..347a3efc28 --- /dev/null +++ b/tests/expected/sfdisk/wipe-gpt-to-dos-auto @@ -0,0 +1,58 @@ + +=====Create GPT================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes +Disklabel type: dos +Disk identifier: + +Old situation: + +Device Boot Start End Sectors Size Id Type +1 2048 102399 100352 49M 83 Linux + +>>> Created a new . +1: Created a new . +2: Done. + +New situation: +Disklabel type: gpt +Disk identifier: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +The partition table has been altered. + +=====Create DOS================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes +Disklabel type: gpt +Disk identifier: + +Old situation: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +>>> Created a new . +1: Created a new . +2: Done. + +New situation: +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 2048 102399 100352 49M 83 Linux + +The partition table has been altered. + +=====Check content================================ +offset type +---------------------------------------------------------------- +0x1fe dos [partition table] + diff --git a/tests/expected/sfdisk/wipe-partition b/tests/expected/sfdisk/wipe-partition new file mode 100644 index 0000000000..f447c585e2 --- /dev/null +++ b/tests/expected/sfdisk/wipe-partition @@ -0,0 +1,52 @@ + +=====Create GPT================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes + +>>> Created a new . +1: Created a new . +2: Done. + +New situation: +Disklabel type: gpt +Disk identifier: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +The partition table has been altered. + +=====Create FS in partition================================ + +=====Wipe whole-disk device================================ + +=====Create GPT (again)================================ +Disk : 50 MiB, 52428800 bytes, 102400 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 4096 bytes +I/O size (minimum/optimal): 4096 bytes / bytes + +>>> Created a new . +1: Created a new . +Partition #1 contains a ext4 signature. +The signature will be removed by a write command. +2: Done. + +New situation: +Disklabel type: gpt +Disk identifier: + +Device Start End Sectors Size Type +1 2048 102366 100319 49M Linux filesystem + +The partition table has been altered. + +=====Check content (disk)================================ +offset type +---------------------------------------------------------------- +0x200 gpt [partition table] + + +=====Check content (partition)================================ diff --git a/tests/functions.sh b/tests/functions.sh index 9239ab4f6d..34d966a6e4 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -45,6 +45,16 @@ function ts_cd { fi } +function ts_separator { + local header="$1" + echo >> $TS_OUTPUT + if [ -z "$header" ]; then + echo "============================================" >> $TS_OUTPUT + else + echo "=====$header================================" >> $TS_OUTPUT + fi +} + function ts_report { local desc= diff --git a/tests/ts/sfdisk/wipe b/tests/ts/sfdisk/wipe new file mode 100755 index 0000000000..3739e81e98 --- /dev/null +++ b/tests/ts/sfdisk/wipe @@ -0,0 +1,101 @@ +#!/bin/bash +# +# This file is part of util-linux. +# +# This file 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 2 of the License, or +# (at your option) any later version. +# +# This file 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. +# + + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="wipe" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_SFDISK" +ts_check_test_command "$TS_CMD_WIPEFS" +ts_check_test_command "$TS_CMD_MKSWAP" +ts_check_prog "mkfs.ext4" + +ts_skip_nonroot + +SFDISK_OPTS="--no-tell-kernel --no-reread" + +# set global variable TS_DEVICE +ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3 + + +ts_init_subtest "gpt-to-dos" +ts_separator "Create GPT" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --label=gpt ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +udevadm settle +ts_separator "Create DOS" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --wipe=always --label=dos ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_fdisk_clean $TS_DEVICE +udevadm settle +ts_separator "Check content" +$TS_CMD_WIPEFS ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +# Same as previous test, but without --wipe=always, sfdisk has to wipe +# the device automatically when switch from one PT to another PT +# +ts_init_subtest "gpt-to-dos-auto" +ts_separator "Create GPT" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --label=gpt ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +udevadm settle +ts_separator "Create DOS" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --label=dos ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_fdisk_clean $TS_DEVICE +udevadm settle +ts_separator "Check content" +$TS_CMD_WIPEFS ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_finalize_subtest + + +ts_init_subtest "fs-to-dos" +ts_separator "Create FS" +$TS_CMD_WIPEFS -a ${TS_DEVICE} &> /dev/null +$TS_CMD_MKSWAP ${TS_DEVICE} &> /dev/null +udevadm settle +ts_separator "Create DOS" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --wipe=always --label=dos ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_fdisk_clean $TS_DEVICE +ts_separator "Check content" +$TS_CMD_WIPEFS ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +udevadm settle +ts_finalize_subtest + + +ts_init_subtest "partition" +ts_separator "Create GPT" +$TS_CMD_WIPEFS -a ${TS_DEVICE} &> /dev/null +udevadm settle +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --label=gpt ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +udevadm settle +ts_separator "Create FS in partition" +mkfs.ext4 ${TS_DEVICE}1 &> /dev/null +udevadm settle +ts_separator "Wipe whole-disk device" +$TS_CMD_WIPEFS -a ${TS_DEVICE} &> /dev/null +udevadm settle +ts_separator "Create GPT (again)" +echo ',,L' | $TS_CMD_SFDISK $SFDISK_OPTS --wipe-partition=always --label=gpt ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_separator "Check content (disk)" +$TS_CMD_WIPEFS ${TS_DEVICE} >> $TS_OUTPUT 2>&1 +ts_separator "Check content (partition)" +$TS_CMD_WIPEFS ${TS_DEVICE}1 >> $TS_OUTPUT 2>&1 +ts_fdisk_clean $TS_DEVICE +udevadm settle +ts_finalize_subtest + +ts_finalize