Add tests for assert, abort, and environ. (#105)

To support this, add a mechanism for filtering test output to filter
out uninteresting diffs.

This adds some coverage for the code being changed in
https://github.com/WebAssembly/wasi-libc/pull/184.
pull/106/head
Dan Gohman 5 years ago committed by GitHub
parent 79e5760710
commit b80771e767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
tests/.gitignore vendored

@ -1,2 +1,3 @@
*.observed
*.observed.filtered
*.wasm

@ -0,0 +1,6 @@
#include <stdlib.h>
int main(void) {
abort();
return 0;
}

@ -0,0 +1,6 @@
Error: failed to run main module `abort.c.---.wasm`
Caused by:
0: failed to invoke `_start`
1: wasm trap: unreachable, source location: @----
wasm backtrace:

@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
cat \
| sed -e 's/main module `abort\.c\.[^`]*\.wasm`/main module `abort.c.---.wasm`/' \
| sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \
| head -n 6

@ -0,0 +1,7 @@
#include <assert.h>
#include <stdbool.h>
int main(void) {
assert(false);
return 0;
}

@ -0,0 +1,7 @@
Assertion failed: false (assert-fail.c: main: 5)
Error: failed to run main module `assert-fail.c.---.wasm`
Caused by:
0: failed to invoke `_start`
1: wasm trap: unreachable, source location: @----
wasm backtrace:

@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
cat \
| sed -e 's/main module `assert-fail\.c\.[^`]*\.wasm`/main module `assert-fail.c.---.wasm`/' \
| sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \
| head -n 7

@ -0,0 +1,7 @@
#include <assert.h>
#include <stdbool.h>
int main(void) {
assert(true);
return 0;
}

@ -0,0 +1,18 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
extern char **environ;
int main(void) {
assert(environ != NULL);
for (char **p = environ; *p; ++p) {
assert(p != NULL);
}
for (char **p = environ; *p; ++p) {
if (strncmp(*p, "HELLO=", 5) == 0) {
printf("HELLO = %s\n", *p + 6);
}
}
return 0;
}

@ -60,11 +60,27 @@ 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

Loading…
Cancel
Save