Skip to content

Commit 1a08187

Browse files
authored
Merge pull request #465 from wasmx/ci_spectests
CI: Convert WAST test to JSON
2 parents 2340104 + 5670f26 commit 1a08187

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

circle.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ commands:
2727
name: "Install system dependencies"
2828
command: HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install cmake ninja
2929

30+
install_wabt:
31+
description: "Install WABT tools"
32+
steps:
33+
- run:
34+
name: "Install WABT tools"
35+
command: |
36+
if type wast2json; then
37+
wast2json --version
38+
else
39+
[[ $OSTYPE = darwin* ]] && os=macos || os=ubuntu
40+
cd /usr/local
41+
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.19/wabt-1.0.19-$os.tar.gz | sudo tar xz --strip 1
42+
fi
43+
3044
build:
3145
description: "Build"
3246
parameters:
@@ -174,20 +188,24 @@ commands:
174188
default: 477
175189

176190
steps:
191+
- install_wabt
177192
- run:
178193
name: "Download spectest files"
179194
working_directory: ~/build
180195
command: |
181196
if [ ! -d wasm-spec ]; then
182-
git clone https://github.com/wasmx/wasm-spec --branch w3c-1.0-jsontests-20200813 --depth 1
197+
git clone https://github.com/wasmx/wasm-spec --branch w3c-1.0-jsontests-20200813 --depth 1 wasm-spec
198+
mkdir json && cd json
199+
options='--disable-saturating-float-to-int --disable-sign-extension --disable-multi-value'
200+
find ../wasm-spec/test/core -name '*.wast' -exec wast2json $options {} \;
183201
fi
184202
- run:
185203
name: "Run spectest<<#parameters.skip_validation>> (skip validation)<</parameters.skip_validation>>"
186204
working_directory: ~/build
187205
command: |
188206
set +e
189207
expected=" PASSED <<parameters.expected_passed>>, FAILED <<parameters.expected_failed>>, SKIPPED <<parameters.expected_skipped>>."
190-
result=$(bin/fizzy-spectests <<#parameters.skip_validation>>--skip-validation<</parameters.skip_validation>> wasm-spec/test/core/json | tail -1)
208+
result=$(bin/fizzy-spectests <<#parameters.skip_validation>>--skip-validation<</parameters.skip_validation>> json | tail -1)
191209
echo $result
192210
if [ "$expected" != "$result" ]; then exit 1; fi
193211
@@ -207,10 +225,7 @@ jobs:
207225
name: "Run codespell"
208226
command: |
209227
codespell --quiet-level=4 -I .codespell-whitelist
210-
- run:
211-
name: "Install wabt"
212-
working_directory: ~/bin
213-
command: curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.15/wabt-1.0.15-linux.tar.gz | tar xz --strip=1
228+
- install_wabt
214229
- run:
215230
name: "Check wat2wasm4cpp"
216231
command: |

test/spectests/README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,39 @@
33
## Build and run
44

55
Fizzy must be built with the `FIZZY_TESTING` option turned on:
6-
```sh
7-
$ mkdir build && cd build
8-
$ cmake -DFIZZY_TESTING=ON ..
9-
$ cmake --build .
6+
```shell script
7+
mkdir build && cd build
8+
cmake -DFIZZY_TESTING=ON ..
9+
cmake --build .
1010
```
1111

1212
It can then be executed:
13-
```sh
14-
$ bin/fizzy-spectests <test directory>
15-
```
16-
17-
This will execute all test cases, but since Fizzy does not implement the complete validation specification, most of
18-
those cases will fail. It is possible to skip them:
19-
```sh
20-
$ bin/fizzy-spectests --skip-validation <test directory>
13+
```shell script
14+
bin/fizzy-spectests <test directory>
2115
```
2216

2317
## Preparing tests
2418

2519
Fizzy uses the official WebAssembly "[spec tests]", albeit not directly.
2620
It requires the Wast files to be translated into a JSON format using [wabt]'s `wast2json` tool.
2721

28-
The reason for this is a design decision of Fizzy to not support the WebAssembly text format –– and unfortunately
22+
The reason for this is a design decision of Fizzy to not support the WebAssembly text format, and unfortunately
2923
the official test cases are in a text format.
3024

3125
In order to prepare the tests, run the following command for each file:
32-
```sh
33-
$ wast2json <file.wast> -o <file.json>
26+
```shell script
27+
wast2json <file.wast> -o <file.json>
28+
```
29+
30+
Make sure to disable all WebAssembly extensions when using `wast2json`:
31+
```shell script
32+
wast2json --disable-saturating-float-to-int --disable-sign-extension --disable-multi-value
33+
```
34+
35+
To convert all files at once:
36+
```shell script
37+
# Make sure $options here contains the above settings
38+
find test/core -name '*.wast' -exec wast2json $options {} \;
3439
```
3540

3641
For ease of use, we have placed the JSON files of the spec tests [w3c-v1.0 branch] here:

wat2wasm4cpp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
DEBUG = False
3030

3131
WAT2WASM_TOOL = 'wat2wasm'
32+
WAT2WASM_DEFAULT_OPTIONS = ['--disable-saturating-float-to-int',
33+
'--disable-sign-extension', '--disable-multi-value']
3234
FORMAT_TOOL = 'clang-format'
3335

3436
WAT_RE = re.compile(r'/\* wat2wasm(.*)\n([^*]*)\*/', re.MULTILINE)
@@ -88,6 +90,7 @@ def report_wat_errors(errmsg, source, source_path, wat_pos):
8890
with open(TMP_WAT_FILE, 'w') as f:
8991
f.write(wat)
9092

93+
options = WAT2WASM_DEFAULT_OPTIONS + options
9194
r = subprocess.run([WAT2WASM_TOOL, TMP_WAT_FILE] + options,
9295
capture_output=True, text=True)
9396
if r.returncode != 0:

0 commit comments

Comments
 (0)