Skip to content

Commit 5a9740f

Browse files
committed
util: add run-wasi-tests-docker.sh for local Linux verification
1 parent 31ad414 commit 5a9740f

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

util/run-wasi-tests-docker.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
3+
# spell-checker:ignore mktemp wasip wasmtime UUTESTS rustup
4+
5+
# Run the WASI integration tests in an Ubuntu 24.04 container. Mirrors the
6+
# "Run integration tests via wasmtime" step of .github/workflows/wasi.yml
7+
# (the unit-test step cross-compiles to wasm and runs under wasmtime on any
8+
# host, so macOS already covers it). Keep the selector list below in sync
9+
# with that workflow.
10+
#
11+
# The gap this closes: integration tests are host-built and many are gated
12+
# with #[cfg(not(target_vendor = "apple"))] / #[cfg(target_os = "linux")],
13+
# so macOS silently excludes them.
14+
15+
set -euo pipefail
16+
17+
command -v docker >/dev/null 2>&1 || {
18+
echo "error: docker not found in PATH" >&2
19+
exit 1
20+
}
21+
docker info >/dev/null 2>&1 || {
22+
echo "error: docker daemon not reachable" >&2
23+
exit 1
24+
}
25+
26+
ME="${0}"
27+
ME_resolved="$(readlink -f -- "${ME}" 2>/dev/null || python3 -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' "${ME}" 2>/dev/null || true)"
28+
if [[ -z "${ME_resolved}" || ! -f "${ME_resolved}" ]]; then
29+
echo "error: could not resolve script path (neither 'readlink -f' nor python3 available)" >&2
30+
exit 1
31+
fi
32+
ME_dir="$(dirname -- "${ME_resolved}")"
33+
REPO_main_dir="$(dirname -- "${ME_dir}")"
34+
35+
HOST_LOG_DIR="$(mktemp -d -t wasi-coreutils-XXXXXX)"
36+
HOST_LOG="${HOST_LOG_DIR}/wasi-test-output.log"
37+
38+
# Report the log location on every exit path (including docker failure).
39+
trap 'echo; echo "Full log saved to ${HOST_LOG}"' EXIT
40+
41+
# Source is mounted read-only; only the log dir is writable by the container.
42+
docker run --rm -i \
43+
-v "${REPO_main_dir}:/src:ro" \
44+
-v "${HOST_LOG_DIR}:/host-tmp" \
45+
ubuntu:24.04 bash -se <<'EOF'
46+
set -euo pipefail
47+
export DEBIAN_FRONTEND=noninteractive
48+
apt-get update -qq
49+
apt-get install -y -qq curl rsync ca-certificates build-essential pkg-config libssl-dev xz-utils >/dev/null
50+
51+
curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal --target wasm32-wasip1 >/dev/null
52+
. "$HOME/.cargo/env"
53+
54+
curl -sSf https://wasmtime.dev/install.sh | bash >/dev/null
55+
export PATH="$HOME/.wasmtime/bin:$PATH"
56+
57+
mkdir -p /work
58+
rsync -a --exclude='target' --exclude='target-linux' --exclude='.git' /src/ /work/
59+
cd /work
60+
mkdir -p target-linux
61+
export CARGO_TARGET_DIR=/work/target-linux
62+
63+
LOG=/host-tmp/wasi-test-output.log
64+
: > "$LOG"
65+
66+
echo "=== Building WASI binary ===" | tee -a "$LOG"
67+
RUSTFLAGS="--cfg wasi_runner" \
68+
cargo build --target wasm32-wasip1 --no-default-features --features feat_wasm 2>&1 | tee -a "$LOG"
69+
70+
# `set +e` around the pipeline so a test failure still reaches the summary.
71+
echo "=== Running integration tests via wasmtime ===" | tee -a "$LOG"
72+
set +e
73+
RUSTFLAGS="--cfg wasi_runner" \
74+
UUTESTS_BINARY_PATH="$CARGO_TARGET_DIR/wasm32-wasip1/debug/coreutils.wasm" \
75+
UUTESTS_WASM_RUNNER=wasmtime \
76+
cargo test --test tests -- \
77+
test_base32:: test_base64:: test_basenc:: test_basename:: \
78+
test_cat:: test_comm:: test_cut:: test_dirname:: test_echo:: \
79+
test_expand:: test_factor:: test_false:: test_fold:: \
80+
test_head:: test_link:: test_nl:: test_numfmt:: \
81+
test_od:: test_paste:: test_printf:: test_shuf:: test_sort:: \
82+
test_sum:: test_tail:: test_tee:: test_touch:: test_tr:: \
83+
test_true:: test_truncate:: test_unexpand:: test_unlink:: test_wc:: \
84+
2>&1 | tee -a "$LOG"
85+
test_status=${PIPESTATUS[0]}
86+
set -e
87+
88+
echo "" | tee -a "$LOG"
89+
echo "=== Failure summary (from saved log) ===" | tee -a "$LOG"
90+
grep -E "FAILED|^failures:|test result" "$LOG" || echo "no FAILED / failures: / test result lines found"
91+
exit "$test_status"
92+
EOF

0 commit comments

Comments
 (0)