Repository navigation
test/units: make the unit tests a usable framework - #8035
Conversation
Report every unit build and test as a TAP line with failure details, and exit nonzero when any of them fails. Ignore the test/units/out build directory. Previously run_unit.py always exited 0: a nonzero test exit code was not counted as a failure and a unit that failed to build was skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A unit can now list real source files to compile unchanged under "sources:", extra include directories under "include:", and shim directories under "shim:". Shim directories in test/units/shim/ hold small stand-ins for headers such as mpl.h and are searched first, so the sources build without autogen or configure. A test can use "expect_err:" to expect a failing exit with a message in its output, and "$top_srcdir" in its command to refer to files in the tree. Previously a unit could only test functions copied out of a source file between START UNIT and END UNIT markers, along with hand-written copies of whatever they depend on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build units with -g -Wall, plus -fsanitize=address,undefined when a probe program builds and runs with it. A sanitizer report fails the test. --no-sanitize turns sanitizers off and UNIT_CFLAGS adds extra flags. Build warnings are shown under the build line. Fix what this exposes: the rankmap driver leaked the returned string, and the slurm unit's HYDU_ERR_POP returned instead of jumping to fn_fail like the real macro. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
node_markers has one entry per node id from min_id to max_id, so index it by node id minus min_id everywhere. Previously two places indexed it by the raw node id, writing past the end of the array when the smallest node id in the map was not 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run each test command in its own process group and kill the group if it runs longer than --timeout seconds (default 60), reporting the test as failed. Previously a test that never finished hung the whole run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge the two rankmap units into mpl_rankmap.unit, which compiles src/mpl/src/mpl_rankmap.c as-is against a stand-in mpl.h in test/units/shim/mpl, and drop the now unused START UNIT/END UNIT markers from that file. Add cases for malformed mapping strings and round-trip checks that array2str output parses back to the same map. Previously the units copied the functions out between the markers along with hand-written definitions of MPL_malloc and the error codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lines indented deeper than "expect:" continue the expected output, so a test can check output of several lines. Trailing whitespace on each line is ignored when comparing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a shim for mpiimpl.h in test/units/shim/core, with the MPIR_ERR_ macros recording their message in unit_last_error, and use it to test src/mpi/coll/algorithms/circ_graph/circ_graph.c. The test prints the p = 17 schedules to compare with the example in the source comment, and simulates a bcast for every p up to 32 with up to 40 blocks, checking that sends match receives, that a process only sends blocks it already has, and that every process ends up with every block. It also checks that MPII_circ_graph_create_all agrees with MPII_circ_graph_create. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PlanThe plan this PR was developed from, including the design decisions and what the new tests found. plan.mdPlan: unit testing framework for MPICH internals (
|
"make unit-testing" runs test/units/run_unit.py with the configured compiler. run_unit.py now builds each unit in its own subdirectory of test/units/out under the current directory, creating it as needed, so an out-of-tree build keeps the build products in the build tree. When started from test/units itself, it builds in test/units/out as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe test/units in doc/wiki/testing/Unit_Tests.md: when to write a unit test, how to run it with make unit-testing or run_unit.py, the .unit format, shims, and writing a driver. Link it from Index.md and Writing_New_Tests.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --junit FILE, run_unit.py also writes the results as JUnit XML, a test suite per unit and a test case per TAP line, with the failure details and build warnings. CI can publish it like the test/mpi results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fe0b971 to
85aab0c
Compare
|
test:mpich/unit-testing |
The runner captures probe output with stdout/stderr pipes, which Python 3.6 supports, and adds -std=gnu99 when the compiler does not accept C99 code by default. Previously it failed on CentOS 7, whose Python 3.6 lacks capture_output and whose gcc 4.8 defaults to C89. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pull Request Description
test/unitscan test internal routines without building MPICH, but its runner always exited 0, nothing ran it, and a unit could only test functions copied out of a source file along with hand-written copies of their dependencies.This PR makes it a usable framework:
make unit-testing, orpython3 test/units/run_unit.pybefore autogen/configure.--timeout).--junit FILEalso writes JUnit XML for CI result publishers.sources:compiles real source files unchanged against small header shims intest/units/shim/(mpl,core), so units need no generated headers.doc/wiki/testing/Unit_Tests.md.Found by the new tests:
MPL_rankmap_array_to_strwrote past an array when the smallest node id is not 0; fixed here.Author Checklist
Particularly focus on why, not what. Reference background, issues, test failures, xfail entries, etc.
Commits are self-contained and do not do two things at once.
Commit message is of the form:
module: short descriptionCommit message explains what's in the commit.
Whitespace checker. Warnings test. Additional tests via comments.
For non-Argonne authors, check contribution agreement.
If necessary, request an explicit comment from your companies PR approval manager.
🤖 Generated with Claude Code