Skip to content

test: sweep the decode paths a single instantiation leaves unrun (77% -> 93%) - #113

Merged
Andste82 merged 1 commit into
mainfrom
test/decode-path-coverage
Aug 9, 2026
Merged

Andste82 merged 1 commit into
mainfrom
test/decode-path-coverage

Conversation

@Andste82

@Andste82 Andste82 commented Aug 9, 2026

Copy link
Copy Markdown
Member

What

gcovr reported 77.1 % line coverage of include/sofab/sofab.hpp. Almost all of
the gap had one shape: the header is templates, gcov counts every instantiation
separately, and a case written once for one destination type leaves the same case
unexecuted for every other one. The additions here are therefore swept rather
than enumerated — written once, run per type.

metric before after
lines 77.1 % (3334/4323) 93.4 % (4539/4859)
functions 90.2 % 99.7 %
branches 52.0 % 67.6 %

Measured with this repo's own tooling, exactly as .github/workflows/coverage.yaml
runs it.

The four sweeps

  • arrayDecodeSweep() — readArray / readIntElements driven through the whole
    §7 decision matrix, per element type and destination shape: the tag (§7.3), the
    declared count (§7.1 → INVALID), the configured policy cap (generator#102 →
    LimitExceeded, deliberately not INVALID), the destination's own capacity
    (issue MESSAGE_SPEC 3: readArray silently truncates an unbounded array to the destination's capacity and still reports COMPLETE #81, including which of the two verdicts it earns), the declared element
    width applied per element, a >64-bit varint (§4.1) both in a stored element and out
    in the surplus, a payload cut mid-array and cut inside an element's varint — and
    each of them again one byte at a time, which is what runs the checked element loops
    instead of the windowed ones.
  • checkStreamReuse<M>() — destinationReuse() pinned reset() for one message
    type. IStreamObject::reset() is a template that re-initialises the owned message,
    so every message type the suite declares now gets the contract checked on its own
    instantiation: the buffered partial field dropped, the latched terminal INVALID
    cleared (§5.2 — terminal for the message, not for the object).
  • chunkIndependence() — §7.2 item 4. Real messages (every wrapper-array
    collector and both nesting forms in one, a nested sub-message field, a gapped
    sub-message array, every scalar wire form, a varint array and a fixlen array) fed at
    every split point and one byte at a time, each restart landing on the same
    values. A cut inside a sub-message abandons the level where it began and the whole
    top-level field is re-delivered, and that restart is instantiated per callback type.
  • utf8AcrossChunkBoundaries() — the known gap. The shared invalid_utf8 vectors
    never place the invalid sequence at a chunk offset at or beyond the total fed so
    far; a validator that only looks at the bytes in hand, or resumes a payload from the
    wrong offset, reports COMPLETE there. Swept over both destination kinds
    (std::string and the heap-free FixedString), with the blob payload and the
    skipped string as the controls §6.4 exempts, and a valid 4-byte sequence in the same
    position as the control that says the verdict comes from the bytes and not from the
    chunking.

What is still uncovered, and why

The remaining ~6.6 % is dominated by code that is dead per instantiation and cannot
be reached by feeding bytes:

  • dispatchLevel's element-index bound (elemBound_ >= 0 && elemWire_ >= 0) in a
    dispatch instantiated for a callback that publishes neither — a plain nested message
    sets both to −1 before descending;
  • its SequenceEnd reject, which only fires with stopAtEnd == false, i.e. only in
    the top-level instantiation;
  • the MAX_DEPTH guard in read<T> for every message type that is not the one
    maxDepth() nests 255 deep;
  • the fixlen branch of readArray's grow clamp in the instantiations whose element
    type is never fixlen-framed.

Padding those would mean 255-deep wires per message type and collectors declared only
to reach a branch, which is not worth having.

Notes

  • No library change: include/sofab/sofab.hpp is untouched. Every new check passes on
    main's header — they cover behaviour that was right and untested.
  • Green locally on GCC 15 (Debug + Release), Clang 21 (Release) and the coverage
    build; the fixlen-array test wire is written little-endian explicitly, so the
    big-endian ppc64 leg sees the same bytes.
  • README's test_roundtrip description gained a paragraph on the four sweeps.

… -> 93%)

gcovr reported 77.1% line coverage of include/sofab/sofab.hpp. Almost all of
the gap was one shape of hole: the header is templates, gcov counts every
instantiation separately, and a case written once for one destination type
leaves the same case unexecuted for every other one. So the additions here are
swept rather than enumerated -- written once, run per type.

- readArray / readIntElements: the whole §7 decision matrix per element type and
  destination shape. The tag (§7.3), the declared `count` (§7.1, INVALID), the
  configured policy cap (#102, LimitExceeded and deliberately not INVALID), the
  destination's own capacity (#81, and which of the two verdicts it earns), the
  declared element width applied per element, a >64-bit varint (§4.1) both in a
  stored element and out in the surplus, a payload cut mid-array and cut inside
  an element's varint, and every one of it again one byte at a time -- which is
  what runs the checked element loops instead of the windowed ones.
- IStreamObject::reset(): destinationReuse() pinned it for one message type;
  reset() is a template that re-initialises the owned message, so every message
  type the suite declares now gets the contract checked on its own
  instantiation -- the buffered partial field dropped, the latched terminal
  INVALID cleared (§5.2).
- §7.2 item 4: a set of real messages -- every wrapper-array collector and both
  nesting forms in one, a nested sub-message field, a gapped sub-message array,
  every scalar wire form, a varint and a fixlen array -- fed at every split
  point and one byte at a time, each restart landing on the same values.
- §6.4 across chunk boundaries: the invalid sequence begins at an offset at or
  past everything fed so far, which the shared invalid_utf8 vectors never
  reach. A validator that only looks at the chunk in hand, or resumes from the
  wrong offset, reports COMPLETE there. Swept over both destination kinds
  (std::string and FixedString), with a blob and a skipped string as the
  controls §6.4 exempts.

Line coverage 77.1% -> 93.4%, functions 90.2% -> 99.7%, branches 52.0% ->
67.6%. What is left is dominated by per-instantiation dead code: the element
bound in a dispatch for a callback that publishes none, the SequenceEnd reject
in a level that is never the top one, and MAX_DEPTH in a message type that is
not the one nested 255 deep.

No library change.
@Andste82

Andste82 commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Note on the two coverage numbers, since the CI log and the PR body disagree.

Both are gcovr run with the command in .github/workflows/coverage.yaml; the versions
differ in how they treat template instantiations:

gcovr 7.0 (CI, Ubuntu 24.04) gcovr 8.6 (local)
instantiations merged per source line counted separately
lines, main 97.3 % (1002/1030) 77.1 % (3334/4323)
lines, this PR 98.6 % (1016/1030) 93.4 % (4539/4859)
functions 88.6 % → 99.7 % 90.2 % → 99.7 %
branches 83.9 % → 87.5 % 52.0 % → 67.6 %

The per-instantiation view is the one this PR is written against: it is what makes
"one element type is tested, the other eleven are not" visible at all, and merging the
instantiations hides exactly the gap the sweeps close. Both views agree on the
direction and both end above 90 %.

@Andste82
Andste82 merged commit 2531662 into main Aug 9, 2026
9 checks passed
@Andste82
Andste82 deleted the test/decode-path-coverage branch August 9, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant