Skip to content

refactor(dfpt): replace the shared fixture base class with a free-function test tool - #8270

Open
Zanthoxylum wants to merge 2 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-dfpt-test-tool
Open

Zanthoxylum wants to merge 2 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-dfpt-test-tool

Conversation

@Zanthoxylum

Copy link
Copy Markdown
Collaborator

Summary

DFPTSerialBase (the shared gtest fixture base class and its header,
dfpt_serial_fixture.{h,cpp}) is replaced by a free-function test tool,
following the established module_pw test/test_tool.{h,cpp} pattern:
small declaration-only header + one implementation TU compiled into
every test target.

  • dfpt_test_tool.{h,cpp} provides the shared utilities as free
    functions — setup_cell, make_coulomb_atom, make_nc_atom,
    make_two_atom_cell, make_nlcc_two_atom_cell, setup_bases,
    vloc_coulomb, analytic_dvloc, fkey, gkey — plus the shared
    test-world constants (lat0, ecutwfc, rho_mult, cubic_edge).
  • Every test file now derives its own fixture directly from
    ::testing::Test
    , owns its objects (ucell_, pw_rho_, pw_wfc_,
    qlist_, data_, q_cart_, ...) as members and calls exactly the
    utilities it needs. There is no shared fixture base class and no
    fixture header anywhere in the module.
  • The rho files keep their file-local RNG (single-TU determinism).
  • CMakeLists.txt swaps dfpt_serial_fixture.cpp for
    dfpt_test_tool.cpp in every test target.

Relationship to #8268

Both PRs touch dfpt_serial_fixture.cpp — #8268 modifies SetupBases
inside it (to call the new PW_Basis::init_serial); this PR deletes the
file entirely. Either merge order resolves trivially:

Verification

cmake --build build-gcc13 --target MODULE_DFPT_pert_serial \
  MODULE_DFPT_rho_serial MODULE_DFPT_phon_serial MODULE_DFPT_q0_serial \
  MODULE_DFPT_xc_analytic_serial MODULE_DFPT_write_dyn_serial -j 20
ctest --test-dir build-gcc13 -R "MODULE_DFPT"      # 10/10 targets Passed
  • All six reworked targets rebuilt from deleted binaries (make exit
    code 0 per target).
  • Case counts conserved: pert 7 / phon 20 / rho 11 / q0 6 / xc 6 /
    write_dyn 6 (identical case names, none added or lost).
  • Full MODULE_DFPT suite: 10/10.

Documentation

No docs change needed: test-only refactor with no INPUT, interface, or
behavior change.

…ction test tool

The DFPTSerialBase base class and its header are removed in favor of
dfpt_test_tool.{h,cpp} (the module_pw test/test_tool pattern): shared
declarations plus one implementation TU of free functions -- setup_cell,
make_coulomb_atom, make_nc_atom, make_two_atom_cell, make_nlcc_two_atom_
cell, setup_bases, vloc_coulomb, analytic_dvloc, fkey, gkey -- and the
shared test-world constants (lat0 / ecutwfc / rho_mult / cubic_edge).
Every test file now derives its own fixture directly from ::testing::Test,
owns its objects as members and calls the utilities it needs; there is no
shared fixture base class and no fixture header. The rho files keep their
file-local RNG. CMakeLists swaps dfpt_serial_fixture.cpp for
dfpt_test_tool.cpp in every target. setup_bases keeps the raw assembly
chains and adopts PW_Basis::init_serial once deepmodeling#8268 lands. All six serial
targets rebuilt from deleted binaries (make rc=0); case counts conserved
(pert 7 / phon 20 / rho 11 / q0 6 / xc 6 / write_dyn 6); full MODULE_DFPT
ctest 10/10.
@Zanthoxylum Zanthoxylum added Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests DFPT Density Functional Perturbation Theory labels Nov 3, 2026

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review of 68d7f3fd5 found no functional regression in the fixture extraction; two include cleanups are noted below. Builds and tests were not run.

// its own gtest fixture from ::testing::Test, owns the objects it needs
// and calls these functions -- there is no shared fixture base class.

#include "source_base/matrix3.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: This declaration-only header uses Matrix3 and Vector3<double> only by reference. Forward-declare them, as you do for the other argument types, and include their definitions in the implementation and fixtures that need them.

// per-file fixture (self-contained, gtest style): only the members and
// helpers this file's cases need
class DFPTPhonSerialTest : public DFPTSerialBase
#include "gmock/gmock.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: This newly added include block is repeated below the fixture at lines 69–74. Please keep one copy of each header here and remove the analogous duplicates in the other changed phon, pert, q0 and rho test files.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DFPT Density Functional Perturbation Theory Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants