From: Jannis Harder Date: Tue, 5 Jul 2022 13:34:27 +0000 (+0200) Subject: tests: Windows fixes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ea7fc7dc2c0d7eea25dabe06beba6ebe56d58c7d;p=SymbiYosys.git tests: Windows fixes Make tests runnable on Windows, as long as a unix like environment as e.g. provided by MSYS2 is available. --- diff --git a/tests/Makefile b/tests/Makefile index 9b65da7..805d190 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,11 +2,27 @@ test: .PHONY: test clean refresh help +OS_NAME := $(shell python3 -c "import os;print(os.name)") +ifeq (nt,$(OS_NAME)) +ifeq (quoted,$(shell echo "quoted")) +OS_NAME := nt-unix-like +endif +endif + +ifeq (nt,$(OS_NAME)) +$(error This Makefile requires unix-like tools and shell, e.g. MSYS2.) +endif + help: @cat make/help.txt -export SBY_WORKDIR_GITIGNORE=1 -export SBY_MAIN=$(realpath $(dir $(firstword $(MAKEFILE_LIST)))/../sbysrc/sby.py) +export SBY_WORKDIR_GITIGNORE := 1 + +SBY_MAIN := $(realpath $(dir $(firstword $(MAKEFILE_LIST)))/../sbysrc/sby.py) +ifeq (nt-unix-like,$(OS_NAME)) +SBY_MAIN := $(shell cygpath -w $(SBY_MAIN)) +endif +export SBY_MAIN make/rules/collect.mk: make/collect_tests.py python3 make/collect_tests.py diff --git a/tests/make/collect_tests.py b/tests/make/collect_tests.py index 89a68ec..b5f7699 100644 --- a/tests/make/collect_tests.py +++ b/tests/make/collect_tests.py @@ -4,7 +4,8 @@ import re tests = [] checked_dirs = [] -SAFE_PATH = re.compile(r"^[a-zA-Z0-9_./]*$") +SAFE_PATH = re.compile(r"^[a-zA-Z0-9_./\\]*$") + def collect(path): # don't pick up any paths that need escaping nor any sby workdirs @@ -15,8 +16,6 @@ def collect(path): for entry in path.glob("*.sby"): filename = str(entry) if not SAFE_PATH.match(filename): - continue - if not re.match(r"^[a-zA-Z0-9_./]*$", filename): print(f"skipping {filename!r}, use only [a-zA-Z0-9_./] in filenames") continue tests.append(entry) @@ -25,6 +24,10 @@ def collect(path): collect(entry) +def unix_path(path): + return "/".join(path.parts) + + collect(Path(".")) collect(Path("../docs/examples")) @@ -33,16 +36,18 @@ out_file.parent.mkdir(exist_ok=True) with out_file.open("w") as output: - for checked_dir in checked_dirs: print(f"{out_file}: {checked_dir}", file=output) for test in tests: - print(f"make/rules/test/{test}.mk: {test}", file=output) + test_unix = unix_path(test) + print(f"make/rules/test/{test_unix}.mk: {test_unix}", file=output) for ext in [".sh", ".py"]: script_file = test.parent / (test.stem + ext) if script_file.exists(): - print(f"make/rules/test/{test}.mk: {script_file}", file=output) - print(f"make/rules/test/{test}.mk: make/test_rules.py", file=output) + script_file_unix = unix_path(script_file) + print(f"make/rules/test/{test_unix}.mk: {script_file_unix}", file=output) + print(f"make/rules/test/{test_unix}.mk: make/test_rules.py", file=output) for test in tests: - print(f"-include make/rules/test/{test}.mk", file=output) + test_unix = unix_path(test) + print(f"-include make/rules/test/{test_unix}.mk", file=output) diff --git a/tests/make/test_rules.py b/tests/make/test_rules.py index 5c18aca..9607d81 100644 --- a/tests/make/test_rules.py +++ b/tests/make/test_rules.py @@ -7,6 +7,11 @@ from pathlib import Path from required_tools import REQUIRED_TOOLS + +def unix_path(path): + return "/".join(path.parts) + + sby_file = Path(sys.argv[1]) sby_dir = sby_file.parent @@ -56,7 +61,10 @@ with rules_file.open("w") as rules: solvers.add(solver) engine_solvers.add((engine, solver)) - if any(line.startswith("read -verific") or line.startswith("verific") for line in info["script"]): + if any( + line.startswith("read -verific") or line.startswith("verific") + for line in info["script"] + ): required_tools.add("verific") required_tools = sorted(required_tools) @@ -66,12 +74,17 @@ with rules_file.open("w") as rules: shell_script = sby_dir / f"{sby_file.stem}.sh" + sby_dir_unix = unix_path(sby_dir) + if shell_script.exists(): - command = f"cd {sby_dir} && SBY_FILE={sby_file.name} WORKDIR={workdirname} TASK={task} bash {shell_script.name}" + command = f"cd {sby_dir_unix} && env SBY_FILE={sby_file.name} WORKDIR={workdirname} TASK={task} bash {shell_script.name}" else: - command = f"cd {sby_dir} && python3 $(SBY_MAIN) -f {sby_file.name} {task}" + command = f"cd {sby_dir_unix} && python3 $(SBY_MAIN) -f {sby_file.name} {task}" - print(f"\t@python3 make/required_tools.py run {target} {shlex.quote(command)} {shlex.join(required_tools)}", file=rules) + print( + f"\t@python3 make/required_tools.py run {target} {shlex.quote(command)} {shlex.join(required_tools)}", + file=rules, + ) print(f".PHONY: clean-{target}", file=rules) print(f"clean-{target}:", file=rules)