Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/scripts/run-tests-with-miri.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash
#
# Parallelizes the integration tests when running with Miri#
#
# Usage: .github/scripts/run-tests-with-miri.sh
# Env: MIRI_TEST_TIMEOUT_SECS (default 300)
# MIRI_TEST_JOBS (default: nproc)
# MIRI_TEST_TARGETS (default: all targets, space-separated)
# MIRIFLAGS (passed to `cargo miri test`)
set -uo pipefail

manifest_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$manifest_dir"

cargo miri setup

timeout_secs="${MIRI_TEST_TIMEOUT_SECS:-300}"
jobs="${MIRI_TEST_JOBS:-$(nproc)}"

target_flag() {
case "$1" in
lib) echo "--lib" ;;
*) echo "--test $1" ;;
esac
}
export -f target_flag

# shellcheck disable=SC2206
targets=(${MIRI_TEST_TARGETS:-lib core_integration regression_integration custom_page_sizes_integration statistics_integration})

pairs_file="$(mktemp)"
results_file="$(mktemp)"
trap 'rm -f "$pairs_file" "$results_file"' EXIT

for label in "${targets[@]}"; do
target="$(target_flag "$label")"
RUSTFLAGS="--cfg miri" cargo test --quiet $target -- --list 2>/dev/null |
grep ': test$' | sed 's/: test$//' |
sed "s/^/${label}\t/" \
>>"$pairs_file"
done

total=$(wc -l <"$pairs_file")
echo "Running $total tests:"
echo "Executors: $jobs"
echo "Timeout: ${timeout_secs}s"

export TIMEOUT_SECS="$timeout_secs"

run_one() {
local label="$1" name="$2"
local target
target="$(target_flag "$label")"

local out status
out="$(timeout "$TIMEOUT_SECS" cargo miri test --features miri-soft-floats $target -- --exact "$name" 2>&1)"
status=$?

if [ "$status" -eq 0 ]; then
printf 'PASS\t%s\t%s\n' "$label" "$name"
elif [ "$status" -eq 124 ]; then
printf 'TIMEOUT\t%s\t%s\n' "$label" "$name"
echo "!!! TIMED OUT after ${TIMEOUT_SECS}s: $label :: $name" >&2
else
printf 'FAIL\t%s\t%s\n' "$label" "$name"
echo "!!! FAILED: $label :: $name" >&2
echo "$out" >&2
fi
}
export -f run_one

xargs -P "$jobs" -L1 bash -c 'run_one "$@"' _ <"$pairs_file" >>"$results_file"

pass_count=$(grep -c '^PASS' "$results_file" || true)
timeout_lines=$(grep '^TIMEOUT' "$results_file" || true)
fail_lines=$(grep '^FAIL' "$results_file" || true)

echo
echo "$total / $pass_count tests passed."

if [ -n "$timeout_lines" ]; then
echo "Timed out:"
echo "$timeout_lines" | awk -F'\t' '{print " - " $2 " :: " $3}'
fi
if [ -n "$fail_lines" ]; then
echo "Failed:"
echo "$fail_lines" | awk -F'\t' '{print " - " $2 " :: " $3}'
fi

if [ -n "$timeout_lines" ] || [ -n "$fail_lines" ]; then
exit 1
fi
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ jobs:
components: miri

- name: Run Miri
run: cargo miri test -j4 --no-fail-fast --verbose
env:
MIRIFLAGS: -Zmiri-disable-isolation
run: cargo miri test --lib --no-fail-fast --verbose --features miri-soft-floats

coverage:
name: Code Coverage
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: PR Review

on:
pull_request_review:
types: [submitted]
Comment thread
h313 marked this conversation as resolved.
Outdated
Comment thread
Kronos3 marked this conversation as resolved.
Outdated
workflow_dispatch:

permissions:
contents: read

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
miri-integration:
name: Miri Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: miri

