-
Notifications
You must be signed in to change notification settings - Fork 16
add static build CI tests #1073
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,83 @@ | ||
| #!/usr/bin/env python3 | ||
| """Static build test harness. | ||
|
|
||
| Runs the unit tests under tests/unit-tests/static_tests/ compiled with the | ||
| --static flag so that static WASM binaries (no dynamic linking) are tested. | ||
| This is a thin wrapper around wasmtestreport.py that pre-sets the static | ||
| compilation flags. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import subprocess | ||
| import tempfile | ||
| from pathlib import Path | ||
| from typing import Any, Callable | ||
|
|
||
| SCRIPT_DIR = Path(__file__).resolve().parent | ||
| REPO_ROOT = SCRIPT_DIR.parents[1] | ||
| WASMTESTREPORT = SCRIPT_DIR / "wasmtestreport.py" | ||
|
|
||
| # Flags forwarded to wasmtestreport for static builds: | ||
| # --run static_tests : only run tests under static_tests/ | ||
| # --static : pass --static before source file in lind_compile | ||
| # --allow-pre-compiled : use .cwasm AOT binaries (consistent with dynamic harness) | ||
| # --compile-flags -pthread -lpthread : link pthread for thread/TLS tests | ||
| _STATIC_HARNESS_ARGS = [ | ||
| "--run", "static_tests", | ||
| "--static", | ||
| "--allow-pre-compiled", | ||
| "--compile-flags", "-pthread", "-lpthread", | ||
| ] | ||
|
|
||
|
|
||
| def run_harness( | ||
| forward_args: list[str] | None = None, | ||
| execute_with_echo: Callable[[list[str], Path, str], tuple[int, str]] | None = None, | ||
| ) -> dict[str, Any]: | ||
| """Run static tests via wasmtestreport.py and return a harness result dict.""" | ||
| with tempfile.TemporaryDirectory(prefix="harness_statictestreport_") as tmpdir: | ||
| tmp_path = Path(tmpdir) | ||
| json_out = tmp_path / "static.json" | ||
| html_out = tmp_path / "static.html" | ||
|
|
||
| args = [ | ||
| "python3", str(WASMTESTREPORT), | ||
| *_STATIC_HARNESS_ARGS, | ||
| "--output", str(json_out), | ||
| "--report", str(html_out), | ||
| ] | ||
| if forward_args: | ||
| args.extend(forward_args) | ||
|
|
||
| if execute_with_echo is not None: | ||
| return_code, combined_output = execute_with_echo(args, REPO_ROOT, "statictestreport") | ||
| if return_code != 0: | ||
| raise RuntimeError( | ||
| "statictestreport (wasmtestreport --static) failed " | ||
| f"with exit code {return_code}.\nCombined output:\n{combined_output}" | ||
| ) | ||
| else: | ||
| proc = subprocess.run( | ||
| args, | ||
| capture_output=True, | ||
| text=True, | ||
| cwd=REPO_ROOT, | ||
| ) | ||
| if proc.returncode != 0: | ||
| raise RuntimeError( | ||
| "statictestreport (wasmtestreport --static) failed " | ||
| f"with exit code {proc.returncode}.\n" | ||
| f"STDOUT:\n{proc.stdout}\nSTDERR:\n{proc.stderr}" | ||
| ) | ||
|
|
||
| report_data = json.loads(json_out.read_text(encoding="utf-8")) | ||
| html_data = html_out.read_text(encoding="utf-8") | ||
|
|
||
| return { | ||
| "name": "static", | ||
| "json_filename": "static.json", | ||
| "report": report_data, | ||
| "html": html_data, | ||
| } | ||
|
Member
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. Can we rename this file to dynamic related?
Contributor
Author
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. this test runner invokes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <assert.h> | ||
| #include <stdlib.h> | ||
| #include <sys/wait.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main() | ||
| { | ||
| pid_t cpid; | ||
| cpid = fork(); | ||
| assert(cpid >= 0); | ||
|
|
||
| if (cpid == 0) { | ||
| exit(0); | ||
| } else { | ||
| int status; | ||
| pid_t waited_pid = waitpid(cpid, &status, 0); | ||
| assert(waited_pid >= 0); | ||
| assert(WIFEXITED(status)); | ||
| assert(WEXITSTATUS(status) == 0); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include <pthread.h> | ||
| #include <stdio.h> | ||
|
|
||
| void* thread_function(void* arg) { | ||
| printf("Hello from thread\n"); | ||
| return NULL; | ||
| } | ||
|
|
||
| int main() { | ||
| pthread_t thread; | ||
| pthread_create(&thread, NULL, thread_function, NULL); | ||
| pthread_join(thread, NULL); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include <assert.h> | ||
| #include <pthread.h> | ||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
|
|
||
| __thread int tls_var = 233; | ||
|
|
||
| #define NUM_THREADS 5 | ||
|
|
||
| void* thread_function(void* arg) { | ||
| int thread_id = *((int*)arg); | ||
| assert(tls_var == 233); | ||
| tls_var = thread_id * 10; | ||
| assert(tls_var == thread_id * 10); | ||
| return NULL; | ||
| } | ||
|
|
||
| int main() { | ||
| pthread_t threads[NUM_THREADS]; | ||
| int thread_ids[NUM_THREADS]; | ||
|
|
||
| for (int i = 0; i < NUM_THREADS; i++) { | ||
| thread_ids[i] = i + 1; | ||
| pthread_create(&threads[i], NULL, thread_function, &thread_ids[i]); | ||
| } | ||
|
|
||
| for (int i = 0; i < NUM_THREADS; i++) { | ||
| pthread_join(threads[i], NULL); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
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.
Since this harness now owns
static_tests, should we also excludestatic_testsfrom the defaultwasmtestreportrun? As written, I believe the normal wasm harness still discovers alltests/unit-tests/**/*.c, so these tests look like they’ll run once as dynamic-build tests and again here as static-build tests. Would it make sense to add a small guard near the existingif module_name == "wasmtestreport":block, perhaps appending a flag?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.
just resolved this, could you take a look again