tests: take source_base and source_hamilt off #define private public, via accessors that already existed - #7982
Merged
mohanchen merged 1 commit intoSep 17, 2026
Conversation
Two modules go to zero access hacks. In both cases the class already had most of the interface the test needed; nothing is opened up wholesale and no friend is declared. source_hamilt/module_vdw (vdw_test) Vdwd2Parameters already exposes C6(), R0(), damping() and scaling() -- and vdwd2.h's own index_loops() uses exactly those -- while the test reached past them into C6_ and R0_. Those reads now go through the accessors, and radius() is added alongside the existing four. C6_input()/R0_input() were public all along. The one write, R0_["Si"] = 0.0 in D2R0ZeroQuit, goes through the public R0_input() instead, reading a new one-line r0_zero.txt installed next to the existing c6.txt / r0.txt. R0_input() does not validate against zero, so the "R0_sum can not be 0" guard in index_loops() is still what the test hits. source_base (memory_test) The finish test fabricated a record entry by writing name, class_name, consume and init_flag. Setting init_flag = true made the record() call two lines later skip its own allocation, so *name = ... wrote through whatever a previous test had left behind -- and through a null pointer in any order where record() had not run yet. It now just calls record(), which allocates the tables and adds the entry finish() is meant to print and release, and reads the result back through a new is_initialized(), added next to the get_total() that was already public for the same purpose. Assertions and expected values are unchanged in both files. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 18, 2026
Merged
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.
What this does
Takes
source_baseandsource_hamiltto zero#define private public. Inboth cases the class already had most of the interface the test needed; nothing
is opened up wholesale and no
friendis declared.source_hamilt/module_vdw—vdw_testVdwd2Parametersalready exposesC6(),R0(),damping()andscaling(),and
vdwd2.h's ownindex_loops()uses exactly those — while the test reachedpast them into
C6_andR0_. Those reads now go through the accessors, andradius()is added alongside the existing four.C6_input()/R0_input()werepublic all along, so those four sites needed no change at all.
The one write,
R0_["Si"] = 0.0inD2R0ZeroQuit, goes through the publicR0_input()instead, reading a new one-liner0_zero.txtinstalled next to theexisting
c6.txt/r0.txt.R0_input()does not validate against zero, so the"R0_sum can not be 0"guard inindex_loops()is still exactly what the testhits.
source_base—memory_testThe
finishtest fabricated a record entry by writingname,class_name,consumeandinit_flagdirectly. That setup was also unsound: settinginit_flag = truemade therecord()call two lines later skip its ownallocation, so
*name = ...wrote through whatever a previous test had leftbehind — and through a null pointer in any execution order where
record()hadnot run yet.
It now just calls
record(), which allocates the tables and adds the entryfinish()is meant to print and release, and reads the result back through a newis_initialized(), added next to theget_total()that was already public forthe same purpose.
Assertions and expected values are unchanged in both files. No default
arguments were added. No
PARAM/GlobalV/GlobalCreference is added orremoved. No INPUT parameter or user-facing behaviour changed, so no documentation
update is required.
Scope: what I took out, and why
This PR started as a four-file batch. Two files were dropped after measurement,
and I would rather say so than force them through:
source_pw/module_pwdft/structure_factor_test— the twelve reads ofc_eigts*/z_eigts*substitute cleanly into the already-publicget_eigts1_data<FPTYPE>()/2/3, with no production change. But thetest also writes
PARAM.sys.has_float_data, whichStructure_Factor::setup()reads, so the macro only dies if that becomes a parameter — and that turned out
to be wider than it looks:
Structure_Factor::setuphas 8 call sites, not the 3 a first grepsuggested. Two of them are mock definitions in other modules'
tests (
source_psi/test/psi_init_unit_test.cpp,source_estate/test/charge_extra_test.cpp), plussource_hamilt/module_surchem/test/cal_pseudo_test.cpp.charge_extra.cppcurrently has noPARAMreference at all; passing theflag from there would mean adding
parameter.hand two global reads to afile that is clean today — the opposite of the direction this campaign is
going.
So that one belongs in its own PR, where the
has_float_dataplumbing can berouted properly rather than pushed into a clean file.
source_estate/elecstate_occupy_test— needs bothnspininjected intooccupy.cpp(2 reads) and the fourstaticprivate helpers (efermig,sumkg,wgauss,w1gauss, 13 test sites, ~6 internal callers) given a realinterface. All four take their inputs as parameters and touch no private class
state, so extracting them into a namespace is the right fix — but it is a
bigger, self-contained job.
Verification
Remote Linux box,
cmake -B build -G Ninja -DBUILD_TESTING=ON -DENABLE_LCAO=ON -DENABLE_MPI=ON -DENABLE_OPENMP=ON:ninja: no work to doon a follow-up full build
MODULE_BASE_memoryandMODULE_HAMILT_vdwTestboth linkagent_governance_check.py --base upstream/develop --head HEAD: zeroblockers, no access-hack ratchet finding (2 removed, 0 added)
Continues #7921 / #7949 / #7952 / #7953 / #7963 / #7964 / #7965 / #7966 / #7967 /
#7980 / #7981, and keeps their scope rule: a file is either taken fully off the
macro or left alone with a stated reason.
🤖 Generated with Claude Code