@@ -43,7 +43,7 @@ class TimerTest : public testing::Test
4343 int T_Elapse = 100 ; // microseconds = 0.1 milliseconds
4444 void TearDown ()
4545 {
46- remove (" tmp" );
46+ // remove("tmp");
4747 }
4848};
4949
@@ -59,19 +59,22 @@ TEST_F(TimerTest, Tick)
5959 EXPECT_GT (ModuleBase::timer::timer_pool[" wavefunc" ][" evc" ].cpu_second ,0.0001 );
6060}
6161
62+
6263TEST_F (TimerTest, Start)
6364{
6465 ModuleBase::timer::start ();
6566 // start() called tick() once
6667 EXPECT_FALSE (ModuleBase::timer::timer_pool[" " ][" total" ].start_flag );
6768}
6869
70+
6971TEST_F (TimerTest, write_to_json)
7072{
7173 ModuleBase::timer::tick (" wavefunc" ," evc" );
7274 std::this_thread::sleep_for (std::chrono::microseconds (T_Elapse)); // 0.1 ms
7375 ModuleBase::timer::tick (" wavefunc" ," evc" );
7476 ModuleBase::timer::write_to_json (" tmp.json" );
77+
7578 // check if tmp.json exists
7679 ifs.open (" tmp.json" );
7780 EXPECT_TRUE (ifs.good ());
@@ -89,9 +92,6 @@ TEST_F(TimerTest, write_to_json)
8992 content += tmp;
9093 }
9194
92- // check if the content is correct
93- // shuold be like this:
94- // {"total": 0, "sub":[{"class_name": "wavefunc","sub":[{"name":"evc","cpu_second": 0.000318,"calls":2,"cpu_second_per_call":0.000159,"cpu_second_per_total": null}]}]}
9595 EXPECT_THAT (content,testing::HasSubstr (" \" total\" :" ));
9696 EXPECT_THAT (content,testing::HasSubstr (" \" sub\" :[{\" class_name\" :\" wavefunc\" ,\" sub\" :[{\" name\" :\" evc\" ,\" cpu_second\" :" ));
9797 EXPECT_THAT (content,testing::HasSubstr (" \" calls\" :2,\" cpu_second_per_call\" :" ));
@@ -106,25 +106,29 @@ TEST_F(TimerTest, PrintAll)
106106 ModuleBase::timer::tick (" wavefunc" ," evc" );
107107 std::this_thread::sleep_for (std::chrono::microseconds (T_Elapse)); // 0.1 ms
108108 ModuleBase::timer::tick (" wavefunc" ," evc" );
109+
109110 // call print_all
110111 ofs.open (" tmp" );
111112 testing::internal::CaptureStdout ();
112113 ModuleBase::timer::print_all (ofs);
113114 output = testing::internal::GetCapturedStdout ();
114115 ofs.close ();
116+
115117 // checout output on screen
116- std::cout << " Get captured stdout: \n " << std::endl;
117- std::cout << output << std::endl;
118+ // std::cout << "Get captured stdout: \n" << std::endl;
119+ // std::cout << output << std::endl;
118120 EXPECT_THAT (output,testing::HasSubstr (" TIME STATISTICS" ));
119121 EXPECT_THAT (output,testing::HasSubstr (" CLASS_NAME" ));
120122 EXPECT_THAT (output,testing::HasSubstr (" NAME" ));
121123 EXPECT_THAT (output,testing::HasSubstr (" TIME/s" ));
122124 EXPECT_THAT (output,testing::HasSubstr (" CALLS" ));
123125 EXPECT_THAT (output,testing::HasSubstr (" AVG/s" ));
124126 EXPECT_THAT (output,testing::HasSubstr (" PER/%" ));
127+
125128 // check output in file
126129 ifs.open (" tmp" );
127- std::cout << " Capture contents line by line from output file: \n " << std::endl;
130+ // std::cout << "Capture contents line by line from output file: \n" << std::endl;
131+ getline (ifs,output);
128132 getline (ifs,output);
129133 EXPECT_THAT (output,testing::HasSubstr (" TIME STATISTICS" ));
130134 getline (ifs,output);
@@ -139,36 +143,41 @@ TEST_F(TimerTest, PrintAll)
139143 remove (" time.json" );
140144}
141145
146+
142147TEST_F (TimerTest, PrintUntilNow)
143148{
144149 long double time = ModuleBase::timer::print_until_now ();
145150 EXPECT_TRUE (time>0.0 );
146151}
147152
153+
148154TEST_F (TimerTest, Finish)
149155{
150156 ModuleBase::timer::tick (" wavefunc" ," evc" );
151157 std::this_thread::sleep_for (std::chrono::microseconds (T_Elapse)); // 0.1 ms
152158 ModuleBase::timer::tick (" wavefunc" ," evc" );
159+
153160 // call print_all
154161 ofs.open (" tmp" );
155162 testing::internal::CaptureStdout ();
156163 ModuleBase::timer::finish (ofs);
157164 output = testing::internal::GetCapturedStdout ();
158165 ofs.close ();
159166 // checout output on screen
160- std::cout << " Get captured stdout: \n " << std::endl;
161- std::cout << output << std::endl;
167+ // std::cout << "Get captured stdout: \n" << std::endl;
168+ // std::cout << output << std::endl;
162169 EXPECT_THAT (output,testing::HasSubstr (" TIME STATISTICS" ));
163170 EXPECT_THAT (output,testing::HasSubstr (" CLASS_NAME" ));
164171 EXPECT_THAT (output,testing::HasSubstr (" NAME" ));
165172 EXPECT_THAT (output,testing::HasSubstr (" TIME/s" ));
166173 EXPECT_THAT (output,testing::HasSubstr (" CALLS" ));
167174 EXPECT_THAT (output,testing::HasSubstr (" AVG/s" ));
168175 EXPECT_THAT (output,testing::HasSubstr (" PER/%" ));
176+
169177 // check output in file
170178 ifs.open (" tmp" );
171- std::cout << " Capture contents line by line from output file: \n " << std::endl;
179+ // std::cout << "Capture contents line by line from output file: \n" << std::endl;
180+ getline (ifs,output);
172181 getline (ifs,output);
173182 EXPECT_THAT (output,testing::HasSubstr (" TIME STATISTICS" ));
174183 getline (ifs,output);
@@ -182,7 +191,6 @@ TEST_F(TimerTest, Finish)
182191 ifs.close ();
183192}
184193
185- // use __MPI to activate parallel environment
186194#ifdef __MPI
187195int main (int argc, char **argv)
188196{
0 commit comments