Skip to content

Commit b80771e

Browse files
authoredMar 11, 2020
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 WebAssembly/wasi-libc#184.
1 parent 79e5760 commit b80771e

14 files changed

+86
-0
lines changed
 

‎tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.observed
2+
*.observed.filtered
23
*.wasm

‎tests/general/abort.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdlib.h>
2+
3+
int main(void) {
4+
abort();
5+
return 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
134

‎tests/general/abort.c.stderr.expected

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Error: failed to run main module `abort.c.---.wasm`
2+
3+
Caused by:
4+
0: failed to invoke `_start`
5+
1: wasm trap: unreachable, source location: @----
6+
wasm backtrace:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
cat \
5+
| sed -e 's/main module `abort\.c\.[^`]*\.wasm`/main module `abort.c.---.wasm`/' \
6+
| sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \
7+
| head -n 6

‎tests/general/assert-fail.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
int main(void) {
5+
assert(false);
6+
return 0;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Assertion failed: false (assert-fail.c: main: 5)
2+
Error: failed to run main module `assert-fail.c.---.wasm`
3+
4+
Caused by:
5+
0: failed to invoke `_start`
6+
1: wasm trap: unreachable, source location: @----
7+
wasm backtrace:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
cat \
5+
| sed -e 's/main module `assert-fail\.c\.[^`]*\.wasm`/main module `assert-fail.c.---.wasm`/' \
6+
| sed -e 's/source location: @[[:xdigit:]]*$/source location: @----/' \
7+
| head -n 7

‎tests/general/assert-pass.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
int main(void) {
5+
assert(true);
6+
return 0;
7+
}

‎tests/general/environ.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdlib.h>
2+
#include <assert.h>
3+
#include <string.h>
4+
#include <stdio.h>
5+
extern char **environ;
6+
7+
int main(void) {
8+
assert(environ != NULL);
9+
for (char **p = environ; *p; ++p) {
10+
assert(p != NULL);
11+
}
12+
for (char **p = environ; *p; ++p) {
13+
if (strncmp(*p, "HELLO=", 5) == 0) {
14+
printf("HELLO = %s\n", *p + 6);
15+
}
16+
}
17+
return 0;
18+
}

‎tests/general/environ.c.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO=hello
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HELLO = hello

‎tests/testcase.sh

+16
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,27 @@ echo $exit_status > "$exit_status_observed"
6060
# Determine the reference files to compare with.
6161
if [ -e "$input.stdout.expected" ]; then
6262
stdout_expected="$input.stdout.expected"
63+
64+
# Apply output filters.
65+
if [ -e "$input.stdout.expected.filter" ]; then
66+
cat "$stdout_observed" \
67+
| "$input.stdout.expected.filter" \
68+
> "${stdout_observed}.filtered"
69+
stdout_observed="${stdout_observed}.filtered"
70+
fi
6371
else
6472
stdout_expected="/dev/null"
6573
fi
6674
if [ -e "$input.stderr.expected" ]; then
6775
stderr_expected="$input.stderr.expected"
76+
77+
# Apply output filters.
78+
if [ -e "$input.stderr.expected.filter" ]; then
79+
cat "$stderr_observed" \
80+
| "./$input.stderr.expected.filter" \
81+
> "${stderr_observed}.filtered"
82+
stderr_observed="${stderr_observed}.filtered"
83+
fi
6884
else
6985
stderr_expected="/dev/null"
7086
fi

0 commit comments

Comments
 (0)
Please sign in to comment.