Skip to content

test(upgrade): cover per-version on-disk upgrade transforms via synthetic old-format fixtures - #73

Closed
gburd wants to merge 1 commit into
masterfrom
agent/upgrade-cov
Closed

test(upgrade): cover per-version on-disk upgrade transforms via synthetic old-format fixtures#73
gburd wants to merge 1 commit into
masterfrom
agent/upgrade-cov

Conversation

@gburd

@gburd gburd commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Raises coverage of libdb's on-disk-format upgrade code, which was almost
entirely dead (0–14%) because this fork ships only one current-format fixture
and lacks upstream's per-version Tcl upgrade fixture tree
(test/tcl/upgrade/databases/).

test/db/run_upgrade.sh (added in #70) is extended to drive the real
per-version metadata/page transforms in src/db/db_upg.c,
src/btree/bt_upgrade.c, src/hash/hash_upgrade.c, src/qam/qam_upgrade.c.

What the driver now does

  • Runs db_upgrade (→ DB->upgrade__db_upgrade) + db_verify over:
    • the committed btree v9 fixture (test/csharp/bdb4.7.db);
    • freshly-created current-format dbs of every access method
      (btree / hash / queue / recno + btree-with-dups + the -s/DB_DUPSORT
      flag path + salvage) — this covers the full magic/version dispatch and the
      version-current no-op branch for each AM.
  • Manufactures old-format fixtures without an old library: it creates a
    current db and rewrites only its metadata page into the byte layout of an
    older release (HASHHDR v5, HMETA30 v6, BTMETA2X v6, BTMETA30 v7, QMETA30 v1,
    QMETA31 v2 — from dbinc/db_upgrade.h) with the version field set back. Since
    the old→new metadata transforms operate on the meta page in place, these are
    legitimate inputs to __db_upgrade and drive the real transform functions.

No binary fixtures are committed — everything is generated at test time.

Coverage (line), before → after

file before after functions
db/db_upg.c 13.9% 57.2% 40% → 100%
qam/qam_upgrade.c 0.0% 97.1% 0% → 100%
btree/bt_upgrade.c 0.0% 82.4% 0% → 100%
hash/hash_upgrade.c 0.0% 68.5% 0% → 66.7%
db/db_upg_opd.c 0.0% 0.0% (still cold — see below)

Measured with CC=gcc --coverage, lcov captured from .libs, in the nix dev
shell.

Documented gaps (engine NOT changed)

  1. db_upg_opd.c (__db_31_offdup, 3.0→3.1 off-page-dup conversion) needs
    a genuine 3.0-era off-page-duplicate page chain (linked __P_DUPLICATE
    pages). Rewriting a current db can't produce it — current off-page dups are
    already stored as a Recno tree (P_LRECNO/P_IRECNO), not a flat page chain. A
    genuine pre-3.1 fixture is required.

  2. __db_set_lastpgno off-by-one (finding, not fixed). The btree v6/v7
    upgrade path calls __db_set_lastpgno(), which stores __db_lastpgno()'s
    result — the page count (bytes/pagesize) — directly into
    meta->last_pgno, which is the last page number (count-1). On a
    page-aligned file that is off by exactly +1, and db_verify then reports
    last_pgno is not correct: N != N-1 (db_vrfy.c, under HAVE_FTRUNCATE).
    The hash path avoids it because its v8→v9 pass runs through mpool, which
    recomputes last_pgno correctly on close. __db_set_lastpgno is byte-for-byte
    identical to upstream Berkeley DB 4.7/4.8, so this is likely a long-standing
    latent defect. The fixtures here are synthetic, so the driver upgrades the
    btree v6/v7 fixtures (to cover the transform) but skips db_verify on them,
    asserting the metadata version bumped instead — and this is reported to
    confirm against a genuine old fixture rather than patched.

Validation

Built with --enable-debug --enable-test in the nix dev shell; the driver
passes (all db_upgrade/db_verify runs under timeout) and is idempotent
across re-runs. It is already wired into test/coverage/run_coverage.sh via the
COV_XA_UPG block (default on).

…-format fixtures

Extend test/db/run_upgrade.sh to exercise the on-disk-format upgrade code
(src/db/db_upg.c, src/btree/bt_upgrade.c, src/hash/hash_upgrade.c,
src/qam/qam_upgrade.c), which was almost entirely dead (0-14%) because this
fork ships only one current-format fixture and lacks upstream's per-version
Tcl upgrade fixture tree (test/tcl/upgrade/databases/).

The driver now:
- runs db_upgrade (DB->upgrade) + db_verify over the committed btree v9
  fixture and freshly-created current-format dbs of every access method
  (btree/hash/queue/recno + btree-with-dups + the -s DUPSORT flag and
  salvage), covering the full magic/version dispatch and the
  version-current no-op branch for each AM;
- manufactures old-format fixtures WITHOUT an old library, by rewriting a
  current db's metadata page into the byte layout of an older release
  (HASHHDR v5, HMETA30 v6, BTMETA2X v6, BTMETA30 v7, QMETA30 v1, QMETA31 v2
  from dbinc/db_upgrade.h) with the version field set back, driving the real
  per-version transform functions.

Coverage (line), before -> after:
  db/db_upg.c        13.9% -> 57.2%   (functions 40% -> 100%)
  qam/qam_upgrade.c   0.0% -> 97.1%   (functions 0% -> 100%)
  btree/bt_upgrade.c  0.0% -> 82.4%   (functions 0% -> 100%)
  hash/hash_upgrade.c 0.0% -> 68.5%   (functions 0% -> 66.7%)
  db/db_upg_opd.c     0.0% -> 0.0%    (still cold; see below)

Fixtures are generated at test time from current-format dbs, so no binary
fixtures are committed.

Two documented gaps (in test/coverage/README.md, engine NOT changed):
- db_upg_opd.c (__db_31_offdup, 3.0->3.1 off-page-dup conversion) needs a
  genuine 3.0-era off-page-duplicate page chain (linked __P_DUPLICATE pages);
  a rewritten current db can't produce it (current dups are already a Recno
  tree), so it stays 0%.
- __db_set_lastpgno off-by-one: the btree v6/v7 path stores __db_lastpgno()'s
  page COUNT into meta->last_pgno (a page NUMBER = count-1), so db_verify
  rejects last_pgno on a page-aligned file ("last_pgno is not correct: N !=
  N-1", under HAVE_FTRUNCATE). The hash path avoids it (its v8->v9 pass runs
  through mpool, which recomputes last_pgno on close). The code is identical
  to upstream BDB 4.7/4.8. The driver upgrades btree v6/v7 (covering the
  transform) but skips db_verify on them, asserting the version bump instead.
  Reported to confirm against a genuine old fixture; not fixed.
@github-actions

Copy link
Copy Markdown

Coccinelle convention checks

No new violations. ✅

Resolved since baseline (2) -- update dist/cocci/baseline.txt to lock these in.
rule_mutex_unbalanced|MUTEX_UNBALANCED|src/crypto/mersenne/mt19937db.c|return (ret);
rule_mutex_unbalanced|MUTEX_UNBALANCED|src/mp/mp_register.c|return (ret);

@github-actions

Copy link
Copy Markdown

ABI diff vs v5.3.31 (libabigail — authoritative)

Removed exported symbols (nm -D, _NNNN version suffix normalized)

None.


Advisory: libabigail/nm is the authoritative binary-ABI check; Coccinelle is complementary source-level early warning. See dist/cocci/README.md.

@gburd

gburd commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by coverage/upgrade-rebased (rebased onto master to pick up #72); reopening.

@gburd gburd closed this Jul 29, 2026
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