Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
36 changes: 18 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Install 32-bit system libraries
run: |
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Install Rust toolchain
# Pinned to the commit the `stable` branch resolved to (its action.yml
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
Expand All @@ -228,7 +228,7 @@ jobs:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -262,7 +262,7 @@ jobs:
echo "$output"

# Extract the CoreMark score from the output
score=$(echo "$output" | grep "CoreMark Score:" | awk '{print $3}')
score=$(echo "$output" | grep -m1 "CoreMark Score:" | awk '{print $3}')
if [ -z "$score" ]; then
echo "Failed to extract CoreMark score"
exit 1
Expand All @@ -280,7 +280,7 @@ jobs:
git fetch origin main:main
git checkout main
baseline_output=$(cargo bench -p spacewasm_std --bench coremark --no-fail-fast 2>&1) || true
baseline_score=$(echo "$baseline_output" | grep "CoreMark Score:" | awk '{print $3}')
baseline_score=$(echo "$baseline_output" | grep -m1 "CoreMark Score:" | awk '{print $3}')
git checkout -

if [ -n "$baseline_score" ]; then
Expand All @@ -306,7 +306,7 @@ jobs:

- name: Upload benchmark results
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: benchmark-results
path: benchmark-results.json
Expand All @@ -318,12 +318,12 @@ jobs:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0

- name: Run Kani on repo
uses: model-checking/kani-github-action@v1.1
uses: model-checking/kani-github-action@f838096619a707b0f6b2118cf435eaccfa33e51f # v1.1
with:
args: "-j --output-format=terse"

Expand All @@ -332,16 +332,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0

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

- name: Run Miri
Expand All @@ -356,7 +354,7 @@ jobs:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0

