blob: 358a1aa19d76c5241ddc11cded214ebf1e9fad08 (
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
|
#!/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
TMPDIR1=$(mktemp -d)
TMPDIR2=$(mktemp -d)
cleanup() {
cleanup_atftpd
cleanup_rtftpd
cleanup_files
rmdir "$TMPDIR1" "$TMPDIR2"
}
cleanup_files() {
rm -f "$TMPDIR1/testfile" "$TMPDIR2/testfile"
}
compare_files() {
cmp "$TMPDIR1/testfile" "$TMPDIR2/testfile" 1>/dev/null
}
init_atftpd() {
$ATFTPD --port $PORT --user "$USER" --group "$GROUP" --daemon "$TMPDIR2"
}
init_rtftpd() {
$SSD --background --exec "$RTFTPD" --start -- -p $PORT -d "$TMPDIR2" 1>/dev/null
}
init_testfile() {
cleanup_files
dd if=/dev/urandom of="$TMPDIR1/testfile" bs=1M count=100 2>/dev/null
}
cleanup_atftpd() {
killall -q -9 $ATFTPD || true
}
cleanup_rtftpd() {
killall -q -9 "$RTFTPD" || true
}
test_atftpd_rx() {
init_testfile
printf "atftpd rx: "
$RTFTPC -p testfile 127.0.0.1:$PORT 1>/dev/null
compare_files
printf "ok"
}
test_atftpd_tx() {
printf "atftpd tx: "
rm -f testfile
$RTFTPC -g testfile 127.0.0.1:$PORT 1>/dev/null
compare_files
printf "ok"
}
test_atftpc_tx() {
init_testfile
printf "atftpc tx: "
$ATFTPC -p -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
compare_files
printf "ok"
}
test_atftpc_tx_blksize() {
init_testfile
printf "atftpc tx (blksize 1428): "
$ATFTPC -p -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
compare_files
printf "ok"
}
test_atftpc_rx() {
printf "atftpc rx: "
rm -f testfile
$ATFTPC -g -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
compare_files
printf "ok"
}
test_atftpc_rx_blksize() {
printf "atftpc rx (blksize 1428): "
rm -f testfile
$ATFTPC -g -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
compare_files
printf "ok"
}
test_tftpc_tx() {
init_testfile
printf "tftpc tx: "
printf "connect 127.0.0.1 %d\\nmode binary\\nput testfile\\n" $PORT | $TFTPC 1>/dev/null
compare_files
printf "ok"
}
test_tftpc_rx() {
printf "tftpc rx: "
rm -f testfile
printf "connect 127.0.0.1 %d\\nmode binary\\nget testfile\\n" $PORT | $TFTPC 1>/dev/null
compare_files
printf "ok"
}
trap cleanup 0 1 2
cd "$TMPDIR1"
if [ -x $ATFTPD ]; then
init_atftpd
time test_atftpd_rx
time test_atftpd_tx
cleanup_atftpd
fi
if [ -x $ATFTPC ]; then
init_rtftpd
time test_atftpc_tx
time test_atftpc_tx_blksize
time test_atftpc_rx
time test_atftpc_rx_blksize
cleanup_rtftpd
fi
if [ -x $TFTPC ]; then
init_rtftpd
time test_tftpc_tx
time test_tftpc_rx
cleanup_rtftpd
fi
|