Fix handling of oversized requests
[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=1024
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
25         */cfg1)
26                 # Test with export specified in config file
27                 cat > nbd-server.conf <<EOF
28 [generic]
29         oldstyle = true
30 [export]
31         exportname = $tmpnam
32         port = 11112
33 EOF
34                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
35                 PID=$!
36                 sleep 1
37                 ./nbd-tester-client 127.0.0.1 11112
38                 retval=$?
39         ;;
40         */cfgmulti)
41                 # Test with multiple exports specified in config file, and
42                 # testing more options too
43                 cat >nbd-server.conf <<EOF
44 [generic]
45         oldstyle = true
46 [export1]
47         exportname = $tmpnam
48         port = 11113
49         copyonwrite = true
50         listenaddr = 127.0.0.1
51 [export2]
52         exportname = $tmpnam
53         port = 11114
54         readonly = true
55         listenaddr = 127.0.0.1
56 EOF
57                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
58                 PID=$!
59                 sleep 1
60                 ./nbd-tester-client localhost 11113
61                 retval=$?
62                 if [ $retval -ne 0 ]
63                 then
64                         if [ -f nbd-server.pid ]
65                         then
66                                 kill `cat nbd-server.pid`
67                                 rm -f nbd-server.pid
68                         else
69                                 kill $PID
70                         fi
71                         if [ -z "$2" ]
72                         then
73                                 rm -f $tmpnam nbd-server.conf
74                         fi
75                         exit $retval
76                 fi
77                 ./nbd-tester-client localhost 11114
78                 retval=$?
79         ;;
80         */cfgnew)
81                 # Test new-style exports
82                 cat >nbd-server.conf <<EOF
83 [generic]
84 [export1]
85         exportname = $tmpnam
86 EOF
87                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
88                 PID=$!
89                 sleep 1
90                 ./nbd-tester-client localhost -N export1
91                 retval=$?
92         ;;
93         *)
94                 echo "E: unknown test $1"
95                 exit 1
96         ;;
97 esac
98 if [ -f nbd-server.pid ]
99 then
100         kill `cat nbd-server.pid`
101         rm -f nbd-server.pid
102 else
103         kill $PID
104 fi
105 if [ -z "$2" ]
106 then
107         rm -f $tmpnam nbd-server.conf
108 fi
109 if [ $retval -ne 0 ]
110 then
111         exit $retval
112 fi