Expand All @@ -378,7 +376,9 @@ jobs:
sudo cp wabt-${WABT_VERSION}/bin/* /usr/local/bin/

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
uses: taiki-e/install-action@37f7c5781271959fb65b6b35224e28652ff2b63d # v2.87.0
with:
tool: cargo-llvm-cov

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32
Expand Down Expand Up @@ -446,14 +446,14 @@ jobs:

- name: Upload coverage results
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: coverage-results
path: coverage-results.json

- name: Upload coverage to Codecov
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: codecov/codecov-action@v7
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Download CI artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -27,7 +27,7 @@ jobs:
continue-on-error: true

- name: Post benchmark and coverage comments
uses: actions/github-script@v7
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
env:
TRUSTED_PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
with:
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
let comment = '## CoreMark Benchmark Results\n\n';
comment += `**Current Score:** ${currentScore.toFixed(3)}\n`;

if (baselineScore) {
if (baselineScore !== null) {
const diff = currentScore - baselineScore;
const percentChange = ((diff / baselineScore) * 100).toFixed(2);

Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
let comment = '## Code Coverage Report\n\n';
comment += `**Current Coverage:** ${currentCoverage.toFixed(2)}%\n`;

if (baselineCoverage) {
if (baselineCoverage !== null) {
const diff = currentCoverage - baselineCoverage;

comment += `**Baseline Coverage (main):** ${baselineCoverage.toFixed(2)}%\n`;
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/welcome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ jobs:
repo: context.repo.repo,
body: `**Welcome**, new contributor!

Please make sure you've read our [contributing guide](https://github.com/nasa/spacewasm/blob/main/CONTRIBUTING.md), as well as our [policy regarding AI usage](https://github.com/nasa/spacewasm/blob/main/AI_POLICY.md), and we look forward to reviewing your pull request shortly`
Please make sure you've read our [contributing guide](https://github.com/nasa/spacewasm/blob/main/CONTRIBUTING.md), as well as our [policy regarding AI usage](https://github.com/nasa/spacewasm/blob/main/AI_POLICY.md), and we look forward to reviewing your pull request shortly`
})
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ strict-assertions = []
miri-soft-floats = ["libm/force-soft-floats"]

[dependencies]
libm = "0.2.16"
libm = "=0.2.16"

[dev-dependencies]
serde = { version = "1.0", features = ["derive"] }
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help fuzz fuzz-validate fuzz-validate-differential fuzz-malformed seed-to-wasm trace-wasm trace trace-debug clean-artifacts
.PHONY: help fuzz fuzz-validate fuzz-validate-differential fuzz-malformed seed-to-wasm trace-wasm trace-wasm-debug trace trace-debug clean-artifacts gen-header

# Target Configuration (auto-detect if not set)
SPACEWASM_TARGET ?= $(shell rustc -vV | grep 'host:' | cut -d' ' -f2)
Expand Down Expand Up @@ -28,6 +28,9 @@ help:
@echo " make trace-debug CRASH=crash-abc123 LIMIT=100"
@echo " make trace-wasm WASM=output.wasm LIMIT=50"
@echo ""
@echo "C API:"
@echo " make gen-header Regenerate crates/spacewasm_c_api/include/spacewasm.h with cbindgen"
@echo ""
@echo "Utilities:"
@echo " make clean-artifacts Delete all fuzzer artifacts"

Expand Down Expand Up @@ -97,6 +100,12 @@ trace-wasm-debug:
fi
RUSTFLAGS="-Zsanitizer=address" cargo run --target $(SPACEWASM_TARGET) -p spacewasm_util --bin spacewasm-trace -- $(WASM) --limit $(or $(LIMIT),200)

# Regenerate the C API header from the Rust source with cbindgen. The header is
# written as a side effect of building spacewasm_c_api with the `codegen` feature.
gen-header:
cargo build -p spacewasm_c_api --features codegen
@echo "Regenerated crates/spacewasm_c_api/include/spacewasm.h"

# Clean fuzzer artifacts
clean-artifacts:
rm -rf fuzz/artifacts/*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">SpaceWasm</h2>
<h1 align="center">SpaceWasm</h1>

<p align="center">
<img src="docs/logo.svg" width="150" height="150">
Expand Down
2 changes: 1 addition & 1 deletion crates/fuzzing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = "0.4"
wasm-smith = "0.220.0"
wasmprinter = "0.220.0"
env_logger = "0.11"
wasmi = { version = "1", optional = true }
wasmi = { version = "~1.1.0", optional = true }

[features]
# Differential validator testing against wasmi as a reference implementation.
Expand Down
11 changes: 0 additions & 11 deletions crates/fuzzing/src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl ModuleConfig {
// Disable imports - SpaceWasm tests don't provide import environment
min_imports: 0,
max_imports: 0,
// Memory limits (SpaceWasm supports max 256 pages = 16MB)
memory_max_size_required: false,
max_memory32_bytes: 65536 * 32,
// Wasm 1.0 MVP compliance - disable all post-MVP features
Expand Down Expand Up @@ -68,16 +67,6 @@ impl ModuleConfig {
pub fn generate(&self, u: &mut Unstructured<'_>) -> Result<wasm_smith::Module> {
wasm_smith::Module::new(self.config.clone(), u)
}

/// Get the underlying wasm-smith config.
pub fn smith_config(&self) -> &SmithConfig {
&self.config
}

/// Get a mutable reference to the underlying wasm-smith config.
pub fn smith_config_mut(&mut self) -> &mut SmithConfig {
&mut self.config
}
}

impl Default for ModuleConfig {
Expand Down
17 changes: 15 additions & 2 deletions crates/fuzzing/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ unsafe impl Allocator for SystemAllocator {
if layout.size() > MAX_ALLOCATION_BYTES {
return Err(AllocError::OutOfMemory);
}
unsafe { Ok(std::alloc::alloc(layout)) }
let ptr = unsafe { std::alloc::alloc(layout) };
if ptr.is_null() {
return Err(AllocError::AllocationFailed);
}
Ok(ptr)
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
Expand Down Expand Up @@ -503,7 +507,16 @@ pub fn no_traps(wasm: &[u8]) {
// These should never trap since the module was generated with disallow_traps
for (wasm_ref, params) in exported_funcs {
state.reset();
state.invoke(wasm_ref, &params).unwrap();
match state.invoke(wasm_ref, &params) {
Ok(()) => {}
// Wasm Smith cannot avoid deeply-recursive exports; a stack overflow
// here is not a bug, so skip this export.
Err(InvokeError::StackOverflow) => {
log::debug!("export hit a stack overflow during invocation");
continue;
}
Err(e) => panic!("unexpected invoke error in no_traps module: {e:?}"),
}

// Run the interpreter with limited instructions
let interpreter = Interpreter;
Expand Down
14 changes: 6 additions & 8 deletions crates/spacewasi/scripts/wasm2mvp.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env bash

if ! command -v wasm-opt --version >/dev/null 2>&1
if ! command -v wasm-opt >/dev/null 2>&1
then
echo "please install wasm-opt to use this command"
exit 1
fi

if [ "$#" -ne 2 ]; then
if [ "$#" -ne 1 ]; then
echo "usage: $0 input.wasm [output.wasm]"
exit 1
fi
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "usage: $0 input.wasm [output.wasm]"
exit 1
fi

wasm-opt \
Expand All @@ -20,7 +18,7 @@ wasm-opt \
--llvm-nontrapping-fptoint-lowering \
--disable-multivalue \
--disable-simd \
$1 \
-o ${2:-$1}
"$1" \
-o "${2:-$1}"

exit $?
Loading
Loading