forked from facebook/wdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdt_e2e_simple_test.sh
executable file
·167 lines (137 loc) · 4.67 KB
/
wdt_e2e_simple_test.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
#! /bin/bash
#
# Smaller/minimal version of wdt_e2e_simple_test.sh
#
echo "Run from the cmake build dir (or ~/fbcode - or fbmake runtests)"
BASEDIR=/tmp/wdtTest_$USER
usage="
The possible options to this script are
-d base directory to use (defaults to $BASEDIR)
"
if [ "$1" == "-h" ]; then
echo "$usage"
exit 0
fi
while getopts ":d:h:" opt; do
case $opt in
d) BASEDIR="$OPTARG"
;;
h) echo "$usage"
exit
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
# Set DO_VERIFY:
# to 1 : slow/expensive but checks correctness
# to 0 : fast for repeated benchmarking not for correctness
DO_VERIFY=1
if [ -z "$WDT_TEST_SYMLINKS" ] ; then
WDT_TEST_SYMLINKS=1
fi;
echo "WDT_TEST_SYMLINKS=$WDT_TEST_SYMLINKS"
# Verbose / to debug failure:
#WDTBIN="_bin/wdt/wdt -minloglevel 0 -v 99"
# Normal:
WDTBIN_OPTS="-minloglevel=0 -sleep_millis 1 -max_retries 999 -full_reporting "\
"-avg_mbytes_per_sec=3000 -max_mbytes_per_sec=3500 -start_port=0 "\
"-num_ports=4 -throttler_log_time_millis=200 -enable_checksum=true"
WDTBIN="_bin/wdt/wdt $WDTBIN_OPTS"
MD5SUM=`which md5sum`
STATUS=$?
if [ $STATUS -ne 0 ] ; then
MD5SUM=`which md5`
fi
echo "Found md5sum as $MD5SUM"
if [ -z "$HOSTNAME" ] ; then
echo "HOSTNAME not set, will try with 'localhost'"
HOSTNAME=localhost
else
echo "Will self connect to HOSTNAME=$HOSTNAME"
fi
mkdir -p $BASEDIR
DIR=`mktemp -d $BASEDIR/XXXXXX`
echo "Testing in $DIR"
#pkill -x wdt
mkdir $DIR/src
mkdir $DIR/extsrc
#cp -R wdt folly /usr/bin /usr/lib /usr/lib64 /usr/libexec /usr/share $DIR/src
#cp -R wdt folly /usr/bin /usr/lib /usr/lib64 /usr/libexec $DIR/src
#cp -R wdt $DIR/src
#for size in 1k 64K 512K 1M 16M 256M 512M 1G
#for size in 512K 1M 16M 256M 512M 1G
# Mac's dd doesn't understand K,M,G...
for size in 1024 65536 524288 1232896 19726336
do
base=inp$size
echo dd if=/dev/... of=$DIR/src/$base.1 bs=$size count=1
dd if=/dev/urandom of=$DIR/src/$base.1 bs=$size count=1
# dd if=/dev/zero of=$DIR/src/$base.1 bs=$size count=1
for i in {2..8}
do
cp $DIR/src/$base.1 $DIR/src/$base.$i
done
done
echo "done with setup"
if [ $WDT_TEST_SYMLINKS -eq 1 ]; then
# test symlink issues
(cd $DIR/src ; touch a; ln -s doesntexist badlink; dd if=/dev/zero of=c bs=1024 count=1; mkdir d; ln -s ../d d/e; ln -s ../c d/a)
(cd $DIR/extsrc; mkdir TestDir; mkdir TestDir/test; cd TestDir; echo "Text1" >> file1; cd test; echo "Text2" >> file1; ln -s $DIR/extsrc/TestDir; cp -R $DIR/extsrc/TestDir $DIR/src)
fi
CMD="$WDTBIN -minloglevel=0 -directory $DIR/dst 2> $DIR/server.log | head -1 | \
xargs -I URL $WDTBIN -directory $DIR/src -connection_url URL 2>&1 | \
tee $DIR/client1.log"
echo "First transfer: $CMD"
eval $CMD
STATUS=$?
# TODO check for $? / crash... though diff will indirectly find that case
if [ $WDT_TEST_SYMLINKS -eq 1 ]; then
CMD="$WDTBIN -minloglevel=0 -directory $DIR/dst_symlinks 2>> $DIR/server.log |\
head -1 | xargs -I URL $WDTBIN -follow_symlinks -directory $DIR/src \
-connection_url URL 2>&1 | tee $DIR/client2.log"
echo "Second transfer: $CMD"
eval $CMD
# TODO check for $? / crash... though diff will indirectly find that case
fi
if [ $DO_VERIFY -eq 1 ] ; then
echo "Verifying for run without follow_symlinks"
echo "Checking for difference `date`"
NUM_FILES=`(cd $DIR/dst && ( find . -type f | wc -l))`
echo "Transfered `du -ks $DIR/dst` kbytes across $NUM_FILES files"
(cd $DIR/src ; ( find . -type f -print0 | xargs -0 $MD5SUM | sort ) \
> ../src.md5s )
(cd $DIR/dst ; ( find . -type f -print0 | xargs -0 $MD5SUM | sort ) \
> ../dst.md5s )
echo "Should be no diff"
(cd $DIR; diff -u src.md5s dst.md5s)
STATUS=$?
if [ $WDT_TEST_SYMLINKS -eq 1 ]; then
echo "Verifying for run with follow_symlinks"
echo "Checking for difference `date`"
NUM_FILES=`(cd $DIR/dst_symlinks && ( find . -type f | wc -l))`
echo "Transfered `du -ks $DIR/dst_symlinks` kbytes across $NUM_FILES files"
(cd $DIR/src ; ( find -L . -type f -print0 | xargs -0 $MD5SUM | sort ) \
> ../src_symlinks.md5s )
(cd $DIR/dst_symlinks ; ( find . -type f -print0 | xargs -0 $MD5SUM \
| sort ) > ../dst_symlinks.md5s )
echo "Should be no diff"
(cd $DIR; diff -u src_symlinks.md5s dst_symlinks.md5s)
SYMLINK_STATUS=$?
if [ $STATUS -eq 0 ] ; then
STATUS=$SYMLINK_STATUS
fi
fi
else
echo "Skipping independant verification"
fi
echo "Server logs:"
cat $DIR/server.log
if [ $STATUS -eq 0 ] ; then
echo "Good run, deleting logs in $DIR"
find $DIR -type d | xargs chmod 755 # cp -r can make some unreadable dir
rm -rf $DIR
else
echo "Bad run ($STATUS) - keeping full logs and partial transfer in $DIR"
fi
exit $STATUS