avoid segfault on command errors in force style unit tests and print error mesage instead
This commit is contained in:
@ -26,6 +26,7 @@
|
|||||||
#include "angle.h"
|
#include "angle.h"
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -59,7 +60,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
|||||||
delete lmp;
|
delete lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
|
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp;
|
LAMMPS *lmp;
|
||||||
|
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
lmp->input->one(line);
|
try {
|
||||||
|
lmp->input->one(line);
|
||||||
|
} catch (LAMMPSAbortException &ae) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
|
||||||
|
exit(2);
|
||||||
|
} catch (LAMMPSException &e) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
|
||||||
|
exit(3);
|
||||||
|
} catch (fmt::format_error &fe) {
|
||||||
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
exit(4);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "General exception: %s\n", e.what());
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto parse_input_script = [&](const std::string &filename) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "bond.h"
|
#include "bond.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -59,7 +60,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
|||||||
delete lmp;
|
delete lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
|
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp;
|
LAMMPS *lmp;
|
||||||
|
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
lmp->input->one(line);
|
try {
|
||||||
|
lmp->input->one(line);
|
||||||
|
} catch (LAMMPSAbortException &ae) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
|
||||||
|
exit(2);
|
||||||
|
} catch (LAMMPSException &e) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
|
||||||
|
exit(3);
|
||||||
|
} catch (fmt::format_error &fe) {
|
||||||
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
exit(4);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "General exception: %s\n", e.what());
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto parse_input_script = [&](const std::string &filename) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
#include "dihedral.h"
|
#include "dihedral.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
@ -59,7 +60,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
|||||||
delete lmp;
|
delete lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
|
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
|
LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
|
||||||
|
|
||||||
@ -88,7 +89,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
lmp->input->one(line);
|
try {
|
||||||
|
lmp->input->one(line);
|
||||||
|
} catch (LAMMPSAbortException &ae) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
|
||||||
|
exit(2);
|
||||||
|
} catch (LAMMPSException &e) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
|
||||||
|
exit(3);
|
||||||
|
} catch (fmt::format_error &fe) {
|
||||||
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
exit(4);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "General exception: %s\n", e.what());
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto parse_input_script = [&](const std::string &filename) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "improper.h"
|
#include "improper.h"
|
||||||
@ -59,7 +60,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
|||||||
delete lmp;
|
delete lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
|
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp;
|
LAMMPS *lmp;
|
||||||
|
|
||||||
@ -90,7 +91,21 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
lmp->input->one(line);
|
try {
|
||||||
|
lmp->input->one(line);
|
||||||
|
} catch (LAMMPSAbortException &ae) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
|
||||||
|
exit(2);
|
||||||
|
} catch (LAMMPSException &e) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
|
||||||
|
exit(3);
|
||||||
|
} catch (fmt::format_error &fe) {
|
||||||
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
exit(4);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "General exception: %s\n", e.what());
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
auto parse_input_script = [&](const std::string &filename) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
#include "compute.h"
|
#include "compute.h"
|
||||||
#include "domain.h"
|
#include "domain.h"
|
||||||
|
#include "exceptions.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "info.h"
|
#include "info.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
@ -61,7 +62,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
|||||||
delete lmp;
|
delete lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
|
LAMMPS *init_lammps(LAMMPS::argv &args, const TestConfig &cfg, const bool newton = true)
|
||||||
{
|
{
|
||||||
LAMMPS *lmp;
|
LAMMPS *lmp;
|
||||||
|
|
||||||
@ -92,8 +93,23 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
|||||||
|
|
||||||
// utility lambdas to improve readability
|
// utility lambdas to improve readability
|
||||||
auto command = [&](const std::string &line) {
|
auto command = [&](const std::string &line) {
|
||||||
lmp->input->one(line);
|
try {
|
||||||
|
lmp->input->one(line);
|
||||||
|
} catch (LAMMPSAbortException &ae) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", ae.what());
|
||||||
|
exit(2);
|
||||||
|
} catch (LAMMPSException &e) {
|
||||||
|
fprintf(stderr, "LAMMPS Error: %s\n", e.what());
|
||||||
|
exit(3);
|
||||||
|
} catch (fmt::format_error &fe) {
|
||||||
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
exit(4);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "General exception: %s\n", e.what());
|
||||||
|
exit(5);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parse_input_script = [&](const std::string &filename) {
|
auto parse_input_script = [&](const std::string &filename) {
|
||||||
lmp->input->file(filename.c_str());
|
lmp->input->file(filename.c_str());
|
||||||
};
|
};
|
||||||
@ -760,7 +776,7 @@ TEST(PairStyle, gpu)
|
|||||||
"screen", "-nocite", "-sf", "gpu"};
|
"screen", "-nocite", "-sf", "gpu"};
|
||||||
LAMMPS::argv args_noneigh = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf",
|
LAMMPS::argv args_noneigh = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf",
|
||||||
"gpu", "-pk", "gpu", "0", "neigh", "no"};
|
"gpu", "-pk", "gpu", "0", "neigh", "no"};
|
||||||
LAMMPS::argv args = args_neigh;
|
LAMMPS::argv args = args_neigh;
|
||||||
|
|
||||||
// cannot use GPU neighbor list with hybrid pair style (yet)
|
// cannot use GPU neighbor list with hybrid pair style (yet)
|
||||||
if (test_config.pair_style.substr(0, 6) == "hybrid") {
|
if (test_config.pair_style.substr(0, 6) == "hybrid") {
|
||||||
|
|||||||
Reference in New Issue
Block a user