testing/libc/arch_libc: Test every overridable string function. - #3706
Open
Fishwaldo wants to merge 1 commit into
Open
testing/libc/arch_libc: Test every overridable string function.#3706Fishwaldo wants to merge 1 commit into
Fishwaldo wants to merge 1 commit into
Conversation
Contributor
Author
|
The RISC-V series this suite was written for is now open as This PR remains independent of it: the suite is arch-neutral, passes against |
This test covered strcpy. A machine directory can override fourteen string and memory functions, and the mistakes such overrides actually make are specific: the word loop that works aligned and corrupts otherwise, the copy that runs past a guard byte, the overlap memmove must survive in both directions, the terminator that a length cap was supposed to beat, the sign of a comparison whose bytes wrap. So the new suite drives every function through every combination of source and destination offset within a register, twenty one sizes chosen to straddle every internal boundary, overlap at every distance up to a register width each way, terminators probed for by name, caps placed before, at and past differences, and guard bytes around every destination. A speed report follows, one line per scenario, measured through CLOCK_MONOTONIC. Two ways such a benchmark can quietly measure nothing are designed out, both learned by measuring nothing: the compiler will hoist a pure call whose arguments never change, so the pointers are laundered through an asm that claims to change them without disturbing the alignment under test; and an earlier scenario's writes can leave the compare buffers unequal, so equality is verified before the compare timings and the one scenario that needs shifted content prepares it explicitly after every clean reader has run. The suite is a separate source file behind its own option, on by default, and the program's exit status now says whether anything failed. The existing strcpy test is untouched, including its perf_gettime dependency, which configurations without hardware perf counters will want switched off. Assisted-by: Claude:claude-opus-5 Signed-off-by: Justin Hammond <justin@dynam.ac>
Fishwaldo
force-pushed
the
upstream-arch-libc-string
branch
from
August 9, 2026 04:33
542c585 to
555e43f
Compare
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.
Summary
testing/libc/arch_libccoveredstrcpy. A machine directory canoverride fourteen string and memory functions, and the mistakes such
overrides actually make are specific: the word loop that works aligned
and corrupts otherwise, the copy that runs past a guard byte, the overlap
memmovemust survive in both directions, the terminator a length capwas supposed to beat, the sign of a comparison whose bytes wrap.
and destination offset within a register, twenty one sizes chosen to
straddle every internal boundary, overlap at every distance up to a
register width each way, terminators probed for by name, caps placed
before, at and past differences, and guard bytes around every
destination. A speed report follows, one line per scenario, measured
through
CLOCK_MONOTONIC.both learned by measuring nothing: the compiler will hoist a pure call
whose arguments never change, so the pointers are laundered through an
asmthat claims to change them without disturbing the alignment undertest; and an earlier scenario's writes can leave the compare buffers
unequal, so equality is verified before the compare timings and the one
scenario that needs shifted content prepares it explicitly after every
clean reader has run.
and the program's exit status now says whether anything failed. The
existing
strcpytest is untouched, including itsperf_gettimedependency, which configurations without hardware performance counters
will want switched off.
and passes identically against the generic C library when nothing is
overridden.
optimisation series that adds ten functions and reworks two. That series
is a separate PR against
apache/nuttx, which I will link here in acomment as soon as it is open. This suite does not depend on it and
stands on its own; the RISC-V work depends on this suite for its evidence,
which is why it comes first.
Impact
A new test source behind
CONFIG_TESTING_ARCH_LIBC_STRING, default on.The existing
strcpytest is unchanged.enabled. The program's exit status now reflects failure, which is a
change only for anyone scripting the old always-zero behaviour.
the RISC-V work it was written for, and it detects deliberately injected
corruption, shown below.
Testing
I confirm that changes are verified on local setup and works as intended:
15.2.0
downstream board port not yet upstream) and RISC-V rv32 under QEMU
Run against the generic C library, with no machine-directory overrides, on
rv64 hardware:
Run against a fully overridden machine directory on the same rv64 hardware,
with the speed report and its repetition counts:
The same suite on rv32 under QEMU, including
strlcpy:A passing suite proves little on its own, so the detection was verified by
injecting a single-bit fault into an optimized
memcpy(xori t1, t1, 1added to its inner loop) and confirming the suite catches it:
576 detections from one flipped bit, with the neighbouring functions
correctly reporting clean. That last capture is from an earlier revision of
the harness, which covered
memcpy,memsetandstrcmpbefore the suitewas widened to the full set; it is included as evidence that the checks
detect corruption rather than as a run of the final code.
PR verification Self-Check
Claude (claude-opus-5) assisted with authoring this test suite, its code
comments and this PR description. The commit carries an
Assisted-by:tagper CONTRIBUTING.md §1.5.