Fix 'make -j check'
[nbd.git] / simple_test
1 #!/bin/sh
2 # Yes, that's POSIX sh, not bash!
3
4 tmpnam=`mktemp`
5
6 # Create a one-meg device
7 dd if=/dev/zero of=$tmpnam bs=1024 count=1024
8
9 echo $1
10
11 case $1 in
12         */cmd)
13                 # Test with export specified on command line
14                 ./nbd-server -C /dev/null -p `pwd`/nbd-server.pid 11111 $tmpnam &
15                 # -p only works if nbd-server wasn't compiled with -DNOFORK or
16                 # -DNODAEMON, which I sometimes do for testing and debugging.
17                 PID=$!
18                 sleep 1
19                 ./nbd-tester-client 127.0.0.1 11111
20                 retval=$?
21         ;;
22
23         */cfg1)
24                 # Test with export specified in config file
25                 cat > nbd-server.conf <<EOF
26 [generic]
27 [export]
28         exportname = $tmpnam
29         port = 11112
30 EOF
31                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
32                 PID=$!
33                 sleep 1
34                 ./nbd-tester-client 127.0.0.1 11112
35                 retval=$?
36         ;;
37         */cfgmulti)
38                 # Test with multiple exports specified in config file, and
39                 # testing more options too
40                 cat >nbd-server.conf <<EOF
41 [generic]
42 [export1]
43         exportname = $tmpnam
44         port = 11113
45         copyonwrite = true
46         listenaddr = 127.0.0.1
47 [export2]
48         exportname = $tmpnam
49         port = 11114
50         readonly = true
51 EOF
52                 ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
53                 PID=$!
54                 sleep 1
55                 ./nbd-tester-client localhost 11113
56                 retval=$?
57                 if [ $retval -ne 0 ]
58                 then
59                         if [ -f nbd-server.pid ]
60                         then
61                                 kill `cat nbd-server.pid`
62                                 rm -f nbd-server.pid
63                         else
64                                 kill $PID
65                         fi
66                         rm -f $tmpnam nbd-server.conf
67                         exit $retval
68                 fi
69                 ./nbd-tester-client localhost 11114
70                 retval=$?
71         ;;
72         *)
73                 echo "E: unknown test $1"
74                 exit 1
75         ;;
76 esac
77 if [ -f nbd-server.pid ]
78 then
79         kill `cat nbd-server.pid`
80         rm -f nbd-server.pid
81 else
82         kill $PID
83 fi
84 if [ $retval -ne 0 ]
85 then
86         exit $retval
87 fi
88 rm -f $tmpnam nbd-server.conf