Skip to content

Commit bf26381

Browse files
committed
test : Write tests with google test framework
1 parent ce82fcc commit bf26381

18 files changed

+580
-955
lines changed

source/module_pw/pw_distributeg.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "pw_basis.h"
22
#include "../module_base/tool_quit.h"
33
#include "../module_base/global_function.h"
4-
#include <iostream>
54

65
namespace ModulePW
76
{
@@ -94,7 +93,6 @@ void PW_Basis::count_pw_st(
9493
}
9594
}
9695
riy += this->ny;
97-
std::cout<<"liy "<<liy<<" ; riy "<<riy<<std::endl;
9896
return;
9997
}
10098

source/module_pw/pw_distributeg_method1.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../module_base/mymath.h"
33
#include "../src_parallel/parallel_global.h"
44
#include "../module_base/global_function.h"
5-
#include "iostream"
5+
// #include "iostream"
66
#include "../module_base/timer.h"
77

88

@@ -47,9 +47,9 @@ void PW_Basis::distribution_method1()
4747

4848
this->count_pw_st(tot_npw, st_length2D, st_bottom2D);
4949
// for test --------------------------------------------------
50-
std::cout << "The first step done\n";
51-
std::cout << "tot_npw " << tot_npw << '\n';
52-
std::cout << "this->nstot " << this->nstot << '\n';
50+
// std::cout << "The first step done\n";
51+
// std::cout << "tot_npw " << tot_npw << '\n';
52+
// std::cout << "this->nstot " << this->nstot << '\n';
5353
// for (int ix = 0; ix < nx; ++ix)
5454
// {
5555
// for (int iy = 0; iy < ny; ++iy)
@@ -70,7 +70,7 @@ void PW_Basis::distribution_method1()
7070
this->collect_st(st_length2D, st_bottom2D, st_i, st_j, st_length);
7171

7272
// ------------------------------------------------------------
73-
std::cout << "\nThe second step done\n";
73+
// std::cout << "\nThe second step done\n";
7474
// ------------------------------------------------------------
7575

7676
// (3) Distribute sticks to cores.
@@ -91,7 +91,7 @@ void PW_Basis::distribution_method1()
9191
delete[] st_length;
9292

9393
// for test -----------------------------------------------------------------------------
94-
std::cout << "The 3-1 step done\n";
94+
// std::cout << "The 3-1 step done\n";
9595
// std::cout << "st_i ";
9696
// for (int is = 0; is < this->nstot; ++is) cout << st_i[is] << setw(4) ;
9797
// std::cout << std::endl;
@@ -101,7 +101,7 @@ void PW_Basis::distribution_method1()
101101
delete[] st_i;
102102
delete[] st_j;
103103
// for test -----------------------------------------------------------------------------
104-
std::cout << "The 3-2 step done\n";
104+
// std::cout << "The 3-2 step done\n";
105105
// --------------------------------------------------------------------------------------
106106

107107
// (4) Send npw_per, nst[poolrank], st_* to all cores.
@@ -152,7 +152,7 @@ void PW_Basis::distribution_method1()
152152
MPI_Status ierror;
153153
MPI_Recv(&npw, 1, MPI_INT, 0, 0, POOL_WORLD, &ierror); // number of planewaves in current proc.
154154
MPI_Recv(&nst, 1, MPI_INT, 0, 0, POOL_WORLD, &ierror);
155-
std::cout << this->poolrank << " recive done.\n";
155+
// std::cout << this->poolrank << " recive done.\n";
156156
#endif
157157
}
158158
#ifdef __MPI
@@ -176,7 +176,7 @@ void PW_Basis::distribution_method1()
176176
MPI_Bcast(this->ixy2istot, this->nxy, MPI_INT, 0, POOL_WORLD);
177177
MPI_Bcast(this->nst_per, this->poolnproc, MPI_INT, 0 , POOL_WORLD);
178178

179-
std::cout << "Bcast done\n";
179+
// std::cout << "Bcast done\n";
180180
#endif
181181
this->nstnz = this->nst * this->nz;
182182

@@ -186,7 +186,7 @@ void PW_Basis::distribution_method1()
186186
if (st_bottom2D != NULL) delete[] st_bottom2D;
187187
if (st_length2D != NULL) delete[] st_length2D;
188188
// for test ----------------------------------------------
189-
if (poolrank==0) std::cout << "The fifth step done\n";
189+
// if (poolrank==0) std::cout << "The fifth step done\n";
190190
// -------------------------------------------------------
191191
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
192192
return;
@@ -268,7 +268,7 @@ void PW_Basis::collect_st(
268268
}
269269
}
270270
assert(is == this->nstot);
271-
std::cout<<"collect sticks done\n";
271+
// std::cout<<"collect sticks done\n";
272272

273273
// As we will distribute the longest sticks preferentially in Step(3), we rearrange st_* in the order of length decreasing.
274274

