95 lines
2.7 KiB
Bash
Executable File
95 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# W5 parity/performance gate for the config-selectable WASM backend.
|
|
# Runs on k-uce. Requires root because the live service reads /etc/uce/settings.cfg.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/../.."
|
|
|
|
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
|
|
echo "run_w5.sh must run as root so it can switch /etc/uce/settings.cfg and restart uce.service" >&2
|
|
exit 1
|
|
fi
|
|
|
|
OUT=${UCE_W5_OUT:-/tmp/uce/wasm-w5}
|
|
CONFIG=${UCE_CONFIG:-/etc/uce/settings.cfg}
|
|
mkdir -p "$OUT"
|
|
BACKUP="$OUT/settings.cfg.before-w5"
|
|
cp "$CONFIG" "$BACKUP"
|
|
|
|
restore_on_error() {
|
|
if [ "${UCE_W5_KEEP_BACKEND:-0}" != "1" ]; then
|
|
cp "$BACKUP" "$CONFIG"
|
|
systemctl restart uce.service >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
trap restore_on_error EXIT
|
|
|
|
set_backend() {
|
|
local enabled="$1"
|
|
local tmp
|
|
tmp=$(mktemp)
|
|
awk -F= -v enabled="$enabled" '
|
|
BEGIN { found = 0 }
|
|
/^WASM_BACKEND_ENABLED=/ { print "WASM_BACKEND_ENABLED=" enabled; found = 1; next }
|
|
{ print }
|
|
END { if(!found) print "WASM_BACKEND_ENABLED=" enabled }
|
|
' "$CONFIG" > "$tmp"
|
|
for kv in \
|
|
'WASM_BACKEND_VERBOSE=0' \
|
|
'WASM_CORE_PATH=/Code/uce.openfu.com/uce/bin/wasm/core.wasm' \
|
|
'WASM_MEMORY_LIMIT_BYTES=536870912' \
|
|
'WASM_EPOCH_DEADLINE_TICKS=200' \
|
|
'WASM_EPOCH_PERIOD_MS=50'
|
|
do
|
|
key=${kv%%=*}
|
|
if ! grep -q "^${key}=" "$tmp"; then
|
|
printf '%s\n' "$kv" >> "$tmp"
|
|
fi
|
|
done
|
|
cat "$tmp" > "$CONFIG"
|
|
rm -f "$tmp"
|
|
systemctl restart uce.service >/dev/null
|
|
sleep 1
|
|
}
|
|
|
|
summary_total() {
|
|
awk '/^Summary:/ { print $2; found=1 } END { if(!found) print 0 }' "$1"
|
|
}
|
|
|
|
# Native reference baseline.
|
|
set_backend 0
|
|
scripts/run_cli_tests.sh > "$OUT/native-warmup.txt" || true
|
|
scripts/run_cli_tests.sh > "$OUT/native-network.txt"
|
|
python3 tests/wasm_benchmark.py --out-dir "$OUT/native-benchmark" --samples "${UCE_W5_BENCH_SAMPLES:-20}" --timeout 30 >/dev/null
|
|
|
|
# WASM default backend with W5 native fallbacks for host-owned surfaces.
|
|
set_backend 1
|
|
scripts/run_cli_tests.sh --include-wasm-kill > "$OUT/wasm-warmup.txt" || true
|
|
scripts/run_cli_tests.sh --include-wasm-kill > "$OUT/wasm-network.txt"
|
|
python3 tests/wasm_benchmark.py \
|
|
--out-dir "$OUT/benchmark" \
|
|
--backend-label wasm \
|
|
--compare-native-json "$OUT/native-benchmark/benchmark.json" \
|
|
--samples "${UCE_W5_BENCH_SAMPLES:-20}" \
|
|
--timeout 30
|
|
python3 tests/wasm_site_audit.py --out-dir "$OUT" >/dev/null
|
|
|
|
network_cases=$(summary_total "$OUT/wasm-network.txt")
|
|
if [ "$network_cases" -lt 80 ]; then
|
|
echo "W5 HARNESS: FAIL"
|
|
echo "wasm network ran $network_cases cases, expected at least 80"
|
|
exit 1
|
|
fi
|
|
|
|
echo 'W5 HARNESS: PASS'
|
|
echo "network_cases=$network_cases benchmark_rows=see benchmark.json"
|
|
echo "reports=$OUT"
|
|
|
|
if [ "${UCE_W5_KEEP_BACKEND:-0}" = "1" ]; then
|
|
trap - EXIT
|
|
printf 'WASM backend left enabled in %s\n' "$CONFIG"
|
|
else
|
|
cp "$BACKUP" "$CONFIG"
|
|
systemctl restart uce.service >/dev/null
|
|
trap - EXIT
|
|
fi
|