edit: Clean up temporary files.
[libguestfs.git] / tools / test-virt-make-fs.sh
1 #!/bin/bash -
2
3 export LANG=C
4 set -e
5
6 # Engage in some montecarlo testing of virt-make-fs.
7 case $((RANDOM % 4)) in
8     0) type="--type=ext2" ;;
9     1) type="--type=ext3" ;;
10     2) type="--type=ext4" ;;
11     3) type="--type=ntfs" ;;
12     # Can't test vfat because we cannot create a tar archive
13     # where files are owned by UID:GID 0:0.  As a result, tar
14     # in the appliance fails when trying to change the UID of
15     # the files to some non-zero value (not supported by FAT).
16     # 4) type="--type=vfat" ;;
17 esac
18
19 case $((RANDOM % 2)) in
20     0) format="--format=raw" ;;
21     1) format="--format=qcow2" ;;
22 esac
23
24 case $((RANDOM % 3)) in
25     0) partition="--partition" ;;
26     1) partition="--partition=gpt" ;;
27     2) ;;
28 esac
29
30 case $((RANDOM % 2)) in
31     0) ;;
32     1) size="--size=+1M" ;;
33 esac
34
35 if [ -n "$LIBGUESTFS_DEBUG" ]; then debug=--debug; fi
36
37 params="$type $format $partition $size $debug"
38 echo "test-virt-make-fs: parameters: $params"
39
40 rm -f test.file test.tar output.img
41
42 tarsize=$((RANDOM & 8191))
43 echo "test-virt-make-fs: size of test file: $tarsize KB"
44 dd if=/dev/zero of=test.file bs=1024 count=$tarsize
45 tar -c -f test.tar test.file
46 rm test.file
47
48 ./virt-make-fs $params -- test.tar output.img
49
50 rm test.tar output.img