Skip to content

test(base): expand source_base unit-test coverage - #7888

Open
Critsium-xy wants to merge 15 commits into
deepmodeling:developfrom
Critsium-xy:test/source-base-coverage
Open

test(base): expand source_base unit-test coverage#7888
Critsium-xy wants to merge 15 commits into
deepmodeling:developfrom
Critsium-xy:test/source-base-coverage

Conversation

@Critsium-xy

@Critsium-xy Critsium-xy commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

No linked issue. This is a focused source_base coverage and decoupling follow-up.

Unit Tests and/or Case Tests for my changes

  • Commands run for the original coverage work:
    • OMP_NUM_THREADS=1 ctest --test-dir /tmp/abacus-source-base-coverage --output-on-failure --timeout 1700 -R "^MODULE_BASE"
    • OMP_NUM_THREADS=1 ctest --test-dir /tmp/abacus-source-base-coverage --output-on-failure -R "^MODULE_IO_(output_test|orb_io_test|orb_io_test_parallel|write_wfc_nao|read_exit_file_test)$"
    • OMP_NUM_THREADS=1 ctest --test-dir /tmp/abacus-source-base-coverage --output-on-failure -R "^MODULE_BASE_(parallel_reduce_test|parallel_device|parallel_device_parallel)$"
    • lcov capture/extract/remove over /tmp/abacus-source-base-coverage, restricted to production files under source/source_base.
  • Commands run after syncing to upstream develop at c2fa3ac19:
    • cmake -S . -B build-pr7888 -G Ninja -DBUILD_TESTING=ON -DENABLE_MPI=ON -DCMAKE_BUILD_TYPE=Debug
    • cmake --build build-pr7888 --target MODULE_BASE_para_gemm MODULE_BASE_parallel_device MODULE_BASE_parallel_domain_grid -j4
    • OMP_NUM_THREADS=1 ctest --test-dir build-pr7888 --output-on-failure -R '^MODULE_BASE_(para_gemm|para_gemm_parallel|parallel_device|parallel_device_parallel|parallel_domain_grid|parallel_domain_grid_parallel)$'
    • OMP_NUM_THREADS=1 ctest --test-dir build-pr7888 --output-on-failure -R '^MODULE_BASE' -j4
    • clang-format --dry-run --Werror source/source_base/test_parallel/parallel_device_test.cpp source/source_base/test_parallel/parallel_domain_grid_test.cpp source/source_base/test_parallel/test_para_gemm.cpp
    • python3 tools/03_code_analysis/agent_governance_check.py --base upstream/develop --head HEAD --format text
    • python3 tools/03_code_analysis/code_quality_score.py $(git diff --name-only upstream/develop...HEAD | grep -E '\.(cpp|h)$')
    • git diff --check upstream/develop...HEAD
  • Result summary:
    • MODULE_BASE: 77/77 passed against upstream develop at c2fa3ac19, including all affected serial and four-process MPI tests.
    • Related MODULE_IO tests: 5/5 passed in the original coverage verification, including four-process orbital IO.
    • MODULE_BASE_LIBM_UTs passed in a separate ENABLE_ABACUS_LIBM=ON targeted configuration.
    • Final CPU/MPI production coverage from the original coverage run: 87.7% lines (15430/17598), 97.5% functions (1835/1883).
    • No compiled production source file remains entirely at zero function coverage.
    • Code-quality scoring: 27/27 changed C++ files passed the 60-point threshold (average 89.0).
    • Governance check has no deterministic errors; its documentation warning is addressed below.
  • Checks not run, with reason:
    • CUDA, ROCm, and DSP runtime paths were not executed locally because those accelerator environments are unavailable in this CPU/OpenMPI build. CUDA compilation is covered by CI.
    • The remaining 48 gcov zero-count symbols are 40 macro-generated linalg dispatch lambdas for invalid scalar/tensor type combinations plus 8 compiler-generated destructor/inline duplicates or abort-only handlers. The public behavior behind these symbols is covered; aborting child processes cannot flush gcov counters.
    • A whole-file clang-format --dry-run --Werror over every touched legacy file reports existing formatting differences. New standalone tests and directly formatted files pass targeted formatting checks; this PR intentionally avoids unrelated repository-wide formatting churn.
    • An all-target local build was not completed because it would compile roughly 3000 unrelated targets. All MODULE_BASE targets were built, installed with their test assets, and the complete MODULE_BASE test selection passed.

What changed?

  • Added focused coverage for numerical utilities, BLAS/LAPACK wrappers, container integer kernels, MPI communication and reduction type variants, parallel grids/domains, para_gemm float variants, CSR complex parsing, and remaining CPU helpers.
  • Added reusable MPI test setup and new focused test targets where needed.
  • Fixed the no-accelerator set_memory<T, DEVICE_GPU> stub signature to match its declared interface.
  • Fixed TensorBuffer move ownership transfer to clear the moved-from allocator and prevent double deletion; also keeps allocated-byte accounting correct after resize/copy/move assignment.
  • Replaced two backend-sensitive exact floating-point comparisons with tight tolerances.
  • Synced the PR branch with current upstream develop and migrated the added parallel tests from the removed communication_domain.h/size() API to parallel_cell.h and the existing MPICommGroup wrapper.

Governance Notes

  • INPUT/docs changes: none. This PR changes tests and internal source_base correctness only; no user-facing INPUT behavior or parameter metadata changes, so docs/parameters.yaml and docs/advanced/input_files/input-main.md do not require updates.
  • Core module impact: limited to source_base tests plus two internal correctness fixes. No new GlobalV, GlobalC, or PARAM dependency is introduced, and source_base remains independently testable.
  • The parallel test compatibility fix uses the existing MPICommGroup wrapper and adds no direct MPI routine calls.
  • Exceptions requested: none.

@mohanchen mohanchen added Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests labels Sep 1, 2026
mohanchen and others added 5 commits September 1, 2026 20:18
- lapack_test Potrf: the test previously read B.data<Type>() on the host
  after B had been moved to the device via to_device<Device>(). Since
  base::utils::Types includes DEVICE_GPU tuples under __CUDA/__ROCM, this
  dereferenced device memory from host code. Copy back to the CPU before
  inspecting elements.
- lapack_test GetrfGetriGetrs: the test passed host stack arrays to
  lapack_getrf/getrs/getri instantiated with the TypeParam device. The
  cuSolver variants are explicitly instantiated, so a CUDA build linked
  and then received host pointers at runtime. Pin the test to DEVICE_CPU,
  matching the Trtri test.
- TensorBuffer::operator=(const TensorBuffer&): the allocator was deleted
  unconditionally but only reassigned for CpuDevice/GpuDevice. A
  moved-from buffer (now nulled by the move ctor/assignment) or a
  non-owning TensorBuffer(void*) reports DeviceType::UnKnown, so the
  following allocate() call dereferenced the freed allocator. Reset the
  buffer state and bail out for that case.
- math_erf_complex_test: the conjugate-symmetry check used an absolute
  1e-11 tolerance on samples reaching |erf(z)| ~ 7e60, which demands
  bit-exact agreement and is sensitive to libm and FP contraction. Scale
  the tolerance with the magnitude of the expected value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHKnX7j7yhrvgAEMAUY1uH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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