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