4a054dbadc6c031ae5363b0f3707c008965f80c0
[libguestfs.git] / sparsify / test-virt-sparsify.sh
1 #!/bin/bash -
2 # libguestfs virt-sparsify test script
3 # Copyright (C) 2011 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 export LANG=C
20 set -e
21
22 rm -f test1.img test2.img
23
24 # Create a filesystem, fill it with data, then delete the data.  Then
25 # prove that sparsifying it reduces the size of the final filesystem.
26
27 ../fish/guestfish \
28     -N bootrootlv:/dev/VG/LV:ext2:ext4:400M:32M:gpt <<EOF
29 mount-options "" /dev/VG/LV /
30 mkdir /boot
31 mount-options "" /dev/sda1 /boot
32 fill 1 300M /big
33 fill 1 10M /boot/big
34 sync
35 rm /big
36 rm /boot/big
37 umount-all
38 EOF
39
40 ./virt-sparsify --format raw test1.img --convert qcow2 test2.img
41
42 size_before=$(du -s test1.img | awk '{print $1}')
43 size_after=$(du -s test2.img | awk '{print $1}')
44
45 echo "test virt-sparsify: $size_before K -> $size_after K"
46
47 if [ $size_before -lt 310000 ]; then
48     echo "test virt-sparsify: size_before ($size_before) too small"
49     exit 1
50 fi
51
52 if [ $size_after -gt 5000 ]; then
53     echo "test virt-sparsify: size_after ($size_after) too large"
54     echo "sparsification failed"
55     exit 1
56 fi
57
58 rm -f test1.img test2.img