-
Notifications
You must be signed in to change notification settings - Fork 0
Adding more tests #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env python3 | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| import tempfile | ||
| import shutil | ||
|
|
||
| ZPILER = Path("/home/xzist/zust/build/zpiler") | ||
| TESTS_DIR = Path("/home/xzist/zust/tests") | ||
| RUNTIME_DIR = TESTS_DIR / "runtime" | ||
| EXPECTED_DIR = TESTS_DIR / "expected" / "runtime" | ||
|
|
||
| def run_command(cmd, check=True): | ||
| result = subprocess.run(cmd, capture_output=True, text=False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. Source: opengrep |
||
| if check and result.returncode != 0: | ||
| print(f"Command failed: {' '.join(cmd)}") | ||
| print(f"stdout: {result.stdout.decode()}") | ||
| print(f"stderr: {result.stderr.decode()}") | ||
| sys.exit(1) | ||
| return result | ||
|
|
||
| def generate_outputs_for_test(test_file): | ||
| """Generate expected outputs for a single test file""" | ||
| rel_path = test_file.relative_to(RUNTIME_DIR) | ||
| expected_dir = EXPECTED_DIR / rel_path.parent | ||
| expected_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| test_name = test_file.stem | ||
|
|
||
| # Compile to assembly | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| tmpdir = Path(tmpdir) | ||
| asm_file = tmpdir / f"{test_name}.s" | ||
| obj_file = tmpdir / f"{test_name}.o" | ||
| exe_file = tmpdir / f"{test_name}" | ||
|
|
||
| # Compile | ||
| print(f"Compiling {rel_path}...", end=" ") | ||
| result = run_command([str(ZPILER), "--format", "x86_64-linux", "-o", str(asm_file), str(test_file)], check=False) | ||
| if result.returncode != 0: | ||
| print(f"FAILED to compile") | ||
| return False | ||
|
|
||
| # Assemble | ||
| result = run_command(["as", str(asm_file), "-o", str(obj_file)], check=False) | ||
| if result.returncode != 0: | ||
| print(f"FAILED to assemble") | ||
| return False | ||
|
Comment on lines
+39
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Surface more diagnostic info when compile/assemble/link steps fail Because Suggested implementation: # Compile
print(f"Compiling {rel_path}...", end=" ")
result = run_command(
[str(ZPILER), "--format", "x86_64-linux", "-o", str(asm_file), str(test_file)],
check=True,
)
if result.returncode != 0:
print("FAILED to compile")
return False
# Assemble
result = run_command(["as", str(asm_file), "-o", str(obj_file)], check=True)
if result.returncode != 0:
print("FAILED to assemble")
return False
# Link
result = run_command(["gcc", str(obj_file), "-o", str(exe_file)], check=True)
if result.returncode != 0:
print("FAILED to link")
return Falsedef run_command(cmd, check=True):
result = subprocess.run(cmd, capture_output=True, text=False)
if check and result.returncode != 0:
print(f"Command failed: {' '.join(cmd)}")
if result.stdout:
print(f"stdout:\n{result.stdout.decode(errors='replace')}")
if result.stderr:
print(f"stderr:\n{result.stderr.decode(errors='replace')}")If import subprocessnear the other imports. |
||
|
|
||
| # Link | ||
| result = run_command(["gcc", str(obj_file), "-o", str(exe_file)], check=False) | ||
| if result.returncode != 0: | ||
| print(f"FAILED to link") | ||
| return False | ||
|
|
||
| # Run | ||
| result = run_command([str(exe_file)], check=False) | ||
|
|
||
| # Save outputs | ||
| stdout_file = expected_dir / f"{test_name}.stdout" | ||
| stderr_file = expected_dir / f"{test_name}.stderr" | ||
| exitcode_file = expected_dir / f"{test_name}.exitcode" | ||
|
|
||
| stdout_file.write_bytes(result.stdout) | ||
| stderr_file.write_bytes(result.stderr) | ||
| exitcode_file.write_bytes(str(result.returncode).encode()) | ||
|
|
||
| print(f"OK (exit code: {result.returncode})") | ||
| return True | ||
|
|
||
| def main(): | ||
| # Find all .zz files in runtime directory | ||
| test_files = sorted(RUNTIME_DIR.rglob("*.zz")) | ||
|
|
||
| success_count = 0 | ||
| fail_count = 0 | ||
|
|
||
| for test_file in test_files: | ||
| if generate_outputs_for_test(test_file): | ||
| success_count += 1 | ||
| else: | ||
| fail_count += 1 | ||
|
|
||
| print(f"\nGenerated outputs for {success_count} tests, {fail_count} failed") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| true | ||
| false | ||
| false | ||
| true | ||
| false | ||
| true | ||
| false | ||
| true | ||
| true | ||
| true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 1 | ||
| 1 | ||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 1 | ||
| 6 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 10 | ||
| 20 | ||
| 27 | ||
| 15 | ||
| 20 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 5 | ||
| 10 | ||
| 17 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 10 | ||
| 8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 3 | ||
| 4 | ||
| 5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 5 | ||
| 30 | ||
| 15 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 15 | ||
| 9 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 3 | ||
| 8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 15 | ||
| 30 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| true | ||
| false | ||
| true | ||
| false | ||
| true | ||
| true | ||
| false | ||
| false | ||
| true | ||
| true | ||
| true | ||
| true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 1 | ||
| 2 | ||
| 6 | ||
| 24 | ||
| 120 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 0.100000 | ||
| 0.200000 | ||
| 0.300000 | ||
| 0.300000 | ||
| 0.020000 | ||
| 1.234568 | ||
| 9.876543 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 10 | ||
| 11 | ||
| 12 | ||
| 20 | ||
| 19 | ||
| 18 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 13.500000 | ||
| 15.200000 | ||
| 7.000000 | ||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Hello | ||
| World |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -9000000 | ||
| 8000000 | ||
| 2.500000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 255 | ||
| 0 | ||
| 100 | ||
| -42 | ||
| 42 | ||
| 0 | ||
| -84 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0 | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| DO_NOT_USE_SHARED_VARIABLES_STDOUT | ||
| It is what it is |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 0 | ||
| 0 | ||
| 0 | ||
| 10 | ||
| 20 | ||
| 30 | ||
| 50 | ||
| 40 | ||
| 2000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 100 | ||
| 50 | ||
| 100 | ||
| 10 | ||
| 20 | ||
| 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Avoid hardcoded absolute paths to make the script portable within the repo
Using
/home/xzist/...makes this script unusable outside your machine and likely to fail in CI. Instead, derive these paths relative to this file (e.g. viaPath(__file__).resolve()to the repo root, then intobuild/zpilerandtests) so it works for all environments.