Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/source_base/test/math_chebyshev_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ TEST_F(MathChebyshevTest, recurs)
testing::internal::CaptureStdout();
EXPECT_EXIT(ModuleBase::Chebyshev<double> noneche(0), ::testing::ExitedWithCode(1), "");
std::string output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("NOTICE"));
EXPECT_THAT(output, testing::HasSubstr("ERROR"));

int norder = 100;
p_chetest = new ModuleBase::Chebyshev<double>(norder);
Expand Down
8 changes: 4 additions & 4 deletions source/source_base/test/tool_check_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_F(ToolCheckTest, Name)
testing::internal::CaptureStdout();
EXPECT_EXIT(ModuleBase::CHECK_NAME(ifs, "abacus"), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("NOTICE"));
EXPECT_THAT(output,testing::HasSubstr("ERROR"));
ifs.close();
}

Expand All @@ -82,7 +82,7 @@ TEST_F(ToolCheckTest, Int)
testing::internal::CaptureStdout();
EXPECT_EXIT(ModuleBase::CHECK_INT(ifs, 80), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("NOTICE"));
EXPECT_THAT(output,testing::HasSubstr("ERROR"));
ifs.close();
}

Expand All @@ -103,7 +103,7 @@ TEST_F(ToolCheckTest, Double)
testing::internal::CaptureStdout();
EXPECT_EXIT(ModuleBase::CHECK_DOUBLE(ifs, 0.22998), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("NOTICE"));
EXPECT_THAT(output,testing::HasSubstr("ERROR"));
ifs.close();
}

Expand All @@ -124,6 +124,6 @@ TEST_F(ToolCheckTest, String)
testing::internal::CaptureStdout();
EXPECT_EXIT(ModuleBase::CHECK_STRING(ifs, "scf"), ::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("NOTICE"));
EXPECT_THAT(output,testing::HasSubstr("ERROR"));
ifs.close();
}
10 changes: 6 additions & 4 deletions source/source_base/test/tool_quit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ TEST_F(ToolQuitTest,warningquit)
EXPECT_EXIT(ModuleBase::WARNING_QUIT("INPUT","bad input parameter"),
::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
// test output on screening
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
// error exits should keep the error message visible and skip timer output
EXPECT_THAT(output, testing::HasSubstr("ERROR"));
EXPECT_THAT(output, testing::Not(testing::HasSubstr("TIME STATISTICS")));
GlobalV::ofs_warning.close();
GlobalV::ofs_running.close();
ifs.open("warning.log");
Expand All @@ -101,8 +102,9 @@ TEST_F(ToolQuitTest,warningquit_with_ret)
EXPECT_EXIT(ModuleBase::WARNING_QUIT("INPUT","bad input parameter",1),
::testing::ExitedWithCode(1), "");
output = testing::internal::GetCapturedStdout();
// test output on screening
EXPECT_THAT(output,testing::HasSubstr("TIME STATISTICS"));
// error exits should keep the error message visible and skip timer output
EXPECT_THAT(output, testing::HasSubstr("ERROR"));
EXPECT_THAT(output, testing::Not(testing::HasSubstr("TIME STATISTICS")));
GlobalV::ofs_warning.close();
GlobalV::ofs_running.close();
ifs.open("warning.log");
Expand Down
57 changes: 27 additions & 30 deletions source/source_base/tool_quit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tool_quit.h"
#include <cstdlib>
#ifdef __MPI
#include "mpi.h"
#endif
Expand All @@ -18,6 +19,22 @@ namespace
{
std::string g_quit_out_dir;
std::string g_quit_calculation;

[[noreturn]] void quit_impl(const int ret, const bool print_timer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend keeping the C++ syntax simple: just use void and avoid adding new syntax elements.

{
#ifdef __NORMAL
(void)print_timer;
#else
if (print_timer)
{
ModuleBase::timer::finish(GlobalV::ofs_running, GlobalV::MY_RANK == 0, false);
std::cout << " See output information in : " << g_quit_out_dir << std::endl;
}
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK);
#endif

std::exit(ret);
}
}

void set_quit_out_dir(const std::string& dir)
Expand Down Expand Up @@ -64,43 +81,21 @@ void QUIT()

void QUIT(int ret)
{

#ifdef __NORMAL
#else
ModuleBase::timer::finish(GlobalV::ofs_running , !GlobalV::MY_RANK, false);
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK);
std::cout<<" See output information in : "<<g_quit_out_dir<<std::endl;
#endif

exit(ret);
quit_impl(ret, true);
}


void WARNING_QUIT(const std::string &file,const std::string &description)
{
WARNING_QUIT(file, description, 1);

#ifdef __MPI /* if it is MPI run, finalize first, then exit */
std::cout << "Detecting if MPI has been initialized..." << std::endl;
int is_initialized = 0;
MPI_Initialized(&is_initialized);
if (is_initialized) {
std::cout << "Terminating ABACUS with multiprocessing environment." << std::endl;
MPI_Finalize();
}
else{
std::cout << "MPI has not been initialized. Quit normally." << std::endl;
}
/* but seems this is the only correct way to terminate the MPI */
#endif
WARNING_QUIT(file, description, 1);
}

void WARNING_QUIT(const std::string &file,const std::string &description,int ret)
{
#ifdef __NORMAL

std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " !ERROR! " << std::endl;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not always an error. We intentionally set the log level to NOTICE.

std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
std::cout << " https://abacus.deepmodeling.com" << std::endl;
Expand All @@ -110,42 +105,44 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
#else
std::cout << " " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " !ERROR! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " " << std::endl;
std::cout << " " << description << std::endl;
std::cout << " " << std::endl;
std::cout << " CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
std::cout << " " << std::endl;
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
std::cout << " https://abacus.deepmodeling.com" << std::endl;
std::cout << " For any questions, propose issues on the website" << std::endl;
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " !ERROR! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;


GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
GlobalV::ofs_running << " !NOTICE! " << std::endl;
GlobalV::ofs_running << " !ERROR! " << std::endl;
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
GlobalV::ofs_running << std::endl;
GlobalV::ofs_running << " " << description << std::endl;
GlobalV::ofs_running << std::endl;
GlobalV::ofs_running << " CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
GlobalV::ofs_running << std::endl;
GlobalV::ofs_running << " For detailed manual of ABACUS, please see the website" << std::endl;
GlobalV::ofs_running << " https://abacus.deepmodeling.com" << std::endl;
GlobalV::ofs_running << " For any questions, propose issues on the website" << std::endl;
GlobalV::ofs_running << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
GlobalV::ofs_running << " NOTICE " << std::endl;
GlobalV::ofs_running << " !ERROR! " << std::endl;
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;

WARNING(file,description);
GlobalV::ofs_running<<" Check in file : "<<g_quit_out_dir<<"warning.log"<<std::endl;

#endif

QUIT(ret);
quit_impl(ret, false);
}

//Check and print warning information for all cores.
Expand Down
2 changes: 1 addition & 1 deletion source/source_basis/module_pw/test/test-other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST_F(PWTEST,test_other)
testing::internal::CaptureStdout();
EXPECT_EXIT(pwtest.setuptransform(), ::testing::ExitedWithCode(1), "");
string output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output,testing::HasSubstr("NOTICE"));
EXPECT_THAT(output,testing::HasSubstr("ERROR"));

int nks = 2;
ModuleBase::Vector3<double> *kvec_d = new ModuleBase::Vector3<double>[nks];
Expand Down
Loading
Loading