xref: /minix/minix/tests/testvnd.sh (revision 9f988b79)
1#!/bin/sh
2
3# Shell script used to test the VNode Disk (VND) driver.
4
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).
8
9bomb() {
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
18}
19
20PATH=/bin:/usr/bin:/sbin:/usr/sbin
21export PATH
22
23TESTDIR=DIR_VND
24export TESTDIR
25
26echo -n "Test VND "
27
28# We cannot run the test if vnd0 or vnd1 are in use.
29if 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
36  fi
37fi
38if 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
45  fi
46fi
47
48rm -rf $TESTDIR
49mkdir $TESTDIR
50cd $TESTDIR
51
52mkdir mnt0
53mkdir mnt1
54
55# Test persisting a file inside a vnode device.
56dd if=/dev/zero of=image0 bs=4096 count=257 2>/dev/null || bomb "out of space?"
57vndconfig vnd0 image0 || bomb "unable to configure vnd0"
58[ "`devsize /dev/vnd0`" = 2056 ] || bomb "unexpected vnd0 device size"
59mkfs.mfs /dev/vnd0 || bomb "unable to mkfs vnd0"
60mount -t mfs /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
61STRING="Hello, world!"
62echo "$STRING" >mnt0/TEST || bomb "unable to create file on vnd0"
63umount /dev/vnd0 >/dev/null || bomb "unable to unmount vnd0"
64[ ! -f mnt0/TEST ] || bomb "was vnd0 ever really mounted?"
65mount -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"
68umount /dev/vnd0 >/dev/null || bomb "unable to unmount vnd0"
69vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
70vndconfig vnd1 image0 || bomb "unable to configure vnd1"
71mount -t mfs /dev/vnd1 mnt1 >/dev/null || bomb "unable to mount vnd1"
72[ "`cat mnt1/TEST`" = "$STRING" ] || bomb "test file was corrupted"
73
74# Test nesting images.
75dd if=/dev/zero of=mnt1/image1 bs=4096 count=128 2>/dev/null || bomb "dd fail"
76vndconfig vnd0 mnt1/image1
77mkfs.mfs /dev/vnd0 || bomb "unable to mkfs vnd0"
78mount -t mfs /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
79echo "x" >mnt0/TEST2 || bomb "unable to create file on vnd0"
80umount mnt1 >/dev/null 2>&1 && bomb "should not be able to unmount vnd1"
81umount mnt0 >/dev/null || bomb "unable to unmount vnd0"
82umount mnt1 >/dev/null 2>&1 && bomb "should not be able to unmount vnd1"
83vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
84cp mnt1/image1 . || bomb "unable to copy image off vnd1"
85umount mnt1 >/dev/null || bomb "unable to unmount vnd1"
86vndconfig -uS vnd1 || bomb "unable to unconfigure vnd1"
87vndconfig -S vnd1 ./image1
88mount -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"
91umount /dev/vnd1 >/dev/null || bomb "unable to unmount vnd1"
92vndconfig -u /dev/vnd1 || bomb "unable to unconfigure vnd1"
93
94# Test a read-only configuration.
95SUM=`sha1 image0`
96vndconfig -r vnd0 image0
97dd if=/dev/zero of=/dev/vnd0 bs=4096 count=1 2>/dev/null && bomb "dd succeeded"
98mount /dev/vnd0 mnt0 >/dev/null 2>&1 && bomb "mounting read-write should fail"
99mount -r /dev/vnd0 mnt0 >/dev/null || bomb "unable to mount vnd0"
100[ "`cat mnt0/TEST`" = "$STRING" ] || bomb "test file was corrupted"
101dd if=/dev/zero of=/dev/vnd0 bs=4096 count=1 2>/dev/null && bomb "dd succeeded"
102umount /dev/vnd0 >/dev/null
103vndconfig -uS vnd0
104[ "`sha1 image0`" = "$SUM" ] || bomb "read-only file changed"
105
106# Test geometry and sub/partitions.
107vndconfig -c vnd0 image0 512/32/64/2 2>/dev/null && bomb "vndconfig succeeded"
108vndconfig -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"
111partition -mf /dev/vnd0 8 81:512 81:512* 81:512 81:1+ >/dev/null
112partition -f /dev/vnd0p1 81:256 81:1 81:8 81:1+ >/dev/null
113dd if=/dev/zero of=/dev/vnd0p1s2 bs=512 count=8 2>/dev/null || bomb "dd failed"
114dd if=/dev/zero of=/dev/vnd0p1s2 bs=512 count=9 2>/dev/null && bomb "dd nofail"
115mkfs.mfs /dev/vnd0p0 || bomb "unable to mkfs vnd0p1s3"
116mkfs.mfs /dev/vnd0p1s3 || bomb "unable to mkfs vnd0p1s3"
117mount /dev/vnd0p0 mnt0 >/dev/null || bomb "unable to mount vnd0p0"
118mount /dev/vnd0p1s3 mnt1 >/dev/null || bomb "unable to mount vnd0p1s3"
119umount /dev/vnd0p0 >/dev/null || bomb "unable to unmount vnd0p0"
120umount mnt1 >/dev/null || bomb "unable to unmount vnd0p1s3"
121vndconfig -u /dev/vnd0
122vndconfig /dev/vnd1 image1 512/1/1/1025 2>/dev/null && bomb "can config vnd1"
123vndconfig /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"
125dd if=/dev/vnd1 of=/dev/null bs=512 count=1024 2>/dev/null || bomb "dd fail"
126dd if=/dev/vnd1 of=tmp bs=512 skip=1023 count=2 2>/dev/null
127[ "`stat -f '%z' tmp`" = 512 ] || bomb "unexpected dd result"
128
129# Test miscellaneous stuff.
130vndconfig /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!)
132vndconfig -r vnd0 . 2>/dev/null && bomb "config to a directory should not work"
133vndconfig vnd0 /dev/vnd1 2>/dev/null && bomb "config to another vnd? horrible!"
134diskctl /dev/vnd1 flush >/dev/null || bomb "unable to flush vnd1"
135vndconfig -u vnd1
136
137# Test the low-level driver API.
138vndconfig 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
141
142# Invoke the blocktest test set to test various other aspects.
143vndconfig -S vnd0 image0 || bomb "unable to configure vnd0"
144cd ../blocktest
145. ./support.sh
146block_test /dev/vnd0 \
147  "rw,min_read=1,min_write=1,element=1,max=16777216,nocontig,silent" || \
148  bomb "blocktest test set failed"
149vndconfig -u vnd0 || bomb "unable to unconfigure vnd0"
150
151cd ..
152rm -rf $TESTDIR
153
154echo "ok"
155exit 0
156