Refactoring of more tests

This commit is contained in:
Richard Berger
2021-03-29 14:27:42 -04:00
parent 1752bd0276
commit aaf9aa6d69
19 changed files with 627 additions and 847 deletions

View File

@ -22,6 +22,7 @@
#include "variable.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstdlib>
#include <mpi.h>
@ -29,57 +30,23 @@
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::MatchesRegex;
using ::testing::StrEq;
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
class KimCommandsTest : public ::testing::Test {
class KimCommandsTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
Variable *variable;
void SetUp() override
{
const char *args[] = {"KimCommandsTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "KimCommandsTest";
LAMMPSTest::SetUp();
variable = lmp->input->variable;
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(KimCommandsTest, kim)
@ -115,9 +82,9 @@ TEST_F(KimCommandsTest, kim_init)
// TEST_FAILURE(".*ERROR: KIM Model does not support the requested unit system.*",
// command("kim init ex_model_Ar_P_Morse real"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim init LennardJones_Ar real");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
int ifix = lmp->modify->find_fix("KIM_MODEL_STORE");
ASSERT_GE(ifix, 0);
@ -129,81 +96,81 @@ TEST_F(KimCommandsTest, kim_interactions)
TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim init LennardJones_Ar real");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Must use 'kim interactions' command "
"after simulation box is defined.*",
command("kim interactions Ar"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim init LennardJones_Ar real");
command("lattice fcc 4.4300");
command("region box block 0 10 0 10 0 10");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*",
command("kim interactions Ar Ar"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("lattice fcc 4.4300");
command("region box block 0 20 0 20 0 20");
command("create_box 4 box");
command("create_atoms 4 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*",
command("kim interactions Ar Ar"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("lattice fcc 4.4300");
command("region box block 0 10 0 10 0 10");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Must use 'kim init' before 'kim interactions'.*",
command("kim interactions Ar"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones_Ar real");
command("lattice fcc 4.4300");
command("region box block 0 10 0 10 0 10");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: fixed_types cannot be used with a KIM Portable Model.*",
command("kim interactions fixed_types"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("pair_style kim LennardJones_Ar");
command("region box block 0 1 0 1 0 1");
command("create_box 4 box");
command("pair_coeff * * Ar Ar Ar Ar");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal");
command("lattice fcc 4.920");
command("region box block 0 10 0 10 0 10");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Species 'Ar' is not supported by this KIM Simulator Model.*",
command("kim interactions Ar"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal");
command("lattice fcc 4.08");
@ -211,13 +178,13 @@ TEST_F(KimCommandsTest, kim_interactions)
command("create_box 1 box");
command("create_atoms 1 box");
command("kim interactions Au");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// ASSERT_EQ(lmp->output->var_kim_periodic, 1);
// TEST_FAILURE(".*ERROR: Incompatible units for KIM Simulator Model.*",
// command("kim interactions Au"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones_Ar real");
command("lattice fcc 4.4300");
@ -226,12 +193,12 @@ TEST_F(KimCommandsTest, kim_interactions)
command("create_atoms 1 box");
command("kim interactions Ar");
command("mass 1 39.95");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
int ifix = lmp->modify->find_fix("KIM_MODEL_STORE");
ASSERT_GE(ifix, 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones_Ar real");
command("lattice fcc 4.4300");
@ -243,7 +210,7 @@ TEST_F(KimCommandsTest, kim_interactions)
command("run 1");
command("kim interactions Ar");
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
TEST_F(KimCommandsTest, kim_param)
@ -255,18 +222,18 @@ TEST_F(KimCommandsTest, kim_param)
"'kim param get/set' is mandatory.*",
command("kim param unknown shift 1 shift"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: 'kim param' can only be used with a KIM Portable Model.*",
command("kim param get shift 1 shift"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal 'kim param get' command.\nTo get the new "
"parameter values, pair style must be assigned.\nMust use 'kim"
@ -278,7 +245,7 @@ TEST_F(KimCommandsTest, kim_param)
" interactions' or 'pair_style kim' before 'kim param set'.*",
command("kim param set shift 1 2"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real");
command("lattice fcc 4.4300");
@ -287,7 +254,7 @@ TEST_F(KimCommandsTest, kim_param)
command("create_atoms 1 box");
command("kim interactions Ar");
command("mass 1 39.95");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal index '0' for "
"'shift' parameter with the extent of '1'.*",
@ -312,9 +279,9 @@ TEST_F(KimCommandsTest, kim_param)
"Model does not have the requested 'unknown' parameter.*",
command("kim param get unknown 1 unknown"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get shift 1 shift");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_FALSE(variable->find("shift") == -1);
ASSERT_THAT(variable->retrieve("shift"), StrEq("1"));
@ -334,11 +301,11 @@ TEST_F(KimCommandsTest, kim_param)
"Model does not have the requested '0.4989030' parameter.*",
command("kim param set sigmas 1:1 0.5523570 0.4989030"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable new_shift equal 2");
command("kim param set shift 1 ${new_shift}");
command("kim param get shift 1 shift");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("shift"), StrEq("2"));
@ -363,51 +330,51 @@ TEST_F(KimCommandsTest, kim_param)
"split' is mandatory.*",
command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943"));
ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252"));
ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3 explicit");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943"));
ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252"));
ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get cutoffs 1:3 cutoffs split");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943"));
ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252"));
ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get cutoffs 1:3 cutoffs list");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.20943 2.10252 5.666115"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param set cutoffs 1 2.21 cutoffs 2 2.11");
command("kim param get cutoffs 1:2 cutoffs list");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.21 2.11"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param set cutoffs 1:3 2.3 2.2 5.7");
command("kim param get cutoffs 1:3 cutoffs list");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.3 2.2 5.7"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("lattice fcc 4.4300");
@ -417,19 +384,19 @@ TEST_F(KimCommandsTest, kim_param)
command("mass 1 39.95");
command("pair_style kim LennardJones612_UniversalShifted__MO_959249795837_003");
command("pair_coeff * * Ar");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("kim param get shift 1 shift");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("shift"), StrEq("1"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable new_shift equal 2");
command("kim param set shift 1 ${new_shift}");
command("kim param get shift 1 shift");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("shift"), StrEq("2"));
}
@ -467,13 +434,13 @@ TEST_F(KimCommandsTest, kim_property)
command("kim property remove 1 key short-name"););
TEST_FAILURE(".*ERROR: There is no property instance to dump the content.*",
command("kim property dump results.edn"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real");
command("kim property create 1 cohesive-potential-energy-cubic-crystal");
command("kim property modify 1 key short-name source-value 1 fcc");
command("kim property destroy 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
#endif
}
@ -608,16 +575,16 @@ TEST_F(KimCommandsTest, kim_query)
command(squery););
#if defined(KIM_EXTRA_UNITTESTS)
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim query latconst_1 get_lattice_constant_cubic "
"crystal=[fcc] species=[Al] units=[angstrom] "
"model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal");
command("kim query latconst_1 get_lattice_constant_cubic crystal=[fcc] species=[Al] "
@ -626,71 +593,71 @@ TEST_F(KimCommandsTest, kim_query)
command("kim query latconst_2 get_lattice_constant_cubic crystal=[fcc] species=[Al] "
"units=[angstrom] "
"model=[LennardJones612_UniversalShifted__MO_959249795837_003]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349"));
ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("3.328125931322575"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal");
command("kim query latconst split get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] "
"units=[angstrom]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("3.234055244384789"));
ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("5.167650199630013"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim query latconst index get_lattice_constant_hexagonal "
"crystal=[hcp] species=[Zr] units=[angstrom] "
"model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable latconst delete");
command("clear");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal");
command("kim query latconst list get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] "
"units=[angstrom]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789 5.167650199630013"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal");
command("kim query alpha get_linear_thermal_expansion_coefficient_cubic "
"crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] "
"temperature_units=[K]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("alpha"), StrEq("1.654960564704273e-05"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim query model_list list get_available_models species=[Al]");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
std::string model_list = variable->retrieve("model_list");
auto n = model_list.find("EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005");
ASSERT_TRUE(n != std::string::npos);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim query model_name index get_available_models species=[Al]");
command("variable model_name delete");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("kim query model_name index get_available_models "
@ -708,7 +675,7 @@ TEST_F(KimCommandsTest, kim_query)
command("kim query model_name index get_available_models "
"species=[Al] potential_type=[\"eam\",meam]");
command("variable model_name delete");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
#endif
}
} // namespace LAMMPS_NS
@ -718,7 +685,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -22,6 +22,7 @@
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstdio>
#include <cstring>
@ -32,12 +33,6 @@
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
@ -45,51 +40,22 @@ using ::testing::ExitedWithCode;
using ::testing::MatchesRegex;
using ::testing::StrEq;
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
class LatticeRegionTest : public ::testing::Test {
class LatticeRegionTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = {"LatticeRegionTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
lmp->input->one("units metal");
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "LatticeRegionTest";
LAMMPSTest::SetUp();
command("units metal");
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(LatticeRegionTest, lattice_none)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice none 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::NONE);
ASSERT_EQ(lattice->xlattice, 2.0);
@ -103,10 +69,10 @@ TEST_F(LatticeRegionTest, lattice_none)
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin"););
TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units lj");
command("lattice none 1.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->xlattice, 1.0);
ASSERT_EQ(lattice->ylattice, 1.0);
@ -168,27 +134,27 @@ TEST_F(LatticeRegionTest, lattice_sc)
TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*",
command("lattice sc 1.0 spacing 1.0 -0.1 1.0"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units lj");
command("lattice sc 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
lattice = lmp->domain->lattice;
ASSERT_DOUBLE_EQ(lattice->xlattice, pow(0.5, 1.0 / 3.0));
ASSERT_DOUBLE_EQ(lattice->ylattice, pow(0.5, 1.0 / 3.0));
ASSERT_DOUBLE_EQ(lattice->zlattice, pow(0.5, 1.0 / 3.0));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_bcc)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::BCC);
ASSERT_DOUBLE_EQ(lattice->xlattice, sqrt(2.0) * 4.2);
@ -202,18 +168,18 @@ TEST_F(LatticeRegionTest, lattice_bcc)
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.5);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice bcc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_fcc)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 3.5 origin 0.5 0.5 0.5");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::FCC);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.5);
@ -239,18 +205,18 @@ TEST_F(LatticeRegionTest, lattice_fcc)
command("lattice fcc 1.0 a1 0.0 1.0 0.0"););
TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice fcc 1.0"););
}
TEST_F(LatticeRegionTest, lattice_hcp)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice hcp 3.0 orient z 0 0 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::HCP);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0);
@ -283,18 +249,18 @@ TEST_F(LatticeRegionTest, lattice_hcp)
command("lattice hcp 1.0 a2 0.0 1.0 0.0"););
TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*",
command("lattice hcp 1.0 a3 0.0 1.0 0.0"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice hcp 1.0"););
}
TEST_F(LatticeRegionTest, lattice_diamond)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::DIAMOND);
ASSERT_DOUBLE_EQ(lattice->xlattice, 6.6952719636073539);
@ -335,19 +301,19 @@ TEST_F(LatticeRegionTest, lattice_diamond)
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_EQ(lattice->a3[2], 1.0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice diamond 1.0"););
}
TEST_F(LatticeRegionTest, lattice_sq)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice sq 3.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SQ);
ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0);
@ -361,19 +327,19 @@ TEST_F(LatticeRegionTest, lattice_sq)
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 3");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sq 1.0"););
}
TEST_F(LatticeRegionTest, lattice_sq2)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice sq2 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::SQ2);
ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0);
@ -387,19 +353,19 @@ TEST_F(LatticeRegionTest, lattice_sq2)
ASSERT_EQ(lattice->basis[1][1], 0.5);
ASSERT_EQ(lattice->basis[1][2], 0.0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 3");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice sq2 1.0"););
}
TEST_F(LatticeRegionTest, lattice_hex)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
command("lattice hex 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::HEX);
ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0);
@ -422,16 +388,16 @@ TEST_F(LatticeRegionTest, lattice_hex)
ASSERT_EQ(lattice->a3[1], 0.0);
ASSERT_EQ(lattice->a3[2], 1.0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 3");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*",
command("lattice hex 1.0"););
}
TEST_F(LatticeRegionTest, lattice_custom)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable a equal 4.34");
command("variable b equal $a*sqrt(3.0)");
command("variable c equal $a*sqrt(8.0/3.0)");
@ -449,7 +415,7 @@ TEST_F(LatticeRegionTest, lattice_custom)
"basis 0.5 0.5 0.625 "
"basis $t 0.0 0.125 "
"basis $f 0.5 0.125 ");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto lattice = lmp->domain->lattice;
ASSERT_EQ(lattice->style, Lattice::CUSTOM);
ASSERT_DOUBLE_EQ(lattice->xlattice, 4.34);
@ -495,9 +461,9 @@ TEST_F(LatticeRegionTest, lattice_custom)
TEST_FAILURE(".*ERROR: Illegal lattice command.*",
command("lattice custom 1.0 basis 0.0 1.0 0"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dimension 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", command("lattice custom 1.0"););
TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*",
command("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0"););
@ -511,28 +477,28 @@ TEST_F(LatticeRegionTest, lattice_custom)
TEST_F(LatticeRegionTest, region_fail)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice none 2.0");
command("region box block 0 1 0 1 0 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Create_atoms command before simulation box is defined.*",
command("create_atoms 1 box"););
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("create_box 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Cannot create atoms with undefined lattice.*",
command("create_atoms 1 box"););
}
TEST_F(LatticeRegionTest, region_block_lattice)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice sc 1.5");
command("region box block 0 2 0 2 0 2 units lattice");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
auto x = lmp->atom->x;
@ -553,12 +519,12 @@ TEST_F(LatticeRegionTest, region_block_lattice)
TEST_F(LatticeRegionTest, region_block_box)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice sc 1.5 origin 0.75 0.75 0.75");
command("region box block 0 2 0 2 0 2 units box");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
auto x = lmp->atom->x;
@ -570,84 +536,84 @@ TEST_F(LatticeRegionTest, region_block_box)
TEST_F(LatticeRegionTest, region_cone)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0");
command("create_box 1 box");
command("create_atoms 1 region box");
command("write_dump all atom init.lammpstrj");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 42);
}
TEST_F(LatticeRegionTest, region_cylinder)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box cylinder z 1.0 1.0 2.1 0.0 2.0 ");
command("create_box 1 box");
command("create_atoms 1 region box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 114);
}
TEST_F(LatticeRegionTest, region_prism)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice bcc 2.5 origin 0.75 0.75 0.75");
command("region box prism 0 2 0 2 0 2 0.5 0.0 0.0");
command("create_box 1 box");
command("create_atoms 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 1);
ASSERT_EQ(lmp->atom->natoms, 16);
}
TEST_F(LatticeRegionTest, region_sphere)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box sphere 1.0 1.0 1.0 1.1");
command("create_box 1 box");
command("create_atoms 1 region box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 14);
}
TEST_F(LatticeRegionTest, region_union)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region part1 sphere 2.0 1.0 1.0 1.1");
command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region box union 2 part1 part2");
command("create_box 1 box");
command("create_atoms 1 region box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 67);
}
TEST_F(LatticeRegionTest, region_intersect)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region part1 sphere 2.0 1.0 1.0 1.8");
command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region box intersect 2 part1 part2");
command("create_box 1 box");
command("create_atoms 1 region box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 21);
}
TEST_F(LatticeRegionTest, region_plane)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("lattice fcc 2.5 origin 0.5 0.5 0.5");
command("region box block 0.0 2.0 0.0 2.0 0.0 2.0");
command("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0");
@ -656,7 +622,7 @@ TEST_F(LatticeRegionTest, region_plane)
command("create_box 1 box");
command("create_atoms 1 region atoms");
command("write_dump all atom init.lammpstrj");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->domain->triclinic, 0);
ASSERT_EQ(lmp->atom->natoms, 16);
}
@ -668,7 +634,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -21,6 +21,7 @@
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstdio>
#include <mpi.h>
@ -28,12 +29,6 @@
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
@ -41,52 +36,23 @@ using ::testing::MatchesRegex;
#define GETIDX(i) lmp->atom->map(i)
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
#define STRINGIFY(val) XSTR(val)
#define XSTR(val) #val
class ResetIDsTest : public ::testing::Test {
class ResetIDsTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
Info *info = new Info(lmp);
testbinary = "ResetIDsTest";
LAMMPSTest::SetUp();
if (info->has_style("atom", "full")) {
lmp->input->one("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER));
lmp->input->one("include ${input_dir}/in.fourmol");
BEGIN_HIDE_OUTPUT();
command("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER));
command("include ${input_dir}/in.fourmol");
END_HIDE_OUTPUT();
}
delete info;
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(ResetIDsTest, MolIDAll)
@ -126,9 +92,9 @@ TEST_F(ResetIDsTest, MolIDAll)
// the original data file has two different molecule IDs
// for two residues of the same molecule/fragment.
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_mol_ids all");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(molid[GETIDX(1)], 1);
ASSERT_EQ(molid[GETIDX(2)], 1);
@ -168,12 +134,12 @@ TEST_F(ResetIDsTest, DeletePlusAtomID)
auto molid = lmp->atom->molecule;
// delete two water molecules
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("group allwater molecule 3:6");
command("group twowater molecule 4:6:2");
command("delete_atoms group twowater compress no bond yes");
command("reset_mol_ids all");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->natoms, 23);
ASSERT_EQ(lmp->atom->map_tag_max, 26);
@ -230,9 +196,9 @@ TEST_F(ResetIDsTest, DeletePlusAtomID)
ASSERT_GE(GETIDX(25), 0);
ASSERT_GE(GETIDX(26), 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_atom_ids");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->map_tag_max, 23);
for (int i = 1; i <= 23; ++i)
@ -246,11 +212,11 @@ TEST_F(ResetIDsTest, PartialOffset)
auto molid = lmp->atom->molecule;
// delete two water molecules
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("group allwater molecule 3:6");
command("group nowater subtract all allwater");
command("reset_mol_ids allwater offset 4");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->natoms, 29);
ASSERT_EQ(lmp->atom->map_tag_max, 29);
@ -284,9 +250,9 @@ TEST_F(ResetIDsTest, PartialOffset)
ASSERT_EQ(molid[GETIDX(28)], 8);
ASSERT_EQ(molid[GETIDX(29)], 8);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_mol_ids nowater offset 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(molid[GETIDX(1)], 1);
ASSERT_EQ(molid[GETIDX(2)], 1);
@ -326,13 +292,13 @@ TEST_F(ResetIDsTest, DeleteAdd)
auto molid = lmp->atom->molecule;
// delete two water molecules
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("group allwater molecule 3:6");
command("group twowater molecule 4:6:2");
command("group nowater subtract all allwater");
command("delete_atoms group twowater compress no bond yes mol yes");
command("reset_mol_ids allwater");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->natoms, 23);
ASSERT_EQ(lmp->atom->map_tag_max, 26);
@ -389,17 +355,17 @@ TEST_F(ResetIDsTest, DeleteAdd)
ASSERT_GE(GETIDX(25), 0);
ASSERT_GE(GETIDX(26), 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_atom_ids sort yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->map_tag_max, 23);
for (int i = 1; i <= 23; ++i)
ASSERT_GE(GETIDX(i), 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_mol_ids nowater offset 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(molid[GETIDX(1)], 2);
ASSERT_EQ(molid[GETIDX(2)], 2);
@ -425,13 +391,13 @@ TEST_F(ResetIDsTest, DeleteAdd)
ASSERT_EQ(molid[GETIDX(22)], 4);
ASSERT_EQ(molid[GETIDX(23)], 4);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("create_atoms 1 single 0.0 0.0 0.0");
command("create_atoms 2 single 1.0 0.0 0.0");
command("create_atoms 3 single 2.0 0.0 0.0");
command("create_atoms 4 single 3.0 0.0 0.0");
command("reset_mol_ids all single yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->natoms, 27);
ASSERT_EQ(lmp->atom->map_tag_max, 27);
@ -443,9 +409,9 @@ TEST_F(ResetIDsTest, DeleteAdd)
ASSERT_EQ(molid[GETIDX(26)], 6);
ASSERT_EQ(molid[GETIDX(27)], 7);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_mol_ids all single no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(molid[GETIDX(21)], 3);
ASSERT_EQ(molid[GETIDX(22)], 3);
@ -455,9 +421,9 @@ TEST_F(ResetIDsTest, DeleteAdd)
ASSERT_EQ(molid[GETIDX(26)], 0);
ASSERT_EQ(molid[GETIDX(27)], 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_mol_ids all compress no single yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(molid[GETIDX(21)], 21);
ASSERT_EQ(molid[GETIDX(22)], 21);
@ -473,12 +439,12 @@ TEST_F(ResetIDsTest, TopologyData)
if (lmp->atom->natoms == 0) GTEST_SKIP();
// delete two water molecules
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("group allwater molecule 3:6");
command("group twowater molecule 4:6:2");
command("group nowater subtract all allwater");
command("delete_atoms group twowater compress no bond yes mol yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(lmp->atom->natoms, 23);
ASSERT_EQ(lmp->atom->map_tag_max, 26);
@ -562,9 +528,9 @@ TEST_F(ResetIDsTest, TopologyData)
ASSERT_EQ(angle_atom2[GETIDX(24)][0], 24);
ASSERT_EQ(angle_atom3[GETIDX(24)][0], 26);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("reset_atom_ids sort yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
num_bond = lmp->atom->num_bond;
num_angle = lmp->atom->num_angle;
@ -679,41 +645,40 @@ TEST_F(ResetIDsTest, DeathTests)
command("reset_mol_ids all single xxx"););
}
TEST(ResetMolIds, CMDFail)
class ResetMolIDsTest : public LAMMPSTest {
protected:
void SetUp() override
{
testbinary = "ResetIDsTest";
LAMMPSTest::SetUp();
}
};
TEST_F(ResetMolIDsTest, FailBeforeBox)
{
LAMMPS *lmp;
const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*ERROR: Reset_mol_ids command before simulation box is.*",
lmp->input->one("reset_mol_ids all"););
command("reset_mol_ids all"););
}
auto command = [&](const std::string &line) {
lmp->input->one(line.c_str());
};
if (!verbose) ::testing::internal::CaptureStdout();
TEST_F(ResetMolIDsTest, FailMissingId)
{
BEGIN_HIDE_OUTPUT();
command("atom_modify id no");
command("region box block 0 1 0 1 0 1");
command("create_box 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Cannot use reset_mol_ids unless.*", command("reset_mol_ids all"););
}
if (!verbose) ::testing::internal::CaptureStdout();
TEST_F(ResetMolIDsTest, FailOnlyMolecular)
{
BEGIN_HIDE_OUTPUT();
command("clear");
command("region box block 0 1 0 1 0 1");
command("create_box 1 box");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all"););
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
};
}
} // namespace LAMMPS_NS
@ -722,7 +687,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -24,6 +24,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstring>
#include <vector>
@ -31,12 +32,6 @@
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
using LAMMPS_NS::MathConst::MY_PI;
using LAMMPS_NS::utils::split_words;
@ -45,39 +40,18 @@ using ::testing::ExitedWithCode;
using ::testing::MatchesRegex;
using ::testing::StrEq;
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
if (verbose) std::cout << mesg; \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
if (verbose) std::cout << mesg; \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
class VariableTest : public ::testing::Test {
class VariableTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
Group *group;
Domain *domain;
Variable *variable;
void SetUp() override
{
const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen",
"-nocite", "-v", "num", "1"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "VariableTest";
args = {"-log", "none", "-echo", "screen", "-nocite", "-v", "num", "1"};
LAMMPSTest::SetUp();
group = lmp->group;
domain = lmp->domain;
variable = lmp->input->variable;
@ -85,19 +59,14 @@ protected:
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
std::cout.flush();
LAMMPSTest::TearDown();
unlink("test_variable.file");
unlink("test_variable.atomfile");
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
void atomic_system()
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units real");
command("lattice sc 1.0 origin 0.125 0.125 0.125");
command("region box block -2 2 -2 2 -2 2");
@ -109,23 +78,23 @@ protected:
command("region top block INF INF -2.0 -1.0 INF INF");
command("set region left type 2");
command("set region right type 3");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void molecular_system()
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("fix props all property/atom mol rmass q");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
atomic_system();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable molid atom floor(id/4)+1");
command("variable charge atom 2.0*sin(PI/32*id)");
command("set atom * mol v_molid");
command("set atom * charge v_charge");
command("set type 1 mass 0.5");
command("set type 2*4 mass 2.0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void file_vars()
@ -152,7 +121,7 @@ TEST_F(VariableTest, CreateDelete)
{
file_vars();
ASSERT_EQ(variable->nvar, 1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1 2 3 4");
command("variable two equal 1");
command("variable two equal 2");
@ -173,11 +142,11 @@ TEST_F(VariableTest, CreateDelete)
command("variable ten2 uloop 4");
command("variable ten3 uloop 4 pad");
command("variable dummy index 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(variable->nvar, 17);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable dummy delete");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(variable->nvar, 16);
ASSERT_THAT(variable->retrieve("three"), StrEq("three"));
variable->set_string("three", "four");
@ -235,7 +204,7 @@ TEST_F(VariableTest, AtomicSystem)
atomic_system();
file_vars();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1 2 3 4");
command("variable id atom type");
command("variable id atom id");
@ -262,7 +231,7 @@ TEST_F(VariableTest, AtomicSystem)
command("variable rgsum equal sum(v_rg)");
command("variable loop equal v_loop+1");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_EQ(variable->atomstyle(variable->find("one")), 0);
ASSERT_EQ(variable->atomstyle(variable->find("id")), 1);
@ -294,7 +263,7 @@ TEST_F(VariableTest, AtomicSystem)
TEST_F(VariableTest, Expressions)
{
atomic_system();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1");
command("variable two equal 2");
command("variable three equal v_one+v_two");
@ -321,7 +290,7 @@ TEST_F(VariableTest, Expressions)
command("variable err2 equal v_one%v_ten7");
command("variable err3 equal v_ten7^-v_one");
variable->set("dummy index 1 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
int ivar = variable->find("one");
ASSERT_FALSE(variable->equalstyle(ivar));
@ -364,7 +333,7 @@ TEST_F(VariableTest, Functions)
atomic_system();
file_vars();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1");
command("variable two equal random(1,2,643532)");
command("variable three equal atan2(v_one,1)");
@ -377,7 +346,7 @@ TEST_F(VariableTest, Functions)
command("variable ten equal floor(1.85)+ceil(1.85)");
command("variable ten1 equal tan(v_eight/2.0)");
command("variable ten2 equal asin(-1.0)+acos(0.0)");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99);
ASSERT_LT(variable->compute_equal(variable->find("two")), 2.01);
@ -396,74 +365,64 @@ TEST_F(VariableTest, Functions)
TEST_F(VariableTest, IfCommand)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if 1>0 then 'print \"bingo!\"'");
auto text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
auto text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*nope\?.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*nope\?.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if !(a==b) then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if x==x|^1==0 then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
BEGIN_CAPTURE_OUTPUT();
command("if x!=x|^a!=b then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
text = END_CAPTURE_OUTPUT();
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
@ -492,34 +451,34 @@ TEST_F(VariableTest, NextCommand)
{
file_vars();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("variable one index 1 2");
command("variable two equal 2");
command("variable three file test_variable.file");
command("variable four loop 2 4");
command("variable five index 1 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 1);
ASSERT_THAT(variable->retrieve("three"), StrEq("one"));
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("next one");
command("next three");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 2);
ASSERT_THAT(variable->retrieve("three"), StrEq("two"));
ASSERT_GE(variable->find("one"), 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("next one");
command("next three");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// index style variable is deleted if no more next element
ASSERT_EQ(variable->find("one"), -1);
ASSERT_GE(variable->find("three"), 0);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("next three");
command("next three");
command("next three");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// file style variable is deleted if no more next element
ASSERT_EQ(variable->find("three"), -1);
@ -536,7 +495,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -45,14 +45,14 @@ public:
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
if (!dump_modify_options.empty()) {
@ -60,7 +60,7 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
@ -76,7 +76,7 @@ public:
std::string text_modify_options, std::string compressed_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options));
@ -89,17 +89,17 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline =
fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
return converted_file;
}
};

File diff suppressed because it is too large Load Diff

View File

@ -32,14 +32,14 @@ class DumpAtomTest : public MeltTest {
public:
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
if (!dump_modify_options.empty()) {
@ -47,13 +47,13 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file));
@ -63,15 +63,15 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
return fmt::format("{}.txt", binary_file);
}
};
@ -504,27 +504,27 @@ TEST_F(DumpAtomTest, per_processor_multi_file_run1)
TEST_F(DumpAtomTest, dump_modify_scale_invalid)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id scale true"););
}
TEST_F(DumpAtomTest, dump_modify_image_invalid)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id image true"););
}
TEST_F(DumpAtomTest, dump_modify_invalid)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id true"););
}
@ -534,12 +534,12 @@ TEST_F(DumpAtomTest, write_dump)
auto reference = "dump_ref_run0.melt";
auto dump_file = "write_dump_atom_run0.melt";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all atom 1 {}", reference));
command("dump_modify id scale no units yes");
command("run 0");
command("write_dump all atom write_dump_atom_run*.melt modify scale no units yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_FILE_EXISTS(reference);
ASSERT_FILE_EXISTS(dump_file);
@ -556,12 +556,12 @@ TEST_F(DumpAtomTest, binary_write_dump)
auto reference = "dump_run0.melt.bin";
auto dump_file = "write_dump_atom_run0_p0.melt.bin";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all atom 1 {}", reference));
command("dump_modify id scale no units yes");
command("run 0");
command("write_dump all atom write_dump_atom_run*_p%.melt.bin modify scale no units yes");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
ASSERT_FILE_EXISTS(reference);
ASSERT_FILE_EXISTS(dump_file);

View File

@ -340,9 +340,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_bad_param)
{
if (compression_style != "atom/gz") GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt")));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 compression_level 12");
@ -353,9 +353,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param)
{
if (compression_style != "atom/gz") GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt")));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 pad 3 compression_level 12");

