Skip to content

Commit

Permalink
wasip1 target for all unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Oct 5, 2024
1 parent 0acd5d8 commit 667ac4a
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ tar -xvzf binaryen-version_116-x86_64-linux.tar.gz
sudo cp -r binaryen-version_116/* /usr/
rm -Rf binaryen-version_116*

cargo install cargo-wasi

curl https://wasmtime.dev/install.sh -sSf | bash
export PATH="$HOME/.wasmtime/bin:$PATH"

Expand Down
36 changes: 35 additions & 1 deletion examples/minimumweb4/test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
#!/bin/bash
WASMTIME_BACKTRACE_DETAILS=1 RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo wasi test -- --show-output --nocapture

rm ../../target/wasm32-wasip1/debug/deps/quickjs_rust_near_minimum_web4-*.wasm
# Compile the test without running it
echo "Compiling tests for wasm32-wasip1 target..."
RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo test --target=wasm32-wasip1 --no-run

# Check if the compilation was successful
if [ $? -ne 0 ]; then
echo "Compilation failed. Exiting."
exit 1
fi

# Locate the test file in the target/wasm32-wasip1/debug/deps directory
echo "Locating test file..."
TEST_FILE=$(find ../../target/wasm32-wasip1/debug/deps -name "quickjs_rust_near_minimum_web4-*.wasm" -print -quit)

# Check if the test file was found
if [ -z "$TEST_FILE" ]; then
echo "No test file found. Exiting."
exit 1
fi

echo "Found test file: $TEST_FILE"

# Run the test file using wasmtime
echo "Running tests with wasmtime..."
wasmtime "$TEST_FILE"

# Check if the tests ran successfully
if [ $? -eq 0 ]; then
echo "Tests ran successfully!"
else
echo "Tests failed."
exit 1
fi
36 changes: 35 additions & 1 deletion examples/nft/test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
#!/bin/bash
WASMTIME_BACKTRACE_DETAILS=1 RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo wasi test -- --show-output --nocapture

rm ../../target/wasm32-wasip1/debug/deps/quickjs_rust_near_nft-*.wasm
# Compile the test without running it
echo "Compiling tests for wasm32-wasip1 target..."
RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo test --target=wasm32-wasip1 --no-run

# Check if the compilation was successful
if [ $? -ne 0 ]; then
echo "Compilation failed. Exiting."
exit 1
fi

# Locate the test file in the target/wasm32-wasip1/debug/deps directory
echo "Locating test file..."
TEST_FILE=$(find ../../target/wasm32-wasip1/debug/deps -name "quickjs_rust_near_nft-*.wasm" -print -quit)

# Check if the test file was found
if [ -z "$TEST_FILE" ]; then
echo "No test file found. Exiting."
exit 1
fi

echo "Found test file: $TEST_FILE"

# Run the test file using wasmtime
echo "Running tests with wasmtime..."
wasmtime "$TEST_FILE"

# Check if the tests ran successfully
if [ $? -eq 0 ]; then
echo "Tests ran successfully!"
else
echo "Tests failed."
exit 1
fi
2 changes: 1 addition & 1 deletion src/wasimock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub extern "C" fn emscripten_get_now_res() -> f64 {

#[no_mangle]
pub extern "C" fn __wasi_fd_fdstat_get(_p1: i32, _p2: i32) -> i32 {
env::log_str("__wasi_fd_fdstat_get");
// env::log_str("__wasi_fd_fdstat_get");
return 0;
}

Expand Down
36 changes: 35 additions & 1 deletion testenv/test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
#!/bin/bash
RUSTFLAGS='-C link-args=--initial-memory=67108864' cargo wasi test -- --show-output --nocapture

rm ../target/wasm32-wasip1/debug/deps/quickjs_rust_near_testenv-*.wasm
# Compile the test without running it
echo "Compiling tests for wasm32-wasip1 target..."
cargo test --target=wasm32-wasip1 --no-run

# Check if the compilation was successful
if [ $? -ne 0 ]; then
echo "Compilation failed. Exiting."
exit 1
fi

# Locate the test file in the target/wasm32-wasip1/debug/deps directory
echo "Locating test file..."
TEST_FILE=$(find ../target/wasm32-wasip1/debug/deps -name "quickjs_rust_near_testenv-*.wasm" -print -quit)

# Check if the test file was found
if [ -z "$TEST_FILE" ]; then
echo "No test file found. Exiting."
exit 1
fi

echo "Found test file: $TEST_FILE"

# Run the test file using wasmtime
echo "Running tests with wasmtime..."
wasmtime "$TEST_FILE"

# Check if the tests ran successfully
if [ $? -eq 0 ]; then
echo "Tests ran successfully!"
else
echo "Tests failed."
exit 1
fi

0 comments on commit 667ac4a

Please sign in to comment.