Correctly build argv with nullptr at the end

This commit is contained in:
Richard Berger
2023-11-06 23:18:42 -07:00
committed by Richard Berger
parent e655cda066
commit 46768d0ff3
22 changed files with 207 additions and 283 deletions

View File

@ -123,11 +123,9 @@ void AngleWrite::command(int narg, char **arg)
if (comm->me == 0) { if (comm->me == 0) {
// set up new LAMMPS instance with dummy system to evaluate angle potential // set up new LAMMPS instance with dummy system to evaluate angle potential
const char *args[] = {"AngleWrite", "-nocite", "-echo", "none", LAMMPS::argv args = {"AngleWrite", "-nocite", "-echo", "none",
"-log", "none", "-screen", "none"}; "-log", "none", "-screen", "none"};
char **argv = (char **) args; LAMMPS *writer = new LAMMPS(args, singlecomm);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *writer = new LAMMPS(argc, argv, singlecomm);
// create dummy system replicating angle style settings // create dummy system replicating angle style settings
writer->input->one(fmt::format("units {}", update->unit_style)); writer->input->one(fmt::format("units {}", update->unit_style));

View File

@ -124,12 +124,8 @@ void DihedralWrite::command(int narg, char **arg)
if (comm->me == 0) { if (comm->me == 0) {
// set up new LAMMPS instance with dummy system to evaluate dihedral potential // set up new LAMMPS instance with dummy system to evaluate dihedral potential
// const char *args[] = {"DihedralWrite", "-nocite", "-echo", "none", LAMMPS::argv args = {"DihedralWrite", "-nocite", "-echo", "screen", "-log", "none"};
// "-log", "none", "-screen", "none"}; LAMMPS *writer = new LAMMPS(args, singlecomm);
const char *args[] = {"DihedralWrite", "-nocite", "-echo", "screen", "-log", "none"};
char **argv = (char **) args;
int argc = sizeof(args) / sizeof(char *);
LAMMPS *writer = new LAMMPS(argc, argv, singlecomm);
// create dummy system replicating dihedral style settings // create dummy system replicating dihedral style settings
writer->input->one(fmt::format("units {}", update->unit_style)); writer->input->one(fmt::format("units {}", update->unit_style));

View File

@ -107,6 +107,15 @@ using namespace LAMMPS_NS;
* The specifics of setting up and running a simulation are handled by the * The specifics of setting up and running a simulation are handled by the
* individual component class instances. */ * individual component class instances. */
/** Create a LAMMPS simulation instance
*
* \param args list of arguments
* \param communicator MPI communicator used by this LAMMPS instance
*/
LAMMPS::LAMMPS(argv & args, MPI_Comm communicator) :
LAMMPS(args.size(), argv_pointers(args).data(), communicator) {
}
/** Create a LAMMPS simulation instance /** Create a LAMMPS simulation instance
* *
* The LAMMPS constructor starts up a simulation by allocating all * The LAMMPS constructor starts up a simulation by allocating all
@ -1464,3 +1473,17 @@ void LAMMPS::print_config(FILE *fp)
} }
fputs("\n\n",fp); fputs("\n\n",fp);
} }
/** Create vector of argv string pointers including terminating nullptr element
*
* \param args list of arguments
*/
std::vector<char*> LAMMPS::argv_pointers(argv & args){
std::vector<char*> r;
r.reserve(args.size()+1);
for(auto & a : args) {
r.push_back((char*)a.data());
}
r.push_back(nullptr);
return r;
}

View File

@ -16,6 +16,8 @@
#include <cstdio> #include <cstdio>
#include <mpi.h> #include <mpi.h>
#include <string>
#include <vector>
namespace LAMMPS_NS { namespace LAMMPS_NS {
@ -84,6 +86,10 @@ class LAMMPS {
static const char *git_branch(); static const char *git_branch();
static const char *git_descriptor(); static const char *git_descriptor();
using argv = std::vector<std::string>;
static std::vector<char*> argv_pointers(argv & args);
LAMMPS(argv & args, MPI_Comm);
LAMMPS(int, char **, MPI_Comm); LAMMPS(int, char **, MPI_Comm);
~LAMMPS() noexcept(false); ~LAMMPS() noexcept(false);
void create(); void create();

View File

@ -26,10 +26,11 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite",
"-var", "x", "2", "-var", "zpos", "1.5"}; "-var", "x", "2", "-var", "zpos", "1.5",
nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = lammps_open_no_mpi(argc, argv, nullptr); lmp = lammps_open_no_mpi(argc, argv, nullptr);

View File

@ -29,10 +29,11 @@ protected:
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none",
"-echo", "screen", "-nocite", "-echo", "screen", "-nocite",
"-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER),
nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = lammps_open_no_mpi(argc, argv, nullptr); lmp = lammps_open_no_mpi(argc, argv, nullptr);

View File

@ -64,9 +64,9 @@ static void callback(void *handle, step_t timestep, int nlocal, tag_t *, double
TEST(lammps_external, callback) TEST(lammps_external, callback)
{ {
const char *args[] = {"liblammps", "-log", "none", "-nocite"}; const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *handle = lammps_open_no_mpi(argc, argv, nullptr); void *handle = lammps_open_no_mpi(argc, argv, nullptr);
@ -131,9 +131,9 @@ TEST(lammps_external, callback)
TEST(lammps_external, array) TEST(lammps_external, array)
{ {
const char *args[] = {"liblammps", "-log", "none", "-nocite"}; const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *handle = lammps_open_no_mpi(argc, argv, nullptr); void *handle = lammps_open_no_mpi(argc, argv, nullptr);

View File

@ -34,9 +34,9 @@ TEST(MPI, global_box)
int boxflag; int boxflag;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr);
lammps_command(lmp, "units lj"); lammps_command(lmp, "units lj");
lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "atom_style atomic");
@ -77,9 +77,9 @@ TEST(MPI, sub_box)
int boxflag; int boxflag;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr);
lammps_command(lmp, "units lj"); lammps_command(lmp, "units lj");
lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "atom_style atomic");
@ -143,9 +143,9 @@ TEST(MPI, split_comm)
MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm); MPI_Comm_split(MPI_COMM_WORLD, color, key, &newcomm);
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
void *lmp = lammps_open(argc, argv, newcomm, nullptr); void *lmp = lammps_open(argc, argv, newcomm, nullptr);
lammps_command(lmp, "units lj"); lammps_command(lmp, "units lj");
lammps_command(lmp, "atom_style atomic"); lammps_command(lmp, "atom_style atomic");
@ -173,9 +173,9 @@ TEST(MPI, multi_partition)
MPI_Comm_rank(MPI_COMM_WORLD, &me); MPI_Comm_rank(MPI_COMM_WORLD, &me);
const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "4x1", const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "4x1",
"-echo", "screen", "-nocite", "-in", "none"}; "-echo", "screen", "-nocite", "-in", "none", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr);
lammps_command(lmp, "units lj"); lammps_command(lmp, "units lj");
@ -205,9 +205,9 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr);
InitSystem(); InitSystem();

View File

@ -39,9 +39,9 @@ TEST(lammps_open, null_args)
TEST(lammps_open, with_args) TEST(lammps_open, with_args)
{ {
const char *args[] = {"liblammps", "-log", "none", "-nocite"}; const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
// MPI is already initialized // MPI is already initialized
MPI_Comm mycomm; MPI_Comm mycomm;
@ -78,9 +78,9 @@ TEST(lammps_open, with_args)
TEST(lammps_open, with_kokkos) TEST(lammps_open, with_kokkos)
{ {
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP();
const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none"}; const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *alt_ptr; void *alt_ptr;
@ -108,9 +108,9 @@ TEST(lammps_open, with_kokkos)
TEST(lammps_open_no_mpi, no_screen) TEST(lammps_open_no_mpi, no_screen)
{ {
const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite"}; const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *alt_ptr; void *alt_ptr;
@ -139,9 +139,9 @@ TEST(lammps_open_no_mpi, with_omp)
{ {
if (!LAMMPS_NS::LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS_NS::LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no", const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no",
"-sf", "omp", "-log", "none", "-nocite"}; "-sf", "omp", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *alt_ptr; void *alt_ptr;
@ -201,9 +201,9 @@ TEST(lammps_open_fortran, no_args)
TEST(lammps_open_no_mpi, lammps_error) TEST(lammps_open_no_mpi, lammps_error)
{ {
const char *args[] = {"liblammps", "-log", "none", "-nocite"}; const char *args[] = {"liblammps", "-log", "none", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *alt_ptr; void *alt_ptr;

View File

@ -33,10 +33,11 @@ protected:
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none",
"-echo", "screen", "-nocite", "-echo", "screen", "-nocite",
"-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER),
nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = lammps_open_no_mpi(argc, argv, nullptr); lmp = lammps_open_no_mpi(argc, argv, nullptr);
@ -551,10 +552,10 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite"}; const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = lammps_open_no_mpi(argc, argv, nullptr); lmp = lammps_open_no_mpi(argc, argv, nullptr);
@ -632,10 +633,10 @@ TEST(SystemSettings, kokkos)
// clang-format off // clang-format off
const char *args[] = {"SystemSettings", "-log", "none", "-echo", "screen", "-nocite", const char *args[] = {"SystemSettings", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-k", "on", "t", "4", "-sf", "kk", nullptr};
// clang-format on // clang-format on
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *lmp = lammps_open_no_mpi(argc, argv, nullptr); void *lmp = lammps_open_no_mpi(argc, argv, nullptr);

View File

@ -32,10 +32,11 @@ protected:
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none",
"-echo", "screen", "-nocite", "-echo", "screen", "-nocite",
"-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER),
nullptr};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = (sizeof(args) / sizeof(char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = lammps_open_no_mpi(argc, argv, nullptr); lmp = lammps_open_no_mpi(argc, argv, nullptr);

View File

@ -33,11 +33,9 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {testbinary, "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
InitSystem(); InitSystem();
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }

View File

@ -8,6 +8,7 @@
#include <mpi.h> #include <mpi.h>
#include <string> #include <string>
#include "../testing/utils.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box", const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box",
@ -21,9 +22,9 @@ protected:
LAMMPS *lmp; LAMMPS *lmp;
Input_commands() Input_commands()
{ {
const char *args[] = {"LAMMPS_test"}; const char * args[] = {"LAMMPS_test", nullptr};
char **argv = (char **)args; char ** argv = (char**)args;
int argc = sizeof(args) / sizeof(char *); int argc = 1;
int flag; int flag;
MPI_Initialized(&flag); MPI_Initialized(&flag);
@ -33,13 +34,11 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite",
"-var", "zpos", "1.5", "-var", "x", "2"}; "-var", "zpos", "1.5", "-var", "x", "2"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS ("); EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS (");
} }

View File

@ -21,9 +21,9 @@ protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_plain() : lmp(nullptr) LAMMPS_plain() : lmp(nullptr)
{ {
const char *args[] = {"LAMMPS_test"}; const char * args[] = {"LAMMPS_test", nullptr};
char **argv = (char **)args; char ** argv = (char**)args;
int argc = sizeof(args) / sizeof(char *); int argc = 1;
int flag; int flag;
MPI_Initialized(&flag); MPI_Initialized(&flag);
@ -34,12 +34,10 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"}; LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, StartsWith("LAMMPS (")); EXPECT_THAT(output, StartsWith("LAMMPS ("));
} }
@ -159,9 +157,9 @@ protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_omp() : lmp(nullptr) LAMMPS_omp() : lmp(nullptr)
{ {
const char *args[] = {"LAMMPS_test"}; const char * args[] = {"LAMMPS_test", nullptr};
char **argv = (char **)args; char ** argv = (char**)args;
int argc = sizeof(args) / sizeof(char *); int argc = 1;
int flag; int flag;
MPI_Initialized(&flag); MPI_Initialized(&flag);
@ -172,15 +170,13 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen", LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen",
"-pk", "omp", "2", "neigh", "yes", "-sf", "omp"}; "-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 OPENMP package is installed // only run this test fixture with omp suffix if OPENMP package is installed
if (LAMMPS::is_installed_pkg("OPENMP")) if (LAMMPS::is_installed_pkg("OPENMP"))
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
else else
GTEST_SKIP(); GTEST_SKIP();
} }
@ -242,9 +238,9 @@ protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_kokkos() : lmp(nullptr) LAMMPS_kokkos() : lmp(nullptr)
{ {
const char *args[] = {"LAMMPS_test"}; const char * args[] = {"LAMMPS_test", nullptr};
char **argv = (char **)args; char ** argv = (char**)args;
int argc = sizeof(args) / sizeof(char *); int argc = 1;
int flag; int flag;
MPI_Initialized(&flag); MPI_Initialized(&flag);
@ -255,15 +251,13 @@ protected:
void SetUp() override void SetUp() override
{ {
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none", LAMMPS::argv args = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none",
"-k", "on", "t", "1", "-sf", "kk"}; "-k", "on", "t", "1", "-sf", "kk"};
if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[10] = "2"; if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) args[10] = "2";
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (LAMMPS::is_installed_pkg("KOKKOS")) { if (LAMMPS::is_installed_pkg("KOKKOS")) {
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
::testing::internal::GetCapturedStdout(); ::testing::internal::GetCapturedStdout();
} else } else
GTEST_SKIP(); GTEST_SKIP();
@ -333,12 +327,10 @@ TEST(LAMMPS_init, OpenMP)
fputs("\n", fp); fputs("\n", fp);
fclose(fp); fclose(fp);
const char *args[] = {"LAMMPS_init", "-in", "in.lammps_empty", "-log", "none", "-nocite"}; LAMMPS::argv args = {"LAMMPS_init", "-in", "in.lammps_empty", "-log", "none", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, ContainsRegex(".*using 2 OpenMP thread.*per MPI task.*")); EXPECT_THAT(output, ContainsRegex(".*using 2 OpenMP thread.*per MPI task.*"));
@ -366,12 +358,10 @@ TEST(LAMMPS_init, NoOpenMP)
fclose(fp); fclose(fp);
platform::unsetenv("OMP_NUM_THREADS"); platform::unsetenv("OMP_NUM_THREADS");
const char *args[] = {"LAMMPS_init", "-in", "in.lammps_class_noomp", "-log", "none", "-nocite"}; LAMMPS::argv args = {"LAMMPS_init", "-in", "in.lammps_class_noomp", "-log", "none", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, ContainsRegex( EXPECT_THAT(output, ContainsRegex(
".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); ".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*"));

View File

@ -59,11 +59,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -211,11 +211,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg)
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; LAMMPS *lmp = init_lammps(args, config);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -303,13 +301,10 @@ TEST(AngleStyle, plain)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -358,7 +353,7 @@ TEST(AngleStyle, plain)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -422,14 +417,11 @@ TEST(AngleStyle, omp)
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -482,7 +474,7 @@ TEST(AngleStyle, omp)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -525,14 +517,11 @@ TEST(AngleStyle, single)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
// create a LAMMPS instance with standard settings to detect the number of atom types // create a LAMMPS instance with standard settings to detect the number of atom types
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {
@ -672,13 +661,10 @@ TEST(AngleStyle, extract)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {

View File

@ -59,11 +59,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -211,11 +211,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg)
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; LAMMPS *lmp = init_lammps(args, config);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -303,13 +301,10 @@ TEST(BondStyle, plain)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -358,7 +353,7 @@ TEST(BondStyle, plain)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -424,14 +419,11 @@ TEST(BondStyle, omp)
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -484,7 +476,7 @@ TEST(BondStyle, omp)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -527,14 +519,11 @@ TEST(BondStyle, single)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
// create a LAMMPS instance with standard settings to detect the number of atom types // create a LAMMPS instance with standard settings to detect the number of atom types
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {
@ -785,13 +774,10 @@ TEST(BondStyle, extract)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"BondStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {

View File

@ -59,11 +59,9 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
{ {
LAMMPS *lmp; LAMMPS *lmp = new LAMMPS(args, MPI_COMM_WORLD);
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -220,11 +218,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg)
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; LAMMPS *lmp = init_lammps(args, config);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -306,13 +302,10 @@ TEST(DihedralStyle, plain)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -361,7 +354,7 @@ TEST(DihedralStyle, plain)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -427,14 +420,11 @@ TEST(DihedralStyle, omp)
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"DihedralStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -488,7 +478,7 @@ TEST(DihedralStyle, omp)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on

View File

@ -61,11 +61,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool use_respa = false) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool use_respa = false)
{ {
LAMMPS *lmp; LAMMPS *lmp;
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -169,11 +169,8 @@ void restart_lammps(LAMMPS *lmp, const TestConfig &cfg, bool use_rmass, bool use
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"FixIntegrate", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"FixIntegrate", "-log", "none", "-echo", "screen", "-nocite"};
LAMMPS *lmp = init_lammps(args, config);
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -252,13 +249,10 @@ TEST(FixTimestep, plain)
if (test_config.skip_tests.count("static")) GTEST_SKIP(); if (test_config.skip_tests.count("static")) GTEST_SKIP();
#endif #endif
const char *args[] = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -420,7 +414,7 @@ TEST(FixTimestep, plain)
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = init_lammps(argc, argv, test_config, true); lmp = init_lammps(args, test_config, true);
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -554,14 +548,12 @@ TEST(FixTimestep, omp)
if (test_config.skip_tests.count("static")) GTEST_SKIP(); if (test_config.skip_tests.count("static")) GTEST_SKIP();
#endif #endif
const char *args[] = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"FixTimestep", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -723,7 +715,7 @@ TEST(FixTimestep, omp)
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = init_lammps(argc, argv, test_config, true); lmp = init_lammps(args, test_config, true);
output = ::testing::internal::GetCapturedStdout(); output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;

View File

@ -59,11 +59,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -211,11 +211,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg)
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; LAMMPS *lmp = init_lammps(args, config);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -297,13 +295,10 @@ TEST(ImproperStyle, plain)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -352,7 +347,7 @@ TEST(ImproperStyle, plain)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on
@ -418,14 +413,11 @@ TEST(ImproperStyle, omp)
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -479,7 +471,7 @@ TEST(ImproperStyle, omp)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton bond is forced to be on // skip over these tests if newton bond is forced to be on

View File

@ -61,11 +61,11 @@ void cleanup_lammps(LAMMPS *lmp, const TestConfig &cfg)
delete lmp; delete lmp;
} }
LAMMPS *init_lammps(int argc, char **argv, const TestConfig &cfg, const bool newton = true) LAMMPS *init_lammps(LAMMPS::argv & args, const TestConfig &cfg, const bool newton = true)
{ {
LAMMPS *lmp; LAMMPS *lmp;
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(args, MPI_COMM_WORLD);
// check if prerequisite styles are available // check if prerequisite styles are available
Info *info = new Info(lmp); Info *info = new Info(lmp);
@ -225,11 +225,9 @@ void data_lammps(LAMMPS *lmp, const TestConfig &cfg)
void generate_yaml_file(const char *outfile, const TestConfig &config) void generate_yaml_file(const char *outfile, const TestConfig &config)
{ {
// initialize system geometry // initialize system geometry
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; LAMMPS *lmp = init_lammps(args, config);
int argc = sizeof(args) / sizeof(char *);
LAMMPS *lmp = init_lammps(argc, argv, config);
if (!lmp) { if (!lmp) {
std::cerr << "One or more prerequisite styles are not available " std::cerr << "One or more prerequisite styles are not available "
"in this LAMMPS configuration:\n"; "in this LAMMPS configuration:\n";
@ -323,13 +321,10 @@ TEST(PairStyle, plain)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -388,7 +383,7 @@ TEST(PairStyle, plain)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
// skip over these tests if newton pair is forced to be on // skip over these tests if newton pair is forced to be on
@ -469,7 +464,7 @@ TEST(PairStyle, plain)
if (pair->respa_enable) { if (pair->respa_enable) {
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2"); lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2");
run_lammps(lmp); run_lammps(lmp);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
@ -501,17 +496,14 @@ TEST(PairStyle, omp)
if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPENMP")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "omp", "4", "-sf", "omp"}; "-pk", "omp", "4", "-sf", "omp"};
// cannot run dpd styles with more than 1 thread due to using multiple pRNGs // cannot run dpd styles with more than 1 thread due to using multiple pRNGs
if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1"; if (utils::strmatch(test_config.pair_style, "^dpd")) args[8] = "1";
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -570,7 +562,7 @@ TEST(PairStyle, omp)
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
pair = lmp->force->pair; pair = lmp->force->pair;
@ -626,7 +618,7 @@ TEST(PairStyle, kokkos_omp)
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP(); if (!Info::has_accelerator_feature("KOKKOS", "api", "openmp")) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-k", "on", "t", "4", "-sf", "kk"}; "-k", "on", "t", "4", "-sf", "kk"};
// cannot run dpd styles in plain or hybrid with more than 1 thread due to using multiple pRNGs // cannot run dpd styles in plain or hybrid with more than 1 thread due to using multiple pRNGs
@ -642,11 +634,8 @@ TEST(PairStyle, kokkos_omp)
utils::strmatch(test_config.pair_style, " pace")) utils::strmatch(test_config.pair_style, " pace"))
args[9] = "1"; args[9] = "1";
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -704,7 +693,7 @@ TEST(PairStyle, kokkos_omp)
if (lmp->force->newton_pair == 0) { if (lmp->force->newton_pair == 0) {
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);
lmp = init_lammps(argc, argv, test_config, false); lmp = init_lammps(args, test_config, false);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
pair = lmp->force->pair; pair = lmp->force->pair;
@ -767,22 +756,19 @@ TEST(PairStyle, gpu)
(!Info::has_fft_single_support())) (!Info::has_fft_single_support()))
GTEST_SKIP(); GTEST_SKIP();
const char *args_neigh[] = {"PairStyle", "-log", "none", "-echo", LAMMPS::argv args_neigh = {"PairStyle", "-log", "none", "-echo",
"screen", "-nocite", "-sf", "gpu"}; "screen", "-nocite", "-sf", "gpu"};
const char *args_noneigh[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", LAMMPS::argv args_noneigh = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf",
"gpu", "-pk", "gpu", "0", "neigh", "no"}; "gpu", "-pk", "gpu", "0", "neigh", "no"};
LAMMPS::argv args = args_neigh;
char **argv = (char **)args_neigh;
int argc = sizeof(args_neigh) / sizeof(char *);
// cannot use GPU neighbor list with hybrid pair style (yet) // cannot use GPU neighbor list with hybrid pair style (yet)
if (test_config.pair_style.substr(0, 6) == "hybrid") { if (test_config.pair_style.substr(0, 6) == "hybrid") {
argv = (char **)args_noneigh; args = args_noneigh;
argc = sizeof(args_noneigh) / sizeof(char *);
} }
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, false); LAMMPS *lmp = init_lammps(args, test_config, false);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -854,18 +840,15 @@ TEST(PairStyle, intel)
if (!LAMMPS::is_installed_pkg("INTEL")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("INTEL")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite",
"-pk", "intel", "0", "mode", "double", "omp", "-pk", "intel", "0", "mode", "double", "omp",
"4", "lrt", "no", "-sf", "intel"}; "4", "lrt", "no", "-sf", "intel"};
// cannot use more than 1 thread for dpd styles due to pRNG // cannot use more than 1 thread for dpd styles due to pRNG
if (utils::strmatch(test_config.pair_style, "^dpd")) args[12] = "1"; if (utils::strmatch(test_config.pair_style, "^dpd")) args[12] = "1";
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -942,13 +925,10 @@ TEST(PairStyle, opt)
if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("OPT")) GTEST_SKIP();
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"}; LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite", "-sf", "opt"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << output; if (verbose) std::cout << output;
@ -1025,17 +1005,14 @@ TEST(PairStyle, single)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
// need to add this dependency // need to add this dependency
test_config.prerequisites.emplace_back("atom", "full"); test_config.prerequisites.emplace_back("atom", "full");
// create a LAMMPS instance with standard settings to detect the number of atom types // create a LAMMPS instance with standard settings to detect the number of atom types
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config); LAMMPS *lmp = init_lammps(args, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {
@ -1276,13 +1253,10 @@ TEST(PairStyle, extract)
{ {
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
const char *args[] = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"PairStyle", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = init_lammps(argc, argv, test_config, true); LAMMPS *lmp = init_lammps(args, test_config, true);
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
if (!lmp) { if (!lmp) {

View File

@ -71,10 +71,10 @@ protected:
// clang-format off // clang-format off
const char *args[] = const char *args[] =
{ "LAMMPS_Fortran_test", "-l", "none", "-echo", "screen", "-nocite", { "LAMMPS_Fortran_test", "-l", "none", "-echo", "screen", "-nocite",
"-var", "input_dir", input_dir, "-var", "zpos", "1.5", "-var", "x", "2" }; "-var", "input_dir", input_dir, "-var", "zpos", "1.5", "-var", "x", "2", nullptr };
// clang-format on // clang-format on
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(const char *); int argc = (sizeof(args) / sizeof(const char *)) - 1;
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_c_args(argc, argv); lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_c_args(argc, argv);

View File

@ -107,30 +107,20 @@ public:
protected: protected:
std::string testbinary = "LAMMPSTest"; std::string testbinary = "LAMMPSTest";
std::vector<std::string> args = {"-log", "none", "-echo", "screen", "-nocite"}; LAMMPS::argv args = {"-log", "none", "-echo", "screen", "-nocite"};
LAMMPS *lmp; LAMMPS *lmp;
Info *info; Info *info;
void SetUp() override void SetUp() override
{ {
int argc = args.size() + 1; LAMMPS::argv full_args = {testbinary};
char **argv = new char *[argc]; full_args.insert(full_args.end(), args.begin(), args.end());
argv[0] = LAMMPS_NS::utils::strdup(testbinary);
for (int i = 1; i < argc; i++) {
argv[i] = LAMMPS_NS::utils::strdup(args[i - 1]);
}
HIDE_OUTPUT([&] { HIDE_OUTPUT([&] {
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(full_args, MPI_COMM_WORLD);
info = new Info(lmp); info = new Info(lmp);
}); });
InitSystem(); InitSystem();
for (int i = 0; i < argc; i++) {
delete[] argv[i];
argv[i] = nullptr;
}
delete[] argv;
} }
virtual void InitSystem() {} virtual void InitSystem() {}