5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
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
33 # Test the effects of swab on extents.
41 requires nbdsh
--base-allocation
43 files
="swab-extents.out swab-extents.exp8 swab-extents.exp16
44 swab-extents.exp32 swab-extents.exp64"
46 cleanup_fn
rm -f $files
49 # We will set up a plugin that provides the following fine-grained extents
50 # pattern, using [D]ata 0, [H]ole 1, [Z]ero 2, or [B]oth 3
51 # DDDDDDDD DDDDDDDZ ZZZZZZZB BBBBBBBH HZZBBBBH HHHHHHHD
52 # in order to see how swab-bits affects rounding to alignment:
53 # 8 DDDDDDDD DDDDDDDZ ZZZZZZZB BBBBBBBH HZZBBBBH HHHHHHHD
54 # 16 DDDDDDDD DDDDDDDD ZZZZZZZZ BBBBBBHH DDZZBBHH HHHHHHDD
55 # 32 DDDDDDDD DDDDDDDD ZZZZZZZZ BBBBHHHH DDDDHHHH HHHHDDDD
56 # 64 DDDDDDDD DDDDDDDD ZZZZZZZZ HHHHHHHH DDDDDDDD DDDDDDDD
58 cat > swab-extents.exp8
<<EOF
59 [(15, 0), (8, 2), (8, 3), (2, 1), (2, 2), (4, 3), (8, 1), (1, 0)]
61 cat > swab-extents.exp16
<<EOF
62 [(16, 0), (8, 2), (6, 3), (2, 1), (2, 0), (2, 2), (2, 3), (8, 1), (2, 0)]
64 cat > swab-extents.exp32
<<EOF
65 [(16, 0), (8, 2), (4, 3), (4, 1), (4, 0), (8, 1), (4, 0)]
67 cat > swab-extents.exp64
<<EOF
68 [(16, 0), (8, 2), (8, 1), (16, 0)]
71 # We also want to test plugins that supply all v. just one extent per call
84 0 | 1 | 2 | 3 | 4 | 5 | 6 ) echo " 0 7" ;;
86 8 | 9 | 10 | 11 | 12 | 13 | 14 ) echo " 7 8" ;;
88 16 | 17 | 18 | 19 | 20 | 21 | 22 ) echo "15 8 zero" ;;
90 24 | 25 | 26 | 27 | 28 | 29 | 30 ) echo "23 8 zero,hole" ;;
92 32 ) echo "31 2 hole" ;;
93 33 | 34 ) echo "33 2 zero" ;;
94 35 | 36 | 37 | 38 ) echo "35 4 zero,hole" ;;
96 40 | 41 | 42 | 43 | 44 | 45 | 46 ) echo "39 8 hole" ;;
100 # We also need an nbdsh script to parse all extents, coalescing adjacent
101 # types for simplicity
106 def f(metacontext, offset, e, err):
109 assert offs == offset
110 for length, flags in zip(*[iter(e)] * 2):
111 if entries and flags == entries[-1][1]:
112 entries[-1] = (entries[-1][0] + length, flags)
114 entries.append((length, flags))
117 h.block_status(size - offs, offs, f)
121 # Now to test the combinations:
122 for bits
in 8 16 32 64; do
123 for exts
in "$all" "$one"; do
124 nbdkit
-U - --filter=swab
eval swab-bits
=$bits \
125 get_size
='echo 48' pread
='exit 1' extents
="$exts" \
126 --run 'nbdsh --base-allocation -u "$uri" -c "$script"' \
127 > swab-extents.out || fail
=1
128 diff -u swab-extents.exp
$bits swab-extents.out || fail
=1