Require C99
[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
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         *)
103                 echo "E: unknown test $1"
104                 exit 1
105         ;;
106 esac
107 if [ -f nbd-server.pid ]
108 then
109         kill `cat nbd-server.pid`
110         rm -f nbd-server.pid
111 else
112         kill $PID
113 fi
114 if [ -z "$2" ]
115 then
116         rm -f $tmpnam nbd-server.conf
117 fi
118 if [ $retval -ne 0 ]
119 then
120         exit $retval
121 fi