Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
- name: Build tests
shell: bash
working-directory: tests/c
run: CC="./wasi-sdk-${WASI_VERSION}.0-${SYSTEM_NAME}/bin/clang" ./build.sh
run: CC="./wasi-sdk-${WASI_VERSION}.0-${SYSTEM_NAME}/bin/clang" ./build.py

- name: Upload precompiled tests
if: matrix.os == 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/daily-runtime-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
--json-output-location results.json \
-t tests/assemblyscript/testsuite \
tests/rust/testsuite \
tests/c/testsuite
tests/c/testsuite/wasm32-wasip1

- name: Configure git
uses: ./.github/actions/git-config
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.wasm
.DS_Store
.DS_Store
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it's best to use relative path here?

/tests/c/testsuite/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ executor is quite simple; see the [specification] document for the details and t
```bash
python3 test-runner/wasi_test_runner.py \
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
./tests/c/testsuite/ \
./tests/c/testsuite/wasm32-wasip1 \
./tests/rust/testsuite/ \
-r adapters/wasmtime.py # path to a runtime adapter
```
Expand All @@ -56,7 +56,7 @@ Optionally you can specify test cases to skip with the `--exclude-filter` option
```bash
python3 test-runner/wasi_test_runner.py \
-t ./tests/assemblyscript/testsuite/ `# path to folders containing .wasm test files` \
./tests/c/testsuite/ \
./tests/c/testsuite/wasm32-wasip1 \
./tests/rust/testsuite/ \
--exclude-filter examples/skip.json \
-r adapters/wasmtime.py # path to a runtime adapter
Expand Down Expand Up @@ -95,7 +95,7 @@ Here is some additional information for developers who are willing to contribute

### Cleaning up temporary resources

Some of the tests (e.g. [pwrite-with-access](./tests/c/testsuite/pwrite-with-access.c)) generate
Some of the tests (e.g. [pwrite-with-access](./tests/c/src/pwrite-with-access.c)) generate
output artifacts and their existence can affect consecutive test executions. Tests should clean up
the artifacts they generate, but there might be cases where the test fails early. The test runner
will automatically delete all the files and directories in the test suite directory with the
Expand Down
104 changes: 104 additions & 0 deletions tests/c/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just looking at the https://github.com/WebAssembly/wasi-testsuite/pull/114/files and it seems a lot of duplication, I wonder if we can refactor it in a way that the common part can be reused across different languages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, but wdyt about me doing that in a followup? It's a bit easier when the three implementations are actually there in the source tree.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine by me. Could you open a tracking issue so we don't forget about this? Thanks


import argparse
import json
import os
import shlex
import shutil
import subprocess
import sys
from pathlib import Path
from math import inf

# shlex.split() splits according to shell quoting rules
CC = shlex.split(os.getenv("CC", "clang"))

parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", action="store_true")
parser.add_argument("--verbose", action="store_true")

args = parser.parse_args()

SYSTEMS = ['wasm32']
VERSIONS = ['wasip1'] # + ['wasip2', 'wasip3']

def compute_target(system, version):
return f"{system}-{version}"

def compute_cc_target(system, version):
if version == 'wasip3':
# wasm32-wasip3 triple not yet supported.
return compute_target(system, 'wasip2')
return compute_target(system, version)

BASE_DIR = Path(__file__).parent

def maybe_stat(path, default):
try:
return path.stat().st_mtime
except FileNotFoundError:
return default

def needs_rebuild(dst, src):
if maybe_stat(dst, 0) < src.stat().st_mtime:
return True
return (maybe_stat(dst.with_suffix(".json"), -1)
< maybe_stat(src.with_suffix(".json"), -inf))

def run(argv):
if args.verbose:
print(shlex.join([str(x) for x in argv]))
if not args.dry_run:
r = subprocess.run(argv)
if r.returncode != 0:
sys.exit(r.returncode)

def cp(src, dst):
if args.verbose:
print(f"cp {src} {dst}")
if not args.dry_run:
shutil.copy(src, dst)

def cp_R(src, dst):
if args.verbose:
print(f"cp -R {src} {dst}")
if not args.dry_run:
shutil.copytree(src, dst, dirs_exist_ok=True)

def write_manifest(path, manifest):
if args.verbose:
print(f"writing {path}")
if not args.dry_run:
path.write_text(json.dumps(manifest))

def mkdir_p(path):
if args.verbose:
print(f"mkdir -p {path}")
if not args.dry_run:
path.mkdir(parents=True, exist_ok=True)

for system in SYSTEMS:
for version in VERSIONS:
target = compute_target(system, version)
generic_sources = list((BASE_DIR / "src").glob("*.c"))
target_sources = list((BASE_DIR / "src" / target).glob("*.c"))

target_dir = BASE_DIR / "testsuite" / target
mkdir_p(target_dir)
target_args = [f"--target={compute_cc_target(system, version)}"]

write_manifest(target_dir / "manifest.json",
{'name': f"WASI C tests [{target}]"})

for src in generic_sources + target_sources:
dst = (target_dir / src.name).with_suffix(".wasm")
if needs_rebuild(dst, src):
print(f"building testsuite/{target}/{dst.name}")
src_json = src.with_suffix(".json")
if src_json.exists():
dst_json = dst.with_suffix(".json")
with src_json.open() as f:
for d in json.load(f).get('dirs', []):
cp_R(src.parent / d, dst.parent / d)
cp(src_json, dst_json)
run(CC + target_args + [src] + ['-o'] + [dst])
13 changes: 0 additions & 13 deletions tests/c/build.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions tests/c/testsuite/manifest.json

This file was deleted.

Loading