|
| 1 | +# nix/microvms/lib-pair.nix |
| 2 | +# |
| 3 | +# Orchestrator for the two-VM pair test (PLAN-pairs.md, uds-rdma-proxy pattern, console |
| 4 | +# markers as in lib.nix). Both guests drive themselves (pair.nix) and power off when done, |
| 5 | +# so the host only has to: |
| 6 | +# 1. start node0 (server), whose QEMU listens on the socket link; |
| 7 | +# 2. wait until that port is listening (checked with ss, because a probe connection would |
| 8 | +# take the link's only accept); |
| 9 | +# 3. start node1 (client), which connects; |
| 10 | +# 4. wait for both qemu processes to exit, then grep both consoles: |
| 11 | +# node1: HOMA_PAIR_PASS node0: HOMA_PAIR_SERVER_PASS |
| 12 | +# Logs go to $HOMA_VM_LOGDIR (default: a fresh mktemp -d), printed at the start. |
| 13 | + |
| 14 | +{ pkgs |
| 15 | +, lib |
| 16 | +, constants |
| 17 | +, serverRunner # declaredRunner for the pairNode = "server" guest |
| 18 | +, clientRunner # declaredRunner for the pairNode = "client" guest |
| 19 | +, label ? "" # "", "-7_3", "-6_12-7_3", ... |
| 20 | +}: |
| 21 | + |
| 22 | +let |
| 23 | + pair = constants.pair; |
| 24 | +in |
| 25 | +pkgs.writeShellApplication { |
| 26 | + name = "homa-pair-test${label}"; |
| 27 | + runtimeInputs = with pkgs; [ coreutils gnugrep iproute2 procps ]; |
| 28 | + text = '' |
| 29 | + logdir="''${HOMA_VM_LOGDIR:-$(mktemp -d)}" |
| 30 | + mkdir -p "$logdir" |
| 31 | + slog="$logdir/node0${label}.log" |
| 32 | + clog="$logdir/node1${label}.log" |
| 33 | + port=${toString pair.socketPort} |
| 34 | + echo "console logs: $slog $clog" |
| 35 | +
|
| 36 | + if ss -Hltn "sport = :$port" | grep -q .; then |
| 37 | + echo "port $port is already in use (another pair test running?)" |
| 38 | + echo "VERDICT: FAIL" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + timeout --kill-after=10s ${toString pair.runTimeout}s \ |
| 43 | + ${serverRunner}/bin/microvm-run > "$slog" 2>&1 & |
| 44 | + spid=$! |
| 45 | +
|
| 46 | + for _ in $(seq 60); do |
| 47 | + ss -Hltn "sport = :$port" | grep -q . && break |
| 48 | + kill -0 "$spid" 2>/dev/null || break |
| 49 | + sleep 0.5 |
| 50 | + done |
| 51 | + if ! ss -Hltn "sport = :$port" | grep -q .; then |
| 52 | + echo "node0 never listened on 127.0.0.1:$port" |
| 53 | + tail -n 30 "$slog" |
| 54 | + kill "$spid" 2>/dev/null || true |
| 55 | + echo "VERDICT: FAIL" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + cstatus=0 |
| 60 | + timeout --kill-after=10s ${toString pair.runTimeout}s \ |
| 61 | + ${clientRunner}/bin/microvm-run > "$clog" 2>&1 || cstatus=$? |
| 62 | + [ "$cstatus" = 124 ] && echo "node1 timed out" |
| 63 | +
|
| 64 | + # The server powers off after the client's report; give it a moment, then stop it. |
| 65 | + for _ in $(seq 60); do |
| 66 | + kill -0 "$spid" 2>/dev/null || break |
| 67 | + sleep 1 |
| 68 | + done |
| 69 | + kill "$spid" 2>/dev/null || true |
| 70 | + wait "$spid" 2>/dev/null || true |
| 71 | +
|
| 72 | + # Lines look like "[ 13.44] homa-pair-client[522]: HOMA_PAIR_ECHO_OK"; -a because the |
| 73 | + # logs also hold terminal escape sequences. |
| 74 | + show() { grep -aE '\]: HOMA_PAIR_' "$1" | sed -E 's/^.*\]: //' | tr -d '\r' || true; } |
| 75 | + echo "--- node0 (server)" |
| 76 | + show "$slog" |
| 77 | + echo "--- node1 (client)" |
| 78 | + show "$clog" |
| 79 | +
|
| 80 | + verdict=PASS |
| 81 | + grep -aqE '\]: HOMA_PAIR_SERVER_PASS' "$slog" || verdict=FAIL |
| 82 | + grep -aqE '\]: HOMA_PAIR_PASS' "$clog" || verdict=FAIL |
| 83 | + if [ "$verdict" = FAIL ]; then |
| 84 | + for f in "$slog" "$clog"; do |
| 85 | + if ! grep -aqE '\]: HOMA_PAIR_(SERVER_)?(PASS|FAIL)' "$f"; then |
| 86 | + echo "--- $(basename "$f") never reported; last console lines:" |
| 87 | + tail -n 30 "$f" |
| 88 | + fi |
| 89 | + done |
| 90 | + fi |
| 91 | + echo "VERDICT: $verdict" |
| 92 | + [ "$verdict" = PASS ] |
| 93 | + ''; |
| 94 | +} |
0 commit comments