View File

@ -30,7 +30,7 @@ public:
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
if (!dump_modify_options.empty()) {
@ -38,7 +38,7 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
};
@ -54,9 +54,9 @@ TEST_F(DumpCfgTest, require_multifile)
auto fields =
"mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", command("run 0"););
}

View File

@ -230,9 +230,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_bad_param)
if (compression_style != "cfg/gz") GTEST_SKIP();
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 compression_level 12");
@ -244,9 +244,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param)
if (compression_style != "cfg/gz") GTEST_SKIP();
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 pad 3 compression_level 12");

View File

@ -30,15 +30,15 @@ class DumpCustomTest : public MeltTest {
public:
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
if (!dump_modify_options.empty()) {
@ -46,14 +46,14 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields));
@ -63,15 +63,15 @@ public:
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
return fmt::format("{}.txt", binary_file);
}
};
@ -113,9 +113,9 @@ TEST_F(DumpCustomTest, thresh_run0)
TEST_F(DumpCustomTest, compute_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("compute comp all property/atom x y z");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto dump_file = "dump_custom_compute_run0.melt";
auto fields = "id type x y z c_comp[1] c_comp[2] c_comp[3]";
@ -134,9 +134,9 @@ TEST_F(DumpCustomTest, compute_run0)
TEST_F(DumpCustomTest, fix_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("fix numdiff all numdiff 1 0.0001");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto dump_file = "dump_custom_compute_run0.melt";
auto fields = "id x y z f_numdiff[1] f_numdiff[2] f_numdiff[3]";
@ -155,10 +155,10 @@ TEST_F(DumpCustomTest, fix_run0)
TEST_F(DumpCustomTest, custom_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("fix prop all property/atom i_flag1 d_flag2");
command("compute 1 all property/atom i_flag1 d_flag2");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto dump_file = "dump_custom_custom_run0.melt";
auto fields = "id x y z i_flag1 d_flag2";
@ -242,10 +242,10 @@ TEST_F(DumpCustomTest, binary_triclinic_run1)
TEST_F(DumpCustomTest, with_variable_run1)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("compute 1 all property/atom proc");
command("variable p atom (c_1%10)+1");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto dump_file = "dump_custom_with_variable_run1.melt";
auto fields = "id type x y z v_p";

View File

@ -31,9 +31,9 @@ public:
void SetUp() override {
CompressedDumpTest::SetUp();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("compute comp all pair/local dist eng");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
};
@ -205,9 +205,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_bad_param)
auto fields = "index c_comp[1]";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 compression_level 12");
@ -220,9 +220,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param)
auto fields = "index c_comp[1]";
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 pad 3 compression_level 12");

View File

@ -191,9 +191,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_bad_param)
{
if (compression_style != "xyz/gz") GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz")));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 compression_level 12");
@ -204,9 +204,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param)
{
if (compression_style != "xyz/gz") GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz")));
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*",
command("dump_modify id1 pad 3 compression_level 12");

View File

@ -18,6 +18,7 @@
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstring>
#include <mpi.h>
@ -28,28 +29,23 @@ using utils::split_words;
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
class EIMPotentialFileReaderTest : public ::testing::Test {
class EIMPotentialFileReaderTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
PairEIM::Setfl setfl;
static const int nelements = 9;
void SetUp() override
{
const char *args[] = {
"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
lmp->input->one("units metal");
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "EIMPotentialFileReaderTest";
LAMMPSTest::SetUp();
ASSERT_NE(lmp, nullptr);
BEGIN_HIDE_OUTPUT();
command("units metal");
END_HIDE_OUTPUT();
// check if the prerequisite eim pair style is available
Info *info = new Info(lmp);
ASSERT_TRUE(info->has_style("pair", "eim"));
delete info;
int npair = nelements * (nelements + 1) / 2;
setfl.ielement = new int[nelements];
@ -99,17 +95,15 @@ protected:
delete[] setfl.rs;
delete[] setfl.tp;
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
LAMMPSTest::TearDown();
}
};
TEST_F(EIMPotentialFileReaderTest, global_line)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
EIMPotentialFileReader reader(lmp, "ffield.eim");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
reader.get_global(&setfl);
ASSERT_DOUBLE_EQ(setfl.division, 2.0);
@ -119,9 +113,9 @@ TEST_F(EIMPotentialFileReaderTest, global_line)
TEST_F(EIMPotentialFileReaderTest, element_line_sequential)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
EIMPotentialFileReader reader(lmp, "ffield.eim");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
reader.get_element(&setfl, 0, "Li");
ASSERT_EQ(setfl.ielement[0], 3);
@ -144,9 +138,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_sequential)
TEST_F(EIMPotentialFileReaderTest, element_line_random)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
EIMPotentialFileReader reader(lmp, "ffield.eim");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
reader.get_element(&setfl, 0, "Id");
ASSERT_EQ(setfl.ielement[0], 53);
@ -160,9 +154,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_random)
TEST_F(EIMPotentialFileReaderTest, pair_line)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
EIMPotentialFileReader reader(lmp, "ffield.eim");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
reader.get_pair(&setfl, 0, "Li", "Li");
ASSERT_DOUBLE_EQ(setfl.rcutphiA[0], 6.0490e+00);
@ -183,9 +177,9 @@ TEST_F(EIMPotentialFileReaderTest, pair_line)
TEST_F(EIMPotentialFileReaderTest, pair_identical)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
EIMPotentialFileReader reader(lmp, "ffield.eim");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
reader.get_pair(&setfl, 0, "Li", "Na");
reader.get_pair(&setfl, 1, "Na", "Li");

