gnu tests: limit make jobs to nproc output - #13991
kevinburke wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes run-gnu-test.sh to correctly limit make parallelism by executing nproc, validating its output, and passing the job count via -j<N>. It also adds a regression test and updates CI to run all Python tests under util/.
Changes:
- Execute
nproc, validate numeric output, and append-j<JOBS>toMAKEFLAGSinutil/run-gnu-test.sh. - Add an end-to-end Python unittest that asserts the effective
MAKEFLAGScontains-j<N>and rejects invalidnprocoutput. - Update GitHub Actions to discover and run all
util/test_*.pyPython unit tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| util/test_run_gnu_test.py | Adds an end-to-end regression test covering MAKEFLAGS and invalid nproc output behavior. |
| util/run-gnu-test.sh | Fixes job count handling by executing nproc, validating the result, and forming -j<N> correctly. |
| .github/workflows/code-quality.yml | Expands CI to run all Python unit tests in util/ via unittest discovery. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Use GNU nproc for *BSD | ||
| NPROC=$(command -v ${path_GNU}/src/nproc||command -v nproc) | ||
| MAKEFLAGS="${MAKEFLAGS} -j ${NPROC}" | ||
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc) |
| return subprocess.run( | ||
| ["bash", str(RUN_GNU_TEST)], | ||
| cwd=REPO_ROOT, | ||
| env=env, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=10, |
|
|
||
| def run_script(self, nproc_output): | ||
| nproc = self.gnu_dir / "src" / "nproc" | ||
| nproc.write_text(f"#!/bin/sh\nprintf '%s\\n' '{nproc_output}'\n") |
faf2d37 to
9a825e3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
util/run-gnu-test.sh:38
- With
set -e, the script can exit without a clear error message when neither${path_GNU}/src/nprocis executable nornprocexists on PATH (and likewise if invoking nproc itself fails). Consider explicitly selecting an executable path (using-xfor the in-tree binary), handling the “not found” case, and checking the nproc exit status so failures are reported deterministically.
NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc)
JOBS=$("${NPROC_COMMAND}")
9a825e3 to
a7d375f
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc) | ||
| JOBS=$("${NPROC_COMMAND}") | ||
| case "${JOBS}" in | ||
| '' | 0 | *[!0-9]*) | ||
| echo "Error: '${NPROC_COMMAND}' returned an invalid job count: '${JOBS}'" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| MAKEFLAGS="${MAKEFLAGS:+${MAKEFLAGS} }-j${JOBS}" |
a7d375f to
0bb859b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
util/run-gnu-test.sh:42
- The job-count validation rejects
0but still accepts values like00/000(these are effectively zero and would re-enable unlimited make parallelism). Since the intent is to require a positive integer, tighten the check to only allow1..and digits.
JOBS=$("${NPROC_COMMAND}")
case "${JOBS}" in
'' | 0 | *[!0-9]*)
echo "Error: '${NPROC_COMMAND}' returned an invalid job count: '${JOBS}'" >&2
exit 1
;;
esac
|
GNU testsuite comparison: |
|
I don't think it is worth to have 100+ lines just for this. How about removing regression test which is unrelated with actual production? |
|
+1, please make this shorter |
0bb859b to
e7ba126
Compare
|
OK - @oech3 @sylvestre I agree, removed all of the Python tests, there wasn't a good, short way to write them. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
util/run-gnu-test.sh:35
util/build-gnu.shfalls back tognprocon platforms where GNU coreutils are prefixed (e.g., macOS/Homebrew). This updated lookup only checksnproc, sorun-gnu-test.shcan now hard-fail in environments that previously had a usablegnprocin PATH.
NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc || :)
if [ -z "${NPROC_COMMAND}" ] || [ ! -x "${NPROC_COMMAND}" ]; then
echo "Error: unable to find an executable nproc command at '${path_GNU}/src/nproc' or in PATH" >&2
exit 1
util/run-gnu-test.sh:45
- The PR description says an end-to-end regression test was added for the effective
MAKEFLAGS, but this PR only changesrun-gnu-test.shand there is no test coverage protecting the new-j$(nproc)behavior from regressing (e.g., back to-j <path-to-nproc>or bare-j). Please add an integration test that runsutil/run-gnu-test.shagainst a minimal fake GNU tree + fakemake, and asserts theMAKEFLAGSseen bymakeincludes-j<N>where<N>is the mockednprocoutput.
MAKEFLAGS="${MAKEFLAGS:+${MAKEFLAGS} }-j${JOBS}"
export MAKEFLAGS
echo "GNU test make job count: ${JOBS}"
|
@kevinburke thanks |
| if [ -z "${NPROC_COMMAND}" ] || [ ! -x "${NPROC_COMMAND}" ]; then | ||
| echo "Error: unable to find an executable nproc command at '${path_GNU}/src/nproc' or in PATH" >&2 | ||
| exit 1 | ||
| fi | ||
| JOBS=$("${NPROC_COMMAND}") | ||
| case "${JOBS}" in | ||
| '' | 0 | *[!0-9]*) | ||
| echo "Error: '${NPROC_COMMAND}' returned an invalid job count: '${JOBS}'" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac |
There was a problem hiding this comment.
| if [ -z "${NPROC_COMMAND}" ] || [ ! -x "${NPROC_COMMAND}" ]; then | |
| echo "Error: unable to find an executable nproc command at '${path_GNU}/src/nproc' or in PATH" >&2 | |
| exit 1 | |
| fi | |
| JOBS=$("${NPROC_COMMAND}") | |
| case "${JOBS}" in | |
| '' | 0 | *[!0-9]*) | |
| echo "Error: '${NPROC_COMMAND}' returned an invalid job count: '${JOBS}'" >&2 | |
| exit 1 | |
| ;; | |
| esac |
Assume that echo 2 always exist since it is builtin.
| # Use GNU nproc for *BSD | ||
| NPROC=$(command -v ${path_GNU}/src/nproc||command -v nproc) | ||
| MAKEFLAGS="${MAKEFLAGS} -j ${NPROC}" | ||
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc || echo 2) |
There was a problem hiding this comment.
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc || echo 2) | |
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc || echo "echo 2") |
There was a problem hiding this comment.
Actually, we only need to define $JOBS.
Head branch was pushed to by a user without write access
7326357 to
b8774c1
Compare
| NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc || echo 2) | ||
| if [ -z "${NPROC_COMMAND}" ] || [ ! -x "${NPROC_COMMAND}" ]; then | ||
| echo "Error: unable to find an executable nproc command at '${path_GNU}/src/nproc' or in PATH" >&2 | ||
| exit 1 | ||
| fi |
| MAKEFLAGS="${MAKEFLAGS:+${MAKEFLAGS} }-j${JOBS}" | ||
| export MAKEFLAGS | ||
| echo "GNU test make job count: ${JOBS}" |
b8774c1 to
8281bef
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
util/run-gnu-test.sh:44
- This change fixes incorrect
MAKEFLAGSconstruction and introduces new validation/error behavior, but the PR description also calls for an end-to-end regression test of the effectiveMAKEFLAGS/-jhandling. There doesn’t appear to be any test added in this PR for this behavior; per AGENTS.md, bug fixes/new behavior should come with a Rust test to prevent regression.
MAKEFLAGS="${MAKEFLAGS:+${MAKEFLAGS} }-j${JOBS}"
export MAKEFLAGS
echo "GNU test make job count: ${JOBS}"
| if NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc); then | ||
| JOBS=$("${NPROC_COMMAND}") | ||
| else | ||
| JOBS=2 | ||
| fi |
| # Use GNU nproc for *BSD | ||
| NPROC=$(command -v ${path_GNU}/src/nproc||command -v nproc) | ||
| MAKEFLAGS="${MAKEFLAGS} -j ${NPROC}" | ||
| if NPROC_COMMAND=$(command -v "${path_GNU}/src/nproc" || command -v nproc); then |
There was a problem hiding this comment.
We don't need to assume missing nproc binary as we use GNU's one.
| else | ||
| JOBS=2 | ||
| fi | ||
| case "${JOBS}" in |
There was a problem hiding this comment.
Believe existing nproc and remove this if block.
run-gnu-test.sh put the nproc executable path after a bare -j. GNU make treated -j as unlimited parallelism and the path as another target, oversubscribing the test runner. Resolve and execute nproc, fall back to two jobs if it is unavailable, reject invalid output, and attach the resulting count to -j.
8281bef to
cfcd890
Compare
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (8)
NPROC_COMMAND=$(command -v ... || command -v nproc)is executed underset -e. If neither… The PR description says this change adds an end-to-end regression test for the effective… · New Withset -eenabled,JOBS=$(${NPROC_COMMAND})will cause the script to exit immediately if…NPROC_COMMANDcurrently falls back toecho 2, but that produces a non-executable value and… The hard-codedtimeout=10seconds is likely to be flaky in slower CI environments if… If neither${path_GNU}/src/nprocnornprocis found,NPROC_COMMANDcan end up empty and line… The PR description mentions adding an end-to-end regression test for the effectiveMAKEFLAGS, but… This embedsnproc_outputinside single quotes in a shell script, which is brittle if future tests…
| exit 1 | ||
| ;; | ||
| esac | ||
| MAKEFLAGS="${MAKEFLAGS:+${MAKEFLAGS} }-j${JOBS}" |



run-gnu-test.shpassed thenprocexecutable path after a bare-j,which enabled unlimited make parallelism and treated the path as a target.
Execute
nproc, validate its output, and pass the count as an attached-jargument. Add an end-to-end regression test for the effective
MAKEFLAGS.