Repository navigation
Unit tests built once into one binary; customs@v0.3.1 - #141
Merged
Merged
Conversation
customs 0.3.1's mojo-build-per-test (magmalake/customs#7) reported the `test` task: 23 test files, each built into a binary of its own. The code they share (dista, its dependencies) compiled 23 times. scripts/test.sh (census's approach, morca-dev/census scripts/test.sh) builds 21 of them into build/tests/multicall-tests, with tests registered by name rather than found with __functions_in_module(), which is incomplete in an imported module. Each file still runs as its own process, through a link build/tests/<test>, and the number of tests it ran is checked against the `def test_*` found in it. `pixi run test-units` runs them all, and `test-codec` and the others run one file from the same binary. scripts/build-tests.sh builds the binary alongside the other two. Built on their own, as before: - tests/test_libc_abi.mojo: it must fail to build when dista's libc declarations clash with tcp's. In one binary a clash would break every test, or another file's declaration would hide it. - tests/test_head_loop.mojo: its main calls `signal(13, SIG_IGN)` with an integer handler, and dista.signals declares `signal` with a function. Mojo allows one signature per C symbol in a program, so the multicall build failed with "existing function with conflicting signature". - the data environment's test_parquet_tasks and test_iceberg_scan, which have their own tasks. Counts, per file, before and after on Linux x86-64 (sai) and macOS arm64: the same tests ran and passed in every file (175 tests). Co-Authored-By: Claude Opus <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017TycsxF3PkSX49fnv7cSZd
Contributor
Author
|
CI on this PR is green. In its logs, the unit tests ran 23 files, 181 tests run and 181 passed, in both The step times are not a clean comparison: this PR's runs restored main's compile cache, which holds per-file entries and not the new binary. The 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
customs 0.3.1 adds a new check,
mojo-build-per-test(magmalake/customs#7). On main it reportstest: 23 test files, each built into a binary of its own, so the code they share was compiled 23 times.This follows census's
scripts/test.sh:scripts/test.sh. It generates a main underbuild/multicall-gen/tests/(which customs skips) and builds 21 test files intobuild/tests/multicall-tests, throughscripts/mojo-build.shso the build cache still works.def test_*by name rather than using__functions_in_module(), which is incomplete in an imported module.build/tests/<test>to the one binary. After each file the script checks that the count of tests that ran matches itsdef test_*.pixi run test-unitsruns all 21. The task names CI and people call still work:test-codecand the others run one file from the same binary, andtestis unchanged for CI.scripts/build-tests.shbuilds the unit-test binary in parallel withtest-libc-abi,test-head-loopandbuild/dista.Built on their own, and why
tests/test_libc_abi.mojo: it is meant to fail at build time when dista's libc declarations clash with tcp's. In one binary, a clash would break every test, or another file's declaration could hide it.tests/test_head_loop.mojo: its main ignores SIGPIPE withsignal(13, SIG_IGN), which passes an integer as the handler, whiledista.signalsdeclaressignalwith a function. Mojo allows one signature per C symbol in a program, and the multicall build failed with "existing function with conflicting signature". It stays as it was.test_parquet_tasksandtest_iceberg_scan: they need the data environment and have their own tasks. Unchanged.With these,
testbuilds 2 test files on their own (plus the one binary), under customs' threshold of 3, so nowarnis needed.Tests run and passed per file, before and after
The same tests ran and passed in every file, 181 in all. (The commit message says 175; that is a miscount, the table is right.)
def test_sai, 16-core x86-64,pixi run test(default environment).pixi run test-<file>for each of the 23 before, andtest-units,test-libc-abiandtest-head-loopafter.Timings (empty Mojo compile cache and empty
build/each time)pixi run testbuild-tests+ the 23 unit-test tasks onlybuild-testsOn sai,
build-testsalready built the 23 binaries 9 at a time, so wall time hardly changes there, but CPU time halves. A runner with fewer cores, such as GitHub's 4-core one, should gain more, as the macOS row shows; this PR's CI step time is the check. The one binary builds in 116 s on sai and 39 s on macOS.Not checked
No changelog entry: this is test infrastructure, and nothing changes for a user.
🤖 Generated with Claude Code