Repository navigation
Link the gcov runtime into coverage-instrumented unit tests - #601
Merged
Merged
Conversation
With --enable-code-coverage, make check failed to link socket_options_test, hdr_histogram_test and cluster_transaction_test with undefined __gcov_init, __gcov_merge_add and __gcov_exit. These tests compile with memtier_benchmark_CPPFLAGS, which carries the coverage flags, and two of them link the instrumented memtier_benchmark objects, but none links libgcov. The vendored AX_CODE_COVERAGE (serial 15) puts -lgcov in CODE_COVERAGE_LDFLAGS and never defines CODE_COVERAGE_LIBS. The $(CODE_COVERAGE_LIBS) in memtier_benchmark_LDADD, and the one #564 added to hdr_histogram_test_LDADD, therefore expand to nothing. Only the main binary got the runtime, through memtier_benchmark_LDFLAGS. That put -lgcov before the objects, so it also depended on libtool reordering the link line. Use $(CODE_COVERAGE_LDFLAGS) in both LDADD lists in place of the undefined variable. The tests that reuse memtier_benchmark_LDADD inherit it, memtier_benchmark_LDFLAGS is no longer needed, and -lgcov now follows the objects. Run make check in the coverage CI job so this can't regress. Fixes #595 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Now that the coverage CI job runs make check, the instrumented unit test sources (tests/unit/*.cpp) end up in the lcov capture and inflate the reported coverage. Ignore them like the vendored HdrHistogram sources. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira
force-pushed
the
fix/coverage-make-check-link
branch
from
October 14, 2026 02:24
538dfc1 to
1d993ec
Compare
This was referenced Oct 14, 2026
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.
Problem
With
./configure --enable-code-coverage,make checkfails at link time.socket_options_test,hdr_histogram_testandcluster_transaction_testall report undefined__gcov_init/__gcov_merge_add/__gcov_exit. Thememtier_benchmarkbinary still builds, and CI never runsmake checkin a coverage build, so nobody noticed.Root cause
The vendored
m4/ax_code_coverage.m4is#serial 15. It setsCODE_COVERAGE_LDFLAGS="-lgcov"and never definesCODE_COVERAGE_LIBS, so two things follow:$(CODE_COVERAGE_LIBS)inmemtier_benchmark_LDADDhas expanded to nothing since Enabled code-coverage collection #203. So has thehdr_histogram_test_LDADD = $(CODE_COVERAGE_LIBS)added by Avoid histogram copies and batch latency percentile queries #564.memtier_benchmark_LDFLAGS. That puts-lgcovbefore the objects, so it only links because libtool moves-lflags to the end. Without libtool, the main coverage link fails too.The three tests compile with
$(memtier_benchmark_CPPFLAGS), which carries-fprofile-arcs -ftest-coverage.socket_options_testandcluster_transaction_testalso link the instrumentedmemtier_benchmark-*.oobjects. None of them getsmemtier_benchmark_LDFLAGS.Fix
memtier_benchmark_LDADDandhdr_histogram_test_LDADD, replace the undefined$(CODE_COVERAGE_LIBS)with$(CODE_COVERAGE_LDFLAGS).socket_options_testandcluster_transaction_testalready reuse$(memtier_benchmark_LDADD), so they inherit it. Future tests that reuse the instrumented objects will too.memtier_benchmark_LDFLAGS.-lgcovnow follows the objects whether or not libtool is present.'*/tests/*'toCODE_COVERAGE_IGNORE_PATTERNso the unit test sources do not inflate the coverage report.make checkstep to thecoverage-ubuntuCI job (Ubuntu 22.04, lcov 1.14) so this can't regress. The unit tests also add their gcov data to the captured report.Alternatives considered:
<test>_LDFLAGS = $(CODE_COVERAGE_LDFLAGS). This works with libtool, but every new test has to remember it, and it keeps-lgcovbefore the objects.ax_code_coverage.m4(serial 37). This does not fix the bug. The maintainer reviewer tested it: its configure check looks for_gcov_init, but libgcov only exports__gcov_init, soCODE_COVERAGE_LIBScomes out empty. That serial also dropsCODE_COVERAGE_LDFLAGS, so evenmemtier_benchmarkfails to link.Test evidence
Docker
ubuntu:22.04(gcc 11.4, lcov 1.14, same packages as the CI coverage job plus libtool),./configure --enable-code-coverage && make -j8 && make check, repeated 3 times per tree:make checksocket_options_test,hdr_histogram_test,cluster_transaction_testfail to link (60 / 18 / 63 undefined__gcovrefs)./configure)memtier_benchmarkitself here)Coverage report (rebased on 6b6d6df, which includes #594): with
'*/tests/*'added toCODE_COVERAGE_IGNORE_PATTERN,make code-coverage-capturelists 84SF:entries, none undertests/, andmake checkstill passes 5/5. Without it, the capture lists 87 entries, includingtests/unit/{cluster_transaction,hdr_histogram,socket_options}_test.cpp.The result is deterministic: 0 flaky runs.
make code-coverage-capturealso succeeds aftermake check. The new CI step is the regression test: it fails on master and passes with this change.Fixes #595
Affected versions
2.5.2 and master. 2.5.1 and earlier are not affected.
hdr_histogram_test) and Preserve transaction lookahead when a cluster pin is released #583 (cluster_transaction_test) extended the problem to two more tests. The undefinedCODE_COVERAGE_LIBSdates from 78b0a9a (Enabled code-coverage collection #203, 2.0.0) and was harmless until Initialize TCP keepalive and no-delay socket options #541.prometheus_metrics_test, no coverage flags), 2.5.2 fails (socket_options_test), and master fails (three tests).check_PROGRAMS.Found during the build review of #583.
🤖 Generated with Claude Code
Note
Low Risk
Build/CI and coverage linking only; no runtime behavior changes to the benchmark binary.
Overview
Fixes coverage builds where
make checkfailed to link instrumented unit tests (undefined reference to __gcov_*) because$(CODE_COVERAGE_LIBS)is empty with the vendoredax_code_coveragemacro.Makefile now links libgcov via
$(CODE_COVERAGE_LDFLAGS)onmemtier_benchmark_LDADDandhdr_histogram_test_LDADD(so tests that reuse those LDADD lines get the runtime after the objects), drops the redundantmemtier_benchmark_LDFLAGS, and excludestests/from coverage capture viaCODE_COVERAGE_IGNORE_PATTERN.CI runs
make checkin thecoverage-ubuntujob right after the instrumented build so this cannot regress.Reviewed by Cursor Bugbot for commit 1d993ec. Bugbot is set up for automated code reviews on this repo. Configure here.