tests: Make all guestfish tests use runtime check.
[nbdkit/ericb.git] / tests / test-partition1.sh
blob9db0928019bed56d52d4c9baf8a53818191ab28d
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2018-2019 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # SUCH DAMAGE.
33 source ./functions.sh
34 set -e
35 set -x
37 requires sfdisk --help
38 requires test -r /dev/urandom
39 requires qemu-img --version
41 d="partition1.d"
42 rm -rf $d
43 cleanup_fn rm -rf $d
44 mkdir $d
46 do_test ()
48 label=$1
49 nrparts=$2
50 skip_extended=$3
52 rm -f $d/disk
53 truncate -s 1G $d/disk
54 sfdisk -X $label $d/disk
56 # Run nbdkit on each partition, copying data in and out.
57 for ((part=1; part <= $nrparts; ++part)); do
58 # The smallest partition in any test is 1023 sectors. However
59 # to make things quicker only write a sector of random data.
60 dd if=/dev/urandom of=$d/rand bs=512 count=1
62 if [ "$part" != "$skip_extended" ]; then
63 nbdkit -f -v -U - \
64 --filter=partition file $d/disk partition=$part \
65 --run "qemu-img convert -n $d/rand \$nbd"
66 nbdkit -f -v -U - \
67 --filter=partition file $d/disk partition=$part \
68 --run "qemu-img convert \$nbd $d/out"
69 truncate -s 512 $d/out
70 cmp $d/rand $d/out
72 done
75 # Regular MBR with 1-4 primary partitions.
76 do_test dos 1 <<'EOF'
77 2048 1023 L -
78 EOF
80 do_test dos 2 <<'EOF'
81 2048 1023 L -
82 4096 4095 L -
83 EOF
85 do_test dos 3 <<'EOF'
86 2048 1023 L -
87 4096 4095 L -
88 8192 8191 L -
89 EOF
91 do_test dos 4 <<'EOF'
92 2048 1023 L -
93 4096 4095 L -
94 8192 8191 L -
95 16384 16383 L -
96 EOF
98 # MBR with 3 primary partitions and 2 logical partitions.
99 # Ignore partition 4 which is the extended partition.
100 do_test dos 6 4 <<'EOF'
101 2048 2047 L -
102 4096 4095 L -
103 8192 8191 L -
104 16384 16383 E -
105 17000 999 L -
106 18000 999 L -
109 # As above but the extended partition is 1.
110 do_test dos 6 1 <<'EOF'
111 16384 16383 E -
112 2048 2047 L -
113 4096 4095 L -
114 8192 8191 L -
115 17000 999 L -
116 18000 999 L -
119 # MBR also allows missing partitions. This disk has only partition 2.
120 # (Partition 1 must be ignored since it is missing.)
121 do_test dos 2 1 <<'EOF'
122 disk2: start=1024 size=1023 type=83
125 # Regular GPT with 1-6 partitions.
126 do_test gpt 1 <<'EOF'
127 2048 1023 L -
130 do_test gpt 2 <<'EOF'
131 2048 1023 L -
132 4096 4095 L -
135 do_test gpt 3 <<'EOF'
136 2048 1023 L -
137 4096 4095 L -
138 8192 8191 L -
141 do_test gpt 4 <<'EOF'
142 2048 1023 L -
143 4096 4095 L -
144 8192 8191 L -
145 16384 16383 L -
148 do_test gpt 5 <<'EOF'
149 2048 2047 L -
150 4096 4095 L -
151 8192 8191 L -
152 16384 16383 L -
153 32768 32767 L -
156 do_test gpt 6 <<'EOF'
157 2048 2047 L -
158 4096 4095 L -
159 8192 8191 L -
160 16384 16383 L -
161 32768 32767 L -
162 65536 65535 L -