diff --git a/docs/testing.md b/docs/testing.md index ca71914..6e7a5a3 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -138,7 +138,7 @@ cd android The native code is built for arm64-v8a and armeabi-v7a by default; `-PdecoderAbis` takes a list of `arm64-v8a`, `armeabi-v7a`, `x86_64`, `x86` (an empty or unknown one fails the build). -`tests/e2e.sh [API]` plays a camera through a camex server and the tunnel on an x86_64 emulator in Docker (API 21 and 34 are checked): 15 checks (16 with `TRANSPORT=TCP`, the tunnel over TCP), from no camera with Network off to the password of the debug page through the tunnel and a restart of the tunnel with Network → Save. Its output is in `tests/out/` (ignored by git). +`tests/e2e.sh [API]` plays a camera through a camex server and the tunnel on an x86_64 emulator in Docker (API 21 and 34 are checked): 15 checks (16 with `TRANSPORT=TCP`, the tunnel over TCP), from no camera with Network off to the password of the debug page through the tunnel and a restart of the tunnel with Network → Save. The links of the emulator, the hub and the Linux edge get a netem delay of `DELAY_MS` each way (default 30 ms, 60 ms between the box and the hub; `tc` comes from the `decoder-netem` image of `tests/netem`, built on the first run), so the video rate check catches a TCP tunnel that crawls, as camex 4.0.0 did (#281). Its output is in `tests/out/` (ignored by git). A release build needs a keystore at `android/key.jks` and `KEYSTORE_PASS`, `KEY_ALIAS`, `KEY_PASS` in the environment (`./gradlew assembleRelease`). Debug and release builds are signed with different keys: to switch, uninstall first, which removes the saved camera URLs. diff --git a/tests/e2e.sh b/tests/e2e.sh index a28407b..53ae3bb 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -30,6 +30,10 @@ # (default ~/.cache/compot/toolchains/android-emulator) # GRADLE_CACHE Gradle cache (default ~/.gradle) # KVM_GROUP group id of /dev/kvm on the Docker host (default 992) +# DELAY_MS one-way netem delay on the links of the emulator, the hub and the Linux edge +# (default 30: 60 ms between the box and the hub, as camex's throughput test; +# 0: none); a TCP tunnel that crawls (camex#180) looks fast without it (#281) +# NETEM_IMAGE image with tc, built from tests/netem when missing (default decoder-netem) # TRANSPORT the tunnel's transport in Network: UDP or TCP (default UDP); the hub takes # both on one port, the Linux edge stays on UDP # SHOTS 1: slot 1 over TCP, a lighter camera stream and screenshots in tests/out/shots @@ -53,6 +57,8 @@ GRADLE_CACHE=${GRADLE_CACHE:-$HOME/.gradle} KVM_GROUP=${KVM_GROUP:-992} SHOTS=${SHOTS:-} TRANSPORT=${TRANSPORT:-UDP} +DELAY_MS=${DELAY_MS:-30} +NETEM_IMAGE=${NETEM_IMAGE:-decoder-netem} case $TRANSPORT in UDP|TCP) ;; *) echo "TRANSPORT must be UDP or TCP"; exit 2 ;; esac TUNNEL=camex RESTART_MARK="Tunnel initialized" # camex's log line of each new run (bundles/camex/src/camex.c) @@ -80,6 +86,9 @@ trap cleanup EXIT INT TERM mkdir -p "$OUT/w" rm -rf "$OUT/w/.emu" +[ "$DELAY_MS" -eq 0 ] || docker image inspect "$NETEM_IMAGE" >/dev/null 2>&1 || + docker build -q -t "$NETEM_IMAGE" "$ROOT/tests/netem" >/dev/null + echo "== debug APK (x86_64, $TUNNEL)" docker run --rm --pull never -u "$UID_GID" -v "$ROOT:/src" -v "$GRADLE_CACHE:/cache/gradle" \ -w /src/android "$ANDROID_IMAGE" ./gradlew --no-daemon -q -PdecoderAbis=x86_64 assembleDebug \ @@ -146,7 +155,15 @@ until LINUX_IP=$(docker exec "$PEER" cat /proc/net/fib_trie 2>/dev/null | i=$((i + 1)); [ $i -lt 30 ] || { echo "the camex client got no address"; exit 1; } sleep 1 done -echo "hub ($TUNNEL, Decoder on $TRANSPORT): $HUB_IP:$HUB_PORT, Linux client: $LINUX_IP" +# a real round trip: DELAY_MS on what each container sends (box to hub and hub to edge: twice) +delay() { + docker run --rm --pull never --net "container:$1" --cap-add NET_ADMIN "$NETEM_IMAGE" \ + tc qdisc add dev eth0 root netem delay "${DELAY_MS}ms" +} +if [ "$DELAY_MS" -gt 0 ]; then + for c in "$NAME" "$HUB" "$PEER"; do delay "$c" || { echo "no netem delay on $c"; exit 1; }; done +fi +echo "hub ($TUNNEL, Decoder on $TRANSPORT, delay ${DELAY_MS} ms each way): $HUB_IP:$HUB_PORT, Linux client: $LINUX_IP" # the camera: an RTSP server in the Linux edge's network namespace, a 1280x720 test picture # (screenshots: a lighter stream, the emulator's software decoder keeps up with it) @@ -305,8 +322,8 @@ if [ "$TRANSPORT" = TCP ]; then ok "the tunnel runs over TCP to the hub" else bad "no TCP connection to the hub's port $HUB_PORT"; fi fi -# the video keeps coming through the tunnel, hub to box; the Docker network has no real round -# trip, so this does not catch camex#180 (TCP at ~10 KB/s with 60 ms RTT; camex has its own test) +# the video keeps coming through the tunnel, hub to box: with the delay (DELAY_MS) camex 4.0.0 +# over TCP stays far below this (camex#180, ~10 KB/s), 4.0.1 passes (#281) rx() { $ADB shell cat /proc/net/dev | awk -F'[: ]+' '$2 == "tun0" { print $3 }'; } r1=$(rx); sleep 10; r2=$(rx) RATE_KB=$(( (${r2:-0} - ${r1:-0}) / 10240 )) diff --git a/tests/netem/Dockerfile b/tests/netem/Dockerfile new file mode 100644 index 0000000..75a48e5 --- /dev/null +++ b/tests/netem/Dockerfile @@ -0,0 +1,4 @@ +# decoder-netem — tc (iproute2) for tests/e2e.sh: a netem delay on the links of the hub, the +# Linux edge and the emulator, run from a container in each one's network namespace (#281) +FROM alpine:3.22 +RUN apk add --no-cache iproute2