Early Note: Don’t be scared by the PR’s line changes count — most of it’s just doc or part of the test framework API.
Context: Currently, all tests run single-threaded sequentially and the library lacks the ability to specify which test (or group of tests) you would like to run. This is not only inconvenient as more tests are added but also time consuming during development and affects downstream projects that may want to parallelize the workload (such as Bitcoin-Core CI).
PR Goal:
Introduce a lightweight, extensible C89 unit test framework with no dynamic memory allocations, providing a structured way to register, execute, and report tests. The framework supports named command-line arguments in -key=value
form, parallel test execution across multiple worker processes, granular test selection (selecting tests either by name or by module name), and time accumulation reports.
The introduced framework supports:
-help
or-h
: display list of available commands along with their descriptions.-jobs=<num>
: distribute tests across multiple worker processes (default: sequential if 0).-target=<name>
or-t=<name>
: run only specific tests by name; can be repeated to select multiple tests.-target=<module name>
,-t=<module>
Run all tests within a specific module (can be provided multiple times)-seed=<hex>
: set a specific RNG seed (defaults to random if unspecified).-iter=<n>
: specify the number of iterations.-print_tests
: display list of available tests and modules you can run.-log=<0|1>
: enable or disable test execution logging (default: 0 = disabled).
Beyond these features, the idea is to also make future developments smoother, as adding new tests require only a single entry in the central test registry, and new command-line options can be introduced easily by extending the framework’s parse_arg()
function.
Compatibility Note: The framework continues accepting the two positional arguments previously supported (iterations and seed), ensuring existing workflows remain intact.
Testing Notes:
Have fun. You can quickly try it through ./tests -j=<workers_num>
for parallel execution or ./tests -t=<test_name>
to run a specific test (call ./tests -print_tests
to display all available tests and modules).
Extra Note:
I haven’t checked the exhaustive tests file so far, but I will soon. For now, this only runs all tests declared in the tests
binary.
Testing Results: (Current master branch vs PR in seconds)
- Raspberry Pi 5: master ~100 s → PR ~38 s (5 jobs)
- MacBook Pro M1: master ~30 s → PR ~10 s (6 jobs)