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 "atom.h"
|
||||
#include "compute.h"
|
||||
#include "domain.h"
|
||||
#include "exceptions.h"
|
||||
#include "force.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
@ -61,7 +62,7 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
|
||||
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;
|
||||
|
||||
@ -92,8 +93,23 @@ LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newto
|
||||
|
||||
// utility lambdas to improve readability
|
||||
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) {
|
||||
lmp->input->file(filename.c_str());
|
||||
};
|
||||
@ -760,7 +776,7 @@ TEST(PairStyle, gpu)
|
||||
"screen", "-nocite", "-sf", "gpu"};
|
||||
LAMMPS::argv args_noneigh = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf",
|
||||
"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)
|
||||
if (test_config.pair_style.substr(0, 6) == "hybrid") {
|
||||
|
||||
Reference in New Issue
Block a user