github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/.github/wasi_testsuite_adapter.py (about)

     1  # adapter for wazero until/unless https://github.com/WebAssembly/wasi-testsuite/pull/55
     2  
     3  import argparse
     4  import subprocess
     5  import sys
     6  import os
     7  import shlex
     8  
     9  # shlex.split() splits according to shell quoting rules
    10  WAZERO = shlex.split(os.getenv("TEST_RUNTIME_EXE", "wazero"))
    11  
    12  parser = argparse.ArgumentParser()
    13  parser.add_argument("--version", action="store_true")
    14  parser.add_argument("--test-file", action="store")
    15  parser.add_argument("--arg", action="append", default=[])
    16  parser.add_argument("--env", action="append", default=[])
    17  parser.add_argument("--dir", action="append", default=[])
    18  
    19  args = parser.parse_args()
    20  
    21  if args.version:
    22      version = subprocess.run(
    23          WAZERO + ["version"], capture_output=True, text=True
    24      ).stdout.strip()
    25      if version == "dev":
    26          version = "0.0.0"
    27      print("wazero", version)
    28      sys.exit(0)
    29  
    30  TEST_FILE = args.test_file
    31  TEST_DIR = os.path.dirname(TEST_FILE)
    32  PROG_ARGS = []
    33  if args.arg:
    34      PROG_ARGS = ["--"] + args.arg
    35  ENV_ARGS = [f"-env={e}" for e in args.env]
    36  cwd = os.getcwd()
    37  DIR_ARGS = [f"-mount={cwd}/{dir}:{dir}" for dir in args.dir]
    38  
    39  PROG = (
    40      WAZERO
    41      + ["run", "-hostlogging=filesystem"]
    42      + ENV_ARGS
    43      + DIR_ARGS
    44      + [TEST_FILE]
    45      + PROG_ARGS
    46  )
    47  sys.exit(subprocess.run(PROG, cwd=TEST_DIR).returncode)