-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkin of test scripts, copied from wasi-sdk. (#397)
* Initial checkin of test scripts, copied from wasi-sdk. * Add a minimal command test. * Adjust the scripts so that they run the minimal-command.wasm test.
- Loading branch information
1 parent
78b7367
commit 713727f
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -ueo pipefail | ||
|
||
for wat in wat/*.wat; do | ||
wat2wasm "$wat" | ||
done | ||
|
||
mv *.wasm .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(module | ||
(func (export "_start")) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
set -ueo pipefail | ||
|
||
# Top-level test runner. Usage is "run.sh" to run tests in compile-only mode, | ||
# or "run.sh <runwasi>" where <runwasi> is a WASI-capable runtime to run the | ||
# tests in full compile and execute mode. | ||
|
||
# Determine the wasm runtime to use. | ||
runwasi="$1" | ||
|
||
tooldir=$(dirname $0) | ||
|
||
echo "===== Testing =====" | ||
for file in *.wasm; do | ||
"$tooldir/testcase.sh" "$runwasi" "$file" | ||
done | ||
cd - >/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
set -ueo pipefail | ||
|
||
# A simple testcase runner that runs a command, captures all its command-line | ||
# outputs, and compares them against expected outputs. | ||
|
||
# Command-line parsing; this script is meant to be run from a higher-level | ||
# script, so don't do anything fancy. | ||
runwasi="$1" | ||
input="$2" | ||
|
||
# Compile names for generated files. | ||
wasm="$input" | ||
stdout_observed="$input.stdout.observed" | ||
stderr_observed="$input.stderr.observed" | ||
exit_status_observed="$input.exit_status.observed" | ||
tooldir=$(dirname $0) | ||
|
||
echo "Testing $input..." | ||
|
||
# Determine the input file to write to stdin. | ||
if [ -e "$input.stdin" ]; then | ||
stdin="$input.stdin" | ||
else | ||
stdin="/dev/null" | ||
fi | ||
|
||
# Determine any environment variables to set. | ||
if [ -e "$input.env" ]; then | ||
env=$(sed -e 's/^/--env /' < "$input.env") | ||
else | ||
env="" | ||
fi | ||
|
||
# Determine a preopened directory to provide. | ||
if [ -e "$input.dir" ]; then | ||
dir="--dir $input.dir" | ||
dirarg="$input.dir" | ||
else | ||
dir="" | ||
dirarg="" | ||
fi | ||
|
||
# Run the test, capturing stdout, stderr, and the exit status. | ||
exit_status=0 | ||
"$runwasi" $env $dir "$wasm" $dirarg \ | ||
< "$stdin" \ | ||
> "$stdout_observed" \ | ||
2> "$stderr_observed" \ | ||
|| exit_status=$? | ||
echo $exit_status > "$exit_status_observed" | ||
|
||
# Determine the reference files to compare with. | ||
if [ -e "$input.stdout.expected" ]; then | ||
stdout_expected="$input.stdout.expected" | ||
|
||
# Apply output filters. | ||
if [ -e "$input.stdout.expected.filter" ]; then | ||
cat "$stdout_observed" \ | ||
| "$input.stdout.expected.filter" \ | ||
> "${stdout_observed}.filtered" | ||
stdout_observed="${stdout_observed}.filtered" | ||
fi | ||
else | ||
stdout_expected="/dev/null" | ||
fi | ||
if [ -e "$input.stderr.expected" ]; then | ||
stderr_expected="$input.stderr.expected" | ||
|
||
# Apply output filters. | ||
if [ -e "$input.stderr.expected.filter" ]; then | ||
cat "$stderr_observed" \ | ||
| "./$input.stderr.expected.filter" \ | ||
> "${stderr_observed}.filtered" | ||
stderr_observed="${stderr_observed}.filtered" | ||
fi | ||
else | ||
stderr_expected="/dev/null" | ||
fi | ||
if [ -e "$input.exit_status.expected" ]; then | ||
exit_status_expected="$tooldir/$input.exit_status.expected" | ||
else | ||
exit_status_expected="$tooldir/exit_status_zero" | ||
fi | ||
|
||
# If there are any differences, diff will return a non-zero exit status, and | ||
# since this script uses "set -e", it will return a non-zero exit status too. | ||
diff -u "$stderr_expected" "$stderr_observed" | ||
diff -u "$stdout_expected" "$stdout_observed" | ||
diff -u "$exit_status_expected" "$exit_status_observed" |