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