blob: 25963829f540a691dec03b922ee3ee1a24272641 (
plain)
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
|
#!/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
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() {
$ATFTPC -p -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
}
atftpc_rx() {
$ATFTPC -g -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
}
atftpc_blksize1428_tx() {
$ATFTPC -p -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
}
atftpc_blksize1428_rx() {
$ATFTPC -g -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
}
tftpc_tx() {
printf "connect 127.0.0.1 %d\\nmode binary\\nput testfile\\n" $PORT | $TFTPC 1>/dev/null
}
tftpc_rx() {
printf "connect 127.0.0.1 %d\\nmode binary\\nget testfile\\n" $PORT | $TFTPC 1>/dev/null
}
rtftpd() {
$SSD --background --exec "$RTFTPD" --start -- -p $PORT -d "$SERVERDIR" 1>/dev/null
}
rtftpc_tx() {
$RTFTPC -p testfile 127.0.0.1:$PORT 1>/dev/null
}
rtftpc_rx() {
$RTFTPC -g testfile 127.0.0.1:$PORT 1>/dev/null
}
busybox_tftpc_tx() {
$BUSYBOX tftp -p -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null 2>&1
}
busybox_tftpc_rx() {
$BUSYBOX tftp -g -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null 2>&1
}
busybox_tftpc_blksize1428_tx() {
$BUSYBOX tftp -p -l testfile -r testfile -b 1428 127.0.0.1 $PORT 1>/dev/null 2>&1
}
busybox_tftpc_blksize1428_rx() {
$BUSYBOX tftp -g -l testfile -r testfile -b 1428 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 "%s TX (to %s): " $client $server
${client}_tx
compare_files
printf "ok"
)
rm -f "$CLIENTDIR/testfile"
time (
printf "%s RX (from %s): " $client $server
${client}_rx
compare_files
printf "ok"
)
rm -f "$SERVERDIR/testfile"
${server}_cleanup
}
trap cleanup 0 1 2
if [ ! -x "$RTFTPC" ] || [ ! -x "$RTFTPD" ]; then
cargo build --release
fi
cd "$CLIENTDIR"
test_transfer rtftpc rtftpd
if [ -x $ATFTPD ]; then
test_transfer rtftpc atftpd
fi
if [ -x $ATFTPC ]; then
test_transfer atftpc rtftpd
test_transfer atftpc_blksize1428 rtftpd
fi
if [ -x $TFTPC ]; then
test_transfer tftpc rtftpd
fi
if [ -x $BUSYBOX ]; then
test_transfer busybox_tftpc rtftpd
test_transfer busybox_tftpc_blksize1428 rtftpd
fi
|