From: Karel Zak Date: Wed, 23 Apr 2014 07:27:13 +0000 (+0200) Subject: tests: add fdisk 'f' command MBR test X-Git-Tag: v2.25-rc1~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63ed346eca967c794428eeaab8af52b715f65cfd;p=thirdparty%2Futil-linux.git tests: add fdisk 'f' command MBR test Signed-off-by: Karel Zak --- diff --git a/tests/expected/fdisk/mbr-sort b/tests/expected/fdisk/mbr-sort new file mode 100644 index 0000000000..fb897a3869 --- /dev/null +++ b/tests/expected/fdisk/mbr-sort @@ -0,0 +1,77 @@ +Initialize empty image +Create new DOS partition table + +---layout---------- +Disk : 20 MiB, 20971520 bytes, 40960 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 512 bytes +I/O size (minimum/optimal): 512 bytes / 512 bytes + +------------------- + +Create primary partitions + +---layout---------- +Disk : 20 MiB, 20971520 bytes, 40960 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 512 bytes +I/O size (minimum/optimal): 512 bytes / 512 bytes +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 4096 6143 2048 1M 83 Linux +2 2048 4095 2048 1M 83 Linux +3 6144 8191 2048 1M 83 Linux +4 8192 40959 32768 16M 5 Extended + +Partition table entries are not in disk order. + +------------------- + +Create logical partitions + +---layout---------- +Disk : 20 MiB, 20971520 bytes, 40960 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 512 bytes +I/O size (minimum/optimal): 512 bytes / 512 bytes +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 4096 6143 2048 1M 83 Linux +2 2048 4095 2048 1M 83 Linux +3 6144 8191 2048 1M 83 Linux +4 8192 40959 32768 16M 5 Extended +5 14336 16383 2048 1M 83 Linux +6 22528 24575 2048 1M 83 Linux +7 18432 20479 2048 1M 83 Linux +8 10240 12287 2048 1M 83 Linux + +Partition table entries are not in disk order. + +------------------- + +Fix order. + +---layout---------- +Disk : 20 MiB, 20971520 bytes, 40960 sectors +Units: sectors of 1 * 512 = 512 bytes +Sector size (logical/physical): 512 bytes / 512 bytes +I/O size (minimum/optimal): 512 bytes / 512 bytes +Disklabel type: dos +Disk identifier: + +Device Boot Start End Sectors Size Id Type +1 2048 4095 2048 1M 83 Linux +2 4096 6143 2048 1M 83 Linux +3 6144 8191 2048 1M 83 Linux +4 8192 40959 32768 16M 5 Extended +5 10240 12287 2048 1M 83 Linux +6 14336 16383 2048 1M 83 Linux +7 18432 20479 2048 1M 83 Linux +8 22528 24575 2048 1M 83 Linux + +------------------- + diff --git a/tests/ts/fdisk/mbr-sort b/tests/ts/fdisk/mbr-sort new file mode 100755 index 0000000000..3166d867b7 --- /dev/null +++ b/tests/ts/fdisk/mbr-sort @@ -0,0 +1,79 @@ +#!/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="MBR - sort" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_FDISK" + +# cmd to changes system id to 0x1 +FDISK_CMD_WRITE_CLOSE="w\nq\n" +FDISK_CMD_CREATE_DOSLABEL="o\n" #create dos label + +FDISK_CMD_CREATE_1PRIMARY="n\np\n1\n4096\n6143\n" +FDISK_CMD_CREATE_2PRIMARY="n\np\n2\n2048\n4095\n" +FDISK_CMD_CREATE_3PRIMARY="n\np\n3\n6144\n8191\n" +FDISK_CMD_CREATE_EXTENDED="n\ne\n\n\n" + +FDISK_CMD_CREATE_1LOGICAL="n\n14336\n16383\n" +FDISK_CMD_CREATE_2LOGICAL="n\n22528\n24575\n" +FDISK_CMD_CREATE_3LOGICAL="n\n18432\n20479\n" +FDISK_CMD_CREATE_4LOGICAL="n\n10240\n12287\n" + +FDISK_CMD_EXPERT_SORT="x\nf\nr\n" + +function print_layout { + echo -ne "\n---layout----------" >> $TS_OUTPUT + $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT + echo -ne "-------------------\n\n" >> $TS_OUTPUT +} + +#set -x + +ts_log "Initialize empty image" +TEST_IMAGE_NAME=$(ts_image_init 20) # 20 MiB + +ts_log "Create new DOS partition table" +echo -e "${FDISK_CMD_CREATE_DOSLABEL}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Create primary partitions" +echo -e "${FDISK_CMD_CREATE_1PRIMARY}${FDISK_CMD_CREATE_2PRIMARY}${FDISK_CMD_CREATE_3PRIMARY}${FDISK_CMD_CREATE_EXTENDED}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + + +ts_log "Create logical partitions" +echo -e "${FDISK_CMD_CREATE_1LOGICAL}${FDISK_CMD_CREATE_2LOGICAL}${FDISK_CMD_CREATE_3LOGICAL}${FDISK_CMD_CREATE_4LOGICAL}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + + +ts_log "Fix order." +echo -e "${FDISK_CMD_EXPERT_SORT}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_fdisk_clean ${TEST_IMAGE_NAME} +ts_finalize