|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: MPL-2.0 |
| 3 | +# |
| 4 | +# ADR-015 S6b gated smoke (sockets on-ramp): compile an AffineScript |
| 5 | +# program that calls the `net_shutdown` builtin, run it through |
| 6 | +# `tools/componentize.sh --command`, and assert |
| 7 | +# (a) the core module imports `wasi_snapshot_preview1.sock_shutdown`, |
| 8 | +# (b) S6a's `_start` shim is still emitted, |
| 9 | +# (c) the command adapter accepts the socket import without surfacing |
| 10 | +# a host-side `wasi:sockets/*` requirement (it bridges |
| 11 | +# internally for sock_shutdown), |
| 12 | +# (d) `wasmtime run` invokes the component (exit 0 is the contract: |
| 13 | +# net_shutdown(stdin, RDWR) returns ENOTSOCK, the program drops |
| 14 | +# errno and returns 0), and |
| 15 | +# (e) the multi-import canonical-order indexing |
| 16 | +# (`ctx.wasi_func_indices`) doesn't collide when a non-S6 builtin |
| 17 | +# is also live in the same unit (combo regression). |
| 18 | +# |
| 19 | +# SKIPs cleanly (exit 0) when the component toolchain or wasmtime is |
| 20 | +# not provisioned — opt-in, mirroring the S3 and S6a smokes. |
| 21 | +set -euo pipefail |
| 22 | +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 23 | +cd "$ROOT" |
| 24 | + |
| 25 | +if ! command -v wasm-tools >/dev/null \ |
| 26 | + || [ ! -f tools/vendor/wasi_snapshot_preview1.command.wasm ]; then |
| 27 | + echo "SKIP: component toolchain / command adapter not provisioned (tools/provision-component-toolchain.sh)" |
| 28 | + exit 0 |
| 29 | +fi |
| 30 | +if ! command -v wasmtime >/dev/null; then |
| 31 | + echo "SKIP: wasmtime not on PATH (real-host run is the S6b contract)" |
| 32 | + exit 0 |
| 33 | +fi |
| 34 | + |
| 35 | +COMPILER="${AFFINESCRIPT:-$ROOT/_build/default/bin/main.exe}" |
| 36 | +[ -x "$COMPILER" ] || COMPILER="dune exec affinescript --" |
| 37 | + |
| 38 | +work="$(mktemp -d)" |
| 39 | +trap 'rm -rf "$work"' EXIT |
| 40 | + |
| 41 | +# Primary fixture: net_shutdown only. |
| 42 | +cat > "$work/sock.affine" <<'EOF' |
| 43 | +fn main() -> Int { |
| 44 | + net_shutdown(0, 3); // stdin, RDWR — returns ENOTSOCK; we drop it. |
| 45 | + return 0; |
| 46 | +} |
| 47 | +EOF |
| 48 | + |
| 49 | +# Combo fixture: net_shutdown alongside clock_now_ms + env_count to |
| 50 | +# exercise the canonical-order Effect_sites pre-scan + on-demand import |
| 51 | +# assembly without index collisions. |
| 52 | +cat > "$work/combo.affine" <<'EOF' |
| 53 | +fn main() -> Int { |
| 54 | + let t = clock_now_ms(1); |
| 55 | + let n = env_count(()); |
| 56 | + net_shutdown(0, 3); |
| 57 | + return t + n; |
| 58 | +} |
| 59 | +EOF |
| 60 | + |
| 61 | +$COMPILER compile "$work/sock.affine" -o "$work/sock.wasm" |
| 62 | +$COMPILER compile "$work/combo.affine" -o "$work/combo.wasm" |
| 63 | + |
| 64 | +# (a) sock_shutdown import is present |
| 65 | +if ! wasm-tools print "$work/sock.wasm" 2>/dev/null \ |
| 66 | + | grep -q '"wasi_snapshot_preview1" "sock_shutdown"'; then |
| 67 | + echo "FAIL: net_shutdown did not lower to wasi_snapshot_preview1.sock_shutdown" |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# (b) S6a _start shim is still emitted |
| 72 | +if ! wasm-tools print "$work/sock.wasm" 2>/dev/null | grep -q '(export "_start"'; then |
| 73 | + echo "FAIL: S6a _start shim missing when S6b primitive is in use" |
| 74 | + exit 1 |
| 75 | +fi |
| 76 | + |
| 77 | +# (c)+(d) componentize and invoke |
| 78 | +tools/componentize.sh --command "$work/sock.wasm" "$work/sock.component.wasm" |
| 79 | +if ! wasmtime run "$work/sock.component.wasm"; then |
| 80 | + echo "FAIL: wasmtime run rejected the S6b component" |
| 81 | + exit 1 |
| 82 | +fi |
| 83 | + |
| 84 | +# (e) combo: canonical order must be fd_write < clock_time_get < |
| 85 | +# environ_sizes_get < sock_shutdown (insertion order in |
| 86 | +# lib/codegen.ml's optional_wasi list). |
| 87 | +order="$(wasm-tools print "$work/combo.wasm" 2>/dev/null \ |
| 88 | + | grep -oE '"(fd_write|clock_time_get|environ_sizes_get|sock_shutdown)"' \ |
| 89 | + | head -4 | tr -d '"' | tr '\n' ' ')" |
| 90 | +expected='fd_write clock_time_get environ_sizes_get sock_shutdown ' |
| 91 | +if [ "$order" != "$expected" ]; then |
| 92 | + echo "FAIL: combo import canonical order drifted" |
| 93 | + echo " got : $order" |
| 94 | + echo " expected: $expected" |
| 95 | + exit 1 |
| 96 | +fi |
| 97 | + |
| 98 | +tools/componentize.sh --command "$work/combo.wasm" "$work/combo.component.wasm" >/dev/null |
| 99 | +if ! wasmtime run "$work/combo.component.wasm"; then |
| 100 | + echo "FAIL: combo (clock+env+sock) component rejected by wasmtime" |
| 101 | + exit 1 |
| 102 | +fi |
| 103 | + |
| 104 | +echo "ADR-015 S6b sockets smoke: PASSED ✓" |
0 commit comments