Update TODO.
[nbdkit/ericb.git] / tests / test-partitioning1.sh
blob82ce826dfce46f4caad40c2b7aaac9167f092544
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2018 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 # Test the partitioning plugin.
35 # Test 1: check that partitioning + partition filter = identity
37 source ./functions.sh
38 set -e
39 set -x
41 requires qemu-img --version
43 files="partitioning1.out partitioning1-p1 partitioning1-p2 partitioning1-p3 partitioning1-p4 partitioning1-p5 partitioning1-p6"
44 rm -f $files
45 cleanup_fn rm -f $files
47 # Create some odd-sized partitions. These exist to test alignment and
48 # padding.
49 truncate -s 1 partitioning1-p1
50 truncate -s 511 partitioning1-p2
51 truncate -s 10M partitioning1-p3
52 truncate -s 1023 partitioning1-p4
53 truncate -s 1 partitioning1-p5
54 truncate -s 511 partitioning1-p6
56 # Run nbdkit with partitioning plugin and partition filter.
57 nbdkit -f -v -D partitioning.regions=1 -U - \
58 --filter=partition \
59 partitioning \
60 mbr-id=0x83 alignment=512 \
61 partitioning1-p1 \
62 mbr-id=0x82 alignment=$((2048 * 512)) \
63 partitioning1-p2 \
64 mbr-id=default \
65 file-data \
66 mbr-id=0x82 \
67 partitioning1-p3 \
68 partition-type=mbr \
69 partition=3 \
70 --run 'qemu-img convert $nbd partitioning1.out'
72 # Contents of partitioning1.out should be identical to file-data.
73 cmp file-data partitioning1.out
75 # Same test with > 4 MBR partitions.
76 # Note we select partition 6 because partition 4 is the extended partition.
77 nbdkit -f -v -D partitioning.regions=1 -U - \
78 --filter=partition \
79 partitioning \
80 partitioning1-p1 \
81 partitioning1-p2 \
82 partitioning1-p3 \
83 partitioning1-p4 \
84 file-data \
85 partitioning1-p5 \
86 partitioning1-p6 \
87 partition-type=mbr \
88 partition=6 \
89 --run 'qemu-img convert $nbd partitioning1.out'
91 cmp file-data partitioning1.out
93 # Same test with GPT.
94 nbdkit -f -v -D partitioning.regions=1 -U - \
95 --filter=partition \
96 partitioning \
97 partitioning1-p1 \
98 partitioning1-p2 \
99 partitioning1-p3 \
100 partitioning1-p4 \
101 type-guid=A2A0D0EB-E5B9-3344-87C0-68B6B72699C7 \
102 file-data \
103 type-guid=AF3DC60F-8384-7247-8E79-3D69D8477DE4 \
104 partitioning1-p5 \
105 partitioning1-p6 \
106 partition-type=gpt \
107 partition=5 \
108 --run 'qemu-img convert $nbd partitioning1.out'
110 cmp file-data partitioning1.out