diff --git a/docs/markdown/Unit-tests.md b/docs/markdown/Unit-tests.md index b5d3a1b81..898366095 100644 --- a/docs/markdown/Unit-tests.md +++ b/docs/markdown/Unit-tests.md @@ -89,6 +89,10 @@ variable `MESON_TESTTHREADS` like this. $ MESON_TESTTHREADS=5 meson test ``` +Setting `MESON_TESTTHREADS` to 0 enables the default behavior (core +count), whereas setting an invalid value results in setting the job +count to 1. + ## Priorities *(added in version 0.52.0)* diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 9975afa22..c417bc0b3 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -99,13 +99,17 @@ def uniwidth(s: str) -> int: def determine_worker_count() -> int: varname = 'MESON_TESTTHREADS' + num_workers = 0 if varname in os.environ: try: num_workers = int(os.environ[varname]) + if num_workers < 0: + raise ValueError except ValueError: print(f'Invalid value in {varname}, using 1 thread.') num_workers = 1 - else: + + if num_workers == 0: try: # Fails in some weird environments such as Debian # reproducible build.