View File

@ -17,6 +17,7 @@
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstdio>
#include <mpi.h>
@ -31,43 +32,17 @@ using utils::sfgets;
using utils::sfread;
using utils::split_words;
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
class FileOperationsTest : public ::testing::Test {
class FileOperationsTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = {"FileOperationsTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "FileOperationsTest";
LAMMPSTest::SetUp();
ASSERT_NE(lmp, nullptr);
FILE *fp = fopen("safe_file_read_test.txt", "wb");
ASSERT_NE(fp, nullptr);
fputs("one line\n", fp);
@ -79,13 +54,9 @@ protected:
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
LAMMPSTest::TearDown();
remove("safe_file_read_test.txt");
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
#define MAX_BUF_SIZE 128
@ -179,7 +150,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -15,6 +15,7 @@
#include "input.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cmath>
#include <cstring>
@ -28,20 +29,14 @@ using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::Eq;
class ImageFlagsTest : public ::testing::Test {
class ImageFlagsTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = {"ImageFlagsTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "ImageFlagsTest";
LAMMPSTest::SetUp();
ASSERT_NE(lmp, nullptr);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units real");
command("dimension 3");
command("region box block -2 2 -2 2 -2 2");
@ -54,18 +49,14 @@ protected:
command("set atom 1 image -1 2 3");
command("set atom 2 image -2 1 -1");
command("write_data test_image_flags.data");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
LAMMPSTest::TearDown();
remove("test_image_flags.data");
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(ImageFlagsTest, change_box)
@ -87,9 +78,9 @@ TEST_F(ImageFlagsTest, change_box)
ASSERT_EQ(imy, 1);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all boundary f p p");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;
@ -108,9 +99,9 @@ TEST_F(ImageFlagsTest, change_box)
ASSERT_EQ(imy, 1);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all boundary f s p");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;
@ -129,9 +120,9 @@ TEST_F(ImageFlagsTest, change_box)
ASSERT_EQ(imy, 0);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("change_box all boundary p p m");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;
@ -153,14 +144,14 @@ TEST_F(ImageFlagsTest, change_box)
TEST_F(ImageFlagsTest, read_data)
{
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("dimension 3");
command("boundary p p p");
command("pair_style zero 2.0");
command("read_data test_image_flags.data");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
auto image = lmp->atom->image;
int imx = (image[0] & IMGMASK) - IMGMAX;
@ -179,14 +170,14 @@ TEST_F(ImageFlagsTest, read_data)
ASSERT_EQ(imy, 1);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("dimension 3");
command("boundary f p p");
command("pair_style zero 2.0");
command("read_data test_image_flags.data");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;
@ -205,14 +196,14 @@ TEST_F(ImageFlagsTest, read_data)
ASSERT_EQ(imy, 1);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("dimension 3");
command("boundary p s p");
command("pair_style zero 2.0");
command("read_data test_image_flags.data");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;
@ -231,14 +222,14 @@ TEST_F(ImageFlagsTest, read_data)
ASSERT_EQ(imy, 0);
ASSERT_EQ(imz, -1);
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("dimension 3");
command("boundary p p m");
command("pair_style zero 2.0");
command("read_data test_image_flags.data");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
image = lmp->atom->image;
imx = (image[0] & IMGMASK) - IMGMAX;

View File

@ -19,6 +19,7 @@
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstdio>
#include <mpi.h>
@ -33,26 +34,6 @@ using utils::split_words;
#define test_name test_info_->name()
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;
#else
const bool have_openmpi = false;
#endif
#define TEST_FAILURE(errmsg, ...) \
if (Info::has_exceptions()) { \
::testing::internal::CaptureStdout(); \
ASSERT_ANY_THROW({__VA_ARGS__}); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} else { \
if (!have_openmpi) { \
::testing::internal::CaptureStdout(); \
ASSERT_DEATH({__VA_ARGS__}, ""); \
auto mesg = ::testing::internal::GetCapturedStdout(); \
ASSERT_THAT(mesg, MatchesRegex(errmsg)); \
} \
}
static void create_molecule_files()
{
@ -96,27 +77,21 @@ static void create_molecule_files()
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
class MoleculeFileTest : public ::testing::Test {
class MoleculeFileTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = {"MoleculeFileTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
create_molecule_files();
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "MoleculeFileTest";
LAMMPSTest::SetUp();
ASSERT_NE(lmp, nullptr);
BEGIN_HIDE_OUTPUT();
create_molecule_files();
END_HIDE_OUTPUT();
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
LAMMPSTest::TearDown();
remove("h2o.mol");
remove("co2.mol");
}
@ -128,11 +103,9 @@ protected:
fputs(content.c_str(), fp);
fclose(fp);
lmp->input->one(fmt::format("molecule {} {} {}", name, file, args));
command(fmt::format("molecule {} {} {}", name, file, args));
remove(file.c_str());
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(MoleculeFileTest, nofile)
@ -292,7 +265,7 @@ int main(int argc, char **argv)
MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv);
if (have_openmpi && !LAMMPS_NS::Info::has_exceptions())
if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions())
std::cout << "Warning: using OpenMPI without exceptions. "
"Death tests will be skipped\n";

View File

@ -20,6 +20,7 @@
#include "thermo.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cmath>
#include <cstring>
@ -42,23 +43,17 @@ const double p_convert = 1.01325;
// of data in update.cpp. could be 1.0e-12
const double rel_error = 5.0e-7;
class PairUnitConvertTest : public ::testing::Test {
class PairUnitConvertTest : public LAMMPSTest {
protected:
LAMMPS *lmp;
Info *info;
double fold[4][3];
void SetUp() override
{
const char *args[] = {"PairUnitConvertTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
if (!verbose) ::testing::internal::GetCapturedStdout();
testbinary = "PairUnitConvertTest";
LAMMPSTest::SetUp();
ASSERT_NE(lmp, nullptr);
if (!verbose) ::testing::internal::CaptureStdout();
info = new Info(lmp);
BEGIN_HIDE_OUTPUT();
command("units metal");
command("dimension 3");
command("region box block -4 4 -4 4 -4 4");
@ -72,19 +67,14 @@ protected:
command("mass * 1.0");
command("write_data test_pair_unit_convert.data nocoeff");
command("clear");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
}
void TearDown() override
{
if (!verbose) ::testing::internal::CaptureStdout();
delete info;
delete lmp;
if (!verbose) ::testing::internal::GetCapturedStdout();
LAMMPSTest::TearDown();
remove("test_pair_unit_convert.data");
}
void command(const std::string &cmd) { lmp->input->one(cmd); }
};
TEST_F(PairUnitConvertTest, zero)
@ -92,13 +82,13 @@ TEST_F(PairUnitConvertTest, zero)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "zero")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style zero 6.0");
command("pair_coeff * *");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -109,14 +99,14 @@ TEST_F(PairUnitConvertTest, zero)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style zero 6.0");
command("pair_coeff * *");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -135,7 +125,7 @@ TEST_F(PairUnitConvertTest, lj_cut)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "lj/cut")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style lj/cut 6.0");
@ -145,7 +135,7 @@ TEST_F(PairUnitConvertTest, lj_cut)
command("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2");
command("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -156,7 +146,7 @@ TEST_F(PairUnitConvertTest, lj_cut)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
@ -167,7 +157,7 @@ TEST_F(PairUnitConvertTest, lj_cut)
command("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2");
command("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -186,13 +176,13 @@ TEST_F(PairUnitConvertTest, eam)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "eam")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style eam");
command("pair_coeff * * Cu_u3.eam");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -203,14 +193,14 @@ TEST_F(PairUnitConvertTest, eam)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style eam");
command("pair_coeff * * Cu_u3.eam");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -229,13 +219,13 @@ TEST_F(PairUnitConvertTest, eam_alloy)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "eam/alloy")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/alloy");
command("pair_coeff * * AlCu.eam.alloy Al Cu");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -246,14 +236,14 @@ TEST_F(PairUnitConvertTest, eam_alloy)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/alloy");
command("pair_coeff * * AlCu.eam.alloy Al Cu");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -272,13 +262,13 @@ TEST_F(PairUnitConvertTest, eam_fs)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "eam/fs")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/fs");
command("pair_coeff * * FeP_mm.eam.fs Fe P");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -289,14 +279,14 @@ TEST_F(PairUnitConvertTest, eam_fs)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/fs");
command("pair_coeff * * FeP_mm.eam.fs Fe P");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -315,13 +305,13 @@ TEST_F(PairUnitConvertTest, eam_cd)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "eam/cd")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/cd");
command("pair_coeff * * FeCr.cdeam Cr Fe");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -332,14 +322,14 @@ TEST_F(PairUnitConvertTest, eam_cd)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style eam/cd");
command("pair_coeff * * FeCr.cdeam Cr Fe");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -358,13 +348,13 @@ TEST_F(PairUnitConvertTest, eim)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "eim")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style eim");
command("pair_coeff * * Na Cl ffield.eim Na Cl");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -375,14 +365,14 @@ TEST_F(PairUnitConvertTest, eim)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style eim");
command("pair_coeff * * Na Cl ffield.eim Na Cl");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -401,13 +391,13 @@ TEST_F(PairUnitConvertTest, gw)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "gw")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style gw");
command("pair_coeff * * SiC.gw Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -418,14 +408,14 @@ TEST_F(PairUnitConvertTest, gw)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style gw");
command("pair_coeff * * SiC.gw Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -444,13 +434,13 @@ TEST_F(PairUnitConvertTest, gw_zbl)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "gw/zbl")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style gw/zbl");
command("pair_coeff * * SiC.gw.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -461,14 +451,14 @@ TEST_F(PairUnitConvertTest, gw_zbl)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style gw/zbl");
command("pair_coeff * * SiC.gw.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -487,13 +477,13 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "nb3b/harmonic")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style nb3b/harmonic");
command("pair_coeff * * MOH.nb3b.harmonic M O");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -504,14 +494,14 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style nb3b/harmonic");
command("pair_coeff * * MOH.nb3b.harmonic M O");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -530,13 +520,13 @@ TEST_F(PairUnitConvertTest, sw)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "sw")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style sw");
command("pair_coeff * * GaN.sw Ga N");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -547,14 +537,14 @@ TEST_F(PairUnitConvertTest, sw)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style sw");
command("pair_coeff * * GaN.sw Ga N");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -573,7 +563,7 @@ TEST_F(PairUnitConvertTest, table_metal2real)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "table")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style table linear 1000");
@ -581,7 +571,7 @@ TEST_F(PairUnitConvertTest, table_metal2real)
command("pair_coeff 1 2 test.table.metal lj_1_2");
command("pair_coeff 2 2 test.table.metal lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -592,7 +582,7 @@ TEST_F(PairUnitConvertTest, table_metal2real)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
@ -601,7 +591,7 @@ TEST_F(PairUnitConvertTest, table_metal2real)
command("pair_coeff 1 2 test.table.metal lj_1_2");
command("pair_coeff 2 2 test.table.metal lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -620,7 +610,7 @@ TEST_F(PairUnitConvertTest, table_real2metal)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "table")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style table linear 1000");
@ -628,7 +618,7 @@ TEST_F(PairUnitConvertTest, table_real2metal)
command("pair_coeff 1 2 test.table.real lj_1_2");
command("pair_coeff 2 2 test.table.real lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -639,7 +629,7 @@ TEST_F(PairUnitConvertTest, table_real2metal)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units metal");
command("read_data test_pair_unit_convert.data");
@ -648,7 +638,7 @@ TEST_F(PairUnitConvertTest, table_real2metal)
command("pair_coeff 1 2 test.table.real lj_1_2");
command("pair_coeff 2 2 test.table.real lj_2_2");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -667,13 +657,13 @@ TEST_F(PairUnitConvertTest, tersoff)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff");
command("pair_coeff * * SiC.tersoff Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -684,14 +674,14 @@ TEST_F(PairUnitConvertTest, tersoff)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff");
command("pair_coeff * * SiC.tersoff Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -710,13 +700,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/mod")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/mod");
command("pair_coeff * * Si.tersoff.mod Si Si");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -727,14 +717,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/mod");
command("pair_coeff * * Si.tersoff.mod Si Si");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -753,13 +743,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/mod/c")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/mod/c");
command("pair_coeff * * Si.tersoff.modc Si Si");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -770,14 +760,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/mod/c");
command("pair_coeff * * Si.tersoff.modc Si Si");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -796,13 +786,13 @@ TEST_F(PairUnitConvertTest, tersoff_table)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/table")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/table");
command("pair_coeff * * SiC.tersoff Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -813,14 +803,14 @@ TEST_F(PairUnitConvertTest, tersoff_table)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/table");
command("pair_coeff * * SiC.tersoff Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -839,13 +829,13 @@ TEST_F(PairUnitConvertTest, tersoff_zbl)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/zbl")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/zbl");
command("pair_coeff * * SiC.tersoff.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -856,14 +846,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/zbl");
command("pair_coeff * * SiC.tersoff.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -882,14 +872,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "tersoff/zbl/omp")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("package omp 4");
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style tersoff/zbl/omp");
command("pair_coeff * * SiC.tersoff.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -900,7 +890,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("package omp 4");
command("units real");
@ -908,7 +898,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp)
command("pair_style tersoff/zbl/omp");
command("pair_coeff * * SiC.tersoff.zbl Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
@ -927,13 +917,13 @@ TEST_F(PairUnitConvertTest, vashishta)
// check if the prerequisite pair style is available
if (!info->has_style("pair", "vashishta")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("units metal");
command("read_data test_pair_unit_convert.data");
command("pair_style vashishta");
command("pair_coeff * * SiC.vashishta Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
// copy pressure, energy, and force from first step
double pold;
@ -944,14 +934,14 @@ TEST_F(PairUnitConvertTest, vashishta)
for (int j = 0; j < 3; ++j)
fold[i][j] = f[i][j];
if (!verbose) ::testing::internal::CaptureStdout();
BEGIN_HIDE_OUTPUT();
command("clear");
command("units real");
command("read_data test_pair_unit_convert.data");
command("pair_style vashishta");
command("pair_coeff * * SiC.vashishta Si C");
command("run 0 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
END_HIDE_OUTPUT();
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);

View File

@ -22,6 +22,8 @@
#include "exceptions.h"
#include <functional>
#include <vector>
#include <string>
using namespace LAMMPS_NS;
@ -103,20 +105,31 @@ public:
}
protected:
const char *testbinary = "LAMMPSTest";
std::string testbinary = "LAMMPSTest";
std::vector<std::string> args = {"-log", "none", "-echo", "screen", "-nocite"};
LAMMPS *lmp;
Info *info;
void SetUp() override
{
const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
int argc = args.size() + 1;
char ** argv = new char*[argc];
argv[0] = utils::strdup(testbinary);
for(int i = 1; i < argc; i++) {
argv[i] = utils::strdup(args[i-1]);
}
HIDE_OUTPUT([&] {
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
info = new Info(lmp);
});
InitSystem();
for(int i = 0; i < argc; i++) {
delete [] argv[i];
argv[i] = nullptr;
}
delete [] argv;
}
virtual void InitSystem() {}