Add flush test
[nbd.git] / simple_test
1 #!/bin/sh
2 # Yes, that's POSIX sh, not bash!
3
4 tmpnam=`mktemp`
5
6 ulimit -c unlimited
7
8 # Create a one-meg device
9 dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1
10
11 echo $1
12
13 case $1 in
14         */cmd)
15                 # Test with export specified on command line
16                 ./nbd-server -C /dev/null -p `pwd`/nbd-server.pid 11111 $tmpnam &
17                 # -p only works if nbd-server wasn't compiled with -DNOFORK or
18                 # -DNODAEMON, which I sometimes do for testing and debugging.
19                 PID=$!
20                 sleep 1
21                 ./nbd-tester-client 127.0.0.1 11111
22                 retval=$?
23         ;;
24         */cfgsize)
25                 # Test oversized requests
26                 ./nbd-server -C /dev/null -p `pwd`/nbd-server.pid 11111 $tmpnam &
27                 # -p only works if nbd-server wasn't compiled with -DNOFORK or
28                 # -DNODAEMON, which I sometimes do for testing and debugging.
29                 PID=$!
30                 sleep 1
31                 ./nbd-tester-client 127.0.0.1 11111 -o
32                 retval=$?
33         ;;
34         */cfg1)
35                 # Test with export specified in config file
36                 cat > nbd-server.conf <<EOF
37 [generic]
38         oldstyle = true
39 [export]
40         exportname = $tmpnam
41         port = 11112
42 EOF
43                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
44                 PID=$!
45                 sleep 1
46                 ./nbd-tester-client 127.0.0.1 11112
47                 retval=$?
48         ;;
49         */cfgmulti)
50                 # Test with multiple exports specified in config file, and
51                 # testing more options too
52                 cat >nbd-server.conf <<EOF
53 [generic]
54         oldstyle = true
55 [export1]
56         exportname = $tmpnam
57         port = 11113
58         copyonwrite = true
59         listenaddr = 127.0.0.1
60 [export2]
61         exportname = $tmpnam
62         port = 11114
63         readonly = true
64         listenaddr = 127.0.0.1
65 EOF
66                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
67                 PID=$!
68                 sleep 1
69                 ./nbd-tester-client localhost 11113
70                 retval=$?
71                 if [ $retval -ne 0 ]
72                 then
73                         if [ -f nbd-server.pid ]
74                         then
75                                 kill `cat nbd-server.pid`
76                                 rm -f nbd-server.pid
77                         else
78                                 kill $PID
79                         fi
80                         if [ -z "$2" ]
81                         then
82                                 rm -f $tmpnam nbd-server.conf
83                         fi
84                         exit $retval
85                 fi
86                 ./nbd-tester-client localhost 11114
87                 retval=$?
88         ;;
89         */cfgnew)
90                 # Test new-style exports
91                 cat >nbd-server.conf <<EOF
92 [generic]
93 [export1]
94         exportname = $tmpnam
95 EOF
96                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
97                 PID=$!
98                 sleep 1
99                 ./nbd-tester-client localhost -N export1
100                 retval=$?
101         ;;
102         */write)
103                 # Test new-style exports
104                 cat >nbd-server.conf <<EOF
105 [generic]
106 [export1]
107         exportname = $tmpnam
108 EOF
109                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
110                 PID=$!
111                 sleep 1
112                 ./nbd-tester-client localhost -N export1 -w
113                 retval=$?
114         ;;
115         */flush)
116                 # Test new-style exports
117                 cat >nbd-server.conf <<EOF
118 [generic]
119 [export1]
120         exportname = $tmpnam
121 EOF
122                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
123                 PID=$!
124                 sleep 1
125                 ./nbd-tester-client localhost -N export1 -w -f
126                 retval=$?
127         ;;
128         *)
129                 echo "E: unknown test $1"
130                 exit 1
131         ;;
132 esac
133 if [ -f nbd-server.pid ]
134 then
135         kill `cat nbd-server.pid`
136         rm -f nbd-server.pid
137 else
138         kill $PID
139 fi
140 if [ -z "$2" ]
141 then
142         rm -f $tmpnam nbd-server.conf
143 fi
144 if [ $retval -ne 0 ]
145 then
146         exit $retval
147 fi