Skip to content

Commit

Permalink
Enable running spec tests on Windows
Browse files Browse the repository at this point in the history
We don't enable those tests in CI yet as not all of them are passing
  • Loading branch information
loganek committed Aug 7, 2023
1 parent a07d816 commit 68b6708
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 66 deletions.
5 changes: 3 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
}

#ifdef BH_PLATFORM_WINDOWS
if (!os_mem_commit(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
if (memory_data_size > 0
&& !os_mem_commit(mapped_mem, memory_data_size,
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
set_error_buf(error_buf, error_buf_size, "commit memory failed");
os_munmap(mapped_mem, map_size);
goto fail1;
Expand Down
3 changes: 2 additions & 1 deletion product-mini/platforms/windows/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ app_instance_repl(wasm_module_inst_t module_inst)
char *cmd;
size_t n;

while ((printf("webassembly> "), cmd = fgets(buffer, sizeof(buffer), stdin))
while ((printf("webassembly> "), fflush(stdout),
cmd = fgets(buffer, sizeof(buffer), stdin))
!= NULL) {
bh_assert(cmd);
n = strlen(cmd);
Expand Down
36 changes: 30 additions & 6 deletions tests/wamr-test-suites/spec-test-script/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import argparse
import multiprocessing as mp
import os
import platform
import pathlib
import subprocess
import sys
Expand All @@ -28,12 +28,26 @@
--aot-compiler wamrc --gc spec/test/core/xxx.wast
"""

PLATFORM_NAME = os.uname().sysname.lower()
IWASM_CMD = "../../../product-mini/platforms/" + PLATFORM_NAME + "/build/iwasm"
def exe_file_path(base_path: str) -> str:
if platform.system().lower() == "windows":
base_path += ".exe"
return base_path

def get_iwasm_cmd(platform: str) -> str:
build_path = "../../../product-mini/platforms/" + platform + "/build/"
exe_name = "iwasm"

if platform == "windows":
build_path += "RelWithDebInfo/"

return exe_file_path(build_path + exe_name)

PLATFORM_NAME = platform.uname().system.lower()
IWASM_CMD = get_iwasm_cmd(PLATFORM_NAME)
IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm"
IWASM_QEMU_CMD = "iwasm"
SPEC_TEST_DIR = "spec/test/core"
WAST2WASM_CMD = "./wabt/out/gcc/Release/wat2wasm"
WAST2WASM_CMD = exe_file_path("./wabt/out/gcc/Release/wat2wasm")
SPEC_INTERPRETER_CMD = "spec/interpreter/wasm"
WAMRC_CMD = "../../../wamr-compiler/build/wamrc"

Expand Down Expand Up @@ -133,6 +147,7 @@ def test_case(
qemu_flag=False,
qemu_firmware='',
log='',
no_pty=False
):
case_path = pathlib.Path(case_path).resolve()
case_name = case_path.stem
Expand All @@ -151,7 +166,7 @@ def test_case(
):
return True

CMD = ["python3", "runtest.py"]
CMD = [sys.executable, "runtest.py"]
CMD.append("--wast2wasm")
CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD)
CMD.append("--interpreter")
Expand All @@ -161,6 +176,8 @@ def test_case(
CMD.append(IWASM_QEMU_CMD)
else:
CMD.append(IWASM_CMD)
if no_pty:
CMD.append("--no-pty")
CMD.append("--aot-compiler")
CMD.append(WAMRC_CMD)

Expand Down Expand Up @@ -261,6 +278,7 @@ def test_suite(
qemu_flag=False,
qemu_firmware='',
log='',
no_pty=False
):
suite_path = pathlib.Path(SPEC_TEST_DIR).resolve()
if not suite_path.exists():
Expand Down Expand Up @@ -302,6 +320,7 @@ def test_suite(
qemu_flag,
qemu_firmware,
log,
no_pty,
],
)

Expand Down Expand Up @@ -339,6 +358,7 @@ def test_suite(
qemu_flag,
qemu_firmware,
log,
no_pty,
)
successful_case += 1
except Exception as e:
Expand Down Expand Up @@ -460,6 +480,8 @@ def main():
nargs="*",
help=f"Specify all wanted cases. If not the script will go through all cases under {SPEC_TEST_DIR}",
)
parser.add_argument('--no-pty', action='store_true',
help="Use direct pipes instead of pseudo-tty")

options = parser.parse_args()
print(options)
Expand Down Expand Up @@ -490,6 +512,7 @@ def main():
options.qemu_flag,
options.qemu_firmware,
options.log,
options.no_pty
)
end = time.time_ns()
print(
Expand All @@ -512,7 +535,8 @@ def main():
options.gc_flag,
options.qemu_flag,
options.qemu_firmware,
options.log
options.log,
options.no_pty
)
else:
ret = True
Expand Down
Loading

0 comments on commit 68b6708

Please sign in to comment.