update c-library tests
This commit is contained in:
@ -1,21 +1,29 @@
|
||||
// unit tests for the LAMMPS base class
|
||||
// unit tests creating LAMMPS instances via the library interface
|
||||
|
||||
#include "library.h"
|
||||
#include "lammps.h"
|
||||
#include "library.h"
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <mpi.h>
|
||||
#include <cstdio> // for stdin, stdout
|
||||
#include <string>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(lammps_open, null_args) {
|
||||
#include "test_main.h"
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::StartsWith;
|
||||
|
||||
TEST(lammps_open, null_args)
|
||||
{
|
||||
::testing::internal::CaptureStdout();
|
||||
void *handle = lammps_open(0,NULL, MPI_COMM_WORLD, NULL);
|
||||
void *handle = lammps_open(0, NULL, MPI_COMM_WORLD, NULL);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
int mpi_init=0;
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
if (verbose) std::cout << output;
|
||||
int mpi_init = 0;
|
||||
MPI_Initialized(&mpi_init);
|
||||
EXPECT_GT(mpi_init,0);
|
||||
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);
|
||||
@ -24,25 +32,26 @@ TEST(lammps_open, null_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||
if (verbose) std::cout << output;
|
||||
}
|
||||
|
||||
TEST(lammps_open, with_args) {
|
||||
const char *args[] = {"liblammps",
|
||||
"-log", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
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);
|
||||
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);
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
if (verbose) std::cout << output;
|
||||
EXPECT_EQ(handle, alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
// MPI STUBS uses no real communicators
|
||||
@ -60,24 +69,24 @@ TEST(lammps_open, with_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||
if (verbose) std::cout << output;
|
||||
}
|
||||
|
||||
TEST(lammps_open, with_kokkos) {
|
||||
TEST(lammps_open, with_kokkos)
|
||||
{
|
||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
|
||||
const char *args[] = {"liblammps",
|
||||
"-k", "on", "t", "2",
|
||||
"-sf", "kk",
|
||||
"-log", "none" };
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
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);
|
||||
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);
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
if (verbose) std::cout << output;
|
||||
EXPECT_EQ(handle, alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
@ -91,23 +100,22 @@ TEST(lammps_open, with_kokkos) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||
if (verbose) std::cout << output;
|
||||
}
|
||||
|
||||
TEST(lammps_open_no_mpi, no_screen) {
|
||||
const char *args[] = {"liblammps",
|
||||
"-log", "none",
|
||||
"-screen", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
@ -125,22 +133,21 @@ TEST(lammps_open_no_mpi, no_screen) {
|
||||
EXPECT_STREQ(output.c_str(), "");
|
||||
}
|
||||
|
||||
TEST(lammps_open_no_mpi, with_omp) {
|
||||
TEST(lammps_open_no_mpi, with_omp)
|
||||
{
|
||||
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP();
|
||||
const char *args[] = {"liblammps",
|
||||
"-pk", "omp", "2", "neigh", "no",
|
||||
"-sf", "omp",
|
||||
"-log", "none",
|
||||
"-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args)/sizeof(char *);
|
||||
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);
|
||||
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);
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
if (verbose) std::cout << output;
|
||||
EXPECT_EQ(handle, alt_ptr);
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
|
||||
@ -155,18 +162,21 @@ TEST(lammps_open_no_mpi, with_omp) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||
if (verbose) std::cout << output;
|
||||
}
|
||||
|
||||
TEST(lammps_open_fortran, no_args) {
|
||||
TEST(lammps_open_fortran, no_args)
|
||||
{
|
||||
// MPI is already initialized
|
||||
MPI_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);
|
||||
void *handle = lammps_open_fortran(0, NULL, fcomm);
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
|
||||
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||
if (verbose) std::cout << output;
|
||||
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
|
||||
|
||||
// MPI STUBS uses no real communicators
|
||||
@ -182,5 +192,6 @@ TEST(lammps_open_fortran, no_args) {
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_close(handle);
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
|
||||
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||
if (verbose) std::cout << output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user