Repository navigation
Update coverage counters atomically and time out test jobs - #95
Merged
Merged
Conversation
Coverage counters are plain loads and stores, and Swift Testing runs tests in parallel, so a counter that several tests increment can lose an increment. llvm-cov does not count every region directly: it subtracts one counter from another for an `else` branch, or for the code after a `guard` that can return or a call that can throw. A lost increment can then make a line that ran report as never executed, which breaks the 100% coverage target at random. The Linux coverage job now passes `-instrprof-atomic-counter-update-all` to LLVM, which makes every counter update atomic, so every count is exact. This adds about a second to the build. The Xcode jobs still upload coverage built with plain counters. Codecov merges the uploads and counts a line as covered when any upload reports it as run, so the exact Linux report keeps a line that ran from reading as missed. A build system can drop the flag: SwiftPM's swiftbuild build system dropped it from SafeDI's macOS build. A new step after the tests disassembles the test binary with llvm-objdump and fails with an `::error::` annotation if any coverage counter update lacks a `lock` prefix, or if none has one, as when the binary has no counters. It writes the disassembly to a file before reading it, so that a missing llvm-objdump or test binary fails the step with llvm-objdump's own error rather than with a misleading annotation. The check reads x86_64 code, which the ubuntu-24.04 runner runs; on another architecture it finds no `lock` and fails. Every job that runs tests now times out: the simulator jobs after 50 minutes and the others after 15. On recent runs of main, the simulator jobs took 4 to 11 minutes and the others about a minute. A test that deadlocks keeps the test run from ending, and would otherwise hold a runner for GitHub's six-hour default, so for a regression that makes a test hang, the timeout is the failure signal. The unused `Expectation` helper and its tests are removed. They are a copy of the swift-testing-expectation package that no other test refers to, and its `fulfillment(withinSeconds:)` fails a test by wall-clock timeout, so a test that used it would depend on timing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
This was referenced Nov 15, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #95 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 13 11 -2
Lines 1311 1209 -102
==========================================
- Hits 1311 1209 -102 🚀 New features to boost your workflow:
|
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
Four CI and test-target changes that the rest of the 2.0 series relies on. None changes the library.
elsebranch, or for the code after aguardthat can return or a call that can throw. A lost increment can then make a line that ran report as never executed, which breaks the 100% coverage target at random. The Linux coverage job now passes-Xswiftc -Xllvm -Xswiftc -instrprof-atomic-counter-update-all, so every count is exact. This adds about a second to the build.llvm-objdumpinto.build/disassembly.txtand fails with an::error::annotation if any coverage counter update lacks alockprefix, or if none has one, as when the binary has no counters. Writing the disassembly to a file rather than piping it means a missing test binary or a missingllvm-objdumpfails the step withllvm-objdump's or the shell's own error, rather than with a misleading "no atomic coverage counter updates" annotation. The check reads x86_64 code, which the ubuntu-24.04 runner runs; on another architecture it finds nolockand fails rather than passing silently.timeout-minutes: 50 for the Xcode simulator matrix and 15 for the others. On recent runs ofmainthe simulator jobs took 4 to 11 minutes and the others about a minute. A test that deadlocks keeps the test run from ending, and would otherwise hold a runner for GitHub's six-hour default. Later PRs add tests that can only hang when the code they guard regresses, so for those the timeout is the failure signal.Expectationhelper removed.Tests/AsyncQueueTests/Utilities/Expectation.swiftandExpectationTests.swiftare a copy of the swift-testing-expectation package that no other test refers to. Itsfulfillment(withinSeconds:)fails a test by wall-clock timeout, so a test that used it would depend on timing.The Xcode jobs still upload coverage built with plain counters. Codecov merges the uploads and counts a line as covered when any upload reports it as run, so the exact Linux report keeps a line that ran from reading as missed.
Tests
No test is added. The six
ExpectationTeststests are removed with the helper they test.Four lines of
main'sCancellableQueueTests.swiftstill read zero here and in #86: lines 217, 218 and 316 in every run so far, and 315 in some. They are the closing braces of thewhile true { try Task.checkCancellation() }spinner and of its closure, incancelTasks_actorQueue_cancelsCurrentlyExecutingAndPendingTasksandcancelTasks_mainActorQueue_cancelsCurrentlyExecutingAndPendingTasks. They are not lost increments: llvm-cov counts them as the loop's completed iterations (regions 217:5 and 315:5), so they read zero whenever cancellation reaches the spinner before it finishes its first iteration, which depends on thread timing. They read the same with atomic counters. #87 rewrites both spinners, and from #87 on no line inSourcesorTestsreads zero.Series
PR 1 of 10 in the 2.0 series (this PR, then #86 through #94, each stacked on the previous one). It is based on
main, and #86 is stacked on it. It changes no API and no library code.Validation
On Linux, from a
git archivecopy, with Swift 6.2.4 as theswift:6.2job uses:weak varwarningsmainhas, andswiftformat --lintis clean.linux-6-2job's three steps, run from this commit'sci.ymlunderbash -e, pass: "903 atomic and 0 non-atomic coverage counter updates." With the flag dropped from the test command, the check fails with both::error::lines ("885 coverage counter updates in the test binary are not atomic." and "The test binary has no atomic coverage counter updates.").llvm-objdumpis in the Swift 6.2.4 and 6.4.2 toolchains'usr/bin, next to thellvm-covthe job already calls, so it should be in theswift:6.2image; the first CI run confirms it. If it were missing, the step would fail with "llvm-objdump: not found" (exit 127, checked here underbash -eandsh -ewithllvm-objdumpremoved fromPATH); with the test binary missing, it fails withllvm-objdump's "No such file or directory". Neither case prints an::error::annotation.Nothing was run on Apple platforms. CI is the first run there.
Review checklist
Left for code review because no test can check them:
Generated by Claude Code