64-bit VFS_LSEEK_OFF
[minix3.git] / test / testvnd.sh
blob96fdf1833fa47aed27ee803cb5c5a8daeff6a4e7
1 #!/bin/sh
3 # Shell script used to test the VNode Disk (VND) driver.
5 # The main purpose of this script is to test the ability of the driver to cope
6 # with regular operational conditions. It also calls the blocktest test suite
7 # to perform I/O stress testing. It does not aim to cover all of vndconfig(8).
9 bomb() {
10 echo $*
11 cd ..
12 rm -rf $TESTDIR
13 umount /dev/vnd1 >/dev/null 2>&1
14 umount /dev/vnd0 >/dev/null 2>&1
15 vndconfig -u vnd1 >/dev/null 2>&1
16 vndconfig -u vnd0 >/dev/null 2>&1
17 exit 1
20 PATH=/bin:/usr/bin:/sbin:/usr/sbin
21 export PATH
23 TESTDIR=DIR_VND
24 export TESTDIR
26 echo -n "Test VND "
28 # We cannot run the test if vnd0 or vnd1 are in use.
29 if vndconfig -l vnd0 >/dev/null 2>&1; then
30 if ! vndconfig -l vnd0 2>/dev/null | grep "not in use" >/dev/null; then
31 echo "vnd0 in use, skipping test" >&2
32 echo "ok"
33 exit 0
34 else
35 service down vnd0
38 if vndconfig -l vnd1 >/dev/null 2>&1; then
39 if ! vndconfig -l vnd1 2>/dev/null | grep "not in use" >/dev/null; then
40 echo "vnd1 in use, skipping test" >&2
41 echo "ok"
42 exit 0
43 else
44 service down vnd1
48 rm -rf $TESTDIR
49 mkdir $TESTDIR
50 cd $TESTDIR
52 mkdir mnt0
53 mkdir mnt1
55 # Test persisting a file inside a vnode device.
56 dd if=/dev/zero of=image0 bs=4096 count=257 2>/dev/null || bomb "out of space?"
57 vndconfig vnd0 image0 || bomb "unable to configure vnd0"
58 [ "`devsize /dev/vnd0`" = 2056 ] || bomb "unexpected vnd0 device size"
59 mkfs.mfs /dev/vnd0 || bomb "unable to mkfs vnd0"
60 mount -t mfs /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
61 STRING="Hello, world!"
62 echo "$STRING" >mnt0/TEST || bomb "unable to create file on vnd0"
63 umount /dev/vnd0 >/dev/null || bomb "unable to unmount vnd0"
64 [ ! -f mnt0/TEST ] || bomb "was vnd0 ever really mounted?"
65 mount -t mfs /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
66 [ -f mnt0/TEST ] || bomb "test file was not saved across mounts"
67 [ "`cat mnt0/TEST`" = "$STRING" ] || bomb "test file was corrupted"
68 umount /dev/vnd0 >/dev/null || bomb "unable to unmount vnd0"
69 vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
70 vndconfig vnd1 image0 || bomb "unable to configure vnd1"
71 mount -t mfs /dev/vnd1 mnt1 >/dev/null || bomb "unable to mount vnd1"
72 [ "`cat mnt1/TEST`" = "$STRING" ] || bomb "test file was corrupted"
74 # Test nesting images.
75 dd if=/dev/zero of=mnt1/image1 bs=4096 count=128 2>/dev/null || bomb "dd fail"
76 vndconfig vnd0 mnt1/image1
77 mkfs.mfs /dev/vnd0 || bomb "unable to mkfs vnd0"
78 mount -t mfs /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
79 echo "x" >mnt0/TEST2 || bomb "unable to create file on vnd0"
80 umount mnt1 >/dev/null 2>&1 && bomb "should not be able to unmount vnd1"
81 umount mnt0 >/dev/null || bomb "unable to unmount vnd0"
82 umount mnt1 >/dev/null 2>&1 && bomb "should not be able to unmount vnd1"
83 vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
84 cp mnt1/image1 . || bomb "unable to copy image off vnd1"
85 umount mnt1 >/dev/null || bomb "unable to unmount vnd1"
86 vndconfig -uS vnd1 || bomb "unable to unconfigure vnd1"
87 vndconfig -S vnd1 ./image1
88 mount -t mfs /dev/vnd1 mnt1 >/dev/null || bomb "unable to mount vnd1"
89 [ -f mnt1/TEST2 ] || bomb "test file not found, VM cache broken again?"
90 [ "`cat mnt1/TEST2`" = "x" ] || bomb "test file corrupted"
91 umount /dev/vnd1 >/dev/null || bomb "unable to unmount vnd1"
92 vndconfig -u /dev/vnd1 || bomb "unable to unconfigure vnd1"
94 # Test a read-only configuration.
95 SUM=`sha1 image0`
96 vndconfig -r vnd0 image0
97 dd if=/dev/zero of=/dev/vnd0 bs=4096 count=1 2>/dev/null && bomb "dd succeeded"
98 mount /dev/vnd0 mnt0 >/dev/null 2>&1 && bomb "mounting read-write should fail"
99 mount -r /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
100 [ "`cat mnt0/TEST`" = "$STRING" ] || bomb "test file was corrupted"
101 dd if=/dev/zero of=/dev/vnd0 bs=4096 count=1 2>/dev/null && bomb "dd succeeded"
102 umount /dev/vnd0 >/dev/null
103 vndconfig -uS vnd0
104 [ "`sha1 image0`" = "$SUM" ] || bomb "read-only file changed"
106 # Test geometry and sub/partitions.
107 vndconfig -c vnd0 image0 512/32/64/2 2>/dev/null && bomb "vndconfig succeeded"
108 vndconfig -c vnd0 image0 512/32/64/1 || bomb "unable to configure vnd0"
109 # no need for repartition: nobody is holding the device open
110 [ "`devsize /dev/vnd0`" = 2048 ] || bomb "geometry not applied to size"
111 partition -mf /dev/vnd0 8 81:512 81:512* 81:512 81:1+ >/dev/null
112 partition -f /dev/vnd0p1 81:256 81:1 81:8 81:1+ >/dev/null
113 dd if=/dev/zero of=/dev/vnd0p1s2 bs=512 count=8 2>/dev/null || bomb "dd failed"
114 dd if=/dev/zero of=/dev/vnd0p1s2 bs=512 count=9 2>/dev/null && bomb "dd nofail"
115 mkfs.mfs /dev/vnd0p0 || bomb "unable to mkfs vnd0p1s3"
116 mkfs.mfs /dev/vnd0p1s3 || bomb "unable to mkfs vnd0p1s3"
117 mount /dev/vnd0p0 mnt0 >/dev/null || bomb "unable to mount vnd0p0"
118 mount /dev/vnd0p1s3 mnt1 >/dev/null || bomb "unable to mount vnd0p1s3"
119 umount /dev/vnd0p0 >/dev/null || bomb "unable to unmount vnd0p0"
120 umount mnt1 >/dev/null || bomb "unable to unmount vnd0p1s3"
121 vndconfig -u /dev/vnd0
122 vndconfig /dev/vnd1 image1 512/1/1/1025 2>/dev/null && bomb "can config vnd1"
123 vndconfig /dev/vnd1 image1 512/1/1/1024 2>/dev/null || bomb "can't config vnd1"
124 [ "`devsize /dev/vnd1`" = 1024 ] || bomb "invalid vnd1 device size"
125 dd if=/dev/vnd1 of=/dev/null bs=512 count=1024 2>/dev/null || bomb "dd fail"
126 dd if=/dev/vnd1 of=tmp bs=512 skip=1023 count=2 2>/dev/null
127 [ "`stat -f '%z' tmp`" = 512 ] || bomb "unexpected dd result"
129 # Test miscellaneous stuff.
130 vndconfig /dev/vnd1 image1 2>/dev/null && bomb "reconfiguring should not work"
131 # the -r is needed here to pass vndconfig(8)'s open test (which is buggy, too!)
132 vndconfig -r vnd0 . 2>/dev/null && bomb "config to a directory should not work"
133 vndconfig vnd0 /dev/vnd1 2>/dev/null && bomb "config to another vnd? horrible!"
134 diskctl /dev/vnd1 flush >/dev/null || bomb "unable to flush vnd1"
135 vndconfig -u vnd1
137 # Test the low-level driver API.
138 vndconfig vnd0 image0 || bomb "unable to configure vnd0"
139 ../tvnd /dev/vnd0 || bomb "API subtest failed"
140 # the device is now unconfigured, but the driver is still running
142 # Invoke the blocktest test set to test various other aspects.
143 vndconfig -S vnd0 image0 || bomb "unable to configure vnd0"
144 cd ../blocktest
145 . support.sh
146 block_test /dev/vnd0 \
147 "rw,min_read=1,min_write=1,element=1,max=16777216,nocontig,silent" || \
148 bomb "blocktest test set failed"
149 vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
151 cd ..
152 rm -rf $TESTDIR
154 echo "ok"
155 exit 0