Skip to content

Commit 95204b1

Browse files
author
zxy.monado
committed
Fix: remove dead #undef __MPI toggles from source_base tests
`source/source_base/test/CMakeLists.txt:1` calls `abacus_disable_feature_definitions(__MPI)`, so `__MPI` is never defined for any target in that directory and every `#ifdef __MPI` in it is always false. `opt_tn_test.cpp` and gave those two targets a real `mpi_test_main.cpp`. What remains of the pattern is: - `global_function_test.cpp` -- three `#ifdef __MPI / #undef __MPI / #endif` blocks. Their test bodies sit *outside* the `#ifdef`, so they always compiled; the blocks are pure no-ops. - `math_chebyshev_test.cpp` -- guards wrapping `checkconverge` and `checkconverge_float`, so those two bodies were compiled out in *every* configuration: two tests reporting PASS while asserting nothing. - `opt_cg_test.cpp`, `opt_test_tools.cpp` -- a file-level `#undef __MPI` that only duplicates what CMake already does. The `#undef __MPI` / `#define __MPI` pairs were no-ops in any case: the preprocessor cannot retroactively change headers already processed above, and the library these tests link against is a separate translation unit, compiled with `__MPI` regardless of what the test does. The two chebyshev bodies this exposes are handled in the next commit.
1 parent 25ecb4d commit 95204b1

4 files changed

Lines changed: 0 additions & 22 deletions

File tree

‎source/source_base/test/global_function_test.cpp‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,6 @@ TEST_F(GlobalFunctionTest,MemAvailable)
695695

696696
TEST_F(GlobalFunctionTest,BlockHere)
697697
{
698-
#ifdef __MPI
699-
#undef __MPI
700-
#endif
701698
std::string output2;
702699
std::string block_in="111";
703700
GlobalV::MY_RANK=1;
@@ -712,9 +709,6 @@ TEST_F(GlobalFunctionTest,BlockHere)
712709

713710
TEST_F(GlobalFunctionTest,BlockHere2)
714711
{
715-
#ifdef __MPI
716-
#undef __MPI
717-
#endif
718712
std::string output2;
719713
std::string block_in="111";
720714
GlobalV::MY_RANK=0;
@@ -733,9 +727,6 @@ TEST_F(GlobalFunctionTest,BlockHere2)
733727

734728
TEST_F(GlobalFunctionTest,BlockHere3)
735729
{
736-
#ifdef __MPI
737-
#undef __MPI
738-
#endif
739730
std::string output2;
740731
std::string block_in="111";
741732
GlobalV::MY_RANK=0;

‎source/source_base/test/math_chebyshev_test.cpp‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ TEST_F(MathChebyshevTest, tracepolyA)
333333

334334
TEST_F(MathChebyshevTest, checkconverge)
335335
{
336-
#ifdef __MPI
337-
#undef __MPI
338336
const int norder = 100;
339337
p_chetest = new ModuleBase::Chebyshev<double>(norder);
340338
auto fun_sigma_y
@@ -376,8 +374,6 @@ TEST_F(MathChebyshevTest, checkconverge)
376374

377375
delete[] v;
378376
delete p_chetest;
379-
#define __MPI
380-
#endif
381377
}
382378

383379
TEST_F(MathChebyshevTest, recurs)
@@ -622,8 +618,6 @@ TEST_F(MathChebyshevTest, tracepolyA_float)
622618

623619
TEST_F(MathChebyshevTest, checkconverge_float)
624620
{
625-
#ifdef __MPI
626-
#undef __MPI
627621
const int norder = 100;
628622
p_fchetest = new ModuleBase::Chebyshev<float>(norder);
629623

@@ -647,6 +641,5 @@ TEST_F(MathChebyshevTest, checkconverge_float)
647641

648642
delete[] v;
649643
delete p_fchetest;
650-
#endif
651644
}
652645
#endif

‎source/source_base/test/opt_cg_test.cpp‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifdef __MPI
2-
#undef __MPI
3-
#endif
41
#include "gtest/gtest.h"
52
#include "../opt_cg.h"
63
#include "../opt_dcsrch.h"

‎source/source_base/test/opt_test_tools.cpp‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#ifdef __MPI
2-
#undef __MPI
3-
#endif
41
#include "./opt_test_tools.h"
52
#include <math.h>
63

0 commit comments

Comments
 (0)