Make integrity tests respect request ordering.
[nbd.git] / simple_test
1 #!/bin/sh
2 # Yes, that's POSIX sh, not bash!
3
4 tmpdir=`mktemp -d`
5 conffile=${tmpdir}/nbd.conf
6 pidfile=${tmpdir}/nbd.pid
7 tmpnam=${tmpdir}/nbd.dd
8 mydir=$(dirname "`readlink -f $0`")
9
10 ulimit -c unlimited
11
12 # Create a one-meg device
13 dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1
14
15 echo $1
16
17 case $1 in
18         */cmd)
19                 # Test with export specified on command line
20                 ./nbd-server -C /dev/null -p ${pidfile} 11111 $tmpnam &
21                 # -p only works if nbd-server wasn't compiled with -DNOFORK or
22                 # -DNODAEMON, which I sometimes do for testing and debugging.
23                 PID=$!
24                 sleep 1
25                 ./nbd-tester-client 127.0.0.1 11111
26                 retval=$?
27         ;;
28         */cfgsize)
29                 # Test oversized requests
30                 ./nbd-server -C /dev/null -p ${pidfile} 11111 $tmpnam &
31                 # -p only works if nbd-server wasn't compiled with -DNOFORK or
32                 # -DNODAEMON, which I sometimes do for testing and debugging.
33                 PID=$!
34                 sleep 1
35                 ./nbd-tester-client 127.0.0.1 11111 -o
36                 retval=$?
37         ;;
38         */cfg1)
39                 # Test with export specified in config file
40                 cat > ${conffile} <<EOF
41 [generic]
42         oldstyle = true
43 [export]
44         exportname = $tmpnam
45         port = 11112
46 EOF
47                 ./nbd-server -C ${conffile} -p ${pidfile} &
48                 PID=$!
49                 sleep 1
50                 ./nbd-tester-client 127.0.0.1 11112
51                 retval=$?
52         ;;
53         */cfgmulti)
54                 # Test with multiple exports specified in config file, and
55                 # testing more options too
56                 cat >${conffile} <<EOF
57 [generic]
58         oldstyle = true
59 [export1]
60         exportname = $tmpnam
61         port = 11113
62         copyonwrite = true
63         listenaddr = 127.0.0.1
64 [export2]
65         exportname = $tmpnam
66         port = 11114
67         readonly = true
68         listenaddr = 127.0.0.1
69 EOF
70                 ./nbd-server -C ${conffile} -p ${pidfile} &
71                 PID=$!
72                 sleep 1
73                 ./nbd-tester-client localhost 11113
74                 retval=$?
75                 if [ $retval -ne 0 ]
76                 then
77                         if [ -f ${pidfile} ]
78                         then
79                                 kill `cat ${pidfile}`
80                         else
81                                 kill $PID
82                         fi
83                         if [ -z "$2" ]
84                         then
85                                 rm -rf $tmpdir
86                         fi
87                         exit $retval
88                 fi
89                 ./nbd-tester-client localhost 11114
90                 retval=$?
91         ;;
92         */cfgnew)
93                 # Test new-style exports
94                 cat >${conffile} <<EOF
95 [generic]
96 [export1]
97         exportname = $tmpnam
98 EOF
99                 ./nbd-server -C ${conffile} -p ${pidfile} &
100                 PID=$!
101                 sleep 1
102                 ./nbd-tester-client localhost -N export1
103                 retval=$?
104         ;;
105         */write)
106                 # Test writing
107                 cat >${conffile} <<EOF
108 [generic]
109 [export1]
110         exportname = $tmpnam
111 EOF
112                 ./nbd-server -C ${conffile} -p ${pidfile} &
113                 PID=$!
114                 sleep 1
115                 ./nbd-tester-client localhost -N export1 -w
116                 retval=$?
117         ;;
118         */flush)
119                 # Test writes with flush
120                 cat >${conffile} <<EOF
121 [generic]
122 [export1]
123         exportname = $tmpnam
124         flush = true
125         fua = true
126         rotational = true
127 EOF
128                 ./nbd-server -C ${conffile} -p ${pidfile} &
129                 PID=$!
130                 sleep 1
131                 ./nbd-tester-client localhost -N export1 -w -f
132                 retval=$?
133         ;;
134         */integrity)
135                 # Integrity test
136                 cat >${conffile} <<EOF
137 [generic]
138 [export1]
139         exportname = $tmpnam
140         flush = true
141         fua = true
142         rotational = true
143 EOF
144                 # we need a bigger disk
145                 dd if=/dev/zero of=$tmpnam bs=1M count=50 >/dev/null 2>&1
146                 ./nbd-server -C ${conffile} -p ${pidfile} &
147                 PID=$!
148                 sleep 1
149                 ./nbd-tester-client localhost -N export1 -i -t ${mydir}/integrity-test.tr
150                 retval=$?
151         ;;
152         */integrityhuge)
153                 # Integrity test
154                 cat >${conffile} <<EOF
155 [generic]
156 [export1]
157         exportname = $tmpnam
158         flush = true
159         fua = true
160         rotational = true
161 EOF
162                 # we need a bigger disk
163                 dd if=/dev/zero of=$tmpnam bs=1M count=50 >/dev/null 2>&1
164                 ./nbd-server -C ${conffile} -p ${pidfile} &
165                 PID=$!
166                 sleep 1
167                 ./nbd-tester-client localhost -N export1 -i -t ${mydir}/integrityhuge-test.tr
168                 retval=$?
169         ;;
170         *)
171                 echo "E: unknown test $1"
172                 exit 1
173         ;;
174 esac
175 if [ -f ${pidfile} ]
176 then
177         kill `cat ${pidfile}`
178 else
179         kill $PID
180 fi
181 if [ -z "$2" ]
182 then
183         rm -rf $tmpdir
184 fi
185 if [ $retval -ne 0 ]
186 then
187         exit $retval
188 fi