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 plugins/data/disk2data.pl script.
35 # This is a stochastic test to try to find corner cases. However if
36 # we simply used a random disk then we wouldn't be testing the
37 # particular features of this script, namely that it can skip long
38 # runs of zeroes and compress short-period repeated data. So instead
39 # we have a small script which generates this kind of "disk-like"
47 requires perl
--version
48 requires
$PYTHON -c 'import random'
51 requires
hexdump --version
53 disk2data
=$srcdir/..
/plugins
/data
/disk2data.pl
54 requires
test -x $disk2data
56 disk
=test-disk2data.disk
57 cmd
=test-disk2data.cmd
58 out
=test-disk2data.out
59 cleanup_fn
rm -f $disk $cmd $out
80 # Non-zero periodic sequences.
83 pop.append([1,2,3]*10)
84 pop.append([1,2,3,4]*10)
85 pop.append([1,2,3,4,5]*10)
86 pop.append([1,2,3,4,5,6]*10)
87 pop.append([1,2,3,4,5,6,7]*10)
88 pop.append([1,2,3,4,5,6,7,8]*10)
89 pop.append([1,2,3,4,5,6,7,8,9,10]*10) # too long for the script to detect
90 # Random non-repeating data sequences.
91 pop.append([1,4,5,2,9,8,3,5,3,1,3,4,5])
92 pop.append([9,7,5,3,1,2,4,6,8])
94 len = random.randint(0, 20)
95 choices = random.choices(pop, k=len)
96 with open(os.environ["disk"], "w") as f:
98 f.write(bytearray(i).decode("ascii"))
102 # Run the script to convert the disk to an nbdkit data command.
103 $disk2data $disk > $cmd
105 # Modify the generated nbdkit command.
106 $SED -i -e $
's/^nbdkit /nbdkit -U - --run \'nbdcopy "$uri" -\' /' $cmd
110 # Run the command. It should re-generate the original disk image.
114 # Compare the original disk with the output.