summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2019-03-07 22:10:38 +0100
committerReiner Herrmann <reiner@reiner-h.de>2019-03-07 22:26:51 +0100
commit56969aa1e2b80fba625fae494c919bcbf35df3d4 (patch)
treeca782ec7bee44bd7e151bbc83a1729c00ba1e8f5
parent97e6a218f76487354ef34dd152afcac2170e108c (diff)
Simplify test script
-rwxr-xr-xtest.sh151
1 files changed, 66 insertions, 85 deletions
diff --git a/test.sh b/test.sh
index 358a1aa..bdb139d 100755
--- a/test.sh
+++ b/test.sh
@@ -16,131 +16,112 @@ ATFTPD=/usr/sbin/atftpd
TFTPC=/usr/bin/tftp
-TMPDIR1=$(mktemp -d)
-TMPDIR2=$(mktemp -d)
+CLIENTDIR=$(mktemp -d)
+SERVERDIR=$(mktemp -d)
cleanup() {
- cleanup_atftpd
- cleanup_rtftpd
- cleanup_files
- rmdir "$TMPDIR1" "$TMPDIR2"
-}
-
-cleanup_files() {
- rm -f "$TMPDIR1/testfile" "$TMPDIR2/testfile"
+ atftpd_cleanup
+ rtftpd_cleanup
+ rm -f "$CLIENTDIR/testfile" "$SERVERDIR/testfile"
+ rmdir "$CLIENTDIR" "$SERVERDIR"
}
compare_files() {
- cmp "$TMPDIR1/testfile" "$TMPDIR2/testfile" 1>/dev/null
+ cmp "$CLIENTDIR/testfile" "$SERVERDIR/testfile" 1>/dev/null
}
-init_atftpd() {
- $ATFTPD --port $PORT --user "$USER" --group "$GROUP" --daemon "$TMPDIR2"
+atftpd() {
+ $ATFTPD --port $PORT --user "$USER" --group "$GROUP" --daemon "$SERVERDIR"
}
-init_rtftpd() {
- $SSD --background --exec "$RTFTPD" --start -- -p $PORT -d "$TMPDIR2" 1>/dev/null
+atftpc_tx() {
+ $ATFTPC -p -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
}
-init_testfile() {
- cleanup_files
- dd if=/dev/urandom of="$TMPDIR1/testfile" bs=1M count=100 2>/dev/null
+atftpc_rx() {
+ $ATFTPC -g -l testfile -r testfile 127.0.0.1 $PORT 1>/dev/null
}
-cleanup_atftpd() {
- killall -q -9 $ATFTPD || true
+atftpc_blksize1428_tx() {
+ $ATFTPC -p -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
}
-cleanup_rtftpd() {
- killall -q -9 "$RTFTPD" || true
+atftpc_blksize1428_rx() {
+ $ATFTPC -g -l testfile -r testfile --option "blksize 1428" 127.0.0.1 $PORT 1>/dev/null 2>&1
}
-test_atftpd_rx() {
- init_testfile
- printf "atftpd rx: "
- $RTFTPC -p testfile 127.0.0.1:$PORT 1>/dev/null
- compare_files
- printf "ok"
+tftpc_tx() {
+ printf "connect 127.0.0.1 %d\\nmode binary\\nput testfile\\n" $PORT | $TFTPC 1>/dev/null
}
-test_atftpd_tx() {
- printf "atftpd tx: "
- rm -f testfile
- $RTFTPC -g testfile 127.0.0.1:$PORT 1>/dev/null
- compare_files
- printf "ok"
+tftpc_rx() {
+ printf "connect 127.0.0.1 %d\\nmode binary\\nget testfile\\n" $PORT | $TFTPC 1>/dev/null
}
-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"
+rtftpd() {
+ $SSD --background --exec "$RTFTPD" --start -- -p $PORT -d "$SERVERDIR" 1>/dev/null
}
-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"
+rtftpc_tx() {
+ $RTFTPC -p testfile 127.0.0.1:$PORT 1>/dev/null
}
-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"
+rtftpc_rx() {
+ $RTFTPC -g testfile 127.0.0.1:$PORT 1>/dev/null
}
-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"
+atftpd_cleanup() {
+ killall -q -9 $ATFTPD 2>/dev/null || true
}
-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"
+rtftpd_cleanup() {
+ killall -q -9 "$RTFTPD" 2>/dev/null || true
}
-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"
+
+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
-cd "$TMPDIR1"
+if [ ! -x "$RTFTPC" ] || [ ! -x "$RTFTPD" ]; then
+ cargo build --release
+fi
+
+cd "$CLIENTDIR"
if [ -x $ATFTPD ]; then
- init_atftpd
- time test_atftpd_rx
- time test_atftpd_tx
- cleanup_atftpd
+ test_transfer rtftpc 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
+ test_transfer atftpc rtftpd
+ test_transfer atftpc_blksize1428 rtftpd
fi
if [ -x $TFTPC ]; then
- init_rtftpd
- time test_tftpc_tx
- time test_tftpc_rx
- cleanup_rtftpd
+ test_transfer tftpc rtftpd
fi