e049dfe73dba06bc43f31e563e4b38a577cfdebc
[libguestfs.git] / tools / test-virt-make-fs.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2010-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 # Is NTFS supported?
23 if ../fish/guestfish -a /dev/null run : available "ntfs3g ntfsprogs"; then
24   ntfs_supported=yes
25 else
26   ntfs_supported=no
27 fi
28
29 # Engage in some montecarlo testing of virt-make-fs.
30
31 if [ "$ntfs_supported" = "yes" ]; then
32   case $((RANDOM % 4)) in
33       0) type="--type=ext2" ;;
34       1) type="--type=ext3" ;;
35       2) type="--type=ext4" ;;
36       3) type="--type=ntfs" ;;
37       # Can't test vfat because we cannot create a tar archive
38       # where files are owned by UID:GID 0:0.  As a result, tar
39       # in the appliance fails when trying to change the UID of
40       # the files to some non-zero value (not supported by FAT).
41       # 4) type="--type=vfat" ;;
42   esac
43 else
44   case $((RANDOM % 3)) in
45       0) type="--type=ext2" ;;
46       1) type="--type=ext3" ;;
47       2) type="--type=ext4" ;;
48   esac
49 fi
50
51 case $((RANDOM % 2)) in
52     0) format="--format=raw" ;;
53     1) format="--format=qcow2" ;;
54 esac
55
56 case $((RANDOM % 3)) in
57     0) partition="--partition" ;;
58     1) partition="--partition=gpt" ;;
59     2) ;;
60 esac
61
62 case $((RANDOM % 2)) in
63     0) ;;
64     1) size="--size=+1M" ;;
65 esac
66
67 if [ -n "$LIBGUESTFS_DEBUG" ]; then debug=--debug; fi
68
69 params="$type $format $partition $size $debug"
70 echo "test-virt-make-fs: parameters: $params"
71
72 rm -f test.file test.tar output.img
73
74 tarsize=$((RANDOM & 8191))
75 echo "test-virt-make-fs: size of test file: $tarsize KB"
76 dd if=/dev/zero of=test.file bs=1024 count=$tarsize
77 tar -c -f test.tar test.file
78 rm test.file
79
80 ./virt-make-fs $params -- test.tar output.img
81
82 rm test.tar output.img