simplify and modernize. apply clang-format.

This commit is contained in:
Axel Kohlmeyer
2023-04-16 12:14:59 -04:00
parent 7e4d180e57
commit a7460445bb

View File

@ -1,8 +1,8 @@
// unit tests for getting LAMMPS configuration through the Fortran wrapper // unit tests for getting LAMMPS configuration through the Fortran wrapper
#include "info.h"
#include "lammps.h" #include "lammps.h"
#include "library.h" #include "library.h"
#include "info.h"
#ifdef LMP_PLUGIN #ifdef LMP_PLUGIN
#include "plugin.h" #include "plugin.h"
@ -48,9 +48,9 @@ using ::testing::ContainsRegex;
class LAMMPS_configuration : public ::testing::Test { class LAMMPS_configuration : public ::testing::Test {
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
std::vector <std::string> style_category = {"atom","integrate","minimize", const std::vector<std::string> style_category = {
"pair","bond","angle","dihedral","improper","kspace","fix","compute", "atom", "integrate", "minimize", "pair", "bond", "angle", "dihedral",
"region","dump","command"}; "improper", "kspace", "fix", "compute", "region", "dump", "command"};
void SetUp() override void SetUp() override
{ {
@ -119,21 +119,25 @@ TEST_F(LAMMPS_configuration, has_exceptions)
TEST_F(LAMMPS_configuration, has_package) TEST_F(LAMMPS_configuration, has_package)
{ {
std::vector<std::string> pkg_name = {"ADIOS","ASPHERE","ATC","AWPMD","BOCS","BODY","BPM", // clang-format off
"BROWNIAN","CG-DNA","CLASS2","COLLOID","COLVARS","COMPRESS","CORESHELL","DEPEND", std::vector<std::string> pkg_name = {
"DIELECTRIC","DIFFRACTION","DIPOLE","DPD-BASIC","DPD-MESO","DPD-REACT","DPD-SMOOTH","DRUDE", "ADIOS", "AMOEBA", "ASPHERE", "ATC", "AWPMD", "BOCS", "BODY", "BPM", "BROWNIAN", "CG-DNA",
"EFF","ELECTRODE","EXTRA-COMPUTE","EXTRA-DUMP","EXTRA-FIX","EXTRA-MOLECULE","EXTRA-PAIR", "CG-SPICA", "CLASS2", "COLLOID", "COLVARS", "COMPRESS", "CORESHELL", "DEPEND", "DIELECTRIC",
"FEP","GPU","GRANULAR","H5MD","INTEL","INTEL/TEST","INTERLAYER","KIM","KOKKOS","KSPACE", "DIFFRACTION", "DIPOLE", "DPD-BASIC", "DPD-MESO", "DPD-REACT", "DPD-SMOOTH", "DRUDE",
"LATBOLTZ","LATTE","MACHDYN","MAKE","MAKE/MACHINES","MAKE/MINE","MAKE/OPTIONS","MANIFOLD", "EFF", "ELECTRODE", "EXTRA-COMPUTE", "EXTRA-DUMP", "EXTRA-FIX", "EXTRA-MOLECULE",
"MANYBODY","MC","MDI","MEAM","MESONT","MGPT","MISC","ML-HDNNP","ML-IAP","ML-PACE","ML-QUIP", "EXTRA-PAIR", "FEP", "GPU", "GRANULAR", "H5MD", "INTEL", "INTEL/TEST", "INTERLAYER", "KIM",
"ML-RANN","ML-SNAP","MOFFF","MOLECULE","MOLFILE","MPIIO","MSCG","NETCDF","OPENMP","OPT", "KOKKOS", "KSPACE", "LATBOLTZ", "LATTE", "LEPTON", "MACHDYN", "MAKE", "MAKE/MACHINES",
"ORIENT","PERI","PHONON","PLUGIN","PLUMED","POEMS","PTM","PYTHON","QEQ","QMMM","QTB", "MAKE/MINE", "MAKE/OPTIONS", "MANIFOLD", "MANYBODY", "MC", "MDI", "MEAM", "MESONT", "MGPT",
"REACTION","REAXFF","REPLICA","RIGID","SCAFACOS","SHOCK","SMTBQ","SPH","SPIN","SRD","STUBS", "MISC", "ML-HDNNP", "ML-IAP", "ML-PACE", "ML-QUIP", "ML-RANN", "ML-SNAP", "MOFFF",
"TALLY","UEF","VORONOI","VTK","YAFF","CG-SPICA","AMOEBA"}; "MOLECULE", "MOLFILE", "MPIIO", "MSCG", "NETCDF", "OPENMP", "OPT", "ORIENT", "PERI",
"PHONON", "PLUGIN", "PLUMED", "POEMS", "PTM", "PYTHON", "QEQ", "QMMM", "QTB", "REACTION",
"REAXFF", "REPLICA", "RIGID", "SCAFACOS", "SHOCK", "SMTBQ", "SPH", "SPIN", "SRD", "STUBS",
"TALLY", "UEF", "VORONOI", "VTK", "YAFF"
};
// clang-format on
for (std::size_t i = 0; i < pkg_name.size(); i++) for (std::size_t i = 0; i < pkg_name.size(); i++)
EXPECT_EQ(f_lammps_has_package(pkg_name[i].c_str()), EXPECT_EQ(f_lammps_has_package(pkg_name[i].c_str()), Info::has_package(pkg_name[i]));
Info::has_package(pkg_name[i]));
} }
TEST_F(LAMMPS_configuration, package_count) TEST_F(LAMMPS_configuration, package_count)
@ -147,8 +151,7 @@ TEST_F(LAMMPS_configuration, package_count)
TEST_F(LAMMPS_configuration, package_name) TEST_F(LAMMPS_configuration, package_name)
{ {
int i = 0; int i = 0;
while (LAMMPS::installed_packages[i] != nullptr) while (LAMMPS::installed_packages[i] != nullptr) {
{
char *name = f_lammps_package_name(i + 1); // 1 in Fortran is 0 in C char *name = f_lammps_package_name(i + 1); // 1 in Fortran is 0 in C
if (name) if (name)
EXPECT_STREQ(LAMMPS::installed_packages[i], name); EXPECT_STREQ(LAMMPS::installed_packages[i], name);
@ -173,33 +176,22 @@ TEST_F(LAMMPS_configuration, installed_packages)
TEST_F(LAMMPS_configuration, config_accelerator) TEST_F(LAMMPS_configuration, config_accelerator)
{ {
const int npackage = 4; const std::vector<std::string> package = {"GPU", "KOKKOS", "INTEL", "OPENMP"};
const int ncategory = 2; const std::vector<std::string> category = {"api", "precision"};
const int nsetting_api = 7; const std::vector<std::string> setting_api = {"cuda", "hip", "phi", "pthreads",
const int nsetting_precision = 3; "opencl", "openmp", "serial"};
const std::string package[] = {"GPU","KOKKOS","INTEL","OPENMP"}; const std::vector<std::string> setting_precision = {"double", "mixed", "single"};
const std::string category[] = {"api","precision"};
const std::string setting_api[] = {"cuda","hip","phi","pthreads","opencl",
"openmp","serial"};
const std::string setting_precision[] = {"double","mixed","single"};
for (int p=0; p < npackage; p++) for (const auto &p : package) {
{ for (const auto &c : category) {
for (int c=0; c < ncategory; c++) if (c == "api") {
{ for (const auto &s : setting_api)
if (category[c] == "api") EXPECT_EQ(f_lammps_config_accelerator(p.c_str(), c.c_str(), s.c_str()),
{ Info::has_accelerator_feature(p, c, s));
for (int s=0; s < nsetting_api; s++) } else if (c == "precision") {
EXPECT_EQ(f_lammps_config_accelerator(package[p].c_str(), category[c].c_str(), for (const auto &s : setting_precision)
setting_api[s].c_str()), EXPECT_EQ(f_lammps_config_accelerator(p.c_str(), c.c_str(), s.c_str()),
Info::has_accelerator_feature(package[p], category[c], setting_api[s])); Info::has_accelerator_feature(p, c, s));
}
else if (category[c] == "precision")
{
for (int s=0; s < nsetting_precision; s++)
EXPECT_EQ(f_lammps_config_accelerator(package[p].c_str(), category[c].c_str(),
setting_precision[s].c_str()),
Info::has_accelerator_feature(package[p],category[c],setting_precision[s]));
} }
} }
} }
@ -213,16 +205,13 @@ TEST_F(LAMMPS_configuration, has_gpu)
TEST_F(LAMMPS_configuration, get_gpu_info) TEST_F(LAMMPS_configuration, get_gpu_info)
{ {
if (!Info::has_gpu_device()) GTEST_SKIP(); if (!Info::has_gpu_device()) GTEST_SKIP();
size_t n; auto cpp_info = Info::get_gpu_device_info();
std::string cpp_info = Info::get_gpu_device_info(); char *f_string = f_lammps_get_gpu_info(cpp_info.size());
n = cpp_info.size();
char* f_string;
f_string = f_lammps_get_gpu_info(n);
EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str()); EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str());
std::free(f_string); std::free(f_string);
if (n > 80) if (cpp_info.size() > 80) {
{
f_string = f_lammps_get_gpu_info(80); f_string = f_lammps_get_gpu_info(80);
cpp_info.resize(80); cpp_info.resize(80);
EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str()); EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str());
@ -233,15 +222,10 @@ TEST_F(LAMMPS_configuration, get_gpu_info)
TEST_F(LAMMPS_configuration, has_style) TEST_F(LAMMPS_configuration, has_style)
{ {
Info info(lmp); Info info(lmp);
for (std::size_t c = 0; c < style_category.size(); c++) for (const auto &c : style_category) {
{ std::vector<std::string> name = info.get_available_styles(c);
std::vector<std::string> name = for (const auto &s : name)
info.get_available_styles(style_category[c]); EXPECT_EQ(f_lammps_has_style(c.c_str(), s.c_str()), info.has_style(c, s));
for (std::size_t s = 0; s < name.size(); s++)
{
EXPECT_EQ(f_lammps_has_style(style_category[c].c_str(),
name[s].c_str()), info.has_style(style_category[c], name[s]));
}
} }
EXPECT_EQ(f_lammps_has_style("atom", "none"), 0); EXPECT_EQ(f_lammps_has_style("atom", "none"), 0);
}; };
@ -249,25 +233,23 @@ TEST_F(LAMMPS_configuration, has_style)
TEST_F(LAMMPS_configuration, style_count) TEST_F(LAMMPS_configuration, style_count)
{ {
Info info(lmp); Info info(lmp);
for (std::size_t i = 0; i < style_category.size(); i++) for (const auto &c : style_category)
EXPECT_EQ(f_lammps_style_count(style_category[i].c_str()), EXPECT_EQ(f_lammps_style_count(c.c_str()), info.get_available_styles(c.c_str()).size());
info.get_available_styles(style_category[i].c_str()).size());
}; };
TEST_F(LAMMPS_configuration, style_name) TEST_F(LAMMPS_configuration, style_name)
{ {
char *buffer; char *buffer;
Info info(lmp); Info info(lmp);
for (std::size_t c = 0; c < style_category.size(); c++) { for (const auto &c : style_category) {
int nnames = f_lammps_style_count(style_category[c].c_str()); int nnames = f_lammps_style_count(c.c_str());
auto styles = info.get_available_styles(style_category[c]); auto styles = info.get_available_styles(c);
for (int i = 0; i < nnames; i++) { for (int i = 0; i < nnames; i++) {
buffer = f_lammps_style_name(style_category[c].c_str(), i + 1); buffer = f_lammps_style_name(c.c_str(), i + 1);
EXPECT_STREQ(buffer, styles[i].c_str()); EXPECT_STREQ(buffer, styles[i].c_str());
std::free(buffer); std::free(buffer);
} }
} }
}; };
TEST_F(LAMMPS_configuration, has_id) TEST_F(LAMMPS_configuration, has_id)
@ -356,7 +338,6 @@ TEST_F(LAMMPS_configuration, id_name)
name = f_lammps_id_name("variable", 3); name = f_lammps_id_name("variable", 3);
EXPECT_STREQ(name, "pi"); EXPECT_STREQ(name, "pi");
std::free(name); std::free(name);
}; };
TEST_F(LAMMPS_configuration, plugins) TEST_F(LAMMPS_configuration, plugins)
@ -371,5 +352,4 @@ TEST_F(LAMMPS_configuration, plugins)
} }
#endif #endif
}; };
} // namespace LAMMPS_NS } // namespace LAMMPS_NS