Repository navigation
refactor(dfpt): split the oversized DFPT serial tests along the source boundaries - #8259
Merged
Merged
Conversation
dfpt_phon_serial_test.cpp (1062 lines, 20 cases) becomes four files mirroring the sources they exercise (coding rule 11): ion_ion -> test_dfpt_phon_ewald.cpp, accumulate_electron + nlcc fill semantics -> test_dfpt_phon_elec.cpp, the apply_asr family -> test_dfpt_phon_asr.cpp (name anticipates the Phase-2 source split of the ASR family into dfpt_phon_asr.cpp), diagonalize/LO-TO/sum-rule/format -> test_dfpt_phon.cpp. The shared fixture moves to dfpt_phon_serial_fixture.h. Verbatim test moves: case count 20 = 20, MODULE_DFPT_phon_serial passes.
dfpt_rho_serial_test.cpp (880 lines, 11 cases) becomes test_dfpt_rho.cpp (compute_drho brute-force/real-space references, Gamma charge conservation, v_hartree_q closed form, the nlcc drhoc localization/phase regression) and test_dfpt_rho_mixing.cpp (the mix_drho plain/Kerker family and the Broyden convergence/reset regressions; the name anticipates the Phase-2 source split into dfpt_rho_mix.cpp). The shared RNG and fixture move to dfpt_rho_serial_fixture.h. Verbatim test moves: case count 11 = 11, MODULE_DFPT_rho_serial passes.
dfpt_q0_serial_test.cpp (668 lines, 6 cases) becomes test_dfpt_q0.cpp (build_vkb_dk finite difference, compute_eps, compute_born, the star rotation regression -> dfpt_q0.cpp) and test_dfpt_q0_pos.cpp (the pos_matrix kinetic/nonlocal velocity forms -> dfpt_q0_pos.cpp). The shared Gamma-only fixture moves to dfpt_q0_serial_fixture.h. Verbatim test moves: case count 6 = 6, MODULE_DFPT_q0_serial passes.
…ure header dfpt_xc_analytic_serial_test.cpp (544 lines) carries ~130 lines of shared reference machinery (cubic basis builder, synthetic gaussian / cosine fields, FFT gradient / divergence references in physical units, summed libxc vrho / vsigma) used by all six cases; the helpers move to dfpt_xc_analytic_serial_fixture.h in a named namespace, bringing the test file under the 500-line budget (409 lines). Verbatim moves, case count 6 = 6, MODULE_DFPT_xc_analytic_serial passes.
ABACUS-PR-BOT
left a comment
Collaborator
There was a problem hiding this comment.
Static review found a C++17-only declaration in the shared RNG, plus two nonblocking governance/dependency suggestions. The case bodies, assertions and numerical helper formulas are preserved. No builds or runtime tests were run.
The shared test RNG seed was an inline VARIABLE (C++17); the unit-test configuration only raises the language level to C++14. Replace it with an inline accessor returning a function-local static (one instance across the target's TUs, C++11-safe) and update the reseeding call site. dfpt_rho.h moves from the shared phon fixture header into test_dfpt_phon_elec.cpp, the only file instantiating DFPT_Rho, so the Ewald/ASR/core test files do not inherit the dependency. Both affected targets rebuilt from deleted binaries (make rc=0); rho case count 11 intact; full MODULE_DFPT ctest 10/10.
Zanthoxylum
added a commit
to Zanthoxylum/abacus-develop
that referenced
this pull request
Nov 2, 2026
… file; include <algorithm> The header comment referenced test_dfpt_phon_asr.cpp, which only exists after the test split (deepmodeling#8259); point at the current dfpt_phon_serial_ test.cpp with the future name noted. Include <algorithm> directly for std::max instead of relying on transitive standard-library includes. Rebuild from deleted binaries + full MODULE_DFPT ctest: 10/10.
mohanchen
reviewed
Nov 2, 2026
# Conflicts: # source/source_pw/module_dfpt/test_serial/CMakeLists.txt
Per review, test fixture classes live inside the .cpp that uses them instead of shared fixture headers: the four new headers are removed and each file carries a trimmed per-file fixture with only the members and helpers its cases need (the phon Ewald/ASR files get the minimal cell base, the core file adds the LO-TO closed-form helpers, the elec file adds the convolution references; the rho files carry a file-local RNG in an anonymous namespace -- the cross-TU inline accessor is no longer needed; the q0 core drops the unused gy_). The xc reference helpers move back into the single xc test file (550 lines: single-concern, single-source, slightly over the 500-line budget for that reason). test_dfpt_rho_mixing.cpp is renamed to test_dfpt_rho_mix.cpp to match the companion source split dfpt_rho_mix.cpp (deepmodeling#8262) exactly. The pre-existing shared test utility dfpt_serial_fixture.{h,cpp} (cell builders, real serial basis setup) is untouched. Case counts conserved (phon 20, rho 11, q0 6, xc 6); all four targets rebuilt from deleted binaries; full MODULE_DFPT ctest 10/10.
The 'Build extra components with Intel toolchain' run hit runner disk exhaustion during the container pull (no space left on device writing libmkl_sycl_blas.so.5, retried 3x) -- an infrastructure failure on that runner, not a code change; the same check passes on the sibling branches.
mohanchen
approved these changes
Nov 2, 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.
Summary
The oversized DFPT serial test files are split along the source
boundaries they exercise, with verbatim test moves and zero
production-code changes. After this PR no split test file exceeds
550 lines (was 1062 / 880 / 668), and every test file is
self-contained in gtest style: each
.cppcarries its own fixtureclass with only the members and helpers its cases need — no test
fixture headers.
dfpt_phon_serial_test.cpp(1062 lines)test_dfpt_phon_ewald.cpp(ion_ion),test_dfpt_phon_elec.cpp(accumulate_electron + nlcc fill semantics),test_dfpt_phon_asr.cpp(the apply_asr family),test_dfpt_phon.cpp(diagonalize / LO-TO / sum rule / format)dfpt_rho_serial_test.cpp(880 lines)test_dfpt_rho.cpp(compute_drho / charge conservation / v_hartree_q / drhoc localization),test_dfpt_rho_mix.cpp(plain / Kerker / Broyden mixing family)dfpt_q0_serial_test.cpp(668 lines)test_dfpt_q0.cpp(build_vkb_dk / compute_eps / compute_born / star rotation),test_dfpt_q0_pos.cpp(pos_matrix kinetic + nonlocal velocity)dfpt_xc_analytic_serial_test.cppThe pre-existing shared test utility
dfpt_serial_fixture.{h,cpp}(cell builders, real serial basis setup — compiled once per target
like
dfpt_test_mocks.cpp) is untouched; each new file's fixturederives from it and adds only what its family needs. The rho files
carry a file-local RNG in an anonymous namespace (single-translation-
unit determinism; no cross-TU sharing, hence no inline-variable
concerns).
Rationale
A test file that keeps growing is a signal that the source file under
test accumulates unrelated responsibilities ("god file"). The phon test
had grown to 1062 lines covering four disjoint families; this split
restores the one-file-one-concern mapping (coding rule 11 naming,
test_<module>.cpp), and the per-file fixtures keep every fileindependent — editing one file's scaffolding never recompiles or
constrains its siblings.
What did NOT change
test_serial/files andits
CMakeLists.txtSOURCES lists; the CTest target names and linkstructure are unchanged).
adaptations are the per-file fixture splits, the file-local RNG
(one reseeding call site updated to
g_seed = 777u), and thedfpt_rho.hinclude living intest_dfpt_phon_elec.cppalone.Verification
Exact commands run (GCC 13 toolchain build dir
build-gcc13, serial):--gtest_list_tests:phon 20 = 20, rho 11 = 11, q0 6 = 6, xc_analytic 6 = 6 (identical
case names, none added or lost).
code 0); full
MODULE_DFPTsuite re-run after every review round:10/10.
python3 tools/03_code_analysis/agent_governance_check.py --base origin/develop --head HEAD: no findings beyond the standarddocumentation-sync notice.
Documentation
No docs change needed: test-only refactor with no INPUT, interface, or
behavior change.
Governance Exception
test_dfpt_phon_asr.cppandtest_dfpt_rho_mix.cpparenamed after the function family they exercise (the
apply_asrfamily / the
mix_drhostack) rather than after a current sourcefile, because those families currently live inside
dfpt_phon.cpp/dfpt_rho.cppalongside unrelated concerns — rule 11'sone-file-one-source mapping cannot be satisfied while the families
share a source file.
matches its source exactly (ewald / elec / q0 / q0_pos / rho).
comments naming the current source location of the family.
dfpt_phon_asr.cpp)and refactor(dfpt): move the rho mixing family to dfpt_rho_mix.cpp #8262 (
dfpt_rho_mix.cpp) move those families into their ownsource files, after which the names match exactly (the rho test file
already uses the post-split name); if either split is rejected, the
test file is renamed to match its source instead.