Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage #4465

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
toolchain: ${{ env.MSRV }}
targets: "wasm32-wasi"
- name: Install wasm-pack
run: |
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
name = NAME;
src = self;
buildInputs = with pkgs; [
pkgconfig
pkg-config
openssl
llvmPackages_15.libllvm
# Snapshot testing
Expand All @@ -52,6 +52,7 @@

# Test runner
cargo-nextest
cargo-llvm-cov
];
runtimeDependencies = with pkgs; [ ];

Expand Down
33 changes: 33 additions & 0 deletions scripts/code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -Eeuxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# get absolute path of the root dir
ROOT_DIR="$( cd "${DIR}/.." && pwd )"

export CARGO_TARGET_DIR="$ROOT_DIR/target/llvm-cov"

# Set the environment variables needed to get coverage.
source <(cargo llvm-cov show-env --export-prefix)

# Remove artifacts that may affect the coverage results.
# This command should be called after show-env.
# cargo llvm-cov clean --workspace
# Above two commands should be called before build binaries.

# Build rust binaries.
cargo build --locked -p wasmer-cli -F singlepass,cranelift --release

# cargo-llvm-cov expects the debug binaries to be in /debug.
# We compile with --release because otherwise running is way too slow.
# So we copy the release binaries to /debug, which makes things work.
rm -rf "$CARGO_TARGET_DIR/debug"
cp -r "$CARGO_TARGET_DIR/release" "$CARGO_TARGET_DIR/debug"

# Commands using binaries in target/, including `cargo test` and other cargo subcommands.

TEST_RUNNER="$CARGO_TARGET_DIR/release/wasmer" $ROOT_DIR/tests/wasi-fyi/test.sh

# Generate reports.
cargo llvm-cov report --html
9 changes: 7 additions & 2 deletions tests/wasi-fyi/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
#!/usr/bin/env bash

set -ueo pipefail

for input in *.rs; do
output="$(basename $input .rs).wasm"

echo "Compiling $input"
rustc +nightly --target=wasm32-wasi -o "$output" "$input"
# Some of the tests require unstable Rust features.
# RUSTC_BOOTSTRAP=1 is a trick that allows unstable features to work on stable
# compilers. This is done so the builds don't rely on a rustup installation
# and a separate nightly toolchain.
RUSTC_BOOTSTRAP=1 rustc --target=wasm32-wasi -o "$output" "$input"
done
12 changes: 10 additions & 2 deletions tests/wasi-fyi/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/bin/bash
#!/usr/bin/env bash

set -ueo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# get absolute path of the root dir
ROOT_DIR="$( cd "${DIR}/.." && pwd )"

cd "$DIR"

bash build.sh

status=0

# Define skip list as an array
SKIP_LIST=("ported_readlink.wasm" "fs_create_dir-existing-directory.wasm" "fs_rename-directory.wasm" "fs_rename-file.wasm")

cd $DIR

# List and process .foo files
for file in *.wasm; do
if [[ " ${SKIP_LIST[@]} " =~ " ${file} " ]]; then
Expand All @@ -19,4 +28,3 @@ for file in *.wasm; do
done

exit $status

12 changes: 11 additions & 1 deletion tests/wasi-fyi/wasm-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# get absolute path of the root dir
ROOT_DIR="$( cd "${DIR}/../../" && pwd )"
TEST_RUNNER="${TEST_RUNNER:-$ROOT_DIR/target/release/wasmer}"

if [ ! -e "$TEST_RUNNER" ]; then
echo "Test runner not found at '$TEST_RUNNER' - set TEST_RUNNER env var to the correct path."
exit 1
fi

input=$1

input_dir=$(dirname $input)
Expand Down Expand Up @@ -40,7 +50,7 @@ fi

status=0

"../../target/release/wasmer" --mapdir /hamlet:./test_fs/hamlet --mapdir /fyi:./test_fs/fyi "$input_base.wasm" $dir $env -- $arg \
$TEST_RUNNER --mapdir /hamlet:./test_fs/hamlet --mapdir /fyi:./test_fs/fyi "$input_base.wasm" $dir $env -- $arg \
< "$stdin" \
> "$stdout_actual" \
2> "$stderr_actual" \
Expand Down
Loading