-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·159 lines (124 loc) · 3.39 KB
/
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
#!/bin/bash
set -e
PORT=12345
USER=$(whoami)
GROUP=$(groups | cut -d' ' -f 1)
SSD=/sbin/start-stop-daemon
RTFTPC=$(pwd)/target/release/rtftpc
RTFTPD=$(pwd)/target/release/rtftpd
ATFTPC=/usr/bin/atftp
ATFTPD=/usr/sbin/atftpd
TFTPC=/usr/bin/tftp
BUSYBOX=/bin/busybox
CURL=/usr/bin/curl
CLIENTDIR=$(mktemp -d)
SERVERDIR=$(mktemp -d)
cleanup() {
atftpd_cleanup
rtftpd_cleanup
rm -f "$CLIENTDIR/testfile" "$SERVERDIR/testfile"
rmdir "$CLIENTDIR" "$SERVERDIR"
}
compare_files() {
cmp "$CLIENTDIR/testfile" "$SERVERDIR/testfile" 1>/dev/null
}
atftpd() {
$ATFTPD --port $PORT --user "$USER" --group "$GROUP" --daemon "$SERVERDIR"
}
atftpc() {
[ $TX -eq 1 ] && op="-p" || op="-g"
[ -n "$NETASCII" ] && opts="--mode netascii"
if [ -n "$BLKSIZE" ]; then
$ATFTPC $op -l testfile -r testfile $opts --option "blksize $BLKSIZE" 127.0.0.1 $PORT 1>/dev/null 2>&1
else
$ATFTPC $op -l testfile -r testfile $opts 127.0.0.1 $PORT 1>/dev/null
fi
}
tftpc() {
[ $TX -eq 1 ] && op="put" || op="get"
printf "connect 127.0.0.1 $PORT\\nmode binary\\n$op testfile\\n" | $TFTPC 1>/dev/null
}
rtftpd() {
$SSD --background --exec "$RTFTPD" --start -- -p $PORT "$SERVERDIR" 1>/dev/null
}
rtftpc() {
[ $TX -eq 1 ] && op="-p" || op="-g"
[ -n "$BLKSIZE" ] && opts="--blksize $BLKSIZE"
[ -n "$NETASCII" ] && opts="$opts -n"
$RTFTPC $op testfile $opts 127.0.0.1:$PORT 1>/dev/null
}
curl() {
[ $TX -eq 1 ] && op="-T" || op="-o"
[ -n "$BLKSIZE" ] && opts="--tftp-blksize $BLKSIZE"
$CURL --silent $op testfile $opts tftp://127.0.0.1:$PORT/testfile
}
busybox_tftpc() {
[ $TX -eq 1 ] && op="-p" || op="-g"
[ -n "$BLKSIZE" ] && opts="-b $BLKSIZE"
$BUSYBOX tftp $op -l testfile -r testfile $opts 127.0.0.1 $PORT 1>/dev/null 2>&1
}
atftpd_cleanup() {
killall -q -9 $ATFTPD 2>/dev/null || true
}
rtftpd_cleanup() {
killall -q -9 "$RTFTPD" 2>/dev/null || true
}
test_transfer() {
client=$1
server=$2
$server
dd if=/dev/urandom of="$CLIENTDIR/testfile" bs=1M count=100 2>/dev/null
time (
printf "$client TX (to $server): "
TX=1
${client}
compare_files
printf "ok"
) 2>&1
rm -f "$CLIENTDIR/testfile"
time (
printf "$client RX (from $server): "
TX=0
${client}
compare_files
printf "ok"
) 2>&1
rm -f "$SERVERDIR/testfile"
${server}_cleanup
}
trap cleanup 0 1 2
# make sure binaries are up-to-date
cargo build --release
cd "$CLIENTDIR"
# Defaults
printf "Testing with default configuration\\n"
test_transfer rtftpc rtftpd
[ -x $ATFTPD ] && test_transfer rtftpc atftpd
[ -x $ATFTPC ] && test_transfer atftpc rtftpd
[ -x $TFTPC ] && test_transfer tftpc rtftpd
[ -x $BUSYBOX ] && test_transfer busybox_tftpc rtftpd
[ -x $CURL ] && test_transfer curl rtftpd
# with netascii mode
printf "\\n\\nTesting netascii transfers\\n"
NETASCII=1
test_transfer rtftpc rtftpd
[ -x $ATFTPD ] && test_transfer rtftpc atftpd
[ -x $ATFTPC ] && test_transfer atftpc rtftpd
unset NETASCII
# different block size
printf "\\n\\nTesting larger block sizes\\n"
BLKSIZE=1500
test_transfer rtftpc rtftpd
[ -x $ATFTPD ] && test_transfer rtftpc atftpd
[ -x $ATFTPC ] && test_transfer atftpc rtftpd
[ -x $BUSYBOX ] && test_transfer busybox_tftpc rtftpd
[ -x $CURL ] && test_transfer curl rtftpd
unset BLKSIZE
# blocksize and netascii
printf "\\n\\nTesting larger block sizes and netascii\\n"
BLKSIZE=1500
NETASCII=1
test_transfer rtftpc rtftpd
[ -x $ATFTPD ] && test_transfer rtftpc atftpd
[ -x $ATFTPC ] && test_transfer atftpc rtftpd
unset NETASCII