forked from NetworkBlockDevice/nbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_test
executable file
·234 lines (228 loc) · 4.29 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/sh
# Yes, that's POSIX sh, not bash!
tmpdir=`mktemp -d`
conffile=${tmpdir}/nbd.conf
pidfile=${tmpdir}/nbd.pid
tmpnam=${tmpdir}/nbd.dd
mydir=$(dirname "`readlink -f $0`")
set -e
ulimit -c unlimited
# Create a one-meg device
dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1
echo $1
case $1 in
*/cmd)
# Test with export specified on command line
./nbd-server -C /dev/null -p ${pidfile} 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=$?
;;
*/cfgsize)
# Test oversized requests
./nbd-server -C /dev/null -p ${pidfile} 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 -o
retval=$?
;;
*/cfg1)
# Test with export specified in config file
cat > ${conffile} <<EOF
[generic]
oldstyle = true
[export]
exportname = $tmpnam
port = 11112
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
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 >${conffile} <<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 ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost 11113
retval=$?
if [ $retval -ne 0 ]
then
if [ -f ${pidfile} ]
then
kill `cat ${pidfile}`
else
kill $PID
fi
if [ -z "$2" ]
then
rm -rf $tmpdir
fi
exit $retval
fi
./nbd-tester-client localhost 11114
retval=$?
;;
*/cfgnew)
# Test new-style exports
cat >${conffile} <<EOF
[generic]
[export1]
exportname = $tmpnam
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1
retval=$?
;;
*/write)
# Test writing
cat >${conffile} <<EOF
[generic]
[export1]
exportname = $tmpnam
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1 -w
retval=$?
;;
*/flush)
# Test writes with flush
cat >${conffile} <<EOF
[generic]
[export1]
exportname = $tmpnam
flush = true
fua = true
rotational = true
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1 -w -f
retval=$?
;;
*/dirconfig)
# config.d-style configuration
cat >${conffile} <<EOF
[generic]
includedir = $tmpdir/confdir
EOF
mkdir $tmpdir/confdir
cat >$tmpdir/confdir/exp1.conf <<EOF
[export1]
exportname = $tmpnam
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1
retval=$?
;;
*/integrity)
# Integrity test
cat >${conffile} <<EOF
[generic]
[export1]
exportname = $tmpnam
flush = true
fua = true
rotational = true
filesize = 52428800
temporary = true
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1 -i -t ${mydir}/integrity-test.tr
retval=$?
;;
*/integrityhuge)
# Integrity test
cat >${conffile} <<EOF
[generic]
[export1]
exportname = $tmpnam
flush = true
fua = true
rotational = true
filesize = 52428800
temporary = true
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-tester-client localhost -N export1 -i -t ${mydir}/integrityhuge-test.tr
retval=$?
;;
*/list)
# List exports
# This only works if we built nbd-client, which only exists on
# Linux. But hey, testing nbd-client itself isn't a bad idea,
# so here goes.
if [ `uname -s` != "Linux" ]
then
retval=77
else
cat >${conffile} <<EOF
[generic]
listenaddr = 127.0.0.1
allowlist = true
[export1]
exportname = $tmpnam
readonly = true
EOF
./nbd-server -C ${conffile} -p ${pidfile} &
PID=$!
sleep 1
./nbd-client -l localhost
retval=$?
fi
;;
*)
echo "E: unknown test $1"
exit 1
;;
esac
if [ -f ${pidfile} ]
then
kill `cat ${pidfile}`
else
if [ ! -z "$PID" ]
then
kill $PID
fi
fi
if [ -z "$2" ]
then
rm -rf $tmpdir
fi
if [ $retval -ne 0 ]
then
exit $retval
fi