source/module_pw/pw_distributeg_method2.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../module_base/mymath.h"
33
#include "../src_parallel/parallel_global.h"
44
#include "../module_base/global_function.h"
5-
#include "iostream"
5+
// #include "iostream"
66
#include "../module_base/timer.h"
77

88

@@ -48,27 +48,27 @@ void PW_Basis::distribution_method2()
4848

4949
this->count_pw_st(tot_npw, st_length2D, st_bottom2D);
5050
// for test --------------------------------------------------
51-
std::cout << "The first step done\n";
52-
std::cout << "tot_npw " << tot_npw << '\n';
53-
std::cout << "this->nstot " << this->nstot << '\n';
54-
for (int ix = 0; ix < nx; ++ix)
55-
{
56-
for (int iy = 0; iy < ny; ++iy)
57-
{
58-
std::cout << st_length2D[ix * ny + iy] << std::setw(4);
59-
}
60-
std::cout << '\n';
61-
}
51+
// std::cout << "The first step done\n";
52+
// std::cout << "tot_npw " << tot_npw << '\n';
53+
// std::cout << "this->nstot " << this->nstot << '\n';
54+
// for (int ix = 0; ix < nx; ++ix)
55+
// {
56+
// for (int iy = 0; iy < ny; ++iy)
57+
// {
58+
// std::cout << st_length2D[ix * ny + iy] << std::setw(4);
59+
// }
60+
// std::cout << '\n';
61+
// }
6262
// ------------------------------------------------------------
6363

6464
// (2) Devide the sticks to each core, sticks are in the order of ixy increasing.
6565

6666
ModuleBase::GlobalFunc::ZEROS(nst_per, this->poolnproc);
6767
this->divide_sticks2();
6868
// for test ----------------------------------------------------------------------------
69-
std::cout << "nst_per ";
70-
for (int ip = 0; ip < this->poolnproc; ++ip) std::cout << nst_per[ip] << std::setw(4);
71-
std::cout << "\n";
69+
// std::cout << "nst_per ";
70+
// for (int ip = 0; ip < this->poolnproc; ++ip) std::cout << nst_per[ip] << std::setw(4);
71+
// std::cout << "\n";
7272
//--------------------------------------------------------------------------------------
7373

7474
// (3) Create the maps from ixy to ip, istot, and from istot to ixy
@@ -77,9 +77,9 @@ void PW_Basis::distribution_method2()
7777
ModuleBase::GlobalFunc::ZEROS(npw_per, this->poolnproc);
7878
this->create_maps(st_length2D, npw_per);
7979
// for test ----------------------------------------------------------------------------
80-
std::cout << "npw_per ";
81-
for (int ip = 0; ip < this->poolnproc; ++ip) std::cout << npw_per[ip] << std::setw(4);
82-
std::cout << "\n";
80+
// std::cout << "npw_per ";
81+
// for (int ip = 0; ip < this->poolnproc; ++ip) std::cout << npw_per[ip] << std::setw(4);
82+
// std::cout << "\n";
8383
//--------------------------------------------------------------------------------------
8484

8585
// (4) Send npw_per, nst[poolrank], st_* to all cores.
@@ -101,7 +101,7 @@ void PW_Basis::distribution_method2()
101101
MPI_Status ierror;
102102
MPI_Recv(&npw, 1, MPI_INT, 0, 0, POOL_WORLD, &ierror); // number of planewaves in current proc.
103103
MPI_Recv(&nst, 1, MPI_INT, 0, 0, POOL_WORLD, &ierror);
104-
std::cout << this->poolrank << " recive done.\n";
104+
// std::cout << this->poolrank << " recive done.\n";
105105
#endif
106106
}
107107
#ifdef __MPI
@@ -125,7 +125,7 @@ void PW_Basis::distribution_method2()
125125
MPI_Bcast(this->istot2bigixy, this->nstot, MPI_INT, 0, POOL_WORLD);
126126
MPI_Bcast(this->ixy2istot, this->nxy, MPI_INT, 0, POOL_WORLD);
127127

128-
std::cout << "Bcast done\n";
128+
// std::cout << "Bcast done\n";
129129
#endif
130130
this->nstnz = this->nst * this->nz;
131131

@@ -135,7 +135,7 @@ void PW_Basis::distribution_method2()
135135
if (st_bottom2D != NULL) delete[] st_bottom2D;
136136
if (st_length2D != NULL) delete[] st_length2D;
137137
// for test ----------------------------------------------
138-
if (poolrank==0) std::cout << "The fifth step done\n";
138+
// if (poolrank==0) std::cout << "The fifth step done\n";
139139
// -------------------------------------------------------
140140
ModuleBase::timer::tick("PW_Basis", "distributeg_method1");
141141
return;

