OSDN Git Service

bd82fb9c7a80868eafcb5019b2b4f49940c9eba8
[android-x86/external-parted.git] / tests / t9040-many-partitions.sh
1 #!/bin/sh
2 # Ensure that creating many partitions works.
3
4 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
20
21 require_root_
22 require_scsi_debug_module_
23
24 grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
25   skip_ 'this system lacks a new-enough libblkid'
26
27 ss=$sector_size_
28 partition_sectors=256  # sectors per partition
29 n_partitions=60        # how many partitions to create
30 start=2048             # start sector for the first partition
31 gpt_slop=34            # sectors at end of disk reserved for GPT
32
33 n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
34
35 sectors_per_MiB=$((1024 * 1024 / ss))
36 n_MiB=$(((n_sectors + sectors_per_MiB - 1) / sectors_per_MiB))
37 # create memory-backed device
38 scsi_debug_setup_ sector_size=$ss dev_size_mb=$n_MiB > dev-name ||
39   skip_ 'failed to create scsi_debug device'
40 scsi_dev=$(cat dev-name)
41
42 n=$((n_MiB * sectors_per_MiB))
43 printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug;\n" \
44   > exp || fail=1
45
46 parted -s $scsi_dev mklabel gpt || fail=1
47 parted -s $scsi_dev u s p || fail=1
48
49 i=1
50 t0=$(date +%s.%N)
51 while :; do
52     end=$((start + partition_sectors - 1))
53     parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
54     printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
55     test $i = $n_partitions && break
56     start=$((start + partition_sectors))
57     i=$((i+1))
58 done
59 t_final=$(date +%s.%N)
60
61 # Fail the test if it takes too long.
62 # On Fedora 13, it takes about 15 seconds.
63 # With older kernels, it typically takes more than 150 seconds.
64 $AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
65 ' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
66     || fail=1
67
68 parted -m -s $scsi_dev u s p > out || fail=1
69 compare exp out || fail=1
70
71 # We must remove these partitions before terminating.
72 # Otherwise, even though cleanup-driven rmmod will eventually cause
73 # them to be removed, they may continue to be removed long after
74 # the rmmod cleanup lock has been released, and such removals
75 # can (and regularly did) interfere with the following test.
76 i=1
77 while :; do
78     parted -s $scsi_dev rm $i || fail=1
79     test $i = $n_partitions && break
80     i=$((i+1))
81 done
82
83 Exit $fail