test(coverage): cover env_backup.c, env_config.c, and deepen db_rec.c recovery branches - #80
Closed
gburd wants to merge 3 commits into
Closed
test(coverage): cover env_backup.c, env_config.c, and deepen db_rec.c recovery branches#80gburd wants to merge 3 commits into
gburd wants to merge 3 commits into
Conversation
The Tcl backup.tcl test drives hot backup only through the db_hotbackup utility, which calls DB_ENV->backup() with a NULL backup_handle -- so env/env_backup.c (the four backup config setters/getters and the backup callback setter/getter) was never reached (0% line/branch), and the backup->open/write/close callback branches of db/db_backup.c stayed cold. Add test/backup/backup_direct.c (same standalone-driver shape as test/xa/xa_direct.c): it calls set/get_backup_config for all four config enums (READ_COUNT/READ_SLEEP/SIZE/WRITE_DIRECT, the last on and off to hit both F_SET and F_CLR), the getters-before-alloc EINVAL branches, and set/get_backup_callbacks, then runs DB_ENV->backup()/dbbackup() with write callbacks installed so the callback copy path in db_backup.c executes. Self-cleans its home dir and runs under a hard SIGALRM + timeout guard. Lift (coverage subset): env_backup.c 0%->96.7% line / 0%->81.8% branch; db_backup.c callback path 43.0% line / 29.6% branch.
Three recovery record handlers in db/db_rec.c -- __db_merge_recover, __db_pgno_recover, __db_pg_trunc_recover (~330 lines) -- fire only when btree compaction / page-truncation log records are replayed. No recd0NN test runs compaction under recovery, so all three were completely cold. Add test/db/recd_compact.c: it fills a small-page btree, deletes a large contiguous range to leave sparse/empty pages, runs DB->compact(DB_FREE_SPACE) in a transaction (logging __db_merge / __db_pgno / __db_pg_trunc records), then re-opens the environment under DB_RECOVER_FATAL so catastrophic recovery replays the whole log from the start, driving the redo/forward-roll branches of those handlers. It verifies the database still opens and reads back after recovery. Same self-clean + hard-timeout shape as the XA/upgrade drivers. Lift (coverage subset, combined with recd002:btree + recd016): db_rec.c 18%->~27% line, ~13%->~18% branch; merge/pgno/pg_trunc/relink no longer cold.
…vers into subset Add to the default COV_TESTS: env007 (comprehensive DB_CONFIG parser test -- writes a DB_CONFIG with many directives and confirms values via getters, exercising __env_read_db_config + __config_scan; was registered but never in the subset), recd002:btree (split recovery) and recd016:btree (catastrophic recovery) for db_rec.c branch coverage. Add a COV_BACKUP block (default on, same gating shape as COV_XA_UPG) that runs the two new standalone drivers: test/backup/run_backup_direct.sh and test/db/run_recd_compact.sh. Both self-clean and run under a hard timeout. Document the new surface in README.md (COV_BACKUP table row + section). Lift (coverage subset): env_config.c 3.2%->71.8% line / 1.2%->61.4% branch (via env007); env_backup.c 0%->96.7%/81.8%; db_rec.c 18%->27.1% line / 13.2%->18.0% branch.
Coccinelle convention checksNo new violations. ✅ Resolved since baseline (2) -- update dist/cocci/baseline.txt to lock these in. |
ABI diff vs
|
Collaborator
Author
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
Raises coverage of three cold libdb areas, all within the bounded
run_coverage.shsubset. No engine code changed; only tests + wiring.env/env_backup.cenv/env_config.cdb/db_rec.cdb/db_backup.c(bonus)(env_config baseline in the full run was 27.0%/17.7%; the subset baseline is
lower because the subset ran no DB_CONFIG-heavy test. env007 now beats both.)
What and why
env_backup.c is only the four backup config setters/getters and the
callback setter/getter.
backup.tcldrives hot backup through thedb_hotbackuputility, which callsDB_ENV->backup()with a NULLbackup_handle, so none ofenv_backup.cran and thebackup->open/write/closecallback branches ofdb/db_backup.cstayed cold.New standalone driver
test/backup/backup_direct.ccalls those publicentry points directly (all four config enums,
WRITE_DIRECTon+off, thegetters-before-alloc
EINVALbranches,set/get_backup_callbacks), then runsDB_ENV->backup()/dbbackup()with write callbacks installed.env_config.c (
__env_read_db_config+__config_scan/__config_parse)was cold in the subset because no subset test wrote a many-directive
DB_CONFIG. The existing, comprehensive
env007already writes a DB_CONFIGexercising
set_cachesize/set_lg_*/set_lk_detect/set_flags/add_data_dir/set_verbose/mutex_set_*/set_memory_*/… and confirms eachvia getters. It was registered but never in the subset -- now wired into the
default
COV_TESTS. (No newconfig001.tclneeded: env007 already doesexactly the requested many-directive parse + getter verification.)
db/db_rec.c branch coverage:
__db_merge_recover,__db_pgno_recover,__db_pg_trunc_recover(~330 lines) fire only when btree compaction /page-truncation records are replayed, and no
recd0NNtest runs compactionunder recovery, so they were completely cold. New driver
test/db/recd_compact.cfills+sparsifies a small-page btree, runsDB->compact(DB_FREE_SPACE)(logging merge/pgno/pg_trunc records), thenre-opens under
DB_RECOVER_FATAL. Also addedrecd002:btree(splitrecovery) and
recd016:btree(catastrophic recovery) toCOV_TESTS.Both C drivers follow the existing XA/upgrade-driver pattern: self-clean their
home dir, run under a hard SIGALRM +
timeoutguard, so they cannot hang.Gated behind a new
COV_BACKUP=1(default on).Bounded-cost note
Deliberately did not add
recd003/recd004/recd011/recd002:hash:each is 7-8 min under coverage instrumentation for a <1% marginal db_rec gain.
The chosen set (recd002 ~65s, recd016 ~14s, recd_compact ~30s, env007 ~24s,
backup_direct ~5s) is where the ROI is.
Validation
Built with
--coveragein the nix dev shell; every added test/driver run andconfirmed PASS under a timeout (drivers verified reliable on repeat runs).
Deltas above are measured before->after via
lcov+rank_coverage.py.Notes
build_unix/**is gitignored).