Files
btest-rs/scripts/test-local.sh
Siavash Sameni d9007dc169 Initial commit: MikroTik btest server & client in Rust
Full reimplementation of the MikroTik Bandwidth Test protocol:
- Server mode: accepts connections from MikroTik devices on port 2000
- Client mode: connects to MikroTik btest servers
- TCP and UDP protocols with bidirectional support
- MD5 challenge-response authentication
- Dynamic speed adjustment (1.5x algorithm)
- Status exchange matching original C pselect() behavior
- Docker support with multi-stage build

Tested against MikroTik RouterOS achieving:
- 1.05 Gbps server RX (single connection)
- 530 Mbps client TCP download
- 840 Mbps client TCP upload
- 433 Mbps client UDP download

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 11:56:34 +04:00

64 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Local loopback tests - run server and client against each other
set -euo pipefail
BTEST="cargo run --release --"
PORT=2000
echo "=== Building release binary ==="
cargo build --release
BTEST="./target/release/btest"
cleanup() {
echo "Stopping server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
}
echo ""
echo "=== Starting btest server on port $PORT ==="
$BTEST -s -P $PORT -v &
SERVER_PID=$!
trap cleanup EXIT
sleep 1
TIMEOUT_CMD="timeout"
if ! command -v timeout &>/dev/null; then
if command -v gtimeout &>/dev/null; then
TIMEOUT_CMD="gtimeout"
else
# Fallback: background + sleep + kill
TIMEOUT_CMD=""
fi
fi
run_test() {
local desc="$1"
shift
echo ""
echo "--- Test: $desc ---"
if [ -n "$TIMEOUT_CMD" ]; then
$TIMEOUT_CMD 5 $BTEST "$@" || true
else
$BTEST "$@" &
local pid=$!
sleep 5
kill $pid 2>/dev/null || true
wait $pid 2>/dev/null || true
fi
echo "--- Done: $desc ---"
sleep 1
}
run_test "TCP Download (RX)" -c 127.0.0.1 -P $PORT -r
run_test "TCP Upload (TX)" -c 127.0.0.1 -P $PORT -t
run_test "TCP Bidirectional" -c 127.0.0.1 -P $PORT -t -r
run_test "TCP Download 100Mbps limited" -c 127.0.0.1 -P $PORT -r -b 100M
run_test "UDP Download" -c 127.0.0.1 -P $PORT -r -u
run_test "UDP Upload" -c 127.0.0.1 -P $PORT -t -u
run_test "UDP Bidirectional" -c 127.0.0.1 -P $PORT -t -r -u
echo ""
echo "=== All local tests completed ==="