3 # Copyright (C) 2016-2020 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
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 extentlist filter.
40 requires qemu-img
--version
41 requires qemu-img map
--help
43 out
=test-extentlist.out
44 input
=test-extentlist.
in
45 expected
=test-extentlist.expected
46 files
="$out $input $expected"
52 nbdkit
-v -D extentlist.lookup
=1 \
55 null size
=$1 extentlist
=$input \
56 --run 'qemu-img map -f raw --output=json $nbd' |
57 jq
-c '.[] | {start:.start, length:.length, data:.data, zero:.zero}' \
59 diff -u $out $expected
66 cat > $expected <<'EOF'
67 {"start":0,"length":0,"data":false,"zero":false}
70 cat > $expected <<'EOF'
71 {"start":0,"length":1048576,"data":false,"zero":true}
75 # Extent list covering 0-1M with data.
80 cat > $expected <<'EOF'
81 {"start":0,"length":0,"data":false,"zero":false}
84 cat > $expected <<'EOF'
85 {"start":0,"length":1048576,"data":true,"zero":false}
89 # Extent list covering 1-2M with data.
94 cat > $expected <<'EOF'
95 {"start":0,"length":0,"data":false,"zero":false}
98 cat > $expected <<'EOF'
99 {"start":0,"length":1048576,"data":false,"zero":true}
102 cat > $expected <<'EOF'
103 {"start":0,"length":1048576,"data":false,"zero":true}
104 {"start":1048576,"length":1048576,"data":true,"zero":false}
107 cat > $expected <<'EOF'
108 {"start":0,"length":1048576,"data":false,"zero":true}
109 {"start":1048576,"length":1048576,"data":true,"zero":false}
110 {"start":2097152,"length":1048576,"data":false,"zero":true}
114 # Extent list covering 1-2M with data, but in a more fragmented
115 # way than the above.
121 cat > $expected <<'EOF'
122 {"start":0,"length":0,"data":false,"zero":false}
125 cat > $expected <<'EOF'
126 {"start":0,"length":1048576,"data":false,"zero":true}
129 cat > $expected <<'EOF'
130 {"start":0,"length":1048576,"data":false,"zero":true}
131 {"start":1048576,"length":1048576,"data":true,"zero":false}
134 cat > $expected <<'EOF'
135 {"start":0,"length":1048576,"data":false,"zero":true}
136 {"start":1048576,"length":1048576,"data":true,"zero":false}
137 {"start":2097152,"length":1048576,"data":false,"zero":true}
141 # Adjacent data and holes.
148 cat > $expected <<'EOF'
149 {"start":0,"length":0,"data":false,"zero":false}
152 cat > $expected <<'EOF'
153 {"start":0,"length":1048576,"data":true,"zero":false}
156 cat > $expected <<'EOF'
157 {"start":0,"length":1048576,"data":true,"zero":false}
158 {"start":1048576,"length":1048576,"data":false,"zero":true}
161 cat > $expected <<'EOF'
162 {"start":0,"length":1048576,"data":true,"zero":false}
163 {"start":1048576,"length":1048576,"data":false,"zero":true}
164 {"start":2097152,"length":1048576,"data":true,"zero":false}
167 cat > $expected <<'EOF'
168 {"start":0,"length":1048576,"data":true,"zero":false}
169 {"start":1048576,"length":1048576,"data":false,"zero":true}
170 {"start":2097152,"length":1048576,"data":true,"zero":false}
171 {"start":3145728,"length":1048576,"data":false,"zero":true}
172 {"start":4194304,"length":1048576,"data":true,"zero":false}
173 {"start":5242880,"length":1048576,"data":false,"zero":true}