Skip to content

feat: Phase 3 — implement --max-output-len, --cmd/--cmd-exclude, thread safety, graceful Ctrl+C#7

Merged
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:phase3
Mar 9, 2026
Merged

feat: Phase 3 — implement --max-output-len, --cmd/--cmd-exclude, thread safety, graceful Ctrl+C#7
haugoug merged 1 commit intogvsoc:mainfrom
germainh512:phase3

Conversation

@germainh512
Copy link

Summary

Four improvements that fix long-standing gaps and harden the runner.

1. Implement --max-output-len

The flag was accepted by argparse but never enforced. Now caps test output at the specified byte limit with a notice appended:

--- Output truncated at 200 bytes ---

2. Implement --cmd / --cmd-exclude

Both flags were accepted but ignored. Now:

  • --cmd run runs only the command named run within each test
  • --cmd-exclude clean skips the clean command in every test

Useful for skipping build steps when iterating on run/check logic.

3. Thread safety for pending_tests

enqueue_test() now holds the runner lock when modifying pending_tests and nb_pending_tests. check_pending_tests() holds the lock when popping. Prevents a race between the main thread and workers.

4. Graceful Ctrl+C

  • First Ctrl+C clears pending tests, prints a message, and lets currently-running tests finish
  • Second Ctrl+C restores original handler and raises KeyboardInterrupt (force exit)
  • Worker threads are now daemon=True so they exit cleanly with the process

5. __init__.py

Added with public API docstring.

Tests

122 tests, all passing. Real-world testsuite (12/12) verified.

1. Implement --max-output-len (was accepted but ignored)
   Output is now capped at the specified byte limit with a truncation
   notice appended. Tracked via _output_truncated flag per test run.

2. Implement --cmd / --cmd-exclude (were accepted but ignored)
   Commands within a test can now be filtered by name. --cmd runs only
   the named commands; --cmd-exclude skips named commands.

3. Fix thread safety for pending_tests list
   enqueue_test() now holds the lock when modifying pending_tests and
   nb_pending_tests. check_pending_tests() holds the lock when popping.

4. Graceful Ctrl+C handling
   SIGINT installs a handler that clears pending_tests and signals the
   run event so the main thread unblocks. A second Ctrl+C forces exit.
   Worker threads are now daemon threads so they exit with the process.

5. Add __init__.py with public API docstring

122 tests, all passing. Real-world testsuite (12/12) verified.
@haugoug haugoug merged commit fac1a01 into gvsoc:main Mar 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants