simplify and modernize. apply clang-format.

This commit is contained in:
Axel Kohlmeyer
2023-04-16 12:14:59 -04:00
parent 8086228976
commit 98efb19e79

View File

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