- name: Install WABT (WebAssembly Binary Toolkit)
run: |
WABT_VERSION=1.0.41
WABT_PLATFORM="linux-x64"
wget https://github.com/WebAssembly/wabt/releases/download/${WABT_VERSION}/wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz
tar -xzf wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz
sudo cp wabt-${WABT_VERSION}/bin/* /usr/local/bin/
shell: bash

- name: Convert wast files for Miri
run: cargo test --test miri_wast_convert -- --ignored

- name: Run Miri
env:
MIRIFLAGS: -Zmiri-disable-isolation
MIRI_TEST_TIMEOUT_SECS: 300
MIRI_TEST_JOBS: 4
MIRI_TEST_TARGETS: core_integration regression_integration custom_page_sizes_integration statistics_integration
run: ./.github/scripts/run-tests-with-miri.sh
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ default = []
# by the verifier. Useful for fuzzing/regression testing
strict-assertions = []

# Disables inline asm (e.g. x86 `sqrtss`) for Miri
miri-soft-floats = ["libm/force-soft-floats"]

[dependencies]
libm = "0.2.16"

Expand All @@ -65,3 +68,6 @@ panic = "abort"
opt-level = 3
lto = "thin"
codegen-units = 1

[target.'cfg(miri)'.dependencies]
libm = { version = "0.2.16", features = ["force-soft-floats"] }
22 changes: 20 additions & 2 deletions tests/core_integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

mod util;
use spacewasm::vec;
use util::{run_wast_test_file, spectest_host_module};
Expand All @@ -14,6 +12,7 @@ fn address() {
}

#[test]
#[cfg_attr(miri, ignore = "stack recursion")]
fn call() {
run("core/call");
}
Expand All @@ -39,6 +38,7 @@ fn local_get() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn names() {
run("core/names");
}
Expand All @@ -59,11 +59,13 @@ fn align() {
}

#[test]
#[cfg_attr(miri, ignore = "stack recursion")]
fn call_indirect() {
run("core/call_indirect");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f32() {
run("core/f32");
}
Expand Down Expand Up @@ -109,11 +111,13 @@ fn comments() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f32_bitwise() {
run("core/f32_bitwise");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn float_misc() {
run("core/float_misc");
}
Expand Down Expand Up @@ -144,11 +148,13 @@ fn binary_leb128() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn const_() {
run("core/const");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f32_cmp() {
run("core/f32_cmp");
}
Expand All @@ -164,6 +170,7 @@ fn int_exprs() {
}

#[test]
#[cfg_attr(miri, ignore = "long runtime")]
fn loop_() {
run("core/loop");
}
Expand All @@ -184,11 +191,13 @@ fn block() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn conversions() {
run("core/conversions");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f64() {
run("core/f64");
}
Expand All @@ -209,6 +218,7 @@ fn memory() {
}

#[test]
#[cfg_attr(miri, ignore = "stack recursion")]
fn skip_stack_guard_page() {
run("core/skip-stack-guard-page");
}
Expand All @@ -229,6 +239,7 @@ fn custom() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f64_bitwise() {
run("core/f64_bitwise");
}
Expand All @@ -244,6 +255,7 @@ fn labels() {
}

#[test]
#[cfg_attr(miri, ignore = "malloc too slow")]
fn memory_grow() {
run("core/memory_grow");
}
Expand All @@ -269,6 +281,7 @@ fn data() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn f64_cmp() {
run("core/f64_cmp");
}
Expand Down Expand Up @@ -299,6 +312,7 @@ fn unwind() {
}

#[test]
#[cfg_attr(miri, ignore = "long runtime")]
fn br_table() {
run("core/br_table");
}
Expand All @@ -309,11 +323,13 @@ fn elem() {
}

#[test]
#[cfg_attr(miri, ignore = "stack recursion")]
fn fac() {
run("core/fac");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn i32() {
run("core/i32");
}
Expand Down Expand Up @@ -349,11 +365,13 @@ fn endianness() {
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
fn float_exprs() {
run("core/float_exprs");
}

#[test]
#[cfg_attr(miri, ignore = "libm too slow")]
Comment thread
h313 marked this conversation as resolved.
Outdated
fn i64() {
run("core/i64");
}
Expand Down
2 changes: 0 additions & 2 deletions tests/custom_page_sizes_integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

mod util;
use spacewasm::vec;
use util::{run_wast_test_file, spectest_host_module};
Expand Down
9 changes: 9 additions & 0 deletions tests/miri_wast_convert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg(not(miri))]

mod util;

#[test]
#[ignore]
fn convert() {
util::convert_wast_for_miri();
}
2 changes: 0 additions & 2 deletions tests/regression_integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

mod util;
use std::{ops::ControlFlow, sync::Mutex};

Expand Down
Loading
Loading