source/module_pw/unittest/Makefile

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
#==========================
33
# Compiler information
44
#==========================
5-
CPLUSPULS = mpiicpc
5+
CPLUSPLUS = mpiicpc
66
CUDA_COMPILE = nvcc
77
OBJ_DIR = pw_obj
8-
BIN_DIR = testbin
98
NP = 12
109
#==========================
1110
# Objects
@@ -33,32 +32,29 @@ pw_basis_k.o\
3332
pw_operation.o\
3433
pw_transform_k.o
3534

36-
DOUBLEFILE=test1.exe\
37-
test2.exe\
38-
test3.exe\
39-
test4.exe\
40-
test2-1.exe\
41-
test2-2.exe\
42-
test2-3.exe\
43-
test_t1.exe\
44-
test_t2.exe
45-
46-
FLOATFILE=testf2.exe\
47-
testf3.exe\
48-
testf4.exe
35+
DOUBLEFILE=test1-2.o\
36+
test1-3.o\
37+
test1-4.o\
38+
test2-2.o\
39+
test2-3.o
40+
41+
FLOATFILE=test1-2f.o\
42+
test1-3f.o\
43+
test1-4f.o
44+
4945
TESTFILE0 = ${DOUBLEFILE}
5046

5147
#==========================
5248
# Options
5349
#==========================
5450
#No MPI
5551
# HONG = -D__NORMAL
56-
# CPLUSPULS = icpc
52+
# CPLUSPLUS = icpc
5753

5854
#Mix Precision
5955
# HONG = -D__MIX_PRECISION -D__NORMAL
6056
# TESTFILE0 = ${DOUBLEFILE} ${FLOATFILE}
61-
# CPLUSPULS = icpc
57+
# CPLUSPLUS = icpc
6258

6359
#Only MPI
6460
HONG = -D__MPI -D__NORMAL
@@ -76,7 +72,7 @@ HONG = -D__MPI -D__NORMAL
7672

7773

7874
PW_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${PW_OBJS_0})
79-
TESTFILE=$(patsubst %.exe, ${BIN_DIR}/%.exe, ${TESTFILE0})
75+
TESTFILE=$(patsubst %.o, ${OBJ_DIR}/%.o, ${TESTFILE0})
8076

8177
##==========================
8278
## FFTW package needed
@@ -101,6 +97,13 @@ FFTW_LIB = -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core
10197
# CUDA_LIB_DIR = ${CUDA_DIR}/lib64
10298
# CUDA_LIB = -L${CUDA_LIB_DIR} -lcufft -lcublas -lcudart
10399

100+
##==========================
101+
## GTEST needed
102+
##==========================
103+
GTEST_DIR = /home/qianrui/intelcompile/impi_gtest
104+
GTESTOPTS = -I${GTEST_DIR}/include -L${GTEST_DIR}/lib -lgtest -lpthread
105+
106+
104107
#LIBS = ${FFTW_LIB} ${CUDA_LIB} -ltcmalloc -lprofiler
105108
LIBS = ${FFTW_LIB} ${CUDA_LIB}
106109
OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -simd -m64 -qopenmp -Wall -pedantic -g
@@ -110,20 +113,17 @@ OPTS = -I${FFTW_INCLUDE_DIR} ${HONG} -Ofast -std=c++11 -simd -m64 -qopenmp -Wall
110113
#==========================
111114
pw :
112115
@ make init
113-
@ make -j $(NP) ${PW_OBJS}
114-
@ make -j $(NP) ${TESTFILE}
116+
@ make -j $(NP) utest.exe
115117

116118
init :
117119
@ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
118-
@ if [ ! -d $(BIN_DIR) ]; then mkdir $(BIN_DIR); fi
119-
@ if [ ! -d $(OBJ_DIR)/README ]; then echo "This directory contains all of the .o files" > $(OBJ_DIR)/README; fi
120120

121-
${BIN_DIR}/%.exe: %.cpp ${PW_OBJS}
122-
${CPLUSPULS} ${OPTS} $< test_tool.cpp ${PW_OBJS} ${LIBS} -o $@
121+
utest.exe: ${PW_OBJS} ${TESTFILE}
122+
${CPLUSPLUS} ${OPTS} ${TESTFILE} utest.cpp test_tool.cpp ${PW_OBJS} ${LIBS} -o utest.exe ${GTESTOPTS}
123123
${OBJ_DIR}/%.o:%.cpp
124-
${CPLUSPULS} ${OPTS} -c ${HONG} $< -o $@
124+
${CPLUSPLUS} ${OPTS} -c ${HONG} $< -o $@ ${GTESTOPTS}
125125

126126
.PHONY:clean
127127
clean:
128128
@ if [ -d $(OBJ_DIR) ]; then rm -rf $(OBJ_DIR); fi
129-
@ if [ -d $(BIN_DIR) ]; then rm -rf $(BIN_DIR); fi
129+
@ if [ -e utest.exe ]; then rm -f utest.exe; fi

0 commit comments

Comments
 (0)