update c-library tests
This commit is contained in:
@ -1,50 +1,54 @@
|
|||||||
// unit tests for issuing command to a LAMMPS instance through the library interface
|
// unit tests for issuing command to a LAMMPS instance through the library interface
|
||||||
|
|
||||||
#include "library.h"
|
|
||||||
#include "lammps.h"
|
#include "lammps.h"
|
||||||
|
#include "library.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
const char *demo_input[] = {
|
#include "test_main.h"
|
||||||
"region box block 0 $x 0 2 0 2",
|
|
||||||
"create_box 1 box",
|
|
||||||
"create_atoms 1 single 1.0 1.0 ${zpos}" };
|
|
||||||
const char *cont_input[] = {
|
|
||||||
"create_atoms 1 single &",
|
|
||||||
"0.2 0.1 0.1" };
|
|
||||||
|
|
||||||
class LAMMPS_commands : public ::testing::Test
|
using ::testing::HasSubstr;
|
||||||
{
|
using ::testing::StartsWith;
|
||||||
|
|
||||||
|
const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box",
|
||||||
|
"create_atoms 1 single 1.0 1.0 ${zpos}"};
|
||||||
|
const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"};
|
||||||
|
|
||||||
|
class LAMMPS_commands : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void *lmp;
|
void *lmp;
|
||||||
LAMMPS_commands(){};
|
LAMMPS_commands(){};
|
||||||
~LAMMPS_commands() override{};
|
~LAMMPS_commands() override{};
|
||||||
|
|
||||||
void SetUp() override {
|
void SetUp() override
|
||||||
const char *args[] = {"LAMMPS_test",
|
{
|
||||||
"-log", "none",
|
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite",
|
||||||
"-echo", "screen",
|
"-var", "x", "2", "-var", "zpos", "1.5"};
|
||||||
"-nocite", "-var","x","2",
|
|
||||||
"-var", "zpos", "1.5"};
|
|
||||||
char **argv = (char **)args;
|
char **argv = (char **)args;
|
||||||
int argc = sizeof(args) / sizeof(char *);
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lmp = lammps_open_no_mpi(argc, argv, NULL);
|
lmp = lammps_open_no_mpi(argc, argv, NULL);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
|
if (verbose) std::cout << output;
|
||||||
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
}
|
}
|
||||||
void TearDown() override {
|
void TearDown() override
|
||||||
|
{
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(lmp);
|
lammps_close(lmp);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
lmp = nullptr;
|
lmp = nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LAMMPS_commands, from_file) {
|
TEST_F(LAMMPS_commands, from_file)
|
||||||
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
const char demo_file[] = "in.test";
|
const char demo_file[] = "in.test";
|
||||||
const char cont_file[] = "in.cont";
|
const char cont_file[] = "in.cont";
|
||||||
@ -63,30 +67,42 @@ TEST_F(LAMMPS_commands, from_file) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
lammps_file(lmp, demo_file);
|
lammps_file(lmp, demo_file);
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
|
EXPECT_EQ(lammps_get_natoms(lmp), 1);
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
lammps_file(lmp, cont_file);
|
lammps_file(lmp, cont_file);
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
||||||
|
|
||||||
unlink(demo_file);
|
unlink(demo_file);
|
||||||
unlink(cont_file);
|
unlink(cont_file);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LAMMPS_commands, from_line) {
|
TEST_F(LAMMPS_commands, from_line)
|
||||||
|
{
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
|
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
|
||||||
lammps_command(lmp, demo_input[i]);
|
lammps_command(lmp, demo_input[i]);
|
||||||
}
|
}
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 1);
|
EXPECT_EQ(lammps_get_natoms(lmp), 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LAMMPS_commands, from_list) {
|
TEST_F(LAMMPS_commands, from_list)
|
||||||
|
{
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
lammps_commands_list(lmp, sizeof(demo_input) / sizeof(char *), demo_input);
|
lammps_commands_list(lmp, sizeof(demo_input) / sizeof(char *), demo_input);
|
||||||
lammps_commands_list(lmp, sizeof(cont_input) / sizeof(char *), cont_input);
|
lammps_commands_list(lmp, sizeof(cont_input) / sizeof(char *), cont_input);
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(LAMMPS_commands, from_string) {
|
TEST_F(LAMMPS_commands, from_string)
|
||||||
|
{
|
||||||
std::string cmds("");
|
std::string cmds("");
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
|
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
|
||||||
@ -98,6 +114,8 @@ TEST_F(LAMMPS_commands, from_string) {
|
|||||||
cmds += "\n";
|
cmds += "\n";
|
||||||
}
|
}
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
EXPECT_EQ(lammps_get_natoms(lmp), 0);
|
||||||
|
if (!verbose) ::testing::internal::CaptureStdout();
|
||||||
lammps_commands_string(lmp, cmds.c_str());
|
lammps_commands_string(lmp, cmds.c_str());
|
||||||
|
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
EXPECT_EQ(lammps_get_natoms(lmp), 2);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,18 +1,26 @@
|
|||||||
// unit tests for the LAMMPS base class
|
// unit tests creating LAMMPS instances via the library interface
|
||||||
|
|
||||||
#include "library.h"
|
|
||||||
#include "lammps.h"
|
#include "lammps.h"
|
||||||
#include <mpi.h>
|
#include "library.h"
|
||||||
#include <cstdio> // for stdin, stdout
|
#include <cstdio> // for stdin, stdout
|
||||||
|
#include <mpi.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
TEST(lammps_open, null_args) {
|
#include "test_main.h"
|
||||||
|
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
using ::testing::StartsWith;
|
||||||
|
|
||||||
|
TEST(lammps_open, null_args)
|
||||||
|
{
|
||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
void *handle = lammps_open(0, NULL, MPI_COMM_WORLD, NULL);
|
void *handle = lammps_open(0, NULL, MPI_COMM_WORLD, NULL);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
int mpi_init = 0;
|
int mpi_init = 0;
|
||||||
MPI_Initialized(&mpi_init);
|
MPI_Initialized(&mpi_init);
|
||||||
EXPECT_GT(mpi_init, 0);
|
EXPECT_GT(mpi_init, 0);
|
||||||
@ -24,13 +32,13 @@ TEST(lammps_open, null_args) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(handle);
|
lammps_close(handle);
|
||||||
output = ::testing::internal::GetCapturedStdout();
|
output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(lammps_open, with_args) {
|
TEST(lammps_open, with_args)
|
||||||
const char *args[] = {"liblammps",
|
{
|
||||||
"-log", "none",
|
const char *args[] = {"liblammps", "-log", "none", "-nocite"};
|
||||||
"-nocite"};
|
|
||||||
char **argv = (char **)args;
|
char **argv = (char **)args;
|
||||||
int argc = sizeof(args) / sizeof(char *);
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
@ -41,7 +49,8 @@ TEST(lammps_open, with_args) {
|
|||||||
void *alt_ptr;
|
void *alt_ptr;
|
||||||
void *handle = lammps_open(argc, argv, mycomm, &alt_ptr);
|
void *handle = lammps_open(argc, argv, mycomm, &alt_ptr);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
EXPECT_EQ(handle, alt_ptr);
|
EXPECT_EQ(handle, alt_ptr);
|
||||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||||
|
|
||||||
@ -60,15 +69,14 @@ TEST(lammps_open, with_args) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(handle);
|
lammps_close(handle);
|
||||||
output = ::testing::internal::GetCapturedStdout();
|
output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(lammps_open, with_kokkos) {
|
TEST(lammps_open, with_kokkos)
|
||||||
|
{
|
||||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
|
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
|
||||||
const char *args[] = {"liblammps",
|
const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none"};
|
||||||
"-k", "on", "t", "2",
|
|
||||||
"-sf", "kk",
|
|
||||||
"-log", "none" };
|
|
||||||
char **argv = (char **)args;
|
char **argv = (char **)args;
|
||||||
int argc = sizeof(args) / sizeof(char *);
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
@ -76,7 +84,8 @@ TEST(lammps_open, with_kokkos) {
|
|||||||
void *alt_ptr;
|
void *alt_ptr;
|
||||||
void *handle = lammps_open(argc, argv, MPI_COMM_WORLD, &alt_ptr);
|
void *handle = lammps_open(argc, argv, MPI_COMM_WORLD, &alt_ptr);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
EXPECT_EQ(handle, alt_ptr);
|
EXPECT_EQ(handle, alt_ptr);
|
||||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||||
|
|
||||||
@ -91,14 +100,13 @@ TEST(lammps_open, with_kokkos) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(handle);
|
lammps_close(handle);
|
||||||
output = ::testing::internal::GetCapturedStdout();
|
output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(lammps_open_no_mpi, no_screen) {
|
TEST(lammps_open_no_mpi, no_screen)
|
||||||
const char *args[] = {"liblammps",
|
{
|
||||||
"-log", "none",
|
const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite"};
|
||||||
"-screen", "none",
|
|
||||||
"-nocite"};
|
|
||||||
char **argv = (char **)args;
|
char **argv = (char **)args;
|
||||||
int argc = sizeof(args) / sizeof(char *);
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
@ -125,13 +133,11 @@ TEST(lammps_open_no_mpi, no_screen) {
|
|||||||
EXPECT_STREQ(output.c_str(), "");
|
EXPECT_STREQ(output.c_str(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(lammps_open_no_mpi, with_omp) {
|
TEST(lammps_open_no_mpi, with_omp)
|
||||||
|
{
|
||||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
|
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
|
||||||
const char *args[] = {"liblammps",
|
const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no",
|
||||||
"-pk", "omp", "2", "neigh", "no",
|
"-sf", "omp", "-log", "none", "-nocite"};
|
||||||
"-sf", "omp",
|
|
||||||
"-log", "none",
|
|
||||||
"-nocite"};
|
|
||||||
char **argv = (char **)args;
|
char **argv = (char **)args;
|
||||||
int argc = sizeof(args) / sizeof(char *);
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
@ -139,7 +145,8 @@ TEST(lammps_open_no_mpi, with_omp) {
|
|||||||
void *alt_ptr;
|
void *alt_ptr;
|
||||||
void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr);
|
void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
EXPECT_EQ(handle, alt_ptr);
|
EXPECT_EQ(handle, alt_ptr);
|
||||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||||
|
|
||||||
@ -155,10 +162,12 @@ TEST(lammps_open_no_mpi, with_omp) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(handle);
|
lammps_close(handle);
|
||||||
output = ::testing::internal::GetCapturedStdout();
|
output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(lammps_open_fortran, no_args) {
|
TEST(lammps_open_fortran, no_args)
|
||||||
|
{
|
||||||
// MPI is already initialized
|
// MPI is already initialized
|
||||||
MPI_Comm mycomm;
|
MPI_Comm mycomm;
|
||||||
MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm);
|
MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm);
|
||||||
@ -166,7 +175,8 @@ TEST(lammps_open_fortran, no_args) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
void *handle = lammps_open_fortran(0, NULL, fcomm);
|
void *handle = lammps_open_fortran(0, NULL, fcomm);
|
||||||
std::string output = ::testing::internal::GetCapturedStdout();
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||||
|
|
||||||
// MPI STUBS uses no real communicators
|
// MPI STUBS uses no real communicators
|
||||||
@ -182,5 +192,6 @@ TEST(lammps_open_fortran, no_args) {
|
|||||||
::testing::internal::CaptureStdout();
|
::testing::internal::CaptureStdout();
|
||||||
lammps_close(handle);
|
lammps_close(handle);
|
||||||
output = ::testing::internal::GetCapturedStdout();
|
output = ::testing::internal::GetCapturedStdout();
|
||||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// unit tests for checking and changing simulation properties through the library interface
|
// unit tests for checking and changing simulation properties through the library interface
|
||||||
|
|
||||||
#include "lammps.h"
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
#include "lammps.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user