forked from distributed-system-analysis/smallfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regtest.sh
336 lines (290 loc) · 9.38 KB
/
regtest.sh
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
# smallfile regression test
#
# NOTE: this expects you to have /var/tmp in a filesystem that
# supports extended attributes and it expects NFS to support extended attributes
#
# you can set the environment variable PYTHON_PROG
# to switch between python3 and python2
# for example: # PYTHON_PROG=python3 bash regtest.sh
# python3 at present doesn't seem to support xattr module
# so some smallfile operations are not yet supported under python3,
# the regression test knows how to deal with that.
#
# you can have it use a directory in a tmpfs mountpoint,
# this is recommended so as not to wear out laptop drive.
# by default, newer distros have /run tmpfs mountpoint with sufficient space
# so this is default, but TMPDIR overrides
#
# ext4 doesn't support xattrs by default.
# To run a test on xattr-related operation types,
# set TMPDIR to an XFS filesystem.
# You can create an XFS filesystem by using a loopback device, for example:
#
# dd if=/dev/zero of=/var/tmp/xfs-fs.img bs=1024k count=1k
# losetup /dev/loop4 /var/tmp/xfs-fs.img
# mkfs -t xfs /dev/loop4
# mkdir -p /mnt/xattrtest
# mount -t xfs -o noatime,inode64 /dev/loop4 /mnt/xattrtest
# export TMPDIR=/mnt/xattrtest/smf
# mkdir /mnt/xattrtest/smf
# -- run test ---
# unset TMPDIR
# umount /mnt/xattrtest
# losetup -e /dev/loop4
# rm -fv /var/tmp/xfs-fs.img
#
# we don't use "tee" program to display results as they are happening
# because this erases any failure status code returned by smallfile,
# and this status code is vital to regression test.
# Instead we log all smallfile output to smfregtest.log
# where it can be analyzed later if failure occurs
#
localhost_name="$1"
if [ -z "$localhost_name" ] ; then localhost_name="localhost" ; fi
testdir="$TMPDIR/smfregtest"
xattrs=1
if [ "$TMPDIR" = "" ] ; then
# prefer to use tmpfs so we dont wear out disk on laptop or other system disk
testdir='/run/smfregtest'
xattrs=0
fi
nfsdir=/var/tmp/smfnfs
OK=0
NOTOK=1
GREP="grep -q "
PYTHON=${PYTHON_PROG:-python}
f=smfregtest.log
assertfail() {
status=$1
if [ $status == $OK ] ; then
echo "ERROR: unexpected success status $status"
echo "see end of $f for cause"
exit $NOTOK
fi
}
assertok() {
status=$1
if [ $status != $OK ] ; then
echo "ERROR: unexpected failure status $status"
echo "see end of $f for cause"
exit $NOTOK
fi
}
cleanup() {
rm -rf /var/tmp/invoke*.log $testdir/*
sudo mkdir -p $testdir
grep $nfsdir /proc/mounts
if [ $? = $OK ] ; then sudo umount -v $nfsdir ; fi
}
is_systemctl=1
which systemctl
if [ $? != $OK ] ; then # chances are it's pre-systemctl Linux distro, use "service" instead
is_systemctl=0
fi
start_service()
{
svcname=$1
echo "attempting to start service $svcname"
if [ $is_systemctl == 1 ] ; then
sudo systemctl start $svcname
else
sudo service $svcname start
fi
if [ $? != $OK ] ; then
echo "FAILED to start service $svcname"
exit $NOTOK
fi
}
start_service sshd
start_service nfs
# set up NFS mountpoint
cleanup
$GREP $nfsdir /proc/mounts
if [ $? != $OK ] ; then
sudo mkdir -pv $nfsdir
sudo chown $USER $nfsdir
sudo rm -rf $testdir
sudo mkdir -p $testdir
sudo chown $USER $testdir
sudo chmod 777 $testdir
sleep 1
sudo exportfs -v -o rw,no_root_squash,sync,fsid=15 localhost:$testdir
sleep 1
sudo mount -v -t nfs -o nfsvers=3,tcp,actimeo=1 $localhost_name:$testdir $nfsdir
if [ $? != $OK ] ; then
echo "NFS mount failed!"
exit $NOTOK
fi
fi
# test assertion mechanism
cp -r /foo/bar/no-such-dir /tmp/ >> $f 2>&1
assertfail $?
# run the smallfile.py module's unit test
echo "running smallfile.py unit test"
$PYTHON smallfile.py
assertok $?
# run the invoke_process.py unit test
echo "running invoke_process.py unit test"
$PYTHON invoke_process.py
assertok $?
# run drop_buffer_cache.py unit test
echo "running drop_buffer_cache.py unit test"
$PYTHON drop_buffer_cache.py
assertok $?
# test parsing
echo "testing parsing"
scmd="$PYTHON smallfile_cli.py --top $testdir "
cleanup
$scmd --files 0 >> $f
assertfail $?
$GREP 'non-negative' $f
assertok $?
cleanup
$scmd --threads 0 >> $f
assertfail $?
$GREP 'non-negative' $f
assertok $?
$scmd --files -1 >> $f
assertfail $?
$scmd --record-size -1 >> $f
assertfail $?
$scmd --file-size -1 >> $f
assertfail $?
$scmd --files-per-dir 0 >> $f
assertfail $?
$scmd --dirs-per-dir 0 >> $f
assertfail $?
$scmd --record-size -1 >> $f
assertfail $?
$scmd --record-size a >> $f
assertfail $?
$scmd --top / >> $f
assertfail $?
$scmd --response-times foo >> $f
assertfail $?
$scmd --stonewall foo >> $f
assertfail $?
$scmd --finish foo >> $f
assertfail $?
# run a command with all CLI options and verify that they were successfully parsed
cleanup
mkdir -p $nfsdir/smf
scmd="$PYTHON smallfile_cli.py --top $nfsdir/smf "
$scmd --verify-read N --response-times Y --finish N --stonewall N --permute-host-dirs Y --same-dir Y --operation cleanup --threads 5 --files 20 --files-per-dir 5 --dirs-per-dir 3 --record-size 6 --file-size 30 --file-size-distribution exponential --prefix a --suffix b --hash-into-dirs Y --pause 5 --host-set $localhost_name >> $f
assertok $?
expect_strs=( 'verify read? : N' \
"hosts in test : \['$localhost_name'\]" \
'top test directory(s) : ' \
'file size distribution : random exponential'\
'filename prefix : a' \
'filename suffix : b' \
'hash file number into dir.? : Y' \
'pause between files (microsec) : 5' \
'finish all requests? : N' \
'stonewall? : N' \
'measure response times? : Y' \
'log to stderr? : False' \
'permute host directories? : Y' \
'verbose? : False' \
'response times? : Y' \
'finish all requests? : N' \
'threads share directories? : Y' \
'pause between files (microsec) : 5' \
"top test directory(s) : \['$nfsdir/smf'\]" \
'operation : cleanup' \
'threads : 5' \
'files/thread : 20' \
'files per dir : 5' \
'dirs per dir : 3' \
'record size (KB, 0 = maximum) : 6' \
'file size (KB) : 30' )
expect_ct=${#expect_strs[*]}
for j in `seq 1 $expect_ct` ; do
((k = $j - 1))
expected_str="${expect_strs[$k]}"
$GREP "$expected_str" $f
s=$?
if [ $s != $OK ] ; then
echo "expecting: $expected_str"
fi
assertok $s $f
done
supported_ops()
{
multitop=''
if [ "$2" = 'multitop' ] ; then multitop='multiple-topdirs' ; fi
# python3 does not support xattr-related ops yet, I forget why
xattr_ops="setxattr getxattr swift-put swift-get"
if [ "$PYTHON" = "python3" -o "$PYTHON" = "pypy" ] ; then xattr_ops='' ; fi
if [ $xattrs -eq 0 ] ; then xattr_ops='' ; fi
# directory-reading ops do not work with multiple top-level directories at present
single_topdir_ops='readdir ls-l'
if [ -n "$multitop" ] ; then single_topdir_ops='' ; fi
# for debug only: ops="create cleanup"
ops="cleanup create append overwrite read $single_topdir_ops chmod stat $xattr_ops symlink mkdir rmdir rename delete-renamed"
echo $ops
}
run_one_cmd()
{
cmd="$1"
( echo "$cmd" ; $cmd ) | tee -a $f
assertok $?
}
common_params=\
"$PYTHON smallfile_cli.py --files 100 --files-per-dir 5 --dirs-per-dir 2 --threads 4 --file-size 4 --record-size 16 --file-size 32 --verify-read Y --response-times N --xattr-count 9 --xattr-size 253 --stonewall N"
echo "******** testing non-distributed operations"
for op in `supported_ops $xattrs ''` ; do
rm -rf /var/tmp/invoke*.log
echo
echo "testing local op $op"
run_one_cmd "$common_params --operation $op"
done
# we do these kinds of tests to support non-distributed filesystems and NFS exports of them
echo "******** testing non-distributed ops with multiple top-level directories"
topdirlist="${testdir}1,${testdir}2,${testdir}3,${testdir}4"
scmd="$PYTHON smallfile_cli.py --top $topdirlist "
topdirlist_nocomma=`echo $topdirlist | sed 's/,/ /g'`
for d in $topdirlist_nocomma ; do
sudo mkdir -pv $d
sudo chmod 777 $d
done
for op in `supported_ops $xattrs 'multitop'` ; do
rm -rf /var/tmp/invoke*.log
echo
echo "testing local op $op"
run_one_cmd "$common_params --operation $op"
done
for d in $topdirlist_nocomma ; do sudo rm -rf $d ; done
# these kinds of tests are needed for distributed filesystems or NFS/SMB exports
echo "******** testing distributed operations"
mkdir -pv $nfsdir/smf
# as long as we use NFS for regression tests, NFS does not support xattrs at present
save_xattrs=$xattrs
xattrs=0
for op in `supported_ops $xattrs ''` ; do
rm -rf /var/tmp/invoke*.log
echo
echo "testing distributed op $op"
run_one_cmd "$common_params --host-set $localhost_name --stonewall Y --pause 4000 --operation $op"
done
# we do these tests for virtualization (many KVM guests or containers, shared storage but no shared fs)
echo "******* testing distributed operation with a host-local fs"
for op in `supported_ops $xattrs ''` ; do
rm -rf /var/tmp/invoke*.log
rm -rf $nfsdir/sync
echo
echo "testing remote-but-local op $op"
run_one_cmd "$common_params --top $testdir --network-sync-dir $nfsdir/sync --host-set $localhost_name --operation $op"
done
echo "*** run one long test of creates and reads ***"
xattrs=$save_xattrs
for op in create read cleanup ; do
rm -rf /var/tmp/invoke*.log
run_one_cmd "$common_params --top $testdir --files 2000 --stonewall Y --pause 1000"
done
$GREP $nfsdir /proc/mounts
if [ $? == $OK ] ; then
sudo umount -v $nfsdir
fi
sudo rm -rf $testdir