Merge branch 'master' into gpu-unittest
This commit is contained in:
@ -3,6 +3,10 @@ include(GTest)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(formats)
|
||||
add_subdirectory(commands)
|
||||
add_subdirectory(c-library)
|
||||
add_subdirectory(cplusplus)
|
||||
add_subdirectory(fortran)
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(force-styles)
|
||||
|
||||
find_package(ClangFormat 8.0)
|
||||
|
||||
13
unittest/c-library/CMakeLists.txt
Normal file
13
unittest/c-library/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
add_executable(test_library_open test_library_open.cpp)
|
||||
target_link_libraries(test_library_open PRIVATE lammps GTest::GTest GTest::GTestMain)
|
||||
add_test(LibraryOpen test_library_open)
|
||||
|
||||
add_executable(test_library_commands test_library_commands.cpp)
|
||||
target_link_libraries(test_library_commands PRIVATE lammps GTest::GTest GTest::GTestMain)
|
||||
add_test(LibraryCommands test_library_commands)
|
||||
|
||||
add_executable(test_library_properties test_library_properties.cpp)
|
||||
target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GTestMain)
|
||||
add_test(LibraryProperties test_library_properties)
|
||||
|
||||
103
unittest/c-library/test_library_commands.cpp
Normal file
103
unittest/c-library/test_library_commands.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
// unit tests for issuing command to a LAMMPS instance through the library interface
|
||||
|
||||
#include "library.h"
|
||||
#include "lammps.h"
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
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:
|
||||
void *lmp;
|
||||
LAMMPS_commands() {};
|
||||
~LAMMPS_commands() override {};
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test",
|
||||
"-log", "none",
|
||||
"-echo", "screen",
|
||||
"-nocite", "-var","x","2",
|
||||
"-var", "zpos", "1.5"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = lammps_open_no_mpi(argc, argv, NULL);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
|
||||
}
|
||||
void TearDown() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(lmp);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
lmp = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_file) {
|
||||
FILE *fp;
|
||||
const char demo_file[] = "in.test";
|
||||
const char cont_file[] = "in.cont";
|
||||
|
||||
fp = fopen(demo_file,"w");
|
||||
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
|
||||
fputs(demo_input[i],fp);
|
||||
fputc('\n',fp);
|
||||
}
|
||||
fclose(fp);
|
||||
fp = fopen(cont_file,"w");
|
||||
for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) {
|
||||
fputs(cont_input[i],fp);
|
||||
fputc('\n',fp);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),0);
|
||||
lammps_file(lmp,demo_file);
|
||||
lammps_file(lmp,cont_file);
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),2);
|
||||
|
||||
unlink(demo_file);
|
||||
unlink(cont_file);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_line) {
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),0);
|
||||
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
|
||||
lammps_command(lmp,demo_input[i]);
|
||||
}
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),1);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_list) {
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),0);
|
||||
lammps_commands_list(lmp,sizeof(demo_input)/sizeof(char *),demo_input);
|
||||
lammps_commands_list(lmp,sizeof(cont_input)/sizeof(char *),cont_input);
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),2);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_string) {
|
||||
std::string cmds("");
|
||||
|
||||
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
|
||||
cmds += demo_input[i];
|
||||
cmds += "\n";
|
||||
}
|
||||
for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) {
|
||||
cmds += cont_input[i];
|
||||
cmds += "\n";
|
||||
}
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),0);
|
||||
lammps_commands_string(lmp,cmds.c_str());
|
||||
EXPECT_EQ(lammps_get_natoms(lmp),2);
|
||||
};
|
||||
186
unittest/c-library/test_library_open.cpp
Normal file
186
unittest/c-library/test_library_open.cpp
Normal file
@ -0,0 +1,186 @@
|
||||
// unit tests for the LAMMPS base class
|
||||
|
||||
#include "library.h"
|
||||
#include "lammps.h"
|
||||
#include <mpi.h>
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(lammps_open, null_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = lammps_open(0,NULL, MPI_COMM_WORLD, NULL);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
int mpi_init=0;
|
||||
MPI_Initialized(&mpi_init);
|
||||
EXPECT_GT(mpi_init,0);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(lammps_open, with_args) {
|
||||
const char *args[] = {"liblammps",
|
||||
"-log", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
// MPI is already initialized
|
||||
MPI_Comm mycomm;
|
||||
MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm);
|
||||
::testing::internal::CaptureStdout();
|
||||
void *alt_ptr;
|
||||
void *handle = lammps_open(argc, argv, mycomm, &alt_ptr);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
EXPECT_EQ(handle,alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
// MPI STUBS uses no real communicators
|
||||
#if !defined(MPI_STUBS)
|
||||
EXPECT_NE(lmp->world, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
EXPECT_EQ(lmp->world, mycomm);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->kokkos, nullptr);
|
||||
EXPECT_EQ(lmp->atomKK, nullptr);
|
||||
EXPECT_EQ(lmp->memoryKK, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(lammps_open, with_kokkos) {
|
||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
|
||||
const char *args[] = {"liblammps",
|
||||
"-k", "on", "t", "2",
|
||||
"-sf", "kk",
|
||||
"-log", "none" };
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
void *alt_ptr;
|
||||
void *handle = lammps_open(argc, argv, MPI_COMM_WORLD, &alt_ptr);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
EXPECT_EQ(handle,alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->num_package, 0);
|
||||
EXPECT_NE(lmp->kokkos, nullptr);
|
||||
EXPECT_NE(lmp->atomKK, nullptr);
|
||||
EXPECT_NE(lmp->memoryKK, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(lammps_open_no_mpi, no_screen) {
|
||||
const char *args[] = {"liblammps",
|
||||
"-log", "none",
|
||||
"-screen", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
void *alt_ptr;
|
||||
void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.c_str(),"");
|
||||
EXPECT_EQ(handle,alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, nullptr);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->suffix_enable, 0);
|
||||
|
||||
EXPECT_STREQ(lmp->exename, "liblammps");
|
||||
EXPECT_EQ(lmp->num_package, 0);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.c_str(), "");
|
||||
}
|
||||
|
||||
TEST(lammps_open_no_mpi, with_omp) {
|
||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
|
||||
const char *args[] = {"liblammps",
|
||||
"-pk", "omp", "2", "neigh", "no",
|
||||
"-sf", "omp",
|
||||
"-log", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
void *alt_ptr;
|
||||
void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
EXPECT_EQ(handle,alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->suffix_enable, 1);
|
||||
EXPECT_STREQ(lmp->suffix, "omp");
|
||||
EXPECT_EQ(lmp->suffix2, nullptr);
|
||||
EXPECT_STREQ(lmp->exename, "liblammps");
|
||||
EXPECT_EQ(lmp->num_package, 1);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(lammps_open_fortran, no_args) {
|
||||
// MPI is already initialized
|
||||
MPI_Comm mycomm;
|
||||
MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm);
|
||||
int fcomm = MPI_Comm_c2f(mycomm);
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = lammps_open_fortran(0, NULL, fcomm);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
// MPI STUBS uses no real communicators
|
||||
#if !defined(MPI_STUBS)
|
||||
EXPECT_NE(lmp->world, MPI_COMM_WORLD);
|
||||
#endif
|
||||
|
||||
EXPECT_EQ(lmp->world, mycomm);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_NE(lmp->logfile, nullptr);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
45
unittest/c-library/test_library_properties.cpp
Normal file
45
unittest/c-library/test_library_properties.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
// unit tests for checking and changing simulation properties through the library interface
|
||||
|
||||
#include "library.h"
|
||||
#include "lammps.h"
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
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_properties : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void *lmp;
|
||||
LAMMPS_properties() {};
|
||||
~LAMMPS_properties() override {};
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test", "-log", "none",
|
||||
"-echo", "screen", "-nocite" };
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = lammps_open_no_mpi(argc, argv, NULL);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
|
||||
}
|
||||
void TearDown() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(lmp);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
lmp = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_properties, box) {
|
||||
};
|
||||
8
unittest/cplusplus/CMakeLists.txt
Normal file
8
unittest/cplusplus/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
add_executable(test_lammps_class test_lammps_class.cpp)
|
||||
target_link_libraries(test_lammps_class PRIVATE lammps GTest::GMockMain GTest::GTest GTest::GMock)
|
||||
add_test(LammpsClass test_lammps_class)
|
||||
|
||||
add_executable(test_input_class test_input_class.cpp)
|
||||
target_link_libraries(test_input_class PRIVATE lammps GTest::GTest GTest::GTestMain)
|
||||
add_test(InputClass test_input_class)
|
||||
114
unittest/cplusplus/test_input_class.cpp
Normal file
114
unittest/cplusplus/test_input_class.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
// unit tests for issuing command to a LAMMPS instance through the Input class
|
||||
|
||||
#include "lammps.h"
|
||||
#include "input.h"
|
||||
#include "atom.h"
|
||||
#include "memory.h"
|
||||
#include <mpi.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
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" };
|
||||
|
||||
namespace LAMMPS_NS
|
||||
{
|
||||
|
||||
class Input_commands : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
LAMMPS *lmp;
|
||||
Input_commands() {
|
||||
const char *args[] = {"LAMMPS_test"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
int flag;
|
||||
MPI_Initialized(&flag);
|
||||
if (!flag) MPI_Init(&argc,&argv);
|
||||
}
|
||||
~Input_commands() override {}
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test",
|
||||
"-log", "none",
|
||||
"-echo", "screen",
|
||||
"-nocite",
|
||||
"-var", "zpos", "1.5",
|
||||
"-var","x","2"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
|
||||
}
|
||||
void TearDown() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
delete lmp;
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
lmp = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Input_commands, from_file) {
|
||||
FILE *fp;
|
||||
const char demo_file[] = "in.test";
|
||||
const char cont_file[] = "in.cont";
|
||||
|
||||
fp = fopen(demo_file,"w");
|
||||
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
|
||||
fputs(demo_input[i],fp);
|
||||
fputc('\n',fp);
|
||||
}
|
||||
fclose(fp);
|
||||
fp = fopen(cont_file,"w");
|
||||
for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) {
|
||||
fputs(cont_input[i],fp);
|
||||
fputc('\n',fp);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
EXPECT_EQ(lmp->atom->natoms,0);
|
||||
lmp->input->file(demo_file);
|
||||
lmp->input->file(cont_file);
|
||||
EXPECT_EQ(lmp->atom->natoms,2);
|
||||
|
||||
unlink(demo_file);
|
||||
unlink(cont_file);
|
||||
};
|
||||
|
||||
TEST_F(Input_commands, from_line) {
|
||||
EXPECT_EQ(lmp->atom->natoms,0);
|
||||
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
|
||||
lmp->input->one(demo_input[i]);
|
||||
}
|
||||
EXPECT_EQ(lmp->atom->natoms,1);
|
||||
};
|
||||
|
||||
TEST_F(Input_commands, substitute) {
|
||||
char *string,*scratch;
|
||||
int nstring=100,nscratch=100;
|
||||
|
||||
lmp->memory->create(string,nstring,"test:string");
|
||||
lmp->memory->create(scratch,nscratch,"test:scratch");
|
||||
strcpy(string,demo_input[0]);
|
||||
lmp->input->substitute(string,scratch,nstring,nscratch,0);
|
||||
EXPECT_STREQ(string,"region box block 0 2 0 2 0 2");
|
||||
|
||||
strcpy(string,demo_input[2]);
|
||||
lmp->input->substitute(string,scratch,nstring,nscratch,0);
|
||||
EXPECT_STREQ(string,"create_atoms 1 single 1.0 1.0 1.5");
|
||||
lmp->memory->destroy(string);
|
||||
lmp->memory->destroy(scratch);
|
||||
};
|
||||
}
|
||||
351
unittest/cplusplus/test_lammps_class.cpp
Normal file
351
unittest/cplusplus/test_lammps_class.cpp
Normal file
@ -0,0 +1,351 @@
|
||||
// unit tests for the LAMMPS base class
|
||||
|
||||
#include "lammps.h"
|
||||
#include <mpi.h>
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using ::testing::StartsWith;
|
||||
|
||||
namespace LAMMPS_NS
|
||||
{
|
||||
// test fixture for regular tests
|
||||
class LAMMPS_plain : public ::testing::Test {
|
||||
protected:
|
||||
LAMMPS *lmp;
|
||||
LAMMPS_plain() : lmp(nullptr) {
|
||||
const char *args[] = {"LAMMPS_test"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
int flag;
|
||||
MPI_Initialized(&flag);
|
||||
if (!flag) MPI_Init(&argc,&argv);
|
||||
}
|
||||
|
||||
~LAMMPS_plain() override {
|
||||
lmp = nullptr;
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test",
|
||||
"-log", "none",
|
||||
"-echo", "both",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
delete lmp;
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_THAT(output, StartsWith("Total wall time:"));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_plain, InitMembers)
|
||||
{
|
||||
EXPECT_NE(lmp->memory, nullptr);
|
||||
EXPECT_NE(lmp->error, nullptr);
|
||||
EXPECT_NE(lmp->universe, nullptr);
|
||||
EXPECT_NE(lmp->input, nullptr);
|
||||
|
||||
EXPECT_NE(lmp->atom, nullptr);
|
||||
EXPECT_NE(lmp->update, nullptr);
|
||||
EXPECT_NE(lmp->neighbor, nullptr);
|
||||
EXPECT_NE(lmp->comm, nullptr);
|
||||
EXPECT_NE(lmp->domain, nullptr);
|
||||
EXPECT_NE(lmp->force, nullptr);
|
||||
EXPECT_NE(lmp->modify, nullptr);
|
||||
EXPECT_NE(lmp->group, nullptr);
|
||||
EXPECT_NE(lmp->output, nullptr);
|
||||
EXPECT_NE(lmp->timer, nullptr);
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_GE(lmp->initclock, 0.0);
|
||||
|
||||
EXPECT_EQ(lmp->suffix_enable, 0);
|
||||
EXPECT_EQ(lmp->suffix, nullptr);
|
||||
EXPECT_EQ(lmp->suffix2, nullptr);
|
||||
|
||||
EXPECT_STREQ(lmp->exename, "LAMMPS_test");
|
||||
EXPECT_EQ(lmp->num_package, 0);
|
||||
EXPECT_EQ(lmp->clientserver, 0);
|
||||
|
||||
EXPECT_EQ(lmp->kokkos, nullptr);
|
||||
EXPECT_EQ(lmp->atomKK, nullptr);
|
||||
EXPECT_EQ(lmp->memoryKK, nullptr);
|
||||
EXPECT_NE(lmp->python, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
if (LAMMPS::has_git_info) {
|
||||
EXPECT_STRNE(LAMMPS::git_commit,"");
|
||||
EXPECT_STRNE(LAMMPS::git_branch,"");
|
||||
EXPECT_STRNE(LAMMPS::git_descriptor,"");
|
||||
} else {
|
||||
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(LAMMPS_plain, TestStyles)
|
||||
{
|
||||
// skip tests if base class is not available
|
||||
if (lmp == nullptr) return;
|
||||
const char *found;
|
||||
|
||||
const char *atom_styles[] = {
|
||||
"atomic", "body", "charge", "ellipsoid", "hybrid",
|
||||
"line", "sphere", "tri", NULL };
|
||||
for (int i = 0; atom_styles[i] != NULL; ++i) {
|
||||
found = lmp->match_style("atom",atom_styles[i]);
|
||||
EXPECT_STREQ(found, NULL);
|
||||
}
|
||||
|
||||
const char *molecule_atom_styles[] = {
|
||||
"angle", "bond", "full", "molecular", "template", NULL };
|
||||
for (int i = 0; molecule_atom_styles[i] != NULL; ++i) {
|
||||
found = lmp->match_style("atom",molecule_atom_styles[i]);
|
||||
EXPECT_STREQ(found, "MOLECULE");
|
||||
}
|
||||
|
||||
const char *kokkos_atom_styles[] = {
|
||||
"angle/kk", "bond/kk", "full/kk", "molecular/kk", "hybrid/kk", NULL };
|
||||
for (int i = 0; kokkos_atom_styles[i] != NULL; ++i) {
|
||||
found = lmp->match_style("atom",kokkos_atom_styles[i]);
|
||||
EXPECT_STREQ(found, "KOKKOS");
|
||||
}
|
||||
found = lmp->match_style("atom","dipole");
|
||||
EXPECT_STREQ(found,"DIPOLE");
|
||||
found = lmp->match_style("atom","peri");
|
||||
EXPECT_STREQ(found,"PERI");
|
||||
found = lmp->match_style("atom","spin");
|
||||
EXPECT_STREQ(found,"SPIN");
|
||||
found = lmp->match_style("atom","wavepacket");
|
||||
EXPECT_STREQ(found,"USER-AWPMD");
|
||||
found = lmp->match_style("atom","dpd");
|
||||
EXPECT_STREQ(found,"USER-DPD");
|
||||
found = lmp->match_style("atom","edpd");
|
||||
EXPECT_STREQ(found,"USER-MESODPD");
|
||||
found = lmp->match_style("atom","mdpd");
|
||||
EXPECT_STREQ(found,"USER-MESODPD");
|
||||
found = lmp->match_style("atom","tdpd");
|
||||
EXPECT_STREQ(found,"USER-MESODPD");
|
||||
found = lmp->match_style("atom","spin");
|
||||
EXPECT_STREQ(found,"SPIN");
|
||||
found = lmp->match_style("atom","smd");
|
||||
EXPECT_STREQ(found,"USER-SMD");
|
||||
found = lmp->match_style("atom","sph");
|
||||
EXPECT_STREQ(found,"USER-SPH");
|
||||
found = lmp->match_style("atom","i_don't_exist");
|
||||
EXPECT_STREQ(found,NULL);
|
||||
}
|
||||
|
||||
// test fixture for OpenMP with 2 threads
|
||||
class LAMMPS_omp : public ::testing::Test {
|
||||
protected:
|
||||
LAMMPS *lmp;
|
||||
LAMMPS_omp() : lmp(nullptr) {
|
||||
const char *args[] = {"LAMMPS_test"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
int flag;
|
||||
MPI_Initialized(&flag);
|
||||
if (!flag) MPI_Init(&argc,&argv);
|
||||
}
|
||||
|
||||
~LAMMPS_omp() override {
|
||||
lmp = nullptr;
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test",
|
||||
"-log", "none",
|
||||
"-screen", "none",
|
||||
"-echo", "screen",
|
||||
"-pk", "omp","2", "neigh", "yes",
|
||||
"-sf", "omp"
|
||||
};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
// only run this test fixture with omp suffix if USER-OMP package is installed
|
||||
|
||||
if (LAMMPS::is_installed_pkg("USER-OMP"))
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
else GTEST_SKIP();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete lmp;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_omp, InitMembers)
|
||||
{
|
||||
EXPECT_NE(lmp->memory, nullptr);
|
||||
EXPECT_NE(lmp->error, nullptr);
|
||||
EXPECT_NE(lmp->universe, nullptr);
|
||||
EXPECT_NE(lmp->input, nullptr);
|
||||
|
||||
EXPECT_NE(lmp->atom, nullptr);
|
||||
EXPECT_NE(lmp->update, nullptr);
|
||||
EXPECT_NE(lmp->neighbor, nullptr);
|
||||
EXPECT_NE(lmp->comm, nullptr);
|
||||
EXPECT_NE(lmp->domain, nullptr);
|
||||
EXPECT_NE(lmp->force, nullptr);
|
||||
EXPECT_NE(lmp->modify, nullptr);
|
||||
EXPECT_NE(lmp->group, nullptr);
|
||||
EXPECT_NE(lmp->output, nullptr);
|
||||
EXPECT_NE(lmp->timer, nullptr);
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, nullptr);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_GE(lmp->initclock, 0.0);
|
||||
|
||||
EXPECT_EQ(lmp->suffix_enable, 1);
|
||||
EXPECT_STREQ(lmp->suffix, "omp");
|
||||
EXPECT_EQ(lmp->suffix2, nullptr);
|
||||
|
||||
EXPECT_STREQ(lmp->exename, "LAMMPS_test");
|
||||
EXPECT_EQ(lmp->num_package, 1);
|
||||
EXPECT_EQ(lmp->clientserver, 0);
|
||||
|
||||
EXPECT_EQ(lmp->kokkos, nullptr);
|
||||
EXPECT_EQ(lmp->atomKK, nullptr);
|
||||
EXPECT_EQ(lmp->memoryKK, nullptr);
|
||||
EXPECT_NE(lmp->python, nullptr);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
if (LAMMPS::has_git_info) {
|
||||
EXPECT_STRNE(LAMMPS::git_commit,"");
|
||||
EXPECT_STRNE(LAMMPS::git_branch,"");
|
||||
EXPECT_STRNE(LAMMPS::git_descriptor,"");
|
||||
} else {
|
||||
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
// test fixture for Kokkos tests
|
||||
class LAMMPS_kokkos : public ::testing::Test {
|
||||
protected:
|
||||
LAMMPS *lmp;
|
||||
LAMMPS_kokkos() : lmp(nullptr) {
|
||||
const char *args[] = {"LAMMPS_test"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
int flag;
|
||||
MPI_Initialized(&flag);
|
||||
if (!flag) MPI_Init(&argc,&argv);
|
||||
}
|
||||
|
||||
~LAMMPS_kokkos() override {
|
||||
lmp = nullptr;
|
||||
}
|
||||
|
||||
void SetUp() override {
|
||||
const char *args[] = {"LAMMPS_test",
|
||||
"-log", "none",
|
||||
"-echo", "none",
|
||||
"-screen", "none",
|
||||
"-k", "on","t", "2",
|
||||
"-sf", "kk"
|
||||
};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
// only run this test fixture with kk suffix if KOKKOS package is installed
|
||||
// also need to figure out a way to find which parallelizations are enabled
|
||||
|
||||
if (LAMMPS::is_installed_pkg("KOKKOS")) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::"));
|
||||
} else GTEST_SKIP();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete lmp;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_kokkos, InitMembers)
|
||||
{
|
||||
EXPECT_NE(lmp->memory, nullptr);
|
||||
EXPECT_NE(lmp->error, nullptr);
|
||||
EXPECT_NE(lmp->universe, nullptr);
|
||||
EXPECT_NE(lmp->input, nullptr);
|
||||
|
||||
EXPECT_NE(lmp->atom, nullptr);
|
||||
EXPECT_NE(lmp->update, nullptr);
|
||||
EXPECT_NE(lmp->neighbor, nullptr);
|
||||
EXPECT_NE(lmp->comm, nullptr);
|
||||
EXPECT_NE(lmp->domain, nullptr);
|
||||
EXPECT_NE(lmp->force, nullptr);
|
||||
EXPECT_NE(lmp->modify, nullptr);
|
||||
EXPECT_NE(lmp->group, nullptr);
|
||||
EXPECT_NE(lmp->output, nullptr);
|
||||
EXPECT_NE(lmp->timer, nullptr);
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, nullptr);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_GE(lmp->initclock, 0.0);
|
||||
|
||||
EXPECT_EQ(lmp->suffix_enable, 1);
|
||||
EXPECT_STREQ(lmp->suffix, "kk");
|
||||
EXPECT_EQ(lmp->suffix2, nullptr);
|
||||
|
||||
EXPECT_STREQ(lmp->exename, "LAMMPS_test");
|
||||
EXPECT_EQ(lmp->num_package, 0);
|
||||
EXPECT_EQ(lmp->clientserver, 0);
|
||||
|
||||
EXPECT_NE(lmp->kokkos, nullptr);
|
||||
EXPECT_NE(lmp->atomKK, nullptr);
|
||||
EXPECT_NE(lmp->memoryKK, nullptr);
|
||||
EXPECT_NE(lmp->python, nullptr);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
if (LAMMPS::has_git_info) {
|
||||
EXPECT_STRNE(LAMMPS::git_commit,"");
|
||||
EXPECT_STRNE(LAMMPS::git_branch,"");
|
||||
EXPECT_STRNE(LAMMPS::git_descriptor,"");
|
||||
} else {
|
||||
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
|
||||
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
// check help message printing
|
||||
TEST(LAMMPS_help, HelpMessage) {
|
||||
const char *args[] = {"LAMMPS_test", "-h"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_THAT(output,
|
||||
StartsWith("\nLarge-scale Atomic/Molecular Massively Parallel Simulator -"));
|
||||
delete lmp;
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ epsilon: 5e-13
|
||||
prerequisites: ! |
|
||||
atom full
|
||||
pair coul/streitz
|
||||
kspace ewald
|
||||
pre_commands: ! |
|
||||
variable units index metal
|
||||
variable newton_pair delete
|
||||
|
||||
@ -29,6 +29,74 @@ target_link_libraries(test_dump_atom PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpAtom COMMAND test_dump_atom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
|
||||
if (PKG_COMPRESS)
|
||||
find_program(GZIP_BINARY NAMES gzip REQUIRED)
|
||||
|
||||
add_executable(test_dump_atom_gz test_dump_atom_gz.cpp)
|
||||
target_link_libraries(test_dump_atom_gz PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpAtomGZ COMMAND test_dump_atom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
|
||||
|
||||
add_executable(test_dump_custom_gz test_dump_custom_gz.cpp)
|
||||
target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpCustomGZ COMMAND test_dump_custom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
|
||||
|
||||
add_executable(test_dump_cfg_gz test_dump_cfg_gz.cpp)
|
||||
target_link_libraries(test_dump_cfg_gz PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
|
||||
|
||||
add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp)
|
||||
target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
|
||||
|
||||
add_executable(test_dump_local_gz test_dump_local_gz.cpp)
|
||||
target_link_libraries(test_dump_local_gz PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpLocalGZ COMMAND test_dump_local_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}")
|
||||
|
||||
find_program(ZSTD_BINARY NAMES zstd)
|
||||
|
||||
if (ZSTD_BINARY)
|
||||
add_executable(test_dump_atom_zstd test_dump_atom_zstd.cpp)
|
||||
target_link_libraries(test_dump_atom_zstd PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpAtomZstd COMMAND test_dump_atom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
|
||||
|
||||
add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp)
|
||||
target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpCustomZstd COMMAND test_dump_custom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
|
||||
|
||||
add_executable(test_dump_cfg_zstd test_dump_cfg_zstd.cpp)
|
||||
target_link_libraries(test_dump_cfg_zstd PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
|
||||
|
||||
add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp)
|
||||
target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
|
||||
|
||||
add_executable(test_dump_local_zstd test_dump_local_zstd.cpp)
|
||||
target_link_libraries(test_dump_local_zstd PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpLocalZstd COMMAND test_dump_local_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
|
||||
set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_executable(test_dump_custom test_dump_custom.cpp)
|
||||
target_link_libraries(test_dump_custom PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
add_test(NAME DumpCustom COMMAND test_dump_custom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <mpi.h>
|
||||
|
||||
#if !defined(_FORTIFY_SOURCE) || (_FORTIFY_SOURCE == 0)
|
||||
|
||||
266
unittest/formats/test_dump_atom_gz.cpp
Normal file
266
unittest/formats/test_dump_atom_gz.cpp
Normal file
@ -0,0 +1,266 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
char * GZIP_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpAtomGZTest : public MeltTest {
|
||||
std::string dump_style = "atom";
|
||||
public:
|
||||
void enable_triclinic() {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("change_box all triclinic");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
|
||||
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// GZ compressed files
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_run0.melt.gz";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_THAT(converted_file, Eq("dump_gz_compressed_run0.melt"));
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_with_units_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_with_units_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_with_time_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_with_time_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_triclinic_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_tri_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_tri_with_units_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_tri_with_time_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_gz_text_tri_with_image_run0.melt";
|
||||
auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "image yes", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GZIP_BINARY = getenv("GZIP_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
273
unittest/formats/test_dump_atom_zstd.cpp
Normal file
273
unittest/formats/test_dump_atom_zstd.cpp
Normal file
@ -0,0 +1,273 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
char * ZSTD_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpAtomZSTDTest : public MeltTest {
|
||||
std::string dump_style = "atom";
|
||||
public:
|
||||
void enable_triclinic() {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("change_box all triclinic");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
|
||||
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// ZSTD compressed files
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_run0.melt.zst";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_THAT(converted_file, Eq("dump_zstd_compressed_run0.melt"));
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_with_units_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_with_units_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_with_time_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_with_time_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_tri_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_tri_with_units_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_tri_with_time_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_zstd_text_tri_with_image_run0.melt";
|
||||
auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst";
|
||||
|
||||
enable_triclinic();
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "image yes", 0);
|
||||
|
||||
// make sure file is closed
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZSTD_BINARY = getenv("ZSTD_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
@ -46,7 +46,7 @@ TEST_F(DumpCfgTest, invalid_options)
|
||||
|
||||
TEST_F(DumpCfgTest, require_multifile)
|
||||
{
|
||||
auto dump_file = "dump_melt_run.cfg";
|
||||
auto dump_file = "dump.melt.cfg_run.cfg";
|
||||
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();
|
||||
@ -60,58 +60,58 @@ TEST_F(DumpCfgTest, require_multifile)
|
||||
|
||||
TEST_F(DumpCfgTest, run0)
|
||||
{
|
||||
auto dump_file = "dump_cfg_run*.melt";
|
||||
auto dump_file = "dump_cfg_run*.melt.cfg";
|
||||
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_dump(dump_file, fields, "", 0);
|
||||
|
||||
ASSERT_FILE_EXISTS("dump_cfg_run0.melt");
|
||||
auto lines = read_lines("dump_cfg_run0.melt");
|
||||
ASSERT_FILE_EXISTS("dump_cfg_run0.melt.cfg");
|
||||
auto lines = read_lines("dump_cfg_run0.melt.cfg");
|
||||
ASSERT_EQ(lines.size(), 124);
|
||||
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
|
||||
delete_file("dump_cfg_run0.melt");
|
||||
delete_file("dump_cfg_run0.melt.cfg");
|
||||
}
|
||||
|
||||
TEST_F(DumpCfgTest, unwrap_run0)
|
||||
{
|
||||
auto dump_file = "dump_cfg_unwrap_run*.melt";
|
||||
auto dump_file = "dump_cfg_unwrap_run*.melt.cfg";
|
||||
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_dump(dump_file, fields, "", 0);
|
||||
|
||||
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt");
|
||||
auto lines = read_lines("dump_cfg_unwrap_run0.melt");
|
||||
ASSERT_FILE_EXISTS("dump_cfg_unwrap_run0.melt.cfg");
|
||||
auto lines = read_lines("dump_cfg_unwrap_run0.melt.cfg");
|
||||
ASSERT_EQ(lines.size(), 124);
|
||||
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
|
||||
delete_file("dump_cfg_unwrap_run0.melt");
|
||||
delete_file("dump_cfg_unwrap_run0.melt.cfg");
|
||||
}
|
||||
|
||||
TEST_F(DumpCfgTest, no_buffer_run0)
|
||||
{
|
||||
auto dump_file = "dump_cfg_no_buffer_run*.melt";
|
||||
auto dump_file = "dump_cfg_no_buffer_run*.melt.cfg";
|
||||
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_dump(dump_file, fields, "buffer no", 0);
|
||||
|
||||
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt");
|
||||
auto lines = read_lines("dump_cfg_no_buffer_run0.melt");
|
||||
ASSERT_FILE_EXISTS("dump_cfg_no_buffer_run0.melt.cfg");
|
||||
auto lines = read_lines("dump_cfg_no_buffer_run0.melt.cfg");
|
||||
ASSERT_EQ(lines.size(), 124);
|
||||
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
|
||||
delete_file("dump_cfg_no_buffer_run0.melt");
|
||||
delete_file("dump_cfg_no_buffer_run0.melt.cfg");
|
||||
}
|
||||
|
||||
TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
|
||||
{
|
||||
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt";
|
||||
auto dump_file = "dump_cfg_no_unwrap_no_buffer_run*.melt.cfg";
|
||||
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_dump(dump_file, fields, "buffer no", 0);
|
||||
|
||||
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt");
|
||||
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt");
|
||||
ASSERT_FILE_EXISTS("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
|
||||
auto lines = read_lines("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
|
||||
ASSERT_EQ(lines.size(), 124);
|
||||
ASSERT_THAT(lines[0], Eq("Number of particles = 32"));
|
||||
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt");
|
||||
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
|
||||
}
|
||||
|
||||
|
||||
|
||||
129
unittest/formats/test_dump_cfg_gz.cpp
Normal file
129
unittest/formats/test_dump_cfg_gz.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * GZIP_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpCfgGZTest : public MeltTest {
|
||||
std::string dump_style = "cfg";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpCfgGZTest, compressed_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_cfg_gz_text_run*.melt.cfg";
|
||||
auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz";
|
||||
auto text_file = "dump_cfg_gz_text_run0.melt.cfg";
|
||||
auto compressed_file = "dump_cfg_gz_compressed_run0.melt.cfg.gz";
|
||||
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DumpCfgGZTest, compressed_unwrap_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg";
|
||||
auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz";
|
||||
auto text_file = "dump_cfg_unwrap_gz_text_run0.melt.cfg";
|
||||
auto compressed_file = "dump_cfg_unwrap_gz_compressed_run0.melt.cfg.gz";
|
||||
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GZIP_BINARY = getenv("GZIP_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
129
unittest/formats/test_dump_cfg_zstd.cpp
Normal file
129
unittest/formats/test_dump_cfg_zstd.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * ZSTD_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpCfgZstdTest : public MeltTest {
|
||||
std::string dump_style = "cfg";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpCfgZstdTest, compressed_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_cfg_zstd_text_run*.melt.cfg";
|
||||
auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst";
|
||||
auto text_file = "dump_cfg_zstd_text_run0.melt.cfg";
|
||||
auto compressed_file = "dump_cfg_zstd_compressed_run0.melt.cfg.zst";
|
||||
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DumpCfgZstdTest, compressed_unwrap_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg";
|
||||
auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst";
|
||||
auto text_file = "dump_cfg_unwrap_zstd_text_run0.melt.cfg";
|
||||
auto compressed_file = "dump_cfg_unwrap_zstd_compressed_run0.melt.cfg.zst";
|
||||
auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZSTD_BINARY = getenv("ZSTD_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
144
unittest/formats/test_dump_custom_gz.cpp
Normal file
144
unittest/formats/test_dump_custom_gz.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
char * GZIP_BINARY = nullptr;
|
||||
|
||||
class DumpCustomGZTest : public MeltTest {
|
||||
std::string dump_style = "custom";
|
||||
public:
|
||||
void enable_triclinic() {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("change_box all triclinic");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpCustomGZTest, compressed_run1)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_custom_gz_text_run1.melt";
|
||||
auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz";
|
||||
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpCustomGZTest, compressed_triclinic_run1)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_custom_gz_tri_text_run1.melt";
|
||||
auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz";
|
||||
auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz";
|
||||
|
||||
enable_triclinic();
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GZIP_BINARY = getenv("GZIP_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
144
unittest/formats/test_dump_custom_zstd.cpp
Normal file
144
unittest/formats/test_dump_custom_zstd.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
char * ZSTD_BINARY = nullptr;
|
||||
|
||||
class DumpCustomZstdTest : public MeltTest {
|
||||
std::string dump_style = "custom";
|
||||
public:
|
||||
void enable_triclinic() {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("change_box all triclinic");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpCustomZstdTest, compressed_run1)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_custom_zstd_text_run1.melt";
|
||||
auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst";
|
||||
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
TEST_F(DumpCustomZstdTest, compressed_triclinic_run1)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_file = "dump_custom_zstd_tri_text_run1.melt";
|
||||
auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst";
|
||||
auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz";
|
||||
|
||||
enable_triclinic();
|
||||
|
||||
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZSTD_BINARY = getenv("ZSTD_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
106
unittest/formats/test_dump_local_gz.cpp
Normal file
106
unittest/formats/test_dump_local_gz.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * GZIP_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpLocalGZTest : public MeltTest {
|
||||
std::string dump_style = "local";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpLocalGZTest, compressed_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("compute comp all pair/local dist eng");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
auto text_files = "dump_local_gz_text_run*.melt.local";
|
||||
auto compressed_files = "dump_local_gz_compressed_run*.melt.local.gz";
|
||||
auto text_file = "dump_local_gz_text_run0.melt.local";
|
||||
auto compressed_file = "dump_local_gz_compressed_run0.melt.local.gz";
|
||||
auto fields = "index c_comp[1]";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "local/gz", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GZIP_BINARY = getenv("GZIP_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
106
unittest/formats/test_dump_local_zstd.cpp
Normal file
106
unittest/formats/test_dump_local_zstd.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * ZSTD_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpLocalGZTest : public MeltTest {
|
||||
std::string dump_style = "local";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string fields, std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
|
||||
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpLocalGZTest, compressed_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command("compute comp all pair/local dist eng");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
auto text_files = "dump_local_zstd_text_run*.melt.local";
|
||||
auto compressed_files = "dump_local_zstd_compressed_run*.melt.local.zst";
|
||||
auto text_file = "dump_local_zstd_text_run0.melt.local";
|
||||
auto compressed_file = "dump_local_zstd_compressed_run0.melt.local.zst";
|
||||
auto fields = "index c_comp[1]";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "local/zstd", fields, "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZSTD_BINARY = getenv("ZSTD_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
101
unittest/formats/test_dump_xyz_gz.cpp
Normal file
101
unittest/formats/test_dump_xyz_gz.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * GZIP_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpXYZGZTest : public MeltTest {
|
||||
std::string dump_style = "xyz";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
|
||||
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpXYZGZTest, compressed_run0)
|
||||
{
|
||||
if(!GZIP_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_xyz_gz_text_run*.melt.xyz";
|
||||
auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz";
|
||||
auto text_file = "dump_xyz_gz_text_run0.melt.xyz";
|
||||
auto compressed_file = "dump_xyz_gz_compressed_run0.melt.xyz.gz";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "xyz/gz", "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GZIP_BINARY = getenv("GZIP_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
101
unittest/formats/test_dump_xyz_zstd.cpp
Normal file
101
unittest/formats/test_dump_xyz_zstd.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "fmt/format.h"
|
||||
#include "utils.h"
|
||||
#include "../testing/core.h"
|
||||
#include "../testing/systems/melt.h"
|
||||
#include "../testing/utils.h"
|
||||
|
||||
char * ZSTD_BINARY = nullptr;
|
||||
|
||||
using ::testing::Eq;
|
||||
|
||||
class DumpXYZGZTest : public MeltTest {
|
||||
std::string dump_style = "xyz";
|
||||
public:
|
||||
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
|
||||
std::string dump_modify_options, int ntimesteps) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
|
||||
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
|
||||
|
||||
if (!dump_modify_options.empty()) {
|
||||
command(fmt::format("dump_modify id0 {}", dump_modify_options));
|
||||
command(fmt::format("dump_modify id1 {}", dump_modify_options));
|
||||
}
|
||||
|
||||
command(fmt::format("run {}", ntimesteps));
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
std::string convert_compressed_to_text(std::string compressed_file) {
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
|
||||
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
|
||||
system(cmdline.c_str());
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
return converted_file;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DumpXYZGZTest, compressed_run0)
|
||||
{
|
||||
if(!ZSTD_BINARY) GTEST_SKIP();
|
||||
|
||||
auto text_files = "dump_xyz_zstd_text_run*.melt.xyz";
|
||||
auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst";
|
||||
auto text_file = "dump_xyz_zstd_text_run0.melt.xyz";
|
||||
auto compressed_file = "dump_xyz_zstd_compressed_run0.melt.xyz.zst";
|
||||
|
||||
generate_text_and_compressed_dump(text_files, compressed_files, "xyz/zstd", "", 0);
|
||||
|
||||
TearDown();
|
||||
|
||||
ASSERT_FILE_EXISTS(text_file);
|
||||
ASSERT_FILE_EXISTS(compressed_file);
|
||||
|
||||
auto converted_file = convert_compressed_to_text(compressed_file);
|
||||
|
||||
ASSERT_FILE_EXISTS(converted_file);
|
||||
ASSERT_FILE_EQUAL(text_file, converted_file);
|
||||
delete_file(text_file);
|
||||
delete_file(compressed_file);
|
||||
delete_file(converted_file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = utils::split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZSTD_BINARY = getenv("ZSTD_BINARY");
|
||||
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
@ -15,17 +15,15 @@
|
||||
#include "force.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "lammps.h"
|
||||
#include "output.h"
|
||||
#include "pair.h"
|
||||
#include "thermo.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <mpi.h>
|
||||
#include <vector>
|
||||
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
|
||||
#include "MANYBODY/pair_comb.h"
|
||||
#include "MANYBODY/pair_comb3.h"
|
||||
#include "MANYBODY/pair_eim.h"
|
||||
#include "MANYBODY/pair_gw.h"
|
||||
#include "MANYBODY/pair_gw_zbl.h"
|
||||
#include "MANYBODY/pair_nb3b_harmonic.h"
|
||||
@ -26,13 +25,13 @@
|
||||
#include "USER-MISC/pair_tersoff_table.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "lammps.h"
|
||||
#include "potential_file_reader.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <mpi.h>
|
||||
|
||||
#if defined(OMPI_MAJOR_VERSION)
|
||||
|
||||
30
unittest/fortran/CMakeLists.txt
Normal file
30
unittest/fortran/CMakeLists.txt
Normal file
@ -0,0 +1,30 @@
|
||||
include(CheckGeneratorSupport)
|
||||
if(NOT CMAKE_GENERATOR_SUPPORT_FORTRAN)
|
||||
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran support in build tool")
|
||||
return()
|
||||
endif()
|
||||
|
||||
include(CheckLanguage)
|
||||
check_language(Fortran)
|
||||
if(CMAKE_Fortran_COMPILER)
|
||||
enable_language(Fortran)
|
||||
get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE)
|
||||
if(BUILD_MPI)
|
||||
find_package(MPI REQUIRED)
|
||||
else()
|
||||
add_library(fmpi_stubs STATIC mpi_stubs.f90)
|
||||
add_library(MPI::MPI_Fortran ALIAS fmpi_stubs)
|
||||
endif()
|
||||
|
||||
add_library(flammps STATIC ${LAMMPS_FORTRAN_MODULE})
|
||||
|
||||
add_executable(test_fortran_create wrap_create.cpp test_fortran_create.f90)
|
||||
target_link_libraries(test_fortran_create PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTest GTest::GTestMain)
|
||||
add_test(FortranOpen test_fortran_create)
|
||||
|
||||
add_executable(test_fortran_commands wrap_commands.cpp test_fortran_commands.f90)
|
||||
target_link_libraries(test_fortran_commands PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTest GTest::GTestMain)
|
||||
add_test(FortranCommands test_fortran_commands)
|
||||
else()
|
||||
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran compiler")
|
||||
endif()
|
||||
20
unittest/fortran/mpi_stubs.f90
Normal file
20
unittest/fortran/mpi_stubs.f90
Normal file
@ -0,0 +1,20 @@
|
||||
MODULE MPI
|
||||
IMPLICIT NONE
|
||||
PRIVATE
|
||||
|
||||
INTEGER, PARAMETER :: MPI_COMM_WORLD=0
|
||||
INTEGER, PARAMETER :: MPI_SUCCESS=0
|
||||
|
||||
PUBLIC :: MPI_COMM_WORLD, MPI_SUCCESS, &
|
||||
mpi_comm_split
|
||||
|
||||
CONTAINS
|
||||
|
||||
SUBROUTINE mpi_comm_split(comm,color,key,newcomm,ierr)
|
||||
INTEGER, INTENT(in) :: comm,color,key
|
||||
INTEGER, INTENT(out) :: newcomm,ierr
|
||||
|
||||
newcomm = comm + 1
|
||||
ierr = 0
|
||||
END SUBROUTINE mpi_comm_split
|
||||
END MODULE MPI
|
||||
111
unittest/fortran/test_fortran_commands.f90
Normal file
111
unittest/fortran/test_fortran_commands.f90
Normal file
@ -0,0 +1,111 @@
|
||||
MODULE keepcmds
|
||||
USE liblammps
|
||||
TYPE(LAMMPS) :: lmp
|
||||
CHARACTER(len=*), DIMENSION(*), PARAMETER :: demo_input = &
|
||||
[ CHARACTER(len=40) :: &
|
||||
'region box block 0 $x 0 2 0 2', &
|
||||
'create_box 1 box', &
|
||||
'create_atoms 1 single 1.0 1.0 ${zpos}' ]
|
||||
CHARACTER(len=*), DIMENSION(*), PARAMETER :: cont_input = &
|
||||
[ CHARACTER(len=40) :: &
|
||||
'create_atoms 1 single &', &
|
||||
' 0.2 0.1 0.1' ]
|
||||
END MODULE keepcmds
|
||||
|
||||
FUNCTION f_lammps_with_args() BIND(C, name="f_lammps_with_args")
|
||||
USE ISO_C_BINDING, ONLY: c_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
TYPE(c_ptr) :: f_lammps_with_args
|
||||
|
||||
CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = &
|
||||
[ CHARACTER(len=12) :: 'liblammps', '-log', 'none', &
|
||||
'-echo','screen','-nocite','-var','zpos','1.5','-var','x','2']
|
||||
|
||||
lmp = lammps(args)
|
||||
f_lammps_with_args = lmp%handle
|
||||
END FUNCTION f_lammps_with_args
|
||||
|
||||
SUBROUTINE f_lammps_close() BIND(C, name="f_lammps_close")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
|
||||
CALL lmp%close()
|
||||
lmp%handle = c_null_ptr
|
||||
END SUBROUTINE f_lammps_close
|
||||
|
||||
FUNCTION f_lammps_get_natoms() BIND(C, name="f_lammps_get_natoms")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr, c_double
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
REAL(c_double) :: f_lammps_get_natoms
|
||||
|
||||
f_lammps_get_natoms = lmp%get_natoms()
|
||||
END FUNCTION f_lammps_get_natoms
|
||||
|
||||
SUBROUTINE f_lammps_file() BIND(C, name="f_lammps_file")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp, demo_input, cont_input
|
||||
IMPLICIT NONE
|
||||
INTEGER :: i
|
||||
CHARACTER(len=*), PARAMETER :: demo_file = 'in.test', cont_file = 'in.cont'
|
||||
|
||||
OPEN(10, file=demo_file, status='replace')
|
||||
WRITE(10, fmt='(A)') (demo_input(i),i=1,SIZE(demo_input))
|
||||
CLOSE(10)
|
||||
OPEN(11, file=cont_file, status='replace')
|
||||
WRITE(11, fmt='(A)') (cont_input(i),i=1,SIZE(cont_input))
|
||||
CLOSE(11)
|
||||
CALL lmp%file(demo_file)
|
||||
CALL lmp%file(cont_file)
|
||||
OPEN(12, file=demo_file, status='old')
|
||||
CLOSE(12, status='delete')
|
||||
OPEN(13, file=cont_file, status='old')
|
||||
CLOSE(13, status='delete')
|
||||
END SUBROUTINE f_lammps_file
|
||||
|
||||
SUBROUTINE f_lammps_command() BIND(C, name="f_lammps_command")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp, demo_input
|
||||
IMPLICIT NONE
|
||||
INTEGER :: i
|
||||
|
||||
DO i=1,SIZE(demo_input)
|
||||
call lmp%command(demo_input(i))
|
||||
END DO
|
||||
END SUBROUTINE f_lammps_command
|
||||
|
||||
SUBROUTINE f_lammps_commands_list() BIND(C, name="f_lammps_commands_list")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp, demo_input, cont_input
|
||||
IMPLICIT NONE
|
||||
|
||||
CALL lmp%commands_list(demo_input)
|
||||
CALL lmp%commands_list(cont_input)
|
||||
END SUBROUTINE f_lammps_commands_list
|
||||
|
||||
SUBROUTINE f_lammps_commands_string() BIND(C, name="f_lammps_commands_string")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcmds, ONLY: lmp, demo_input, cont_input
|
||||
IMPLICIT NONE
|
||||
INTEGER :: i
|
||||
CHARACTER(len=512) :: cmds
|
||||
|
||||
cmds = ''
|
||||
DO i=1,SIZE(demo_input)
|
||||
cmds = TRIM(cmds) // TRIM(demo_input(i)) // NEW_LINE('A')
|
||||
END DO
|
||||
DO i=1,SIZE(cont_input)
|
||||
cmds = TRIM(cmds) // TRIM(cont_input(i)) // NEW_LINE('A')
|
||||
END DO
|
||||
|
||||
CALL lmp%commands_string(cmds)
|
||||
END SUBROUTINE f_lammps_commands_string
|
||||
86
unittest/fortran/test_fortran_create.f90
Normal file
86
unittest/fortran/test_fortran_create.f90
Normal file
@ -0,0 +1,86 @@
|
||||
MODULE keepcreate
|
||||
USE liblammps
|
||||
TYPE(LAMMPS) :: lmp
|
||||
INTEGER :: mycomm
|
||||
END MODULE keepcreate
|
||||
|
||||
FUNCTION f_lammps_no_mpi_no_args() BIND(C, name="f_lammps_no_mpi_no_args")
|
||||
USE ISO_C_BINDING, ONLY: c_ptr
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
TYPE(c_ptr) :: f_lammps_no_mpi_no_args
|
||||
|
||||
lmp = lammps()
|
||||
f_lammps_no_mpi_no_args = lmp%handle
|
||||
END FUNCTION f_lammps_no_mpi_no_args
|
||||
|
||||
FUNCTION f_lammps_no_mpi_with_args() BIND(C, name="f_lammps_no_mpi_with_args")
|
||||
USE ISO_C_BINDING, ONLY: c_ptr
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
TYPE(c_ptr) :: f_lammps_no_mpi_with_args
|
||||
|
||||
CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = &
|
||||
[ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ]
|
||||
|
||||
lmp = lammps(args)
|
||||
f_lammps_no_mpi_with_args = lmp%handle
|
||||
END FUNCTION f_lammps_no_mpi_with_args
|
||||
|
||||
FUNCTION f_lammps_open_no_args() BIND(C, name="f_lammps_open_no_args")
|
||||
USE ISO_C_BINDING, ONLY: c_ptr
|
||||
USE MPI, ONLY: MPI_COMM_WORLD, mpi_comm_split
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: lmp,mycomm
|
||||
IMPLICIT NONE
|
||||
TYPE(c_ptr) :: f_lammps_open_no_args
|
||||
INTEGER :: color, key, ierr
|
||||
|
||||
color = 1
|
||||
key = 1
|
||||
CALL mpi_comm_split(MPI_COMM_WORLD, color, key, mycomm, ierr)
|
||||
lmp = lammps(comm=mycomm)
|
||||
f_lammps_open_no_args = lmp%handle
|
||||
END FUNCTION f_lammps_open_no_args
|
||||
|
||||
FUNCTION f_lammps_open_with_args() BIND(C, name="f_lammps_open_with_args")
|
||||
USE ISO_C_BINDING, ONLY: c_ptr
|
||||
USE MPI, ONLY: MPI_COMM_WORLD, mpi_comm_split
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: lmp,mycomm
|
||||
IMPLICIT NONE
|
||||
TYPE(c_ptr) :: f_lammps_open_with_args
|
||||
INTEGER :: color, key, ierr
|
||||
|
||||
CHARACTER(len=*), DIMENSION(*), PARAMETER :: args = &
|
||||
[ CHARACTER(len=12) :: 'liblammps', '-log', 'none', '-nocite' ]
|
||||
|
||||
color = 2
|
||||
key = 1
|
||||
CALL mpi_comm_split(MPI_COMM_WORLD, color, key, mycomm, ierr)
|
||||
lmp = lammps(args,mycomm)
|
||||
f_lammps_open_with_args = lmp%handle
|
||||
END FUNCTION f_lammps_open_with_args
|
||||
|
||||
SUBROUTINE f_lammps_close() BIND(C, name="f_lammps_close")
|
||||
USE ISO_C_BINDING, ONLY: c_null_ptr
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: lmp
|
||||
IMPLICIT NONE
|
||||
|
||||
CALL lmp%close()
|
||||
lmp%handle = c_null_ptr
|
||||
END SUBROUTINE f_lammps_close
|
||||
|
||||
FUNCTION f_lammps_get_comm() BIND(C, name="f_lammps_get_comm")
|
||||
USE liblammps
|
||||
USE keepcreate, ONLY: mycomm
|
||||
IMPLICIT NONE
|
||||
INTEGER :: f_lammps_get_comm
|
||||
|
||||
f_lammps_get_comm = mycomm
|
||||
END FUNCTION f_lammps_get_comm
|
||||
|
||||
|
||||
65
unittest/fortran/wrap_commands.cpp
Normal file
65
unittest/fortran/wrap_commands.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// unit tests for issuing command to a LAMMPS instance through the Fortran wrapper
|
||||
|
||||
#include "lammps.h"
|
||||
#include <mpi.h>
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// prototypes for fortran reverse wrapper functions
|
||||
extern "C" {
|
||||
void *f_lammps_with_args();
|
||||
void f_lammps_close();
|
||||
void f_lammps_file();
|
||||
void f_lammps_command();
|
||||
void f_lammps_commands_list();
|
||||
void f_lammps_commands_string();
|
||||
double f_lammps_get_natoms();
|
||||
}
|
||||
|
||||
class LAMMPS_commands : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
LAMMPS_NS::LAMMPS *lmp;
|
||||
LAMMPS_commands() {};
|
||||
~LAMMPS_commands() override {};
|
||||
|
||||
void SetUp() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_args();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
|
||||
}
|
||||
void TearDown() override {
|
||||
::testing::internal::CaptureStdout();
|
||||
f_lammps_close();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
lmp = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_file) {
|
||||
EXPECT_EQ(f_lammps_get_natoms(),0);
|
||||
f_lammps_file();
|
||||
EXPECT_EQ(f_lammps_get_natoms(),2);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_line) {
|
||||
EXPECT_EQ(f_lammps_get_natoms(),0);
|
||||
f_lammps_command();
|
||||
EXPECT_EQ(f_lammps_get_natoms(),1);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_list) {
|
||||
EXPECT_EQ(f_lammps_get_natoms(),0);
|
||||
f_lammps_commands_list();
|
||||
EXPECT_EQ(f_lammps_get_natoms(),2);
|
||||
};
|
||||
|
||||
TEST_F(LAMMPS_commands, from_string) {
|
||||
EXPECT_EQ(f_lammps_get_natoms(),0);
|
||||
f_lammps_commands_string();
|
||||
EXPECT_EQ(f_lammps_get_natoms(),2);
|
||||
};
|
||||
97
unittest/fortran/wrap_create.cpp
Normal file
97
unittest/fortran/wrap_create.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
// unit tests for the LAMMPS base class
|
||||
|
||||
#include "lammps.h"
|
||||
#include <mpi.h>
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// prototypes for fortran reverse wrapper functions
|
||||
extern "C" {
|
||||
void *f_lammps_open_no_args();
|
||||
void *f_lammps_open_with_args();
|
||||
void *f_lammps_no_mpi_no_args();
|
||||
void *f_lammps_no_mpi_with_args();
|
||||
void f_lammps_close();
|
||||
int f_lammps_get_comm();
|
||||
}
|
||||
|
||||
TEST(open_no_mpi, no_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
int mpi_init=0;
|
||||
MPI_Initialized(&mpi_init);
|
||||
EXPECT_EQ(mpi_init,0);
|
||||
void *handle = f_lammps_no_mpi_no_args();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
MPI_Initialized(&mpi_init);
|
||||
EXPECT_NE(mpi_init,0);
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
f_lammps_close();
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(open_no_mpi, with_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = f_lammps_no_mpi_with_args();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
f_lammps_close();
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(fortran_open, no_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = f_lammps_open_no_args();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
int f_comm = f_lammps_get_comm();
|
||||
MPI_Comm mycomm = MPI_Comm_f2c(f_comm);
|
||||
EXPECT_EQ(lmp->world, mycomm);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_NE(lmp->citeme, nullptr);
|
||||
::testing::internal::CaptureStdout();
|
||||
f_lammps_close();
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
|
||||
TEST(fortran_open, with_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = f_lammps_open_with_args();
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
int f_comm = f_lammps_get_comm();
|
||||
MPI_Comm mycomm = MPI_Comm_f2c(f_comm);
|
||||
EXPECT_EQ(lmp->world, mycomm);
|
||||
EXPECT_EQ(lmp->infile, stdin);
|
||||
EXPECT_EQ(lmp->screen, stdout);
|
||||
EXPECT_EQ(lmp->logfile, nullptr);
|
||||
EXPECT_EQ(lmp->citeme, nullptr);
|
||||
|
||||
::testing::internal::CaptureStdout();
|
||||
f_lammps_close();
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
}
|
||||
46
unittest/python/CMakeLists.txt
Normal file
46
unittest/python/CMakeLists.txt
Normal file
@ -0,0 +1,46 @@
|
||||
# we must have shared libraries enabled for testing the python module
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(STATUS "Skipping Tests for the LAMMPS Python Module: must enable BUILD_SHARED_LIBS")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
find_package(PythonInterp 3.5) # Deprecated since version 3.12
|
||||
if(PYTHONINTERP_FOUND)
|
||||
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
endif()
|
||||
else()
|
||||
find_package(Python3 COMPONENTS Interpreter)
|
||||
endif()
|
||||
|
||||
if (Python_EXECUTABLE)
|
||||
# prepare to augment the environment so that the LAMMPS python module and the shared library is found.
|
||||
set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH})
|
||||
if(APPLE)
|
||||
list(APPEND PYTHON_TEST_ENVIRONMENT DYLD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$ENV{DYLD_LIBRARY_PATH})
|
||||
else()
|
||||
list(APPEND PYTHON_TEST_ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$ENV{LD_LIBRARY_PATH})
|
||||
endif()
|
||||
if(LAMMPS_MACHINE)
|
||||
# convert from '_machine' to 'machine'
|
||||
string(SUBSTRING ${LAMMPS_MACHINE} 1 -1 LAMMPS_MACHINE_NAME)
|
||||
list(APPEND PYTHON_TEST_ENVIRONMENT LAMMPS_MACHINE_NAME=${LAMMPS_MACHINE_NAME})
|
||||
endif()
|
||||
|
||||
add_test(NAME PythonOpen
|
||||
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python-open.py -v
|
||||
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
||||
set_tests_properties(PythonOpen PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
|
||||
|
||||
add_test(NAME PythonCommands
|
||||
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v
|
||||
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
||||
set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
|
||||
|
||||
add_test(NAME PythonNumpy
|
||||
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python-numpy.py -v
|
||||
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
|
||||
set_tests_properties(PythonNumpy PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
|
||||
else()
|
||||
message(STATUS "Skipping Tests for the LAMMPS Python Module: no suitable Python interpreter")
|
||||
endif()
|
||||
90
unittest/python/python-commands.py
Normal file
90
unittest/python/python-commands.py
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
import sys,os,unittest
|
||||
from lammps import lammps
|
||||
|
||||
class PythonCommand(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
machine=None
|
||||
if 'LAMMPS_MACHINE_NAME' in os.environ:
|
||||
machine=os.environ['LAMMPS_MACHINE_NAME']
|
||||
self.lmp=lammps(name=machine,
|
||||
cmdargs=['-nocite',
|
||||
'-log','none',
|
||||
'-echo','screen',
|
||||
'-var','zpos','1.5',
|
||||
'-var','x','2'])
|
||||
# create demo input strings and files
|
||||
# a few commands to set up a box with a single atom
|
||||
self.demo_input="""
|
||||
region box block 0 $x 0 2 0 2
|
||||
create_box 1 box
|
||||
create_atoms 1 single 1.0 1.0 ${zpos}
|
||||
"""
|
||||
# another command to add an atom and use a continuation line
|
||||
self.cont_input="""
|
||||
create_atoms 1 single &
|
||||
0.2 0.1 0.1
|
||||
"""
|
||||
self.demo_file='in.test'
|
||||
with open(self.demo_file,'w') as f:
|
||||
f.write(self.demo_input)
|
||||
self.cont_file='in.cont'
|
||||
with open(self.cont_file,'w') as f:
|
||||
f.write(self.cont_input)
|
||||
|
||||
# clean up temporary files
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.demo_file):
|
||||
os.remove(self.demo_file)
|
||||
if os.path.exists(self.cont_file):
|
||||
os.remove(self.cont_file)
|
||||
|
||||
##############################
|
||||
def testFile(self):
|
||||
"""Test reading commands from a file"""
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,0)
|
||||
self.lmp.file(self.demo_file)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,1)
|
||||
self.lmp.file(self.cont_file)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,2)
|
||||
|
||||
def testNoFile(self):
|
||||
"""Test (not) reading commands from no file"""
|
||||
self.lmp.file(None)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,0)
|
||||
|
||||
def testCommand(self):
|
||||
"""Test executing individual commands"""
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,0)
|
||||
cmds = self.demo_input.splitlines()
|
||||
for cmd in cmds:
|
||||
self.lmp.command(cmd)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,1)
|
||||
|
||||
def testCommandsList(self):
|
||||
"""Test executing commands from list of strings"""
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,0)
|
||||
cmds = self.demo_input.splitlines()+self.cont_input.splitlines()
|
||||
self.lmp.commands_list(cmds)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,2)
|
||||
|
||||
def testCommandsString(self):
|
||||
"""Test executing block of commands from string"""
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,0)
|
||||
self.lmp.commands_string(self.demo_input+self.cont_input)
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,2)
|
||||
|
||||
##############################
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
70
unittest/python/python-numpy.py
Normal file
70
unittest/python/python-numpy.py
Normal file
@ -0,0 +1,70 @@
|
||||
import sys,os,unittest
|
||||
from lammps import lammps, LMP_STYLE_GLOBAL, LMP_STYLE_LOCAL, LMP_STYLE_ATOM, LMP_TYPE_VECTOR, LMP_TYPE_SCALAR, LMP_TYPE_ARRAY
|
||||
from ctypes import c_void_p
|
||||
|
||||
class PythonNumpy(unittest.TestCase):
|
||||
def setUp(self):
|
||||
machine = None
|
||||
if 'LAMMPS_MACHINE_NAME' in os.environ:
|
||||
machine=os.environ['LAMMPS_MACHINE_NAME']
|
||||
self.lmp = lammps(name=machine, cmdargs=['-nocite', '-log','none', '-echo','screen'])
|
||||
|
||||
def tearDown(self):
|
||||
del self.lmp
|
||||
|
||||
def testLammpsPointer(self):
|
||||
self.assertEqual(type(self.lmp.lmp), c_void_p)
|
||||
|
||||
def testExtractComputeGlobalScalar(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def testExtractComputeGlobalVector(self):
|
||||
self.lmp.command("region box block 0 2 0 2 0 2")
|
||||
self.lmp.command("create_box 1 box")
|
||||
self.lmp.command("create_atoms 1 single 1.0 1.0 1.0")
|
||||
self.lmp.command("create_atoms 1 single 1.0 1.0 1.5")
|
||||
self.lmp.command("compute coordsum all reduce sum x y z")
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,2)
|
||||
values = self.lmp.numpy.extract_compute("coordsum", LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR)
|
||||
self.assertEqual(len(values), 3)
|
||||
self.assertEqual(values[0], 2.0)
|
||||
self.assertEqual(values[1], 2.0)
|
||||
self.assertEqual(values[2], 2.5)
|
||||
|
||||
def testExtractComputeGlobalArray(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def testExtractComputePerAtomVector(self):
|
||||
self.lmp.command("region box block 0 2 0 2 0 2")
|
||||
self.lmp.command("create_box 1 box")
|
||||
self.lmp.command("create_atoms 1 single 1.0 1.0 1.0")
|
||||
self.lmp.command("create_atoms 1 single 1.0 1.0 1.5")
|
||||
self.lmp.command("compute ke all ke/atom")
|
||||
natoms = int(self.lmp.get_natoms())
|
||||
self.assertEqual(natoms,2)
|
||||
values = self.lmp.numpy.extract_compute("ke", LMP_STYLE_ATOM, LMP_TYPE_VECTOR)
|
||||
self.assertEqual(len(values), 2)
|
||||
self.assertEqual(values[0], 0.0)
|
||||
self.assertEqual(values[1], 0.0)
|
||||
|
||||
def testExtractComputePerAtomArray(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def testExtractComputeLocalScalar(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def testExtractComputeLocalVector(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def testExtractComputeLocalArray(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
57
unittest/python/python-open.py
Normal file
57
unittest/python/python-open.py
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
import sys,os,unittest
|
||||
from lammps import lammps
|
||||
|
||||
has_mpi=False
|
||||
has_mpi4py=False
|
||||
try:
|
||||
from mpi4py import __version__ as mpi4py_version
|
||||
# tested to work with mpi4py versions 2 and 3
|
||||
has_mpi4py = mpi4py_version.split('.')[0] in ['2','3']
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
lmp = lammps()
|
||||
has_mpi = lmp.has_mpi_support
|
||||
lmp.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
class PythonOpen(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.machine=None
|
||||
if 'LAMMPS_MACHINE_NAME' in os.environ:
|
||||
self.machine=os.environ['LAMMPS_MACHINE_NAME']
|
||||
|
||||
def testNoArgs(self):
|
||||
"""Create LAMMPS instance without any arguments"""
|
||||
|
||||
lmp=lammps(name=self.machine)
|
||||
self.assertIsNot(lmp.lmp,None)
|
||||
self.assertEqual(lmp.opened,1)
|
||||
self.assertEqual(has_mpi4py,lmp.has_mpi4py)
|
||||
self.assertEqual(has_mpi,lmp.has_mpi_support)
|
||||
lmp.close()
|
||||
self.assertIsNone(lmp.lmp,None)
|
||||
self.assertEqual(lmp.opened,0)
|
||||
|
||||
def testWithArgs(self):
|
||||
"""Create LAMMPS instance with a few arguments"""
|
||||
lmp=lammps(name=self.machine,
|
||||
cmdargs=['-nocite','-sf','opt','-log','none'])
|
||||
self.assertIsNot(lmp.lmp,None)
|
||||
self.assertEqual(lmp.opened,1)
|
||||
|
||||
@unittest.skipIf(not (has_mpi and has_mpi4py),"Skipping MPI test since LAMMPS is not parallel or mpi4py is not found")
|
||||
def testWithMPI(self):
|
||||
from mpi4py import MPI
|
||||
mycomm=MPI.Comm.Split(MPI.COMM_WORLD, 0, 1)
|
||||
lmp=lammps(name=self.machine,comm=mycomm)
|
||||
self.assertIsNot(lmp.lmp,None)
|
||||
self.assertEqual(lmp.opened,1)
|
||||
lmp.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@ -71,6 +71,7 @@ protected:
|
||||
{
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
delete lmp;
|
||||
lmp = nullptr;
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
};
|
||||
|
||||
@ -2,6 +2,10 @@ add_executable(test_tokenizer test_tokenizer.cpp)
|
||||
target_link_libraries(test_tokenizer PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)
|
||||
add_test(Tokenizer test_tokenizer)
|
||||
|
||||
add_executable(test_mempool test_mempool.cpp)
|
||||
target_link_libraries(test_mempool PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)
|
||||
add_test(MemPool test_mempool)
|
||||
|
||||
add_executable(test_utils test_utils.cpp)
|
||||
target_link_libraries(test_utils PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)
|
||||
add_test(Utils test_utils)
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using ::testing::Eq;
|
||||
|
||||
347
unittest/utils/test_mempool.cpp
Normal file
347
unittest/utils/test_mempool.cpp
Normal file
@ -0,0 +1,347 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
#include "my_page.h"
|
||||
#include "my_pool_chunk.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
TEST(MyPage, int) {
|
||||
MyPage<int> p;
|
||||
|
||||
// default init. maxchunk=1, pagesize=1024
|
||||
int rv = p.init();
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
int *iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
// use too large chunk size
|
||||
p.vgot(2);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(1));
|
||||
ASSERT_EQ(p.ndatum,3);
|
||||
ASSERT_EQ(p.nchunk,3);
|
||||
|
||||
// restart with custom init. maxchunk=16, pagesize=256
|
||||
rv = p.init(16,64,2);
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,16);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
|
||||
// use too large chunk size
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(32);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(16);
|
||||
iptr = p.vget();
|
||||
p.vgot(4);
|
||||
iptr += 4;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(int)*128.0);
|
||||
ASSERT_EQ(p.ndatum,37);
|
||||
ASSERT_EQ(p.nchunk,4);
|
||||
p.get(16);
|
||||
p.get(16);
|
||||
// allocation on the same page
|
||||
iptr = p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
// allocation on different pages
|
||||
p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_NE(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(int)*256.0);
|
||||
ASSERT_EQ(p.ndatum,133);
|
||||
ASSERT_EQ(p.nchunk,10);
|
||||
}
|
||||
|
||||
TEST(MyPage, double) {
|
||||
MyPage<double> p;
|
||||
|
||||
// default init. maxchunk=1, pagesize=1024
|
||||
int rv = p.init();
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
double *iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
// use too large chunk size
|
||||
p.vgot(2);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(1));
|
||||
ASSERT_EQ(p.ndatum,3);
|
||||
ASSERT_EQ(p.nchunk,3);
|
||||
|
||||
// restart with custom init. maxchunk=16, pagesize=256
|
||||
rv = p.init(16,64,2);
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,16);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
|
||||
// use too large chunk size
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(32);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(16);
|
||||
iptr = p.vget();
|
||||
p.vgot(4);
|
||||
iptr += 4;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(double)*128.0);
|
||||
ASSERT_EQ(p.ndatum,37);
|
||||
ASSERT_EQ(p.nchunk,4);
|
||||
p.get(16);
|
||||
p.get(16);
|
||||
// allocation on the same page
|
||||
iptr = p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
// allocation on different pages
|
||||
p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_NE(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(double)*256.0);
|
||||
ASSERT_EQ(p.ndatum,133);
|
||||
ASSERT_EQ(p.nchunk,10);
|
||||
}
|
||||
|
||||
TEST(MyPage, bigint) {
|
||||
MyPage<bigint> p;
|
||||
|
||||
// default init. maxchunk=1, pagesize=1024
|
||||
int rv = p.init();
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
bigint *iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
// use too large chunk size
|
||||
p.vgot(2);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(1);
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(1));
|
||||
ASSERT_EQ(p.ndatum,3);
|
||||
ASSERT_EQ(p.nchunk,3);
|
||||
|
||||
// restart with custom init. maxchunk=16, pagesize=256
|
||||
rv = p.init(16,64,2);
|
||||
ASSERT_EQ(rv,0);
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
// second call to vget() should give same pointer without vgot()
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,16);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
|
||||
// use too large chunk size
|
||||
ASSERT_EQ(iptr,p.vget());
|
||||
p.vgot(32);
|
||||
ASSERT_EQ(1,p.status());
|
||||
|
||||
p.reset();
|
||||
ASSERT_EQ(0,p.status());
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
|
||||
iptr = p.vget();
|
||||
p.vgot(16);
|
||||
iptr = p.vget();
|
||||
p.vgot(4);
|
||||
iptr += 4;
|
||||
ASSERT_EQ(iptr,p.get());
|
||||
++iptr;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(bigint)*128.0);
|
||||
ASSERT_EQ(p.ndatum,37);
|
||||
ASSERT_EQ(p.nchunk,4);
|
||||
p.get(16);
|
||||
p.get(16);
|
||||
// allocation on the same page
|
||||
iptr = p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_EQ(iptr,p.get(16));
|
||||
// allocation on different pages
|
||||
p.get(16);
|
||||
iptr += 16;
|
||||
ASSERT_NE(iptr,p.get(16));
|
||||
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(bigint)*256.0);
|
||||
ASSERT_EQ(p.ndatum,133);
|
||||
ASSERT_EQ(p.nchunk,10);
|
||||
}
|
||||
|
||||
TEST(MyPoolChunk, int) {
|
||||
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
|
||||
MyPoolChunk<int> p;
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
ASSERT_EQ(p.size(),0.0);
|
||||
|
||||
int idx=~0x0000;
|
||||
int *iptr = p.get(idx);
|
||||
ASSERT_NE(iptr,nullptr);
|
||||
ASSERT_EQ(idx,0);
|
||||
|
||||
iptr = p.get(1,idx);
|
||||
ASSERT_NE(iptr,nullptr);
|
||||
ASSERT_EQ(idx,1);
|
||||
// we have only one page allocated
|
||||
ASSERT_EQ(p.size(),1024*sizeof(int)+1024*sizeof(int)+sizeof(void *)+sizeof(int));
|
||||
ASSERT_EQ(p.ndatum,2);
|
||||
ASSERT_EQ(p.nchunk,2);
|
||||
|
||||
p.put(0);
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
|
||||
iptr = p.get(2,idx);
|
||||
ASSERT_EQ(iptr,nullptr);
|
||||
ASSERT_EQ(p.status(),3);
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
}
|
||||
|
||||
TEST(MyPoolChunk, double) {
|
||||
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
|
||||
MyPoolChunk<double> p;
|
||||
|
||||
ASSERT_EQ(p.ndatum,0);
|
||||
ASSERT_EQ(p.nchunk,0);
|
||||
ASSERT_EQ(p.size(),0.0);
|
||||
|
||||
int idx=~0x0000;
|
||||
double *dptr = p.get(idx);
|
||||
ASSERT_NE(dptr,nullptr);
|
||||
ASSERT_EQ(idx,0);
|
||||
|
||||
dptr = p.get(1,idx);
|
||||
ASSERT_NE(dptr,nullptr);
|
||||
ASSERT_EQ(idx,1);
|
||||
// we have only one page allocated
|
||||
ASSERT_EQ(p.size(),1024*sizeof(int)+1024*sizeof(double)+sizeof(void *)+sizeof(int));
|
||||
|
||||
p.put(0);
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
|
||||
dptr = p.get(2,idx);
|
||||
ASSERT_EQ(dptr,nullptr);
|
||||
ASSERT_EQ(p.status(),3);
|
||||
ASSERT_EQ(p.ndatum,1);
|
||||
ASSERT_EQ(p.nchunk,1);
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
#include "tokenizer.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
@ -62,6 +63,37 @@ TEST(Tokenizer, iterate_words)
|
||||
ASSERT_EQ(t.count(), 2);
|
||||
}
|
||||
|
||||
TEST(Tokenizer, no_separator_path)
|
||||
{
|
||||
Tokenizer t("one", ":");
|
||||
ASSERT_EQ(t.has_next(), true);
|
||||
ASSERT_EQ(t.count(), 1);
|
||||
ASSERT_THAT(t.next(), Eq("one"));
|
||||
ASSERT_EQ(t.has_next(), false);
|
||||
}
|
||||
|
||||
TEST(Tokenizer, unix_paths)
|
||||
{
|
||||
Tokenizer t(":one:two:three:", ":");
|
||||
ASSERT_EQ(t.count(), 3);
|
||||
ASSERT_THAT(t.next(), Eq("one"));
|
||||
ASSERT_THAT(t.next(), Eq("two"));
|
||||
ASSERT_EQ(t.has_next(), true);
|
||||
ASSERT_THAT(t.next(), Eq("three"));
|
||||
ASSERT_EQ(t.has_next(), false);
|
||||
}
|
||||
|
||||
TEST(Tokenizer, windows_paths)
|
||||
{
|
||||
Tokenizer t("c:\\one;\\two\\three;d:four;", ";");
|
||||
ASSERT_EQ(t.count(), 3);
|
||||
ASSERT_THAT(t.next(), Eq("c:\\one"));
|
||||
ASSERT_EQ(t.has_next(), true);
|
||||
ASSERT_THAT(t.next(), Eq("\\two\\three"));
|
||||
ASSERT_THAT(t.next(), Eq("d:four"));
|
||||
ASSERT_EQ(t.has_next(), false);
|
||||
}
|
||||
|
||||
TEST(Tokenizer, default_separators)
|
||||
{
|
||||
Tokenizer t(" \r\n test \t word \f");
|
||||
|
||||
@ -11,12 +11,12 @@
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -25,6 +25,10 @@ using ::testing::EndsWith;
|
||||
using ::testing::Eq;
|
||||
using ::testing::StrEq;
|
||||
|
||||
#if !defined(FLERR)
|
||||
#define FLERR __FILE__,__LINE__
|
||||
#endif
|
||||
|
||||
TEST(Utils, trim)
|
||||
{
|
||||
auto trimmed = utils::trim("\t some text");
|
||||
@ -362,6 +366,136 @@ TEST(Utils, strmatch_whitespace_nonwhitespace)
|
||||
ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\S+\\s+\\S+\\s"));
|
||||
}
|
||||
|
||||
TEST(Utils, bounds_case1)
|
||||
{
|
||||
int nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,9);
|
||||
ASSERT_EQ(nhi,9);
|
||||
utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,1);
|
||||
ASSERT_EQ(nhi,1);
|
||||
}
|
||||
|
||||
TEST(Utils, bounds_case2)
|
||||
{
|
||||
int nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,0);
|
||||
ASSERT_EQ(nhi,10);
|
||||
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-10);
|
||||
ASSERT_EQ(nhi,5);
|
||||
}
|
||||
|
||||
TEST(Utils, bounds_case3)
|
||||
{
|
||||
int nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,2);
|
||||
ASSERT_EQ(nhi,10);
|
||||
utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,3);
|
||||
ASSERT_EQ(nhi,5);
|
||||
}
|
||||
|
||||
TEST(Utils, bounds_case4)
|
||||
{
|
||||
int nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "*2", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,0);
|
||||
ASSERT_EQ(nhi,2);
|
||||
utils::bounds(FLERR, "*3", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-10);
|
||||
ASSERT_EQ(nhi,3);
|
||||
}
|
||||
|
||||
TEST(Utils, bounds_case5)
|
||||
{
|
||||
int nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "2*5", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,2);
|
||||
ASSERT_EQ(nhi,5);
|
||||
utils::bounds(FLERR, "-2*3", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-2);
|
||||
ASSERT_EQ(nhi,3);
|
||||
}
|
||||
|
||||
TEST(Utils, boundsbig_case1)
|
||||
{
|
||||
bigint nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,9);
|
||||
ASSERT_EQ(nhi,9);
|
||||
utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,1);
|
||||
ASSERT_EQ(nhi,1);
|
||||
}
|
||||
|
||||
TEST(Utils, boundsbig_case2)
|
||||
{
|
||||
bigint nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,0);
|
||||
ASSERT_EQ(nhi,10);
|
||||
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-10);
|
||||
ASSERT_EQ(nhi,5);
|
||||
}
|
||||
|
||||
TEST(Utils, boundsbig_case3)
|
||||
{
|
||||
bigint nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,2);
|
||||
ASSERT_EQ(nhi,10);
|
||||
utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,3);
|
||||
ASSERT_EQ(nhi,5);
|
||||
}
|
||||
|
||||
TEST(Utils, boundsbig_case4)
|
||||
{
|
||||
bigint nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "*2", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,0);
|
||||
ASSERT_EQ(nhi,2);
|
||||
utils::bounds(FLERR, "*3", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-10);
|
||||
ASSERT_EQ(nhi,3);
|
||||
}
|
||||
|
||||
TEST(Utils, boundsbig_case5)
|
||||
{
|
||||
bigint nlo, nhi;
|
||||
|
||||
nlo = nhi = -1;
|
||||
utils::bounds(FLERR, "2*5", 0, 10, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,2);
|
||||
ASSERT_EQ(nhi,5);
|
||||
utils::bounds(FLERR, "-2*3", -10, 5, nlo, nhi, nullptr);
|
||||
ASSERT_EQ(nlo,-2);
|
||||
ASSERT_EQ(nhi,3);
|
||||
}
|
||||
|
||||
TEST(Utils, guesspath)
|
||||
{
|
||||
char buf[256];
|
||||
@ -477,3 +611,20 @@ TEST(Utils, timespec2seconds_hhmmss)
|
||||
{
|
||||
ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0);
|
||||
}
|
||||
|
||||
|
||||
TEST(Utils, date2num)
|
||||
{
|
||||
ASSERT_EQ(utils::date2num("1Jan05"),20050101);
|
||||
ASSERT_EQ(utils::date2num("10Feb2005"),20050210);
|
||||
ASSERT_EQ(utils::date2num("02Mar10"),20100302);
|
||||
ASSERT_EQ(utils::date2num(" 5Apr1900"),19000405);
|
||||
ASSERT_EQ(utils::date2num("10May22 "),20220510);
|
||||
ASSERT_EQ(utils::date2num("1 Jun 05"),20050601);
|
||||
ASSERT_EQ(utils::date2num("10 Jul 2005"),20050710);
|
||||
ASSERT_EQ(utils::date2num("02 Aug 10"),20100802);
|
||||
ASSERT_EQ(utils::date2num(" 5 September 99"),20990905);
|
||||
ASSERT_EQ(utils::date2num("10October22 "),20221010);
|
||||
ASSERT_EQ(utils::date2num("30November 02"),20021130);
|
||||
ASSERT_EQ(utils::date2num("31December100"),1001231);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user