| # WebAssembly Debugger Test Framework |
| |
| A simplified, high-performance testing framework for WebAssembly debugging functionality in WebKit's JavaScriptCore with intelligent parallel execution. |
| |
| ## ๐๏ธ Architecture |
| |
| ### Sequential Mode (Default) |
| |
| **Single Test Execution**: One test at a time using port 12340 |
| |
| ```txt |
| Framework Process (PID: 12345): |
| โโโ Main Thread (TID: 100) - coordinates execution |
| โโโ Per Test: |
| โโโ JSC Process (PID: 12346) |
| โโโ LLDB Process (PID: 12347) |
| โโโ 4 Monitor Threads (TIDs: 101-104): JSC stdout/stderr, LLDB stdout/stderr |
| |
| Total: 3 Processes, 5 Threads per test |
| Simple, reliable execution for debugging individual tests |
| ``` |
| |
| ### Parallel Mode (`--parallel`) |
| |
| **Multi-Worker Execution**: ThreadPoolExecutor with smart worker calculation |
| |
| - Each worker = thread that runs one test case |
| - Each worker gets unique port and ProcessManager |
| - I/O-bound optimization: More workers than CPU cores for better utilization |
| |
| **Example: 3 Tests, 2 Workers** |
| |
| ```txt |
| Framework Process (PID: 12345): |
| โโโ Main Thread (TID: 100) - coordinates execution |
| โโโ Worker Thread 1 (TID: 101) - TestA (Port: 12340) |
| โ โโโ JSC Process (PID: 12346) |
| โ โโโ LLDB Process (PID: 12347) |
| โ โโโ 4 Monitor Threads (TIDs: 103-106): JSC stdout/stderr, LLDB stdout/stderr |
| โโโ Worker Thread 2 (TID: 102) - TestB (Port: 12341) |
| โโโ JSC Process (PID: 12348) |
| โโโ LLDB Process (PID: 12349) |
| โโโ 4 Monitor Threads (TIDs: 107-110): JSC stdout/stderr, LLDB stdout/stderr |
| |
| Peak Concurrent: 5 Processes, 11 Threads |
| Total Used: 7 Processes, 15 Threads (when TestA finishes, Worker 1 picks up TestC) |
| ``` |
| |
| ### Framework Structure |
| |
| ```txt |
| lib/ |
| โโโ core/ # Core framework components |
| โ โโโ base.py # BaseTestCase with pattern matching |
| โ โโโ environment.py # WebKit environment setup |
| โ โโโ registry.py # Test case registry |
| โ โโโ utils.py # Logging with PID/TID support |
| โโโ discovery/ # Test discovery system |
| โ โโโ auto_discovery.py # Automatic test case discovery |
| โโโ runners/ # Test execution engines |
| โโโ sequential.py # Sequential test runner |
| โโโ parallel.py # Parallel test execution |
| โโโ process_manager.py # Per-test process isolation |
| tests/ # Auto-discovered test cases |
| โโโ add.py # WebAssembly debugging tests |
| โโโ ... # Additional test cases |
| ``` |
| |
| ## ๐งช Writing Test Cases |
| |
| Create file in `tests/my_test.py` |
| |
| ```python |
| from lib.core.base import BaseTestCase |
| |
| class MyTestCase(BaseTestCase): |
| def execute(self): |
| # Setup debugging session (JSC + LLDB) |
| self.setup_debugging_session_or_raise("resources/c-wasm/add/main.js") |
| |
| # Send LLDB commands |
| self.send_lldb_command_or_raise("b main") |
| self.send_lldb_command_or_raise("c") |
| |
| # Validate results |
| self.send_lldb_command_or_raise("dis") |
| ``` |
| |
| **Auto-Discovery**: Test automatically appears in `--list` and runs with framework. No manual registration required. |
| |
| ## ๐ Requirements |
| |
| ### LLDB Configuration |
| |
| The test framework requires a **TOT (Tip of Tree) built LLDB** with WebAssembly debugging support, not the system LLDB. The LLDB path is hardcoded in [`lib/core/environment.py`](lib/core/environment.py): |
| |
| ```python |
| hardcoded_lldb = "/Users/yijiahuang/git/WebKit/llvm/build/bin/lldb" |
| ``` |
| |
| **Why TOT LLDB is Required:** |
| - System LLDB lacks the latest WebAssembly debugging features |
| - TOT LLDB includes WebAssembly plugin support (`--plugin wasm`) |
| - Custom LLDB build ensures compatibility with WebKit's WASM debugging protocol |
| |
| **Fallback Behavior:** |
| - If the hardcoded path doesn't exist, the framework falls back to system `lldb` |
| - Tests may fail with system LLDB due to missing WebAssembly debugging capabilities |
| |
| To build the required LLDB, follow the WebKit LLVM build instructions. |
| |
| ## ๐ Quick Start |
| |
| ```bash |
| # Run all tests (sequential) |
| python3 test-wasm-debugger.py |
| |
| # Run all tests in parallel (auto-detects optimal workers) |
| python3 test-wasm-debugger.py --parallel |
| |
| # Run with specific number of parallel workers |
| python3 test-wasm-debugger.py --parallel=4 |
| |
| # Run specific test with verbose logging |
| python3 test-wasm-debugger.py --test AddTestCase --verbose |
| |
| # List all available tests |
| python3 test-wasm-debugger.py --list |
| |
| # Use specific build configuration |
| python3 test-wasm-debugger.py --debug # Force Debug build |
| python3 test-wasm-debugger.py --release # Force Release build |
| ``` |