From: Jim Meyering Date: Sun, 22 Jan 2012 13:56:47 +0000 (+0100) Subject: tests: test for yesterday's bug fix X-Git-Tag: android-x86-4.4-r1~39 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=552995beccf1c7543b37584bb037e6a1f508c8a4;p=android-x86%2Fexternal-parted.git tests: test for yesterday's bug fix * tests/Makefile.am (TESTS): Add it. * tests/t0211-gpt-rewrite-header.sh: New test. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 77a1cae..88efbdd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,7 @@ TESTS = \ t0207-IEC-binary-notation.sh \ t0208-mkpart-end-in-IEC.sh \ t0210-gpt-resized-partition-entry-array.sh \ + t0211-gpt-rewrite-header.sh \ t0220-gpt-msftres.sh \ t0250-gpt.sh \ t0280-gpt-corrupt.sh \ diff --git a/tests/t0211-gpt-rewrite-header.sh b/tests/t0211-gpt-rewrite-header.sh new file mode 100644 index 0000000..475c3db --- /dev/null +++ b/tests/t0211-gpt-rewrite-header.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# exercise parted's gpt-rewriting code +# When it encounters a GPT device with backup not at the end, +# parted (without -s) offers to correct that by moving the backup +# header to the end of the device. Before parted-3.1, when it attempted +# to do that, starting with a 9-PTE array, it would render the result invalid. + +# Copyright (C) 2012 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 . + +. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir +require_perl_digest_crc_ + +ss=$sector_size_ + +ns=100 # Initial number of sectors. +ns2=$((ns+64)) # Some larger number of sectors. +dev=loop-file +# create a file large enough to hold a GPT partition table +dd if=/dev/null of=$dev bs=$ss seek=$ns || framework_failure + +# create a GPT partition table with 9 PTEs. +parted -a min -s $dev mklabel gpt \ + mkpart p1 34s 34s \ + mkpart p2 35s 35s \ + mkpart p3 36s 36s \ + mkpart p4 37s 37s \ + mkpart p5 38s 38s \ + mkpart p6 39s 39s \ + mkpart p7 40s 40s \ + mkpart p8 41s 41s \ + mkpart p9 42s 42s \ + > out 2>&1 || fail=1 +# expect no output +compare /dev/null out || fail=1 + +# Adjust the GPT table to have only 9 PTEs. +gpt-header-munge --sector-size=$ss --n=9 $dev || fail=1 + +# Extend size of the device. +dd if=/dev/null of=$dev bs=$ss seek=$ns2 || fail=1 + +printf '%s\n' f f > in || fail=1 + +# This would always succeed, even before. +parted ---pretend-input-tty $dev u s p < in || fail=1 + +printf '%s\n' \ + 'BYT;' \ + "...:${ns2}s:file:$ss:$ss:gpt:;" \ + '1:34s:34s:1s::p1:;' \ + '2:35s:35s:1s::p2:;' \ + '3:36s:36s:1s::p3:;' \ + '4:37s:37s:1s::p4:;' \ + '5:38s:38s:1s::p5:;' \ + '6:39s:39s:1s::p6:;' \ + '7:40s:40s:1s::p7:;' \ + '8:41s:41s:1s::p8:;' \ + '9:42s:42s:1s::p9:;' \ + > exp || fail=1 + +# Before parted-3.1, this would fail, reporting that both tables are corrupt. +parted -m -s $dev u s p > out 2>&1 || fail=1 +sed '2s/^[^:]*:/...:/' out > k && mv k out +compare exp out || fail=1 + +Exit $fail