tests: Split images -> tests/data + tests/guests
[libguestfs.git] / df / test-virt-df.sh
1 #!/bin/bash -
2
3 export LANG=C
4 set -e
5
6 # Run virt-df.
7 output=$(./virt-df ../tests/guests/fedora.img)
8
9 # Check title is the first line.
10 if [[ ! $output =~ ^Filesystem.* ]]; then
11     echo "$0: error: no title line"
12     exit 1
13 fi
14
15 # Check 6 lines (title line + 5 * filesystems).
16 if [ $(echo "$output" | wc -l) -ne 6 ]; then
17     echo "$0: error: not all filesystems were found"
18     exit 1
19 fi
20
21 # Check /dev/VG/LV[1-3] and /dev/VG/Root were found.
22 if [[ ! $output =~ fedora.img:/dev/VG/LV1 ]]; then
23     echo "$0: error: filesystem /dev/VG/LV1 was not found"
24     exit 1
25 fi
26 if [[ ! $output =~ fedora.img:/dev/VG/LV2 ]]; then
27     echo "$0: error: filesystem /dev/VG/LV2 was not found"
28     exit 1
29 fi
30 if [[ ! $output =~ fedora.img:/dev/VG/LV3 ]]; then
31     echo "$0: error: filesystem /dev/VG/LV3 was not found"
32     exit 1
33 fi
34 if [[ ! $output =~ fedora.img:/dev/VG/Root ]]; then
35     echo "$0: error: filesystem /dev/VG/Root was not found"
36     exit 1
37 fi
38
39 # Check /dev/sda1 was found.  Might be called /dev/vda1.
40 if [[ ! $output =~ fedora.img:/dev/[hsv]da1 ]]; then
41     echo "$0: error: filesystem /dev/VG/sda1 was not found"
42     exit 1
43 fi
44
45 # This is what df itself prints for these filesystems (determined
46 # by running the test image under virt-rescue):
47 #
48 # ><rescue> df -h
49 # Filesystem            Size  Used Avail Use% Mounted on
50 # /dev/dm-1              31M   28K   30M   1% /sysroot/lv1
51 # /dev/dm-2              31M  395K   29M   2% /sysroot/lv2
52 # /dev/dm-3              62M  144K   59M   1% /sysroot/lv3
53 # ><rescue> df -i
54 # Filesystem            Inodes   IUsed   IFree IUse% Mounted on
55 # /dev/dm-1               8192      11    8181    1% /sysroot/lv1
56 # /dev/dm-2               8192      11    8181    1% /sysroot/lv2
57 # /dev/dm-3              16384      11   16373    1% /sysroot/lv3
58 # ><rescue> df
59 # Filesystem           1K-blocks      Used Available Use% Mounted on
60 # /dev/dm-1                31728        28     30064   1% /sysroot/lv1
61 # /dev/dm-2                31729       395     29696   2% /sysroot/lv2
62 # /dev/dm-3                63472       144     60052   1% /sysroot/lv3
63 #
64 # This test is disabled (XXX).  See:
65 # https://www.redhat.com/archives/libguestfs/2011-November/msg00051.html
66
67 #if [ "$(echo "$output" | sort | awk '/VG.LV[123]/ { print $2 " " $3 " " $4 " " $5 }')" != \
68 #"31728 28 30064 1%
69 #31729 395 29696 2%
70 #63472 144 60052 1%" ]; then
71 #    echo "$0: error: output of virt-df did not match expected (df) output"
72 #    echo "$output"
73 #    exit 1
74 #fi