Skip to content

Commit c884b41

Browse files
committed
Per-target Assemblyscript testsuite
As in #112, we reorganize the directory structure and change to a python build script, with the goal of harmonizing the various test suites, so that testsuite/ is always a built dir. Before, it was: - tests/assemblyscript/: Root of npm repo - tests/assemblyscript/testsuite: AS source files, JSON test files; built .wasm files dumped here Now it is: - tests/assemblyscript/wasm32-wasip1: Root of npm package for wasip1 builds - tests/assemblyscript/wasm32-wasip1/src: Assemblyscript source, but also JSON - tests/assemblyscript/testsuite/: Removed; instead it is a built dir - tests/assemblyscript/testsuite/wasm32-wasip1: All wasm and json files copied here
1 parent 9315be9 commit c884b41

31 files changed

+952
-327
lines changed

.github/workflows/compile-tests.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,10 @@ jobs:
2424
with:
2525
node-version: 22
2626

27-
- name: Install dependencies
28-
working-directory: tests/assemblyscript
29-
run: |
30-
npm install
31-
32-
- name: Check prettier codestyle
33-
working-directory: tests/assemblyscript
34-
run: |
35-
npm run prettier-format-check
36-
3727
- name: Build tests
3828
working-directory: tests/assemblyscript
3929
run: |
40-
npm run build
30+
./build.py
4131
4232
- name: Upload precompiled tests
4333
if: matrix.os == 'ubuntu-latest'

.github/workflows/daily-runtime-validation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
python3 test-runner/wasi_test_runner.py \
7777
-r ./adapters/${{ matrix.runtime }}.py \
7878
--json-output-location results.json \
79-
-t tests/assemblyscript/testsuite \
79+
-t tests/assemblyscript/testsuite/wasm32-wasip1 \
8080
tests/rust/testsuite \
8181
tests/c/testsuite
8282

doc/adapters.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ The adapter must return exit code to the environment that was passed as an argum
3030
)
3131
```
3232
and check if the exit code is equal to `13`. There are also two test cases in Assembly Script test suite that verify the behavior:
33-
* [proc_exit-failure](../tests/assemblyscript/testsuite/proc_exit-failure.ts)
34-
* [proc_exit-success](../tests/assemblyscript/testsuite/proc_exit-success.ts)
33+
* [proc_exit-failure](../tests/assemblyscript/wasm32-wasip1/src/proc_exit-failure.ts)
34+
* [proc_exit-success](../tests/assemblyscript/wasm32-wasip1/src/proc_exit-success.ts)
3535
### Examples:
3636

3737
Print runtime version:
@@ -61,4 +61,4 @@ See the [`adapters`](../adapters) directory for example adapters.
6161

6262
We prefer runtime maintainers to maintain adapters in their own repository We'll only maintain adapters for [Bytecode Alliance](https://bytecodealliance.org/) projects and we'll aim for compatibility with the most recent stable version.
6363

64-
We'll accept pull requests for new adapters in this repository, but we can't guarantee we'll have the capacity to maintain them (so they might stop working with the new runtime release).
64+
We'll accept pull requests for new adapters in this repository, but we can't guarantee we'll have the capacity to maintain them (so they might stop working with the new runtime release).

tests/assemblyscript/build.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import contextlib
5+
import json
6+
import shlex
7+
import shutil
8+
import subprocess
9+
import sys
10+
from pathlib import Path
11+
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument("--dry-run", action="store_true")
14+
parser.add_argument("--verbose", action="store_true")
15+
16+
args = parser.parse_args()
17+
18+
TARGETS = ['wasm32-wasip1']
19+
BASE_DIR = Path(__file__).parent
20+
21+
def run(argv):
22+
if args.verbose:
23+
print(shlex.join([str(x) for x in argv]))
24+
if not args.dry_run:
25+
r = subprocess.run(argv)
26+
if r.returncode != 0:
27+
sys.exit(r.returncode)
28+
29+
def cp(src, dst):
30+
if args.verbose:
31+
print(f"cp {src} {dst}")
32+
if not args.dry_run:
33+
shutil.copy(src, dst)
34+
35+
def cp_R(src, dst):
36+
if args.verbose:
37+
print(f"cp -R {src} {dst}")
38+
if not args.dry_run:
39+
shutil.copytree(src, dst, dirs_exist_ok=True)
40+
41+
def write_manifest(path, manifest):
42+
if args.verbose:
43+
print(f"writing {path}")
44+
if not args.dry_run:
45+
path.write_text(json.dumps(manifest))
46+
47+
def mkdir_p(path):
48+
if args.verbose:
49+
print(f"mkdir -p {path}")
50+
if not args.dry_run:
51+
path.mkdir(parents=True, exist_ok=True)
52+
53+
for target in TARGETS:
54+
with contextlib.chdir(BASE_DIR / target):
55+
run(["npm", "install"])
56+
run(["npm", "run", "prettier-format-check"])
57+
run(["npm", "run", "build"])
58+
59+
src_dir = BASE_DIR / target / "src"
60+
obj_dir = src_dir
61+
dst_dir = BASE_DIR / "testsuite" / target
62+
mkdir_p(dst_dir)
63+
64+
write_manifest(dst_dir / "manifest.json",
65+
{'name': f"WASI Assemblyscript tests [{target}]"})
66+
67+
for src in src_dir.glob("*.ts"):
68+
obj = (obj_dir / src.name).with_suffix(".wasm")
69+
dst = (dst_dir / src.name).with_suffix(".wasm")
70+
cp(obj, dst)
71+
src_json = src.with_suffix(".json")
72+
if src_json.exists():
73+
cp(src_json, dst.with_suffix(".json"))
74+
with src_json.open() as f:
75+
for d in json.load(f).get('dirs', []):
76+
cp_R(src.parent / d, dst.parent / d)

tests/assemblyscript/testsuite/manifest.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/assemblyscript/buildscripts/build.ts renamed to tests/assemblyscript/wasm32-wasip1/buildscripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function isBinaryOutdated(srcPath: string, wasmPath: string): boolean {
2525
}
2626

2727
async function compileTests() {
28-
const testSuiteFiles = getPathsInDirectory("testsuite");
28+
const testSuiteFiles = getPathsInDirectory("src");
2929
const pendingCompilations = testSuiteFiles
3030
.filter((filePath) => doesFileHaveExtension(filePath, "ts"))
3131
.map((filePath) => ({

0 commit comments

Comments
 (0)