From 62ff23abe7c202b2ff82bd337b2d484145cf5fe8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 15:59:48 -0500 Subject: [PATCH 01/48] simplify building serial executables by incorporating the STUBS/mpi.o object in LAMMPS library --- cmake/CMakeLists.txt | 23 +++-------------------- cmake/Modules/Packages/GPU.cmake | 4 ++-- unittest/force-styles/CMakeLists.txt | 2 -- unittest/fortran/mpi_stubs.f90 | 2 +- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 408528f6dd..62507dd29a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -290,25 +290,8 @@ if(BUILD_MPI) endif() endif() else() - file(GLOB MPI_SOURCES ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) - add_library(mpi_stubs STATIC ${MPI_SOURCES}) - set_target_properties(mpi_stubs PROPERTIES OUTPUT_NAME lammps_mpi_stubs${LAMMPS_MACHINE}) - target_include_directories(mpi_stubs PUBLIC $) - if(BUILD_SHARED_LIBS) - target_link_libraries(lammps PRIVATE mpi_stubs) - if(MSVC) - target_link_libraries(lmp PRIVATE mpi_stubs) - target_include_directories(lmp INTERFACE $) - target_compile_definitions(lmp INTERFACE $) - endif() - target_include_directories(lammps INTERFACE $) - target_compile_definitions(lammps INTERFACE $) - else() - target_include_directories(lammps INTERFACE $) - target_compile_definitions(lammps INTERFACE $) - target_link_libraries(lammps PUBLIC mpi_stubs) - endif() - add_library(MPI::MPI_CXX ALIAS mpi_stubs) + target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) + target_include_directories(lammps PUBLIC ${LAMMPS_SOURCE_DIR}/STUBS) endif() set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") @@ -594,7 +577,7 @@ if(PKG_ATC) if(BUILD_MPI) target_link_libraries(atc PRIVATE MPI::MPI_CXX) else() - target_link_libraries(atc PRIVATE mpi_stubs) + target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS) endif() target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}) target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES}) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index 048c0ed473..863265250d 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -424,8 +424,8 @@ RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) if(NOT BUILD_MPI) - # mpistubs is aliased to MPI::MPI_CXX, but older versions of cmake won't work forward the include path - target_link_libraries(gpu PRIVATE mpi_stubs) + # add include include path to MPI STUBS for non-MPI build + target_include_directories(gpu PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS) else() target_link_libraries(gpu PRIVATE MPI::MPI_CXX) endif() diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 464cd9426a..fd794bd8d7 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -48,8 +48,6 @@ target_include_directories(style_tests PRIVATE ${LAMMPS_SOURCE_DIR}) target_link_libraries(style_tests PUBLIC gmock Yaml::Yaml lammps) if(BUILD_MPI) target_link_libraries(style_tests PUBLIC MPI::MPI_CXX) -else() - target_link_libraries(style_tests PUBLIC mpi_stubs) endif() # propagate sanitizer options to test tools if(ENABLE_SANITIZER AND (NOT (ENABLE_SANITIZER STREQUAL "none"))) diff --git a/unittest/fortran/mpi_stubs.f90 b/unittest/fortran/mpi_stubs.f90 index 3f87fc38f7..8601f436d2 100644 --- a/unittest/fortran/mpi_stubs.f90 +++ b/unittest/fortran/mpi_stubs.f90 @@ -9,7 +9,7 @@ MODULE MPI mpi_comm_split CONTAINS - + SUBROUTINE mpi_comm_split(comm,color,key,newcomm,ierr) INTEGER, INTENT(in) :: comm,color,key INTEGER, INTENT(out) :: newcomm,ierr From d391ae845bef545379894664371f7a93eb15841b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 17:20:05 -0500 Subject: [PATCH 02/48] convert static class members with git info to functions to simplify auto-export on Windows --- cmake/Modules/generate_lmpgitversion.cmake | 8 ++--- src/Makefile | 8 ++--- src/info.cpp | 4 +-- src/lammps.cpp | 4 +-- src/lammps.h | 8 ++--- unittest/cplusplus/test_lammps_class.cpp | 42 +++++++++++----------- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cmake/Modules/generate_lmpgitversion.cmake b/cmake/Modules/generate_lmpgitversion.cmake index b19716d74b..f066269723 100644 --- a/cmake/Modules/generate_lmpgitversion.cmake +++ b/cmake/Modules/generate_lmpgitversion.cmake @@ -24,10 +24,10 @@ if(GIT_FOUND AND EXISTS ${LAMMPS_DIR}/.git) OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -set(temp "${temp}const bool LAMMPS_NS::LAMMPS::has_git_info = ${temp_git_info};\n") -set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_commit[] = \"${temp_git_commit}\";\n") -set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_branch[] = \"${temp_git_branch}\";\n") -set(temp "${temp}const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"${temp_git_describe}\";\n") +set(temp "${temp}bool LAMMPS_NS::LAMMPS::has_git_info() { return ${temp_git_info}; }\n") +set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_commit() { return \"${temp_git_commit}\"; }\n") +set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_branch() { return \"${temp_git_branch}\"; }\n") +set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_descriptor() { return \"${temp_git_describe}\"; }\n") set(temp "${temp}#endif\n\n") message(STATUS "Generating lmpgitversion.h...") diff --git a/src/Makefile b/src/Makefile index d23058447a..eeccc19ae0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -356,10 +356,10 @@ gitversion: branch='(unknown)' ; \ describe='(unknown)' ; \ fi ; \ - echo "const bool LAMMPS_NS::LAMMPS::has_git_info = $${git};" >> ${TMPNAME}.lmpgitversion ; \ - echo "const char LAMMPS_NS::LAMMPS::git_commit[] = \"$${commit}\";" >> ${TMPNAME}.lmpgitversion ; \ - echo "const char LAMMPS_NS::LAMMPS::git_branch[] = \"$${branch}\";" >> ${TMPNAME}.lmpgitversion ; \ - echo "const char LAMMPS_NS::LAMMPS::git_descriptor[] = \"$${describe}\";" >> ${TMPNAME}.lmpgitversion + echo "bool LAMMPS_NS::LAMMPS::has_git_info() { return $${git}; }" >> ${TMPNAME}.lmpgitversion ; \ + echo "const char *LAMMPS_NS::LAMMPS::git_commit() { return \"$${commit}\"; }" >> ${TMPNAME}.lmpgitversion ; \ + echo "const char *LAMMPS_NS::LAMMPS::git_branch() { return \"$${branch}\"; }" >> ${TMPNAME}.lmpgitversion ; \ + echo "const char *LAMMPS_NS::LAMMPS::git_descriptor() { return \"$${describe}\"; }" >> ${TMPNAME}.lmpgitversion @echo '#endif' >> ${TMPNAME}.lmpgitversion @if [ -f lmpgitversion.h ]; \ then test "`diff --brief ${TMPNAME}.lmpgitversion lmpgitversion.h`" != "" && \ diff --git a/src/info.cpp b/src/info.cpp index 297633cd9d..66430c6f4b 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -278,9 +278,9 @@ void Info::command(int narg, char **arg) fmt::print(out,"\nLAMMPS version: {} / {}\n", lmp->version, lmp->num_ver); - if (lmp->has_git_info) + if (lmp->has_git_info()) fmt::print(out,"Git info: {} / {} / {}\n", - lmp->git_branch, lmp->git_descriptor,lmp->git_commit); + lmp->git_branch(), lmp->git_descriptor(),lmp->git_commit()); fmt::print(out,"\nOS information: {}\n\n",platform::os_info()); diff --git a/src/lammps.cpp b/src/lammps.cpp index 55b7755c83..e6ff6efb23 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1149,9 +1149,9 @@ void _noopt LAMMPS::help() // general help message about command line and flags - if (has_git_info) { + if (has_git_info()) { fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - " - LAMMPS_VERSION UPDATE_STRING "\nGit info (%s / %s)\n\n",git_branch, git_descriptor); + LAMMPS_VERSION UPDATE_STRING "\nGit info (%s / %s)\n\n",git_branch(), git_descriptor()); } else { fprintf(fp,"\nLarge-scale Atomic/Molecular Massively Parallel Simulator - " LAMMPS_VERSION UPDATE_STRING "\n\n"); diff --git a/src/lammps.h b/src/lammps.h index 71b731204c..5ccc1a90a9 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -73,10 +73,10 @@ class LAMMPS { static const char *installed_packages[]; static bool is_installed_pkg(const char *pkg); - static const bool has_git_info; - static const char git_commit[]; - static const char git_branch[]; - static const char git_descriptor[]; + static bool has_git_info(); + static const char *git_commit(); + static const char *git_branch(); + static const char *git_descriptor(); LAMMPS(int, char **, MPI_Comm); ~LAMMPS(); diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 3a1bde51ff..eb6735a738 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -90,14 +90,14 @@ TEST_F(LAMMPS_plain, InitMembers) 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, ""); + 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)"); + EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)"); } } @@ -225,14 +225,14 @@ TEST_F(LAMMPS_omp, InitMembers) 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, ""); + 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)"); + EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)"); } } @@ -312,14 +312,14 @@ TEST_F(LAMMPS_kokkos, InitMembers) 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, ""); + 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)"); + EXPECT_STREQ(LAMMPS::git_commit(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_branch(), "(unknown)"); + EXPECT_STREQ(LAMMPS::git_descriptor(), "(unknown)"); } } From 0bf941219fc3ec17306df6f7ba8d2b1b4c591c26 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 17:21:50 -0500 Subject: [PATCH 03/48] silence compiler warnings --- src/atom.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index aece451b9b..0b448a5433 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1052,7 +1052,7 @@ void Atom::deallocate_topology() void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset, int type_offset, int shiftflag, double *shift) { - int m,xptr,iptr; + int xptr,iptr; imageint imagedata; double xdata[3],lamda[3]; double *coord; @@ -1197,7 +1197,7 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset, void Atom::data_vels(int n, char *buf, tagint id_offset) { - int j,m; + int m; char *next; next = strchr(buf,'\n'); @@ -1576,7 +1576,7 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset, void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset) { - int j,m; + int m; char *next; next = strchr(buf,'\n'); From cd8b674f4b1a5495fa8db458398db1c417a53cc6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 17:46:18 -0500 Subject: [PATCH 04/48] expand path to include LAMMPS shared lib --- unittest/utils/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unittest/utils/CMakeLists.txt b/unittest/utils/CMakeLists.txt index 28486048c4..6a3a2efc8e 100644 --- a/unittest/utils/CMakeLists.txt +++ b/unittest/utils/CMakeLists.txt @@ -40,3 +40,8 @@ add_test(FmtLib test_fmtlib) add_executable(test_math_eigen_impl test_math_eigen_impl.cpp) target_include_directories(test_math_eigen_impl PRIVATE ${LAMMPS_SOURCE_DIR}) add_test(MathEigen test_math_eigen_impl 10 5) + +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set_tests_properties(Tokenizer MemPool ArgUtils Utils Platform FmtLib MathEigen PROPERTIES + ENVIRONMENT "PATH=${CMAKE_BINARY_DIR}:$ENV{PATH}") +endif() From ac815fdfba732e46b930b686aa599df0e3f8d767 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 22:16:43 -0500 Subject: [PATCH 05/48] use improved accessors for fixes --- src/KOKKOS/fix_deform_kokkos.cpp | 2 +- src/fix_deform.cpp | 49 ++++++++++++-------------------- src/fix_deform.h | 3 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/KOKKOS/fix_deform_kokkos.cpp b/src/KOKKOS/fix_deform_kokkos.cpp index 576e34503c..104ac41188 100644 --- a/src/KOKKOS/fix_deform_kokkos.cpp +++ b/src/KOKKOS/fix_deform_kokkos.cpp @@ -319,7 +319,7 @@ void FixDeformKokkos::end_of_step() // if (mask[i] & groupbit) // domain->x2lamda(x[i],x[i]); - if (nrigid) + if (rfix.size() > 0) error->all(FLERR,"Cannot (yet) use rigid bodies with fix deform and Kokkos"); //for (i = 0; i < nrigid; i++) // modify->fix[rfix[i]]->deform(0); diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 71429ac0f8..68893701a0 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -45,7 +45,7 @@ enum{ONE_FROM_ONE,ONE_FROM_TWO,TWO_FROM_ONE}; /* ---------------------------------------------------------------------- */ FixDeform::FixDeform(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), -rfix(nullptr), irregular(nullptr), set(nullptr) +irregular(nullptr), set(nullptr) { if (narg < 4) error->all(FLERR,"Illegal fix deform command"); @@ -127,8 +127,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) error->all(FLERR,"Illegal fix deform command"); - delete [] set[index].hstr; - delete [] set[index].hratestr; + delete[] set[index].hstr; + delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; @@ -185,8 +185,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); if (strstr(arg[iarg+3],"v_") != arg[iarg+3]) error->all(FLERR,"Illegal fix deform command"); - delete [] set[index].hstr; - delete [] set[index].hratestr; + delete[] set[index].hstr; + delete[] set[index].hratestr; set[index].hstr = utils::strdup(&arg[iarg+2][2]); set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; @@ -344,7 +344,6 @@ rfix(nullptr), irregular(nullptr), set(nullptr) force_reneighbor = 1; next_reneighbor = -1; - nrigid = 0; flip = 0; if (force_reneighbor) irregular = new Irregular(lmp); @@ -359,12 +358,11 @@ FixDeform::~FixDeform() { if (set) { for (int i = 0; i < 6; i++) { - delete [] set[i].hstr; - delete [] set[i].hratestr; + delete[] set[i].hstr; + delete[] set[i].hratestr; } } - delete [] set; - delete [] rfix; + delete[] set; delete irregular; @@ -396,9 +394,8 @@ void FixDeform::init() // domain, fix nvt/sllod, compute temp/deform only work on single h_rate int count = 0; - for (int i = 0; i < modify->nfix; i++) - if (strcmp(modify->fix[i]->style,"deform") == 0) count++; - if (count > 1) error->all(FLERR,"More than one fix deform"); + if (modify->get_fix_by_style("deform").size() > 1) + error->all(FLERR,"More than one fix deform"); // Kspace setting @@ -609,20 +606,12 @@ void FixDeform::init() } // detect if any rigid fixes exist so rigid bodies can be rescaled - // rfix[] = indices to each fix rigid + // rfix[] = vector with pointers to each fix rigid - delete [] rfix; - nrigid = 0; - rfix = nullptr; + rfix.clear(); - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) nrigid++; - if (nrigid) { - rfix = new int[nrigid]; - nrigid = 0; - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->rigid_flag) rfix[nrigid++] = i; - } + for (auto ifix : modify->get_fix_list()) + if (ifix->rigid_flag) rfix.push_back(ifix); } /* ---------------------------------------------------------------------- @@ -894,9 +883,8 @@ void FixDeform::end_of_step() if (mask[i] & groupbit) domain->x2lamda(x[i],x[i]); - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(0); + for (auto ifix : rfix) + ifix->deform(0); } // reset global and local box to new size/shape @@ -934,9 +922,8 @@ void FixDeform::end_of_step() if (mask[i] & groupbit) domain->lamda2x(x[i],x[i]); - if (nrigid) - for (i = 0; i < nrigid; i++) - modify->fix[rfix[i]]->deform(1); + for (auto ifix : rfix) + ifix->deform(1); } // redo KSpace coeffs since box has changed diff --git a/src/fix_deform.h b/src/fix_deform.h index c1becf58f9..90aabbd228 100644 --- a/src/fix_deform.h +++ b/src/fix_deform.h @@ -45,8 +45,7 @@ class FixDeform : public Fix { double *h_rate, *h_ratelo; int varflag; // 1 if VARIABLE option is used, 0 if not int kspace_flag; // 1 if KSpace invoked, 0 if not - int nrigid; // number of rigid fixes - int *rfix; // indices of rigid fixes + std::vector rfix; // pointers to rigid fixes class Irregular *irregular; // for migrating atoms after box flips double TWOPI; From db4e69bf38ed57695145445565eb9dc1a9b6ec8c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jan 2022 23:28:54 -0500 Subject: [PATCH 06/48] further simplification by making STUBS an interface and alias to MPI::MPI_CXX --- cmake/CMakeLists.txt | 14 +++++--------- cmake/Modules/Packages/GPU.cmake | 7 +------ examples/plugins/LAMMPSInterfaceCXX.cmake | 4 +--- unittest/force-styles/CMakeLists.txt | 4 +--- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 62507dd29a..49d3bfb845 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -280,10 +280,8 @@ if(BUILD_MPI) # We use a non-standard procedure to cross-compile with MPI on Windows if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) include(MPI4WIN) - target_link_libraries(lammps PUBLIC MPI::MPI_CXX) else() find_package(MPI REQUIRED) - target_link_libraries(lammps PUBLIC MPI::MPI_CXX) option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF) if(LAMMPS_LONGLONG_TO_LONG) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) @@ -291,8 +289,11 @@ if(BUILD_MPI) endif() else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) - target_include_directories(lammps PUBLIC ${LAMMPS_SOURCE_DIR}/STUBS) + add_library(mpi_stubs INTERFACE) + target_include_directories(mpi_stubs INTERFACE $) + add_library(MPI::MPI_CXX ALIAS mpi_stubs) endif() +target_link_libraries(lammps PUBLIC MPI::MPI_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) @@ -573,12 +574,7 @@ if(PKG_ATC) if(LAMMPS_SIZES STREQUAL "BIGBIG") message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG") endif() - target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES}) - if(BUILD_MPI) - target_link_libraries(atc PRIVATE MPI::MPI_CXX) - else() - target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS) - endif() + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX) target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}) target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES}) endif() diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index 863265250d..ee839e20e1 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -423,13 +423,8 @@ RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) -if(NOT BUILD_MPI) - # add include include path to MPI STUBS for non-MPI build - target_include_directories(gpu PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS) -else() - target_link_libraries(gpu PRIVATE MPI::MPI_CXX) -endif() target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES}) set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE}) target_sources(lammps PRIVATE ${GPU_SOURCES}) target_include_directories(lammps PRIVATE ${GPU_SOURCES_DIR}) +target_link_libraries(gpu PRIVATE MPI::MPI_CXX) diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index d52cf8f4e5..e910ec2923 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -42,10 +42,8 @@ if(BUILD_MPI) if(LAMMPS_LONGLONG_TO_LONG) target_compile_definitions(lammps INTERFACE -DLAMMPS_LONGLONG_TO_LONG) endif() - target_link_libraries(lammps INTERFACE MPI::MPI_CXX) -else() - target_include_directories(lammps INTERFACE "${LAMMPS_SOURCE_DIR}/STUBS") endif() +target_link_libraries(lammps INTERFACE MPI::MPI_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index fd794bd8d7..5fec488e22 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -46,9 +46,7 @@ else() endif() target_include_directories(style_tests PRIVATE ${LAMMPS_SOURCE_DIR}) target_link_libraries(style_tests PUBLIC gmock Yaml::Yaml lammps) -if(BUILD_MPI) - target_link_libraries(style_tests PUBLIC MPI::MPI_CXX) -endif() + # propagate sanitizer options to test tools if(ENABLE_SANITIZER AND (NOT (ENABLE_SANITIZER STREQUAL "none"))) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) From 96502ae49da079ce3a996bd39bf2d661f8aadc0c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 17:07:03 -0500 Subject: [PATCH 07/48] whitespace --- src/dump.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dump.cpp b/src/dump.cpp index 181a56ff46..da5a827667 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -1009,13 +1009,13 @@ void Dump::balance() // send for this proc if (iproc_prev != me) { - MPI_Send(&buf[procstart*size_one],procnsend*size_one,MPI_DOUBLE,procsend,0,world); + MPI_Send(&buf[procstart*size_one],procnsend*size_one,MPI_DOUBLE,procsend,0,world); } else { // sending to self, copy buffers - int offset_me = proc_offsets[me] - proc_new_offsets[me]; - memcpy(&buf_balance[(offset_me + procstart)*size_one],&buf[procstart*size_one],procnsend*size_one*sizeof(double)); + int offset_me = proc_offsets[me] - proc_new_offsets[me]; + memcpy(&buf_balance[(offset_me + procstart)*size_one],&buf[procstart*size_one],procnsend*size_one*sizeof(double)); } procstart = i; From f6d0be12574edd89965a9b967c41031ac7088819 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 17:08:16 -0500 Subject: [PATCH 08/48] avoid integer overflow due to precedence --- src/dump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dump.cpp b/src/dump.cpp index da5a827667..46622c2efa 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -1015,7 +1015,7 @@ void Dump::balance() // sending to self, copy buffers int offset_me = proc_offsets[me] - proc_new_offsets[me]; - memcpy(&buf_balance[(offset_me + procstart)*size_one],&buf[procstart*size_one],procnsend*size_one*sizeof(double)); + memcpy(&buf_balance[(offset_me + procstart)*size_one],&buf[procstart*size_one],sizeof(double)*procnsend*size_one); } procstart = i; From 5c0c3df035706c36ecab60d680b3f1202365527f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 21:10:30 -0500 Subject: [PATCH 09/48] make use of CMAKE_(RUNTIME|LIBRARY)_OUTPUT_DIRECTORY --- cmake/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 49d3bfb845..2487537f8c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -19,6 +19,9 @@ set(SOVERSION 0) get_filename_component(LAMMPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE) get_filename_component(LAMMPS_LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/lib ABSOLUTE) +# collect all executables and shared libs in the top level build folder +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} CACHE PATH "Folder for executables, DLLs and shared objects" FORCE) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} CACHE PATH "Folder for libraries" FORCE) set(LAMMPS_SOURCE_DIR ${LAMMPS_DIR}/src) set(LAMMPS_LIB_SOURCE_DIR ${LAMMPS_DIR}/lib) From 7978bf671d2375541f97bca2608904bfc4ddfa77 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 21:12:13 -0500 Subject: [PATCH 10/48] use canonical syntax for adding tests --- unittest/c-library/CMakeLists.txt | 14 +++++++------- unittest/cplusplus/CMakeLists.txt | 6 +++--- unittest/force-styles/CMakeLists.txt | 2 +- unittest/fortran/CMakeLists.txt | 4 ++-- unittest/utils/CMakeLists.txt | 20 ++++++++------------ 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 3d57dbbc90..4a0442968d 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -1,26 +1,26 @@ add_executable(test_library_open test_library_open.cpp test_main.cpp) target_link_libraries(test_library_open PRIVATE lammps GTest::GMock) -add_test(LibraryOpen test_library_open) +add_test(NAME LibraryOpen COMMAND test_library_open WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_library_commands test_library_commands.cpp test_main.cpp) target_link_libraries(test_library_commands PRIVATE lammps GTest::GMock) -add_test(LibraryCommands test_library_commands) +add_test(NAME LibraryCommands COMMAND test_library_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_library_external test_library_external.cpp test_main.cpp) target_link_libraries(test_library_external PRIVATE lammps GTest::GMock) -add_test(LibraryExternal test_library_external) +add_test(NAME LibraryExternal COMMAND test_library_external WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_library_properties test_library_properties.cpp test_main.cpp) target_link_libraries(test_library_properties PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) -add_test(LibraryProperties test_library_properties) +add_test(NAME LibraryProperties COMMAND test_library_properties WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(LibraryProperties PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_library_scatter_gather test_library_scatter_gather.cpp test_main.cpp) target_link_libraries(test_library_scatter_gather PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_scatter_gather PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) -add_test(LibraryScatterGather test_library_scatter_gather) +add_test(NAME LibraryScatterGather COMMAND test_library_scatter_gather WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(LibraryScatterGather PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set(TEST_CONFIG_DEFS "-DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR};-DLAMMPS_${LAMMPS_SIZES}") @@ -65,9 +65,9 @@ endforeach() add_executable(test_library_config test_library_config.cpp test_main.cpp) target_link_libraries(test_library_config PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_config PRIVATE ${TEST_CONFIG_DEFS}) -add_test(LibraryConfig test_library_config) +add_test(NAME LibraryConfig COMMAND test_library_config WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_library_mpi test_library_mpi.cpp) target_link_libraries(test_library_mpi PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS}) -add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $) +add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/cplusplus/CMakeLists.txt b/unittest/cplusplus/CMakeLists.txt index efd194b9d2..ff192dd8d0 100644 --- a/unittest/cplusplus/CMakeLists.txt +++ b/unittest/cplusplus/CMakeLists.txt @@ -1,13 +1,13 @@ add_executable(test_lammps_class test_lammps_class.cpp) target_link_libraries(test_lammps_class PRIVATE lammps GTest::GMockMain) -add_test(LammpsClass test_lammps_class) +add_test(NAME LammpsClass COMMAND test_lammps_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(LammpsClass PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=1") add_executable(test_input_class test_input_class.cpp) target_link_libraries(test_input_class PRIVATE lammps GTest::GTestMain) -add_test(InputClass test_input_class) +add_test(NAME InputClass COMMAND test_input_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_error_class test_error_class.cpp) target_link_libraries(test_error_class PRIVATE lammps GTest::GMock) -add_test(ErrorClass test_error_class) +add_test(NAME ErrorClass COMMAND test_error_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 5fec488e22..b8e8bce9c2 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -59,7 +59,7 @@ endif() add_executable(test_error_stats test_error_stats.cpp) target_include_directories(test_error_stats PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LAMMPS_SOURCE_DIR}) target_link_libraries(test_error_stats PRIVATE gtest_main) -add_test(NAME ErrorStats COMMAND test_error_stats) +add_test(NAME ErrorStats COMMAND test_error_stats WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) # pair style tester add_executable(test_pair_style test_pair_style.cpp) diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index 6e7e165018..4b4d51b7ae 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -26,11 +26,11 @@ if(CMAKE_Fortran_COMPILER) 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::GTestMain) - add_test(FortranOpen test_fortran_create) + add_test(NAME FortranOpen COMMAND test_fortran_create WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 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::GTestMain) - add_test(FortranCommands test_fortran_commands) + add_test(NAME FortranCommands COMMAND test_fortran_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) else() message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran compiler") endif() diff --git a/unittest/utils/CMakeLists.txt b/unittest/utils/CMakeLists.txt index 6a3a2efc8e..156cb62f11 100644 --- a/unittest/utils/CMakeLists.txt +++ b/unittest/utils/CMakeLists.txt @@ -1,22 +1,23 @@ + add_executable(test_tokenizer test_tokenizer.cpp) target_link_libraries(test_tokenizer PRIVATE lammps GTest::GMockMain) -add_test(Tokenizer test_tokenizer) +add_test(NAME Tokenizer COMMAND test_tokenizer WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_mempool test_mempool.cpp) target_link_libraries(test_mempool PRIVATE lammps GTest::GMockMain) -add_test(MemPool test_mempool) +add_test(NAME MemPool COMMAND test_mempool WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_argutils test_argutils.cpp) target_link_libraries(test_argutils PRIVATE lammps GTest::GMockMain) -add_test(ArgUtils test_argutils) +add_test(NAME ArgUtils COMMAND test_argutils WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_utils test_utils.cpp) target_link_libraries(test_utils PRIVATE lammps GTest::GMockMain) -add_test(Utils test_utils) +add_test(NAME Utils COMMAND test_utils WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_platform test_platform.cpp) target_link_libraries(test_platform PRIVATE lammps GTest::GMockMain) -add_test(Platform test_platform) +add_test(NAME Platform COMMAND test_platform WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(Utils Platform PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") @@ -35,13 +36,8 @@ endif() add_executable(test_fmtlib test_fmtlib.cpp) target_link_libraries(test_fmtlib PRIVATE lammps GTest::GMockMain) -add_test(FmtLib test_fmtlib) +add_test(NAME FmtLib COMMAND test_fmtlib WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_executable(test_math_eigen_impl test_math_eigen_impl.cpp) target_include_directories(test_math_eigen_impl PRIVATE ${LAMMPS_SOURCE_DIR}) -add_test(MathEigen test_math_eigen_impl 10 5) - -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - set_tests_properties(Tokenizer MemPool ArgUtils Utils Platform FmtLib MathEigen PROPERTIES - ENVIRONMENT "PATH=${CMAKE_BINARY_DIR}:$ENV{PATH}") -endif() +add_test(NAME MathEigen COMMAND test_math_eigen_impl 10 5 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) From 8423ecb2116e5ba5b2ec2079ede3666d4c157f9b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 21:28:37 -0500 Subject: [PATCH 11/48] small tweaks to make things work with the new settings --- unittest/commands/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 49603a8b22..d7b49ea24e 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -11,7 +11,7 @@ endif() target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock) add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(SimpleCommands PROPERTIES - ENVIRONMENT "LAMMPS_PLUGIN_BIN_DIR=${CMAKE_BINARY_DIR}/build-plugins") + ENVIRONMENT "LAMMPS_PLUGIN_BIN_DIR=${CMAKE_BINARY_DIR}") add_executable(test_lattice_region test_lattice_region.cpp) target_link_libraries(test_lattice_region PRIVATE lammps GTest::GMock) From d6fa3a08cd42c66d6c6137cc3470c046ed534328 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Jan 2022 21:54:32 -0500 Subject: [PATCH 12/48] roll back library aliasing changes as that negatively interferes with unit tests --- cmake/CMakeLists.txt | 13 ++++++++++--- cmake/Modules/Packages/GPU.cmake | 6 +++++- examples/plugins/LAMMPSInterfaceCXX.cmake | 4 +++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2487537f8c..2bfe3ce245 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -290,13 +290,13 @@ if(BUILD_MPI) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) endif() endif() + target_link_libraries(lammps PUBLIC MPI::MPI_CXX) else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) add_library(mpi_stubs INTERFACE) target_include_directories(mpi_stubs INTERFACE $) - add_library(MPI::MPI_CXX ALIAS mpi_stubs) + target_link_libraries(lammps PUBLIC mpi_stubs) endif() -target_link_libraries(lammps PUBLIC MPI::MPI_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) @@ -577,7 +577,11 @@ if(PKG_ATC) if(LAMMPS_SIZES STREQUAL "BIGBIG") message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG") endif() - target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX) + if(BUILD_MPI) + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX) + else() + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs) + endif() target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}) target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES}) endif() @@ -691,6 +695,9 @@ foreach(_DEF ${LAMMPS_DEFINES}) endforeach() if(BUILD_SHARED_LIBS) install(TARGETS lammps EXPORT LAMMPS_Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(NOT BUILD_MPI) + install(TARGETS mpi_stubs EXPORT LAMMPS_Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() configure_file(pkgconfig/liblammps.pc.in ${CMAKE_CURRENT_BINARY_DIR}/liblammps${LAMMPS_MACHINE}.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblammps${LAMMPS_MACHINE}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(EXPORT LAMMPS_Targets FILE LAMMPS_Targets.cmake NAMESPACE LAMMPS:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LAMMPS) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index ee839e20e1..fe15917f47 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -422,9 +422,13 @@ RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES) RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) +if(BUILD_MPI) + target_link_libraries(gpu PRIVATE MPI::MPI_CXX) +else() + target_link_libraries(gpu PRIVATE mpi_stubs) +endif() target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES}) set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE}) target_sources(lammps PRIVATE ${GPU_SOURCES}) target_include_directories(lammps PRIVATE ${GPU_SOURCES_DIR}) -target_link_libraries(gpu PRIVATE MPI::MPI_CXX) diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake index e910ec2923..d52cf8f4e5 100644 --- a/examples/plugins/LAMMPSInterfaceCXX.cmake +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -42,8 +42,10 @@ if(BUILD_MPI) if(LAMMPS_LONGLONG_TO_LONG) target_compile_definitions(lammps INTERFACE -DLAMMPS_LONGLONG_TO_LONG) endif() + target_link_libraries(lammps INTERFACE MPI::MPI_CXX) +else() + target_include_directories(lammps INTERFACE "${LAMMPS_SOURCE_DIR}/STUBS") endif() -target_link_libraries(lammps INTERFACE MPI::MPI_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) From d62e25decc02442bf7d0a0d075dd71bc4bc2f851 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 11:10:23 -0500 Subject: [PATCH 13/48] don't specify default working directory for tests explicitly --- unittest/CMakeLists.txt | 9 ++---- unittest/c-library/CMakeLists.txt | 14 ++++---- unittest/commands/CMakeLists.txt | 12 +++---- unittest/cplusplus/CMakeLists.txt | 6 ++-- unittest/force-styles/CMakeLists.txt | 20 ++++++------ unittest/formats/CMakeLists.txt | 48 ++++++++++++++-------------- unittest/fortran/CMakeLists.txt | 4 +-- unittest/python/CMakeLists.txt | 4 +-- unittest/utils/CMakeLists.txt | 14 ++++---- 9 files changed, 64 insertions(+), 67 deletions(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 6489287097..a310b82c07 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -26,24 +26,21 @@ add_library(GTest::GMockMain ALIAS gmock_main) # the LAMMPS version header in the output for an empty input file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/in.empty "") add_test(NAME RunLammps - COMMAND $ -log none -echo none -in in.empty - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + COMMAND $ -log none -echo none -in in.empty) set_tests_properties(RunLammps PROPERTIES ENVIRONMENT "TSAN_OPTIONS=ignore_noninstrumented_modules=1;HWLOC_HIDE_ERRORS=1" PASS_REGULAR_EXPRESSION "LAMMPS \\([0-9]+ [A-Za-z]+ 2[0-9][0-9][0-9]( - Update [0-9]+)?\\)") # check if the compiled executable will print the help message add_test(NAME HelpMessage - COMMAND $ -h - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + COMMAND $ -h) set_tests_properties(HelpMessage PROPERTIES ENVIRONMENT "TSAN_OPTIONS=ignore_noninstrumented_modules=1;HWLOC_HIDE_ERRORS=1" PASS_REGULAR_EXPRESSION ".*Large-scale Atomic/Molecular Massively Parallel Simulator -.*Usage example:.*") # check if the compiled executable will error out on an invalid command line flag add_test(NAME InvalidFlag - COMMAND $ -xxx - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + COMMAND $ -xxx) set_tests_properties(InvalidFlag PROPERTIES ENVIRONMENT "TSAN_OPTIONS=ignore_noninstrumented_modules=1;HWLOC_HIDE_ERRORS=1" PASS_REGULAR_EXPRESSION "ERROR: Invalid command-line argument.*") diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 4a0442968d..e9409be0cc 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -1,26 +1,26 @@ add_executable(test_library_open test_library_open.cpp test_main.cpp) target_link_libraries(test_library_open PRIVATE lammps GTest::GMock) -add_test(NAME LibraryOpen COMMAND test_library_open WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryOpen COMMAND test_library_open) add_executable(test_library_commands test_library_commands.cpp test_main.cpp) target_link_libraries(test_library_commands PRIVATE lammps GTest::GMock) -add_test(NAME LibraryCommands COMMAND test_library_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryCommands COMMAND test_library_commands) add_executable(test_library_external test_library_external.cpp test_main.cpp) target_link_libraries(test_library_external PRIVATE lammps GTest::GMock) -add_test(NAME LibraryExternal COMMAND test_library_external WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryExternal COMMAND test_library_external) add_executable(test_library_properties test_library_properties.cpp test_main.cpp) target_link_libraries(test_library_properties PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME LibraryProperties COMMAND test_library_properties WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryProperties COMMAND test_library_properties) set_tests_properties(LibraryProperties PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_library_scatter_gather test_library_scatter_gather.cpp test_main.cpp) target_link_libraries(test_library_scatter_gather PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_scatter_gather PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) -add_test(NAME LibraryScatterGather COMMAND test_library_scatter_gather WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryScatterGather COMMAND test_library_scatter_gather) set_tests_properties(LibraryScatterGather PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set(TEST_CONFIG_DEFS "-DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR};-DLAMMPS_${LAMMPS_SIZES}") @@ -65,9 +65,9 @@ endforeach() add_executable(test_library_config test_library_config.cpp test_main.cpp) target_link_libraries(test_library_config PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_config PRIVATE ${TEST_CONFIG_DEFS}) -add_test(NAME LibraryConfig COMMAND test_library_config WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LibraryConfig COMMAND test_library_config) add_executable(test_library_mpi test_library_mpi.cpp) target_link_libraries(test_library_mpi PRIVATE lammps GTest::GMock) target_compile_definitions(test_library_mpi PRIVATE ${TEST_CONFIG_DEFS}) -add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_mpi_test(NAME LibraryMPI NUM_PROCS 4 COMMAND $) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index d7b49ea24e..d4f437dc4c 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -9,21 +9,21 @@ if((NOT (CMAKE_SYSTEM_NAME STREQUAL "Windows")) AND PKG_PLUGIN) endif() target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock) -add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME SimpleCommands COMMAND test_simple_commands) set_tests_properties(SimpleCommands PROPERTIES ENVIRONMENT "LAMMPS_PLUGIN_BIN_DIR=${CMAKE_BINARY_DIR}") add_executable(test_lattice_region test_lattice_region.cpp) target_link_libraries(test_lattice_region PRIVATE lammps GTest::GMock) -add_test(NAME LatticeRegion COMMAND test_lattice_region WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LatticeRegion COMMAND test_lattice_region) add_executable(test_groups test_groups.cpp) target_link_libraries(test_groups PRIVATE lammps GTest::GMock) -add_test(NAME Groups COMMAND test_groups WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME Groups COMMAND test_groups) add_executable(test_variables test_variables.cpp) target_link_libraries(test_variables PRIVATE lammps GTest::GMock) -add_test(NAME Variables COMMAND test_variables WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME Variables COMMAND test_variables) add_executable(test_kim_commands test_kim_commands.cpp) if(KIM_EXTRA_UNITTESTS) @@ -34,12 +34,12 @@ if(KIM_EXTRA_UNITTESTS) endif() endif() target_link_libraries(test_kim_commands PRIVATE lammps GTest::GMock) -add_test(NAME KimCommands COMMAND test_kim_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME KimCommands COMMAND test_kim_commands) add_executable(test_reset_ids test_reset_ids.cpp) target_compile_definitions(test_reset_ids PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(test_reset_ids PRIVATE lammps GTest::GMock) -add_test(NAME ResetIDs COMMAND test_reset_ids WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME ResetIDs COMMAND test_reset_ids) add_executable(test_mpi_load_balancing test_mpi_load_balancing.cpp) target_link_libraries(test_mpi_load_balancing PRIVATE lammps GTest::GMock) diff --git a/unittest/cplusplus/CMakeLists.txt b/unittest/cplusplus/CMakeLists.txt index ff192dd8d0..88f082a204 100644 --- a/unittest/cplusplus/CMakeLists.txt +++ b/unittest/cplusplus/CMakeLists.txt @@ -1,13 +1,13 @@ add_executable(test_lammps_class test_lammps_class.cpp) target_link_libraries(test_lammps_class PRIVATE lammps GTest::GMockMain) -add_test(NAME LammpsClass COMMAND test_lammps_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME LammpsClass COMMAND test_lammps_class) set_tests_properties(LammpsClass PROPERTIES ENVIRONMENT "OMP_NUM_THREADS=1") add_executable(test_input_class test_input_class.cpp) target_link_libraries(test_input_class PRIVATE lammps GTest::GTestMain) -add_test(NAME InputClass COMMAND test_input_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME InputClass COMMAND test_input_class) add_executable(test_error_class test_error_class.cpp) target_link_libraries(test_error_class PRIVATE lammps GTest::GMock) -add_test(NAME ErrorClass COMMAND test_error_class WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME ErrorClass COMMAND test_error_class) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index b8e8bce9c2..0a4a1ce33e 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -59,7 +59,7 @@ endif() add_executable(test_error_stats test_error_stats.cpp) target_include_directories(test_error_stats PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LAMMPS_SOURCE_DIR}) target_link_libraries(test_error_stats PRIVATE gtest_main) -add_test(NAME ErrorStats COMMAND test_error_stats WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME ErrorStats COMMAND test_error_stats) # pair style tester add_executable(test_pair_style test_pair_style.cpp) @@ -77,7 +77,7 @@ endif() foreach(TEST ${MOL_PAIR_TESTS}) string(REGEX REPLACE "^.*mol-pair-(.*)\.yaml" "MolPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -87,7 +87,7 @@ file(GLOB ATOMIC_PAIR_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/atomic-p foreach(TEST ${ATOMIC_PAIR_TESTS}) string(REGEX REPLACE "^.*atomic-pair-(.*)\.yaml" "AtomicPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -97,7 +97,7 @@ file(GLOB MANYBODY_PAIR_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/manybo foreach(TEST ${MANYBODY_PAIR_TESTS}) string(REGEX REPLACE "^.*manybody-pair-(.*)\.yaml" "ManybodyPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -110,7 +110,7 @@ file(GLOB BOND_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/bond-*.yaml) foreach(TEST ${BOND_TESTS}) string(REGEX REPLACE "^.*bond-(.*)\.yaml" "BondStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_bond_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_bond_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -123,7 +123,7 @@ file(GLOB ANGLE_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/angle-*.yaml) foreach(TEST ${ANGLE_TESTS}) string(REGEX REPLACE "^.*angle-(.*)\.yaml" "AngleStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_angle_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_angle_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -137,7 +137,7 @@ endif() foreach(TEST ${KSPACE_TESTS}) string(REGEX REPLACE "^.*kspace-(.*)\.yaml" "KSpaceStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -154,7 +154,7 @@ file(GLOB FIX_TIMESTEP_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/fix-tim foreach(TEST ${FIX_TIMESTEP_TESTS}) string(REGEX REPLACE "^.*fix-timestep-(.*)\.yaml" "FixTimestep:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_fix_timestep ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_fix_timestep ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -167,7 +167,7 @@ file(GLOB DIHEDRAL_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/dihedral-*. foreach(TEST ${DIHEDRAL_TESTS}) string(REGEX REPLACE "^.*dihedral-(.*)\.yaml" "DihedralStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_dihedral_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_dihedral_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -180,7 +180,7 @@ file(GLOB IMPROPER_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/improper-*. foreach(TEST ${IMPROPER_TESTS}) string(REGEX REPLACE "^.*improper-(.*)\.yaml" "ImproperStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) - add_test(NAME ${TNAME} COMMAND test_improper_style ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME ${TNAME} COMMAND test_improper_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index be8e055adb..8a198d4c64 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -1,49 +1,49 @@ add_executable(test_atom_styles test_atom_styles.cpp) target_link_libraries(test_atom_styles PRIVATE lammps GTest::GMock) -add_test(NAME AtomStyles COMMAND test_atom_styles WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME AtomStyles COMMAND test_atom_styles) add_executable(test_image_flags test_image_flags.cpp) target_link_libraries(test_image_flags PRIVATE lammps GTest::GMock) -add_test(NAME ImageFlags COMMAND test_image_flags WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME ImageFlags COMMAND test_image_flags) add_executable(test_input_convert test_input_convert.cpp) target_link_libraries(test_input_convert PRIVATE lammps GTest::GMockMain) -add_test(NAME InputConvert COMMAND test_input_convert WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME InputConvert COMMAND test_input_convert) add_executable(test_molecule_file test_molecule_file.cpp) target_link_libraries(test_molecule_file PRIVATE lammps GTest::GMock) -add_test(NAME MoleculeFile COMMAND test_molecule_file WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME MoleculeFile COMMAND test_molecule_file) add_executable(test_pair_unit_convert test_pair_unit_convert.cpp) target_link_libraries(test_pair_unit_convert PRIVATE lammps GTest::GMock) -add_test(NAME PairUnitConvert COMMAND test_pair_unit_convert WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME PairUnitConvert COMMAND test_pair_unit_convert) set_tests_properties(PairUnitConvert PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_potential_file_reader test_potential_file_reader.cpp) target_link_libraries(test_potential_file_reader PRIVATE lammps GTest::GMock) -add_test(NAME PotentialFileReader COMMAND test_potential_file_reader WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME PotentialFileReader COMMAND test_potential_file_reader) set_tests_properties(PotentialFileReader PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") if(PKG_MANYBODY) add_executable(test_eim_potential_file_reader test_eim_potential_file_reader.cpp) target_link_libraries(test_eim_potential_file_reader PRIVATE lammps GTest::GMock) - add_test(NAME EIMPotentialFileReader COMMAND test_eim_potential_file_reader WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME EIMPotentialFileReader COMMAND test_eim_potential_file_reader) set_tests_properties(EIMPotentialFileReader PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") endif() add_executable(test_text_file_reader test_text_file_reader.cpp) target_link_libraries(test_text_file_reader PRIVATE lammps GTest::GMock) -add_test(NAME TextFileReader COMMAND test_text_file_reader WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME TextFileReader COMMAND test_text_file_reader) set_tests_properties(TextFileReader PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_file_operations test_file_operations.cpp) target_link_libraries(test_file_operations PRIVATE lammps GTest::GMock) -add_test(NAME FileOperations COMMAND test_file_operations WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME FileOperations COMMAND test_file_operations) add_executable(test_dump_atom test_dump_atom.cpp) target_link_libraries(test_dump_atom PRIVATE lammps GTest::GMock) -add_test(NAME DumpAtom COMMAND test_dump_atom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME DumpAtom COMMAND test_dump_atom) set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") if(PKG_COMPRESS) @@ -64,19 +64,19 @@ if(PKG_COMPRESS) add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_xyz_compressed PRIVATE lammps GTest::GMock) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz) set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_test(NAME DumpCustomGZ COMMAND test_dump_custom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpCustomGZ COMMAND test_dump_custom_compressed gz) set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz) set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz) set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_compressed gz) set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") find_package(PkgConfig REQUIRED) @@ -84,43 +84,43 @@ if(PKG_COMPRESS) find_program(ZSTD_BINARY NAMES zstd) if(Zstd_FOUND AND ZSTD_BINARY) - add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd) set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_test(NAME DumpCustomZstd COMMAND test_dump_custom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpCustomZstd COMMAND test_dump_custom_compressed zstd) set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd) set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd) set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_compressed zstd) set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") endif() endif() add_executable(test_dump_custom test_dump_custom.cpp) target_link_libraries(test_dump_custom PRIVATE lammps GTest::GMock) -add_test(NAME DumpCustom COMMAND test_dump_custom WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME DumpCustom COMMAND test_dump_custom) set_tests_properties(DumpCustom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_dump_cfg test_dump_cfg.cpp) target_link_libraries(test_dump_cfg PRIVATE lammps GTest::GMock) -add_test(NAME DumpCfg COMMAND test_dump_cfg WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME DumpCfg COMMAND test_dump_cfg) set_tests_properties(DumpCfg PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") add_executable(test_dump_local test_dump_local.cpp) target_link_libraries(test_dump_local PRIVATE lammps GTest::GMock) -add_test(NAME DumpLocal COMMAND test_dump_local WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME DumpLocal COMMAND test_dump_local) set_tests_properties(DumpLocal PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") if(PKG_NETCDF) find_program(NCDUMP NAMES ncdump ncdump.exe) add_executable(test_dump_netcdf test_dump_netcdf.cpp) target_link_libraries(test_dump_netcdf PRIVATE lammps GTest::GMock) - add_test(NAME DumpNetCDF COMMAND test_dump_netcdf WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME DumpNetCDF COMMAND test_dump_netcdf) if(NOT (NCDUMP STREQUAL "NCDUMP-NOTFOUND")) set_tests_properties(DumpNetCDF PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};NCDUMP_BINARY=${NCDUMP}") endif() diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index 4b4d51b7ae..2e7703747b 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -26,11 +26,11 @@ if(CMAKE_Fortran_COMPILER) 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::GTestMain) - add_test(NAME FortranOpen COMMAND test_fortran_create WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME FortranOpen COMMAND 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::GTestMain) - add_test(NAME FortranCommands COMMAND test_fortran_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_test(NAME FortranCommands COMMAND test_fortran_commands) else() message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran compiler") endif() diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index f61a9c61ab..3cc6b9a91b 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -28,7 +28,7 @@ if(Python3_Development_FOUND) target_compile_definitions(test_python_package PRIVATE -DTEST_HAVE_PYTHON_DEVELOPMENT=1) target_link_libraries(test_python_package PRIVATE Python3::Python) endif() -add_test(NAME PythonPackage COMMAND test_python_package WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME PythonPackage COMMAND test_python_package) set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH};PYTHONUNBUFFERED=1") if(Python_EXECUTABLE) @@ -36,7 +36,7 @@ if(Python_EXECUTABLE) set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}) get_property(BUILD_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(BUILD_IS_MULTI_CONFIG) - set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) else() set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}) endif() diff --git a/unittest/utils/CMakeLists.txt b/unittest/utils/CMakeLists.txt index 156cb62f11..c01313ad8d 100644 --- a/unittest/utils/CMakeLists.txt +++ b/unittest/utils/CMakeLists.txt @@ -1,23 +1,23 @@ add_executable(test_tokenizer test_tokenizer.cpp) target_link_libraries(test_tokenizer PRIVATE lammps GTest::GMockMain) -add_test(NAME Tokenizer COMMAND test_tokenizer WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME Tokenizer COMMAND test_tokenizer) add_executable(test_mempool test_mempool.cpp) target_link_libraries(test_mempool PRIVATE lammps GTest::GMockMain) -add_test(NAME MemPool COMMAND test_mempool WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME MemPool COMMAND test_mempool) add_executable(test_argutils test_argutils.cpp) target_link_libraries(test_argutils PRIVATE lammps GTest::GMockMain) -add_test(NAME ArgUtils COMMAND test_argutils WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME ArgUtils COMMAND test_argutils) add_executable(test_utils test_utils.cpp) target_link_libraries(test_utils PRIVATE lammps GTest::GMockMain) -add_test(NAME Utils COMMAND test_utils WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME Utils COMMAND test_utils) add_executable(test_platform test_platform.cpp) target_link_libraries(test_platform PRIVATE lammps GTest::GMockMain) -add_test(NAME Platform COMMAND test_platform WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME Platform COMMAND test_platform) set_tests_properties(Utils Platform PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") @@ -36,8 +36,8 @@ endif() add_executable(test_fmtlib test_fmtlib.cpp) target_link_libraries(test_fmtlib PRIVATE lammps GTest::GMockMain) -add_test(NAME FmtLib COMMAND test_fmtlib WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME FmtLib COMMAND test_fmtlib) add_executable(test_math_eigen_impl test_math_eigen_impl.cpp) target_include_directories(test_math_eigen_impl PRIVATE ${LAMMPS_SOURCE_DIR}) -add_test(NAME MathEigen COMMAND test_math_eigen_impl 10 5 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME MathEigen COMMAND test_math_eigen_impl 10 5) From 845ab2dd71436a75dc8fdacd5af7f090421e3f55 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 16:35:30 -0500 Subject: [PATCH 14/48] On Windows the Regex matcher for '.' does not match '\n' Thus we have to use ContainsRegex instead of MatchesRegex --- unittest/commands/test_groups.cpp | 1 - unittest/commands/test_kim_commands.cpp | 1 - unittest/commands/test_lattice_region.cpp | 6 ++-- unittest/commands/test_reset_ids.cpp | 1 - unittest/commands/test_simple_commands.cpp | 32 +++++++++---------- unittest/commands/test_variables.cpp | 24 +++++++------- unittest/cplusplus/test_error_class.cpp | 10 +++--- unittest/cplusplus/test_lammps_class.cpp | 6 ++-- unittest/formats/test_file_operations.cpp | 1 - unittest/formats/test_molecule_file.cpp | 16 +++++----- .../formats/test_potential_file_reader.cpp | 1 - unittest/python/test_python_package.cpp | 4 +-- unittest/testing/core.h | 6 ++-- 13 files changed, 52 insertions(+), 57 deletions(-) diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 9d69b5412e..a356a02cca 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -34,7 +34,6 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::ExitedWithCode; -using ::testing::MatchesRegex; using ::testing::StrEq; class GroupTest : public LAMMPSTest { diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 183d333ab4..953b4e5a00 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -33,7 +33,6 @@ bool verbose = false; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { -using ::testing::MatchesRegex; using ::testing::StrEq; class KimCommandsTest : public LAMMPSTest { diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 1bbda21001..590180326c 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -36,7 +36,7 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::ExitedWithCode; -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using ::testing::StrEq; class LatticeRegionTest : public LAMMPSTest { @@ -82,7 +82,7 @@ TEST_F(LatticeRegionTest, lattice_sc) BEGIN_CAPTURE_OUTPUT(); command("lattice sc 1.0 spacing 1.5 2.0 3.0"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 1.5.* 2.* 3.*")); + ASSERT_THAT(output, ContainsRegex(".*Lattice spacing in x,y,z = 1.5.* 2.* 3.*")); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->xlattice, 1.5); @@ -92,7 +92,7 @@ TEST_F(LatticeRegionTest, lattice_sc) BEGIN_CAPTURE_OUTPUT(); command("lattice sc 2.0"); output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 2.* 2.* 2.*")); + ASSERT_THAT(output, ContainsRegex(".*Lattice spacing in x,y,z = 2.* 2.* 2.*")); lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SC); diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index c67f90b341..8ca5fe5c05 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -32,7 +32,6 @@ bool verbose = false; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { -using ::testing::MatchesRegex; #define GETIDX(i) lmp->atom->map(i) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 1844752d33..c75cbb22b9 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -40,7 +40,7 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::ExitedWithCode; -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using ::testing::StrEq; class SimpleCommandsTest : public LAMMPSTest { @@ -394,62 +394,62 @@ TEST_F(SimpleCommandsTest, Plugin) lmp->input->one(fmt::format(loadfmt, "hello")); auto text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Loading plugin: Hello world command.*")); + ASSERT_THAT(text, ContainsRegex(".*Loading plugin: Hello world command.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "xxx")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Open of file .*xxx.* failed.*")); + ASSERT_THAT(text, ContainsRegex(".*Open of file .*xxx.* failed.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "nve2")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Loading plugin: NVE2 variant fix style.*")); + ASSERT_THAT(text, ContainsRegex(".*Loading plugin: NVE2 variant fix style.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin list"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*1: command style plugin hello" + ASSERT_THAT(text, ContainsRegex(".*1: command style plugin hello" ".*2: fix style plugin nve2.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "hello")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Ignoring load of command style hello: " + ASSERT_THAT(text, ContainsRegex(".*Ignoring load of command style hello: " "must unload existing hello plugin.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin unload command hello"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Unloading command style hello.*")); + ASSERT_THAT(text, ContainsRegex(".*Unloading command style hello.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin unload pair nve2"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of pair style nve2: not from a plugin.*")); + ASSERT_THAT(text, ContainsRegex(".*Ignoring unload of pair style nve2: not from a plugin.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin unload fix nve2"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Unloading fix style nve2.*")); + ASSERT_THAT(text, ContainsRegex(".*Unloading fix style nve2.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin unload fix nve"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of fix style nve: not from a plugin.*")); + ASSERT_THAT(text, ContainsRegex(".*Ignoring unload of fix style nve: not from a plugin.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin list"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Currently loaded plugins.*")); + ASSERT_THAT(text, ContainsRegex(".*Currently loaded plugins.*")); } #endif @@ -495,8 +495,8 @@ TEST_F(SimpleCommandsTest, CiteMe) std::string text = END_CAPTURE_OUTPUT(); // find the two unique citations, but not the third - ASSERT_THAT(text, MatchesRegex(".*one.*two.*")); - ASSERT_THAT(text, Not(MatchesRegex(".*one.*two.*one.*"))); + ASSERT_THAT(text, ContainsRegex(".*one.*two.*")); + ASSERT_THAT(text, Not(ContainsRegex(".*one.*two.*one.*"))); BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 0\n"); @@ -507,8 +507,8 @@ TEST_F(SimpleCommandsTest, CiteMe) text = END_CAPTURE_OUTPUT(); // find the forth (only differs in long citation) and sixth added citation - ASSERT_THAT(text, MatchesRegex(".*one.*three.*")); - ASSERT_THAT(text, Not(MatchesRegex(".*two.*"))); + ASSERT_THAT(text, ContainsRegex(".*one.*three.*")); + ASSERT_THAT(text, Not(ContainsRegex(".*two.*"))); BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 1\n"); @@ -521,7 +521,7 @@ TEST_F(SimpleCommandsTest, CiteMe) text = END_CAPTURE_OUTPUT(); // no new citation. no CITE-CITE-CITE- lines - ASSERT_THAT(text, Not(MatchesRegex(".*CITE-CITE-CITE-CITE.*"))); + ASSERT_THAT(text, Not(ContainsRegex(".*CITE-CITE-CITE-CITE.*"))); } } // namespace LAMMPS_NS diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index fb0aa58069..af52df8e28 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -37,7 +37,7 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::ExitedWithCode; -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using ::testing::StrEq; class VariableTest : public LAMMPSTest { @@ -394,58 +394,58 @@ TEST_F(VariableTest, IfCommand) BEGIN_CAPTURE_OUTPUT(); command("if 1>0 then 'print \"bingo!\"'"); auto text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); + ASSERT_THAT(text, ContainsRegex(".*nope\?.*")); BEGIN_CAPTURE_OUTPUT(); command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); + ASSERT_THAT(text, ContainsRegex(".*nope\?.*")); BEGIN_CAPTURE_OUTPUT(); command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if !(a==b) then 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if x==x|^1==0 then 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); BEGIN_CAPTURE_OUTPUT(); command("if x!=x|^a!=b then 'print \"bingo!\"'"); text = END_CAPTURE_OUTPUT(); - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, ContainsRegex(".*bingo!.*")); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", command("if () then 'print \"bingo!\"'");); diff --git a/unittest/cplusplus/test_error_class.cpp b/unittest/cplusplus/test_error_class.cpp index f4f0d3b28b..27318646be 100644 --- a/unittest/cplusplus/test_error_class.cpp +++ b/unittest/cplusplus/test_error_class.cpp @@ -17,7 +17,7 @@ bool verbose = false; namespace LAMMPS_NS { -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using utils::split_words; class Error_class : public LAMMPSTest { @@ -39,7 +39,7 @@ TEST_F(Error_class, message) auto output = CAPTURE_OUTPUT([&] { error->message(FLERR, "one message"); }); - ASSERT_THAT(output, MatchesRegex("one message .*test_error_class.cpp:.*")); + ASSERT_THAT(output, ContainsRegex("one message .*test_error_class.cpp:.*")); }; TEST_F(Error_class, warning) @@ -48,7 +48,7 @@ TEST_F(Error_class, warning) auto output = CAPTURE_OUTPUT([&] { error->warning(FLERR, "one warning"); }); - ASSERT_THAT(output, MatchesRegex("WARNING: one warning .*test_error_class.cpp:.*")); + ASSERT_THAT(output, ContainsRegex("WARNING: one warning .*test_error_class.cpp:.*")); ASSERT_THAT(error->get_maxwarn(), 100); // warnings disabled @@ -72,7 +72,7 @@ TEST_F(Error_class, warning) output = CAPTURE_OUTPUT([&] { thermo->lost_check(); }); - ASSERT_THAT(output, MatchesRegex("WARNING: Too many warnings: 5 vs 2. All future.*")); + ASSERT_THAT(output, ContainsRegex("WARNING: Too many warnings: 5 vs 2. All future.*")); output = CAPTURE_OUTPUT([&] { error->warning(FLERR, "one warning"); @@ -91,7 +91,7 @@ TEST_F(Error_class, warning) output = CAPTURE_OUTPUT([&] { error->warning(FLERR, "one warning"); }); - ASSERT_THAT(output, MatchesRegex("WARNING: one warning.*")); + ASSERT_THAT(output, ContainsRegex("WARNING: one warning.*")); BEGIN_HIDE_OUTPUT(); command("thermo_modify warn default"); diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index eb6735a738..6bbeb385e9 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -11,7 +11,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using ::testing::StartsWith; namespace LAMMPS_NS { @@ -339,7 +339,7 @@ TEST(LAMMPS_init, OpenMP) ::testing::internal::CaptureStdout(); LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(output, MatchesRegex(".*using 2 OpenMP thread.*per MPI task.*")); + EXPECT_THAT(output, ContainsRegex(".*using 2 OpenMP thread.*per MPI task.*")); if (LAMMPS_NS::Info::has_accelerator_feature("OPENMP", "api", "openmp")) EXPECT_EQ(lmp->comm->nthreads, 2); @@ -373,7 +373,7 @@ TEST(LAMMPS_init, NoOpenMP) LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, - MatchesRegex(".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); + ContainsRegex(".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); EXPECT_EQ(lmp->comm->nthreads, 1); ::testing::internal::CaptureStdout(); delete lmp; diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index bb26dff391..08c1c2fd9a 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -29,7 +29,6 @@ using namespace LAMMPS_NS; -using testing::MatchesRegex; using testing::StrEq; using utils::read_lines_from_file; diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index e802ebfa2c..b67ed746b9 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -26,7 +26,7 @@ using namespace LAMMPS_NS; -using testing::MatchesRegex; +using testing::ContainsRegex; using testing::StrEq; using utils::split_words; @@ -173,7 +173,7 @@ TEST_F(MoleculeFileTest, minimal) BEGIN_CAPTURE_OUTPUT(); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); } TEST_F(MoleculeFileTest, notype) @@ -184,7 +184,7 @@ TEST_F(MoleculeFileTest, notype) command("create_box 1 box"); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); } @@ -199,7 +199,7 @@ TEST_F(MoleculeFileTest, extramass) " Types\n\n 1 1\n Masses\n\n 1 1.0\n"); command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*WARNING: Molecule attributes do not match " + ASSERT_THAT(output, ContainsRegex(".*WARNING: Molecule attributes do not match " "system attributes.*")); } @@ -211,7 +211,7 @@ TEST_F(MoleculeFileTest, twomols) " Coords\n\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n" " Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*2 molecules.*2 atoms " + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*2 molecules.*2 atoms " "with max type 2.*0 bonds.*")); } @@ -220,7 +220,7 @@ TEST_F(MoleculeFileTest, twofiles) BEGIN_CAPTURE_OUTPUT(); command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " + ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " "with max type 2.*2 bonds with max type 1.*" "1 angles with max type 1.*0 dihedrals.*" ".*Read molecule template twomols:.*1 molecules.*3 atoms " @@ -254,14 +254,14 @@ TEST_F(MoleculeFileTest, bonds) " 1 1 1 2\n" " 2 2 1 3\n\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*" + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*" "2 bonds.*type.*2.*0 angles.*")); BEGIN_CAPTURE_OUTPUT(); command("mass * 2.0"); command("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235"); output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, MatchesRegex(".*Created 4 atoms.*")); + ASSERT_THAT(output, ContainsRegex(".*Created 4 atoms.*")); BEGIN_HIDE_OUTPUT(); Molecule *mol = lmp->atom->molecules[0]; diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 7cd61d25a4..f9dee16c14 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -37,7 +37,6 @@ #include using namespace LAMMPS_NS; -using ::testing::MatchesRegex; using utils::split_words; // whether to print verbose output (i.e. not capturing LAMMPS screen output). diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index e04be89df1..07b9a29f28 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -45,7 +45,7 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::Eq; using ::testing::HasSubstr; -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; using ::testing::StrEq; class PythonPackageTest : public LAMMPSTest { @@ -238,7 +238,7 @@ TEST_F(PythonPackageTest, python_variable) std::string output = CAPTURE_OUTPUT([&] { command("print \"${sq}\""); }); - ASSERT_THAT(output, MatchesRegex("print.*2.25.*")); + ASSERT_THAT(output, ContainsRegex("print.*2.25.*")); } TEST_F(PythonPackageTest, InlineFunction) diff --git a/unittest/testing/core.h b/unittest/testing/core.h index c922e96cc0..81a7112934 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -28,20 +28,20 @@ using namespace LAMMPS_NS; -using ::testing::MatchesRegex; +using ::testing::ContainsRegex; #define TEST_FAILURE(errmsg, ...) \ if (Info::has_exceptions()) { \ ::testing::internal::CaptureStdout(); \ ASSERT_ANY_THROW({__VA_ARGS__}); \ auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ + ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ } else { \ if (platform::mpi_vendor() != "Open MPI") { \ ::testing::internal::CaptureStdout(); \ ASSERT_DEATH({__VA_ARGS__}, ""); \ auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ + ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ } else { \ std::cerr << "[ ] [ INFO ] Skipping death test (no exception support) \n"; \ } \ From bd4814a51e627170369d2ba874282ee8a3920e39 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 16:37:40 -0500 Subject: [PATCH 15/48] don't cache OUTPUT_DIRECTORY variable settings but set them every time --- cmake/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2bfe3ce245..256b663fd6 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -20,8 +20,8 @@ set(SOVERSION 0) get_filename_component(LAMMPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE) get_filename_component(LAMMPS_LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/lib ABSOLUTE) # collect all executables and shared libs in the top level build folder -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} CACHE PATH "Folder for executables, DLLs and shared objects" FORCE) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} CACHE PATH "Folder for libraries" FORCE) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(LAMMPS_SOURCE_DIR ${LAMMPS_DIR}/src) set(LAMMPS_LIB_SOURCE_DIR ${LAMMPS_DIR}/lib) From 75d0a5098f1e9892b7a5a0d6d0ca97b14ae78940 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 17:06:30 -0500 Subject: [PATCH 16/48] use -Og for Debug config for better warnings and debug experience --- cmake/presets/gcc.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/presets/gcc.cmake b/cmake/presets/gcc.cmake index c2dbacf674..cb626ea019 100644 --- a/cmake/presets/gcc.cmake +++ b/cmake/presets/gcc.cmake @@ -3,19 +3,19 @@ set(CMAKE_CXX_COMPILER "g++" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "gcc" CACHE STRING "" FORCE) set(CMAKE_Fortran_COMPILER "gfortran" CACHE STRING "" FORCE) -set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Og -g" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) set(MPI_CXX "g++" CACHE STRING "" FORCE) set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) set(MPI_C "gcc" CACHE STRING "" FORCE) set(MPI_C_COMPILER "mpicc" CACHE STRING "" FORCE) -set(CMAKE_C_FLAGS_DEBUG "-Wall -g" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_DEBUG "-Wall -Og -g" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) set(MPI_Fortran "gfortran" CACHE STRING "" FORCE) set(MPI_Fortran_COMPILER "mpifort" CACHE STRING "" FORCE) -set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -g -std=f2003" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Og -g -std=f2003" CACHE STRING "" FORCE) set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG -std=f2003" CACHE STRING "" FORCE) set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG -std=f2003" CACHE STRING "" FORCE) unset(HAVE_OMP_H_INCLUDE CACHE) From c9de8fca1d40ed45e60fda8578dee37d1028285f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 17:07:00 -0500 Subject: [PATCH 17/48] silence compiler warnings --- tools/msi2lmp/src/GetParameters.c | 4 ++-- unittest/formats/test_file_operations.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/msi2lmp/src/GetParameters.c b/tools/msi2lmp/src/GetParameters.c index 192b4d296c..921e37491f 100644 --- a/tools/msi2lmp/src/GetParameters.c +++ b/tools/msi2lmp/src/GetParameters.c @@ -9,14 +9,14 @@ static int find_improper_body_data(char [][5],struct FrcFieldItem,int *); static void rearrange_improper(int,int); static int find_trigonal_body_data(char [][5],struct FrcFieldItem); -static int find_angleangle_data(char [][5],struct FrcFieldItem,int[]); +static int find_angleangle_data(char [][5],struct FrcFieldItem,int[3]); static int find_match(int, char [][5],struct FrcFieldItem,int *); static int match_types(int,int,char [][5],char [][5],int *); static double get_r0(int,int); static double get_t0(int,int,int); static int quo_cp(); static void get_equivs(int,char [][5],char[][5]); -static int find_equiv_type(char[]); +static int find_equiv_type(char[5]); /**********************************************************************/ /* */ diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index 08c1c2fd9a..3ca889b76e 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -334,7 +334,7 @@ TEST_F(FileOperationsTest, write_restart) ASSERT_FILE_EXISTS("multi2-0.restart"); ASSERT_FILE_EXISTS("multi3-base.restart"); ASSERT_FILE_EXISTS("multi3-0.restart"); - if (info->has_package("MPIIO")) ASSERT_FILE_EXISTS("test.restart.mpiio"); + if (info->has_package("MPIIO")) { ASSERT_FILE_EXISTS("test.restart.mpiio"); } if (!info->has_package("MPIIO")) { TEST_FAILURE(".*ERROR: Writing to MPI-IO filename when MPIIO package is not inst.*", From 7b3adb3f1ab3e6977741d40bee5ebf449bc6f47c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 17:09:40 -0500 Subject: [PATCH 18/48] must always initialize jtag --- src/compute_pair_local.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_pair_local.cpp b/src/compute_pair_local.cpp index b98f6eec33..3dc37707c6 100644 --- a/src/compute_pair_local.cpp +++ b/src/compute_pair_local.cpp @@ -226,13 +226,13 @@ int ComputePairLocal::compute_pairs(int flag) factor_lj = special_lj[sbmask(j)]; factor_coul = special_coul[sbmask(j)]; j &= NEIGHMASK; + jtag = tag[j]; if (!(mask[j] & groupbit)) continue; // itag = jtag is possible for long cutoffs that include images of self if (newton_pair == 0 && j >= nlocal) { - jtag = tag[j]; if (itag > jtag) { if ((itag+jtag) % 2 == 0) continue; } else if (itag < jtag) { From c464c40d678371eb44fda60319f8fb54e89c0303 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 18:12:15 -0500 Subject: [PATCH 19/48] avoid accessing uninitialized data and triggering bogus memcheck output --- unittest/formats/test_dump_cfg.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index a180c6b342..c2ab96c5ed 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -81,6 +81,7 @@ TEST_F(DumpCfgTest, write_dump) auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; BEGIN_HIDE_OUTPUT(); + command("run 0 post no"); command(std::string("write_dump all cfg dump_cfg.melt.cfg ") + fields); command(std::string("write_dump all cfg dump_cfg*.melt.cfg ") + fields); END_HIDE_OUTPUT(); From 9323a09b39409387e2141c2ffd845a553817c8b1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 18:12:53 -0500 Subject: [PATCH 20/48] reduce number of reported memory leaks with google test death tests --- src/write_dump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/write_dump.cpp b/src/write_dump.cpp index 53ab80149a..19826eba1b 100644 --- a/src/write_dump.cpp +++ b/src/write_dump.cpp @@ -68,6 +68,7 @@ void WriteDump::command(int narg, char **arg) #undef DUMP_CLASS } else error->all(FLERR,utils::check_packages_for_style("dump",arg[1],lmp)); + delete[] dumpargs; if (modindex < narg) dump->modify_params(narg-modindex-1,&arg[modindex+1]); @@ -89,5 +90,4 @@ void WriteDump::command(int narg, char **arg) // delete the Dump instance and local storage delete dump; - delete [] dumpargs; } From cd5d1f8a30fa7d13c4cd60d4367aa9fd4d77c4f9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 18:13:01 -0500 Subject: [PATCH 21/48] reformat --- src/dump_cfg.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index 8e87f4104e..d52dac745f 100644 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -167,16 +167,13 @@ int DumpCFG::convert_string(int n, double *mybuf) offset += sprintf(&sbuf[offset],"%s \n",typenames[(int) mybuf[m]]); } else if (j >= 2) { if (vtype[j] == Dump::INT) - offset += - sprintf(&sbuf[offset],vformat[j],static_cast (mybuf[m])); + offset += sprintf(&sbuf[offset],vformat[j],static_cast (mybuf[m])); else if (vtype[j] == Dump::DOUBLE) offset += sprintf(&sbuf[offset],vformat[j],mybuf[m]); else if (vtype[j] == Dump::STRING) - offset += - sprintf(&sbuf[offset],vformat[j],typenames[(int) mybuf[m]]); + offset += sprintf(&sbuf[offset],vformat[j],typenames[(int) mybuf[m]]); else if (vtype[j] == Dump::BIGINT) - offset += - sprintf(&sbuf[offset],vformat[j],static_cast (mybuf[m])); + offset += sprintf(&sbuf[offset],vformat[j],static_cast (mybuf[m])); } m++; } From c420f804d96e78a5d92db7ad56e33e8f2bf4f49c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 18:52:49 -0500 Subject: [PATCH 22/48] make multi-line regex checks compatible with googletests Windows regex syntax --- unittest/formats/test_molecule_file.cpp | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index b67ed746b9..0fe66e22c5 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -173,7 +173,8 @@ TEST_F(MoleculeFileTest, minimal) BEGIN_CAPTURE_OUTPUT(); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" + ".*1 atoms.*\n.*0 bonds.*")); } TEST_F(MoleculeFileTest, notype) @@ -184,7 +185,8 @@ TEST_F(MoleculeFileTest, notype) command("create_box 1 box"); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" + ".*1 atoms.*\n.*0 bonds.*")); TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); } @@ -211,8 +213,8 @@ TEST_F(MoleculeFileTest, twomols) " Coords\n\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n" " Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*2 molecules.*2 atoms " - "with max type 2.*0 bonds.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*2 molecules.*\n" + ".*2 atoms with max type 2.*\n.*0 bonds.*")); } TEST_F(MoleculeFileTest, twofiles) @@ -220,12 +222,12 @@ TEST_F(MoleculeFileTest, twofiles) BEGIN_CAPTURE_OUTPUT(); command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " - "with max type 2.*2 bonds with max type 1.*" - "1 angles with max type 1.*0 dihedrals.*" - ".*Read molecule template twomols:.*1 molecules.*3 atoms " - "with max type 4.*2 bonds with max type 2.*" - "1 angles with max type 2.*0 dihedrals.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*\n.*1 molecules.*\n" + ".*3 atoms with max type 2.*\n.*2 bonds with max type 1.*\n" + ".*1 angles with max type 1.*\n.*0 dihedrals.*\n" + ".*Read molecule template twomols:.*\n.*1 molecules.*\n" + ".*3 atoms with max type 4.*\n.*2 bonds with max type 2.*\n" + ".*1 angles with max type 2.*\n.*0 dihedrals.*")); } TEST_F(MoleculeFileTest, bonds) @@ -254,8 +256,9 @@ TEST_F(MoleculeFileTest, bonds) " 1 1 1 2\n" " 2 2 1 3\n\n"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*" - "2 bonds.*type.*2.*0 angles.*")); + ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" + ".*4 atoms.*type.*2.*\n" + ".*2 bonds.*type.*2.*\n.*0 angles.*")); BEGIN_CAPTURE_OUTPUT(); command("mass * 2.0"); From 9014664c1312ba7dad7e86946a34fa3cee426624 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 19:07:35 -0500 Subject: [PATCH 23/48] really fix unit test regexes for windows --- unittest/formats/test_molecule_file.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 0fe66e22c5..6f24c0f758 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -174,7 +174,7 @@ TEST_F(MoleculeFileTest, minimal) run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" - ".*1 atoms.*\n.*0 bonds.*")); + ".*0 fragments.*\n.*1 atoms.*\n.*0 bonds.*")); } TEST_F(MoleculeFileTest, notype) @@ -186,7 +186,7 @@ TEST_F(MoleculeFileTest, notype) run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" - ".*1 atoms.*\n.*0 bonds.*")); + ".*0 fragments.*\n.*1 atoms.*\n.*0 bonds.*")); TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); } @@ -214,7 +214,7 @@ TEST_F(MoleculeFileTest, twomols) " Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*2 molecules.*\n" - ".*2 atoms with max type 2.*\n.*0 bonds.*")); + ".*0 fragments.*\n.*2 atoms with max type 2.*\n.*0 bonds.*")); } TEST_F(MoleculeFileTest, twofiles) @@ -223,10 +223,10 @@ TEST_F(MoleculeFileTest, twofiles) command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*\n.*1 molecules.*\n" - ".*3 atoms with max type 2.*\n.*2 bonds with max type 1.*\n" - ".*1 angles with max type 1.*\n.*0 dihedrals.*\n" + ".*0 fragments.*\n.*3 atoms with max type 2.*\n.*2 bonds with max type 1.*\n" + ".*1 angles with max type 1.*\n.*0 dihedrals.*\n.*0 impropers.*\n" ".*Read molecule template twomols:.*\n.*1 molecules.*\n" - ".*3 atoms with max type 4.*\n.*2 bonds with max type 2.*\n" + ".*0 fragments.*\n.*3 atoms with max type 4.*\n.*2 bonds with max type 2.*\n" ".*1 angles with max type 2.*\n.*0 dihedrals.*")); } @@ -257,7 +257,7 @@ TEST_F(MoleculeFileTest, bonds) " 2 2 1 3\n\n"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*Read molecule template.*\n.*1 molecules.*\n" - ".*4 atoms.*type.*2.*\n" + ".*0 fragments.*\n.*4 atoms.*type.*2.*\n" ".*2 bonds.*type.*2.*\n.*0 angles.*")); BEGIN_CAPTURE_OUTPUT(); From 0bfc5269ddc2f14f6132581f3f0955778d161417 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 20:52:25 -0500 Subject: [PATCH 24/48] fix mismatches causing failures on windows --- unittest/formats/test_potential_file_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index f9dee16c14..db235722a4 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -282,7 +282,7 @@ TEST_F(OpenPotentialTest, Sw_conv) { int convert_flag = utils::get_supported_conversions(utils::ENERGY); ASSERT_EQ(convert_flag, utils::METAL2REAL | utils::REAL2METAL); - BEGIN_HIDE_OUTPUT(); + BEGIN_CAPTURE_OUTPUT(); command("units real"); FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag); auto text = END_CAPTURE_OUTPUT(); @@ -300,7 +300,7 @@ TEST_F(OpenPotentialTest, Sw_noconv) BEGIN_HIDE_OUTPUT(); command("units real"); END_HIDE_OUTPUT(); - TEST_FAILURE(".*potential.*requires metal units but real.*", + TEST_FAILURE(".*Potential.*requires metal units but real.*", utils::open_potential("Si.sw", lmp, nullptr);); BEGIN_HIDE_OUTPUT(); command("units lj"); From 6c98915a9c024791e57e1ebd22c8a5fc80bcd9fd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 20:52:37 -0500 Subject: [PATCH 25/48] port to windows --- unittest/commands/test_simple_commands.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index c75cbb22b9..862c3a8c4a 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -478,7 +478,12 @@ TEST_F(SimpleCommandsTest, Shell) test_var = getenv("TEST_VARIABLE"); ASSERT_NE(test_var, nullptr); +#if defined(_WIN32) + // we cannot create empty environment variables on Windows so platform::putenv() sets their value to "1" + ASSERT_THAT(test_var, StrEq("1")); +#else ASSERT_THAT(test_var, StrEq("")); +#endif } TEST_F(SimpleCommandsTest, CiteMe) @@ -495,8 +500,8 @@ TEST_F(SimpleCommandsTest, CiteMe) std::string text = END_CAPTURE_OUTPUT(); // find the two unique citations, but not the third - ASSERT_THAT(text, ContainsRegex(".*one.*two.*")); - ASSERT_THAT(text, Not(ContainsRegex(".*one.*two.*one.*"))); + ASSERT_THAT(text, ContainsRegex("test citation one.\n.*test citation two.*")); + ASSERT_THAT(text, Not(ContainsRegex("test citation one.\n.*test citation two.*\n.*test citation one.*"))); BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 0\n"); @@ -507,8 +512,8 @@ TEST_F(SimpleCommandsTest, CiteMe) text = END_CAPTURE_OUTPUT(); // find the forth (only differs in long citation) and sixth added citation - ASSERT_THAT(text, ContainsRegex(".*one.*three.*")); - ASSERT_THAT(text, Not(ContainsRegex(".*two.*"))); + ASSERT_THAT(text, ContainsRegex("test citation one.*\n.*test citation three.*")); + ASSERT_THAT(text, Not(ContainsRegex("test_citation two.*\n"))); BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 1\n"); From 02cadf1b712821892e8eea8e88c86f41b8808c7e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 20:53:17 -0500 Subject: [PATCH 26/48] port to windows where text file reading may gobble up carriage returns --- src/MANYBODY/pair_eam_cd.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MANYBODY/pair_eam_cd.cpp b/src/MANYBODY/pair_eam_cd.cpp index dc1ec360c6..376469e238 100644 --- a/src/MANYBODY/pair_eam_cd.cpp +++ b/src/MANYBODY/pair_eam_cd.cpp @@ -505,8 +505,10 @@ void PairEAMCD::read_h_coeff(char *filename) utils::getsyserror()); char *buf = new char[MAXLINE+1]; - utils::sfread(FLERR, buf, 1, MAXLINE, fptr, filename, error); - buf[MAXLINE] = '\0'; // must 0-terminate buffer for string processing + auto rv = fread(buf,1,MAXLINE,fptr); + if (rv == 0) error->one(FLERR,"Failure to read h(x) coeffs: {}", utils::getsyserror()); + buf[rv] = '\0'; // must 0-terminate buffer for string processing + Tokenizer lines(buf, "\n"); delete[] buf; From 571821694e9b747ef23044bb9f442490376fc1ef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 21:01:35 -0500 Subject: [PATCH 27/48] remove links broken on windows --- unittest/commands/data.fourmol | 1 - unittest/commands/in.fourmol | 1 - 2 files changed, 2 deletions(-) delete mode 120000 unittest/commands/data.fourmol delete mode 120000 unittest/commands/in.fourmol diff --git a/unittest/commands/data.fourmol b/unittest/commands/data.fourmol deleted file mode 120000 index ebbe325d24..0000000000 --- a/unittest/commands/data.fourmol +++ /dev/null @@ -1 +0,0 @@ -../force-styles/tests/data.fourmol \ No newline at end of file diff --git a/unittest/commands/in.fourmol b/unittest/commands/in.fourmol deleted file mode 120000 index cc47b5adb9..0000000000 --- a/unittest/commands/in.fourmol +++ /dev/null @@ -1 +0,0 @@ -../force-styles/tests/in.fourmol \ No newline at end of file From cc0d91b2227eee68a635539d2cebddff86426bfa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 21:01:49 -0500 Subject: [PATCH 28/48] re-add copies of linked files --- unittest/commands/data.fourmol | 223 +++++++++++++++++++++++++++++++++ unittest/commands/in.fourmol | 30 +++++ 2 files changed, 253 insertions(+) create mode 100644 unittest/commands/data.fourmol create mode 100644 unittest/commands/in.fourmol diff --git a/unittest/commands/data.fourmol b/unittest/commands/data.fourmol new file mode 100644 index 0000000000..70dc685895 --- /dev/null +++ b/unittest/commands/data.fourmol @@ -0,0 +1,223 @@ +LAMMPS data file via write_data, version 5 May 2020, timestep = 0 + +29 atoms +5 atom types +24 bonds +5 bond types +30 angles +4 angle types +31 dihedrals +5 dihedral types +2 impropers +2 improper types + + -6.024572 8.975428 xlo xhi + -7.692866 7.307134 ylo yhi + -8.086924 6.913076 zlo zhi + +Masses + +1 12.0107 +2 4.00794 +3 14.0067 +4 15.9994 +5 15.9994 + +Pair Coeffs # zero + +1 +2 +3 +4 +5 + +Bond Coeffs # zero + +1 1.5 +2 1.1 +3 1.3 +4 1.2 +5 1 + +Angle Coeffs # zero + +1 110.1 +2 111 +3 120 +4 108.5 + +Dihedral Coeffs # zero + +1 +2 +3 +4 +5 + +Improper Coeffs # zero + +1 +2 + +Atoms # full + +10 2 1 7.0000000000000007e-02 2.0185283555536988e+00 -1.4283966846517357e+00 -9.6733527271133024e-01 0 0 0 +11 2 2 8.9999999999999997e-02 1.7929780509347666e+00 -1.9871047540768743e+00 -1.8840626643185674e+00 0 0 0 +12 2 1 -2.7000000000000002e-01 3.0030247876861225e+00 -4.8923319967572748e-01 -1.6188658531537248e+00 0 0 0 +13 2 2 8.9999999999999997e-02 4.0447273787895934e+00 -9.0131998547446246e-01 -1.6384447268320836e+00 0 0 0 +14 2 2 8.9999999999999997e-02 2.6033152817257075e+00 -4.0789761505963579e-01 -2.6554413538823063e+00 0 0 0 + 2 1 2 3.1000000000000000e-01 3.0197083955402204e-01 2.9515239068888608e+00 -8.5689735572907566e-01 0 0 0 + 3 1 1 -2.0000000000000000e-02 -6.9435377880558602e-01 1.2440473127136711e+00 -6.2233801468892025e-01 0 0 0 + 4 1 2 8.9999999999999997e-02 -1.5771614164685133e+00 1.4915333140468066e+00 -1.2487126845040522e+00 0 0 0 + 6 1 1 5.1000000000000001e-01 2.9412607937706009e-01 2.2719282656652909e-01 -1.2843094067857870e+00 0 0 0 + 7 1 4 -5.1000000000000001e-01 3.4019871062879609e-01 -9.1277350075786561e-03 -2.4633113224304561e+00 0 0 0 +19 3 2 4.2359999999999998e-01 1.5349125211132961e+00 2.6315969880333707e+00 -4.2472859440220647e+00 0 0 0 +15 2 2 8.9999999999999997e-02 2.9756315249791303e+00 5.6334269722969288e-01 -1.2437650754599008e+00 0 0 0 +18 3 4 -8.4719999999999995e-01 2.1384791188033843e+00 3.0177261773770208e+00 -3.5160827596876225e+00 0 0 0 +20 3 2 4.2359999999999998e-01 2.7641167828863153e+00 3.6833419064000221e+00 -3.9380850623312638e+00 0 0 0 + 8 2 3 -4.6999999999999997e-01 1.1641187171852805e+00 -4.8375305955385234e-01 -6.7659823767368688e-01 0 0 0 + 9 2 2 3.1000000000000000e-01 1.3777459838125838e+00 -2.5366338669522998e-01 2.6877644730326306e-01 0 0 0 +16 2 1 5.1000000000000001e-01 2.6517554244980306e+00 -2.3957110424978438e+00 3.2908335999178327e-02 0 0 0 +17 2 4 -5.1000000000000001e-01 2.2309964792710639e+00 -2.1022918943319384e+00 1.1491948328949437e+00 0 0 0 + 1 1 3 -4.6999999999999997e-01 -2.7993683669226832e-01 2.4726588069312840e+00 -1.7200860244148433e-01 0 0 0 + 5 1 2 8.9999999999999997e-02 -8.9501761359359255e-01 9.3568128743071344e-01 4.0227731871484346e-01 0 0 0 +21 4 5 -8.4719999999999995e-01 4.9064454390208301e+00 -4.0751205255383196e+00 -3.6215576073601046e+00 0 0 0 +22 4 2 4.2359999999999998e-01 4.3687453488627543e+00 -4.2054270536772504e+00 -4.4651491269372565e+00 0 0 0 +23 4 2 4.2359999999999998e-01 5.7374928154769504e+00 -3.5763355905184966e+00 -3.8820297194230728e+00 0 0 0 +24 5 5 -8.4719999999999995e-01 2.0684115301174013e+00 3.1518221747664397e+00 3.1554242678474576e+00 0 0 0 +25 5 2 4.2359999999999998e-01 1.2998381073113014e+00 3.2755513587518097e+00 2.5092990173114837e+00 0 0 0 +26 5 2 4.2359999999999998e-01 2.5807438597688113e+00 4.0120175892854135e+00 3.2133398379059099e+00 0 0 0 +27 6 5 -8.4719999999999995e-01 -1.9613581876744359e+00 -4.3556300596085160e+00 2.1101467673534788e+00 0 0 0 +28 6 2 4.2359999999999998e-01 -2.7406520384725965e+00 -4.0207251278130975e+00 1.5828689861678511e+00 0 0 0 +29 6 2 4.2359999999999998e-01 -1.3108232656499081e+00 -3.5992986322410760e+00 2.2680459788743503e+00 0 0 0 + +Velocities + +1 7.7867804888392077e-04 5.8970331623292821e-04 -2.2179517633030531e-04 +2 2.7129529964126462e-03 4.6286427111164284e-03 3.5805549693846352e-03 +3 -1.2736791029204805e-03 1.6108674226414498e-03 -3.3618185901550799e-04 +4 -9.2828595122009308e-04 -1.2537885319521818e-03 -4.1204974953432108e-03 +5 -1.1800848061603740e-03 7.5424401975844038e-04 6.9023177964912290e-05 +6 -3.0914004879905335e-04 1.2755385764678133e-03 7.9574303350202582e-04 +7 -1.1037894966874103e-04 -7.6764845099077425e-04 -7.7217630460203659e-04 +8 3.9060281273221989e-04 -8.1444231918053418e-04 1.5134641148324972e-04 +9 1.2475530960659720e-03 -2.6608454451432528e-03 1.1117602907112732e-03 +10 4.5008983776042893e-04 4.9530197647538077e-04 -2.3336234361093645e-04 +11 -3.6977669078869707e-04 -1.5289071951960539e-03 -2.9176389881837113e-03 +12 1.0850834530183159e-03 -6.4965897903201833e-04 -1.2971152622619948e-03 +13 4.0754559196230639e-03 3.5043502394946119e-03 -7.8324487687854666e-04 +14 -1.3837220448746613e-04 -4.0656048637594394e-03 -3.9333461173944500e-03 +15 -4.3301707382721859e-03 -3.1802661664634938e-03 3.2037919043360571e-03 +16 -9.6715751018414326e-05 -5.0016572678960377e-04 1.4945658875149626e-03 +17 6.5692180538157174e-04 3.6635779995305095e-04 8.3495414466050911e-04 +18 -6.0936815808025862e-04 -9.3774557532468582e-04 -3.3558072507805731e-04 +19 -6.9919768291957119e-04 -3.6060777270430031e-03 4.2833405289822791e-03 +20 4.7777805013736515e-03 5.1003745845520452e-03 1.8002873923729241e-03 +21 -9.5568188553430398e-04 1.6594630943762931e-04 -1.8199788009966615e-04 +22 -3.3137518957653462e-03 -2.8683968287936054e-03 3.6384389958326871e-03 +23 2.4209481134686401e-04 -4.5457709985051130e-03 2.7663581642115042e-03 +24 2.5447450568861086e-04 4.8412447786110117e-04 -4.8021914527341357e-04 +25 4.3722771097312743e-03 -4.5184411669545515e-03 2.5200952006556795e-03 +26 -1.9250110555001179e-03 -3.0342169883610837e-03 3.5062814567984532e-03 +27 -2.6510179146429716e-04 3.6306203629019116e-04 -5.6235585400647747e-04 +28 -2.3068708109787484e-04 -8.5663070212203200e-04 2.1302563179109169e-03 +29 -2.5054744388303732e-03 -1.6773997805290820e-04 2.8436699761004796e-03 + +Bonds + +1 5 1 2 +2 3 1 3 +3 2 3 4 +4 2 3 5 +5 1 3 6 +6 3 6 8 +7 4 6 7 +8 5 8 9 +9 3 8 10 +10 2 10 11 +11 1 10 12 +12 1 10 16 +13 2 12 13 +14 2 12 14 +15 2 12 15 +16 4 16 17 +17 5 18 19 +18 5 18 20 +19 5 21 22 +20 5 21 23 +21 5 24 25 +22 5 24 26 +23 5 27 28 +24 5 27 29 + +Angles + +1 4 2 1 3 +2 4 1 3 5 +3 4 1 3 4 +4 4 1 3 6 +5 4 4 3 5 +6 2 5 3 6 +7 2 4 3 6 +8 3 3 6 7 +9 3 3 6 8 +10 3 7 6 8 +11 2 6 8 9 +12 2 9 8 10 +13 3 6 8 10 +14 2 8 10 11 +15 3 8 10 16 +16 2 11 10 12 +17 1 12 10 16 +18 1 8 10 12 +19 2 11 10 16 +20 2 10 12 15 +21 2 10 12 14 +22 2 10 12 13 +23 4 13 12 15 +24 4 13 12 14 +25 4 14 12 15 +26 4 10 16 17 +27 1 19 18 20 +28 1 22 21 23 +29 1 25 24 26 +30 1 28 27 29 + +Dihedrals + +1 2 2 1 3 6 +2 2 2 1 3 4 +3 3 2 1 3 5 +4 1 1 3 6 8 +5 1 1 3 6 7 +6 5 4 3 6 8 +7 5 4 3 6 7 +8 5 5 3 6 8 +9 5 5 3 6 7 +10 4 3 6 8 9 +11 3 3 6 8 10 +12 3 7 6 8 9 +13 4 7 6 8 10 +14 2 6 8 10 12 +15 2 6 8 10 16 +16 2 6 8 10 11 +17 2 9 8 10 12 +18 4 9 8 10 16 +19 5 9 8 10 11 +20 5 8 10 12 13 +21 1 8 10 12 14 +22 5 8 10 12 15 +23 4 8 10 16 17 +24 5 11 10 12 13 +25 5 11 10 12 14 +26 5 11 10 12 15 +27 2 11 10 16 17 +28 2 12 10 16 17 +29 5 16 10 12 13 +30 5 16 10 12 14 +31 5 16 10 12 15 + +Impropers + +1 1 6 3 8 7 +2 2 8 6 10 9 diff --git a/unittest/commands/in.fourmol b/unittest/commands/in.fourmol new file mode 100644 index 0000000000..df936da78e --- /dev/null +++ b/unittest/commands/in.fourmol @@ -0,0 +1,30 @@ +variable newton_pair index on +variable newton_bond index on +variable bond_factor index 0.10 +variable angle_factor index 0.25 +variable dihedral_factor index 0.50 +variable units index real +variable input_dir index . +variable data_file index ${input_dir}/data.fourmol +variable pair_style index 'zero 8.0' +variable bond_style index zero +variable angle_style index zero +variable dihedral_style index zero +variable improper_style index zero +variable t_target index 100.0 + +atom_style full +atom_modify map array +neigh_modify delay 2 every 2 check no +units ${units} +timestep 0.1 +newton ${newton_pair} ${newton_bond} +special_bonds lj/coul ${bond_factor} ${angle_factor} ${dihedral_factor} + +pair_style ${pair_style} +bond_style ${bond_style} +angle_style ${angle_style} +dihedral_style ${dihedral_style} +improper_style ${improper_style} + +read_data ${data_file} From 33be5ff0b461509b542393bad975a45f967382e2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 21:04:59 -0500 Subject: [PATCH 29/48] allow that the include command may have quoted arguments with variables --- src/input.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 30424ad5cb..c1ee05999e 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -966,10 +966,15 @@ void Input::include() if (nfile == maxfile) error->one(FLERR,"Too many nested levels of input scripts"); - infile = fopen(arg[0],"r"); + // expand variables + int n = strlen(arg[0]) + 1; + if (n > maxline) reallocate(line,maxline,n); + strcpy(line,arg[0]); + substitute(line,work,maxline,maxwork,0); + + infile = fopen(line,"r"); if (infile == nullptr) - error->one(FLERR,"Cannot open input script {}: {}", - arg[0], utils::getsyserror()); + error->one(FLERR,"Cannot open input script {}: {}", line, utils::getsyserror()); infiles[nfile++] = infile; } From 6ff157a099789be6d08b0550695919d18ce86a3b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 21:05:19 -0500 Subject: [PATCH 30/48] use quoting to avoid issues with blanks and special characters --- unittest/commands/test_reset_ids.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 8ca5fe5c05..1506f9a892 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -46,8 +46,8 @@ protected: LAMMPSTest::SetUp(); if (info->has_style("atom", "full")) { BEGIN_HIDE_OUTPUT(); - command("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER)); - command("include ${input_dir}/in.fourmol"); + command("variable input_dir index \"" STRINGIFY(TEST_INPUT_FOLDER) "\""); + command("include \"${input_dir}/in.fourmol\""); END_HIDE_OUTPUT(); } } From ebeb29adf6ec8d9bd2f6dc649e34a5ca462ed95a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jan 2022 21:34:51 -0500 Subject: [PATCH 31/48] skip python folder tests for now on windows --- unittest/python/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 3cc6b9a91b..0d343582ef 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -11,6 +11,11 @@ if(NOT BUILD_SHARED_LIBS) return() endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + message(STATUS "Skipping Tests for the LAMMPS Python Module: not yet ported to Windows") + return() +endif() + if(CMAKE_VERSION VERSION_LESS 3.12) find_package(PythonInterp 3.5) # Deprecated since version 3.12 if(PYTHONINTERP_FOUND) @@ -36,7 +41,7 @@ if(Python_EXECUTABLE) set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}) get_property(BUILD_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(BUILD_IS_MULTI_CONFIG) - set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) else() set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}) endif() From a8632d5cb6e8ae34448358089afbe6a75c00adce Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 05:11:32 -0500 Subject: [PATCH 32/48] always have the lib prefix on the LAMMPS library (windows may drop it on the .dll file) --- cmake/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 256b663fd6..7ee4563b6e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -676,6 +676,7 @@ endif() set_target_properties(lammps PROPERTIES OUTPUT_NAME lammps${LAMMPS_MACHINE}) set_target_properties(lammps PROPERTIES SOVERSION ${SOVERSION}) +set_target_properties(lammps PROPERTIES PREFIX "lib") target_include_directories(lammps PUBLIC $) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/includes/lammps) foreach(_HEADER ${LAMMPS_CXX_HEADERS}) From 923b0cfc4638dd39ac229f46f7d9cd8a1a380250 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 05:13:17 -0500 Subject: [PATCH 33/48] allow to override the LAMMPS dll location on windows this is to work around the situation that windows has no equivalent to LD_LIBRARY_PATH (short of augmenting %PATH%, which is tricky for CMake before 3.20) --- python/lammps/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index 0bc8d0cb3f..62b0f5d8b6 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -89,6 +89,9 @@ class lammps(object): modpath = dirname(abspath(getsourcefile(lambda:0))) # for windows installers the shared library is in a different folder winpath = abspath(os.path.join(modpath,'..','..','bin')) + # allow override for running tests on Windows + if (os.environ.get("LAMMPSDLLPATH")): + winpath = os.environ.get("LAMMPSDLLPATH") self.lib = None self.lmp = None From 4bb7457d6e3bfd05abc97c48421ffc2fbe1a6c29 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 05:14:57 -0500 Subject: [PATCH 34/48] add option to allow skipping tests by setting a no${CMAKE_SYSTEM_NAME} tag --- unittest/force-styles/CMakeLists.txt | 36 +++++++++++++++++++ .../tests/fix-timestep-python_move_nve.yaml | 1 + .../tests/mol-pair-python_hybrid.yaml | 1 + .../tests/mol-pair-python_lj.yaml | 1 + 4 files changed, 39 insertions(+) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 0a4a1ce33e..ebad38ed0b 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -77,6 +77,10 @@ endif() foreach(TEST ${MOL_PAIR_TESTS}) string(REGEX REPLACE "^.*mol-pair-(.*)\.yaml" "MolPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -87,6 +91,10 @@ file(GLOB ATOMIC_PAIR_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/atomic-p foreach(TEST ${ATOMIC_PAIR_TESTS}) string(REGEX REPLACE "^.*atomic-pair-(.*)\.yaml" "AtomicPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -97,6 +105,10 @@ file(GLOB MANYBODY_PAIR_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/manybo foreach(TEST ${MANYBODY_PAIR_TESTS}) string(REGEX REPLACE "^.*manybody-pair-(.*)\.yaml" "ManybodyPairStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -110,6 +122,10 @@ file(GLOB BOND_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/bond-*.yaml) foreach(TEST ${BOND_TESTS}) string(REGEX REPLACE "^.*bond-(.*)\.yaml" "BondStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_bond_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -123,6 +139,10 @@ file(GLOB ANGLE_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/angle-*.yaml) foreach(TEST ${ANGLE_TESTS}) string(REGEX REPLACE "^.*angle-(.*)\.yaml" "AngleStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_angle_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -137,6 +157,10 @@ endif() foreach(TEST ${KSPACE_TESTS}) string(REGEX REPLACE "^.*kspace-(.*)\.yaml" "KSpaceStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -154,6 +178,10 @@ file(GLOB FIX_TIMESTEP_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/fix-tim foreach(TEST ${FIX_TIMESTEP_TESTS}) string(REGEX REPLACE "^.*fix-timestep-(.*)\.yaml" "FixTimestep:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_fix_timestep ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -167,6 +195,10 @@ file(GLOB DIHEDRAL_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/dihedral-*. foreach(TEST ${DIHEDRAL_TESTS}) string(REGEX REPLACE "^.*dihedral-(.*)\.yaml" "DihedralStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_dihedral_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") @@ -180,6 +212,10 @@ file(GLOB IMPROPER_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/improper-*. foreach(TEST ${IMPROPER_TESTS}) string(REGEX REPLACE "^.*improper-(.*)\.yaml" "ImproperStyle:\\1" TNAME ${TEST}) extract_tags(TEST_TAGS ${TEST}) + list(FIND TEST_TAGS "no${CMAKE_SYSTEM_NAME}" _SKIPME) + if(_SKIPME GREATER_EQUAL 0) + continue() + endif() add_test(NAME ${TNAME} COMMAND test_improper_style ${TEST}) set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") diff --git a/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml index 04bd81670b..9b1fe755ca 100644 --- a/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml +++ b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml @@ -1,6 +1,7 @@ --- lammps_version: 10 Mar 2021 date_generated: Wed Mar 24 18:57:26 2021 +tags: noWindows skip_tests: static epsilon: 9e-12 prerequisites: ! | diff --git a/unittest/force-styles/tests/mol-pair-python_hybrid.yaml b/unittest/force-styles/tests/mol-pair-python_hybrid.yaml index 5383ee113f..fc55d85304 100644 --- a/unittest/force-styles/tests/mol-pair-python_hybrid.yaml +++ b/unittest/force-styles/tests/mol-pair-python_hybrid.yaml @@ -1,6 +1,7 @@ --- lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:08 2021 +tags: noWindows epsilon: 5e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-python_lj.yaml b/unittest/force-styles/tests/mol-pair-python_lj.yaml index ac4fcd9207..ecdacdedef 100644 --- a/unittest/force-styles/tests/mol-pair-python_lj.yaml +++ b/unittest/force-styles/tests/mol-pair-python_lj.yaml @@ -1,6 +1,7 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:56 2021 +tags: noWindows epsilon: 5e-14 prerequisites: ! | atom full From 213259b732da1fb5d105b50486edb1e6a3f90ae3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 05:54:21 -0500 Subject: [PATCH 35/48] temporarily switch repo and branch to run on --- .github/workflows/compile-msvc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index e8cfcd4788..3cbc857b8e 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -3,12 +3,12 @@ name: "Native Windows Compilation" on: push: - branches: [develop] + branches: [mpi-stubs-simplify] jobs: build: name: Windows Compilation Test - if: ${{ github.repository == 'lammps/lammps' }} + if: ${{ github.repository == 'akohlmey/lammps' }} runs-on: windows-latest steps: From b17d8b4494d9234eb16d079debb69f7f0919ac43 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 05:54:35 -0500 Subject: [PATCH 36/48] add building and running unit tests --- .github/workflows/compile-msvc.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index 3cbc857b8e..a099a891f1 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -1,5 +1,5 @@ # GitHub action to build LAMMPS on Windows with Visual C++ -name: "Native Windows Compilation" +name: "Native Windows Compilation and Unit Tests" on: push: @@ -23,7 +23,8 @@ jobs: cmake -C cmake/presets/windows.cmake \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ - -D LAMMPS_EXCEPTIONS=on + -D LAMMPS_EXCEPTIONS=on \ + -D ENABLE_TESTING=on cmake --build build --config Release - name: Run LAMMPS executable @@ -31,3 +32,8 @@ jobs: run: | ./build/Release/lmp.exe -h ./build/Release/lmp.exe -in bench/in.lj + + - name: Run Unit Tests + working-directory: build + shell: bash + run: ctest -V -C Release From 99cb494594c1671525ba69a867b087c7f16f2480 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 07:08:15 -0500 Subject: [PATCH 37/48] remove automatic generated tag --- unittest/force-styles/tests/mol-pair-harmonic_cut.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/unittest/force-styles/tests/mol-pair-harmonic_cut.yaml b/unittest/force-styles/tests/mol-pair-harmonic_cut.yaml index f1c39f1bd5..fb2714626f 100644 --- a/unittest/force-styles/tests/mol-pair-harmonic_cut.yaml +++ b/unittest/force-styles/tests/mol-pair-harmonic_cut.yaml @@ -1,6 +1,5 @@ --- lammps_version: 7 Jan 2022 -tags: generated date_generated: Sat Jan 15 17:42:24 2022 epsilon: 5e-14 skip_tests: From dc0e013297516d5eac1e0806c76bfa06153ad062 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 07:48:16 -0500 Subject: [PATCH 38/48] create alias target MPI::ANY_CXX to be used instead of MPI::MPI_CXX With this alias it is possible to transparently refer to either the real imported MPI library or to the MPI stub library. this further reduced the need for if statements related to MPI. Some uses of MPI::MPI_CXX remain but they are all in branches of the script code where BUILD_MPI is enabled and thus the imported target will be present. --- cmake/CMakeLists.txt | 11 ++++------- cmake/Modules/Packages/GPU.cmake | 6 +----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7ee4563b6e..1778c7b7f2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -290,13 +290,14 @@ if(BUILD_MPI) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) endif() endif() - target_link_libraries(lammps PUBLIC MPI::MPI_CXX) + add_library(MPI::ANY_CXX ALIAS MPI::MPI_CXX) else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) add_library(mpi_stubs INTERFACE) target_include_directories(mpi_stubs INTERFACE $) - target_link_libraries(lammps PUBLIC mpi_stubs) + add_library(MPI::ANY_CXX ALIAS mpi_stubs) endif() +target_link_libraries(lammps PUBLIC MPI::ANY_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) @@ -577,11 +578,7 @@ if(PKG_ATC) if(LAMMPS_SIZES STREQUAL "BIGBIG") message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG") endif() - if(BUILD_MPI) - target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX) - else() - target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs) - endif() + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::ANY_CXX) target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}) target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES}) endif() diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index fe15917f47..feee45ee68 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -422,11 +422,7 @@ RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES) RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) -if(BUILD_MPI) - target_link_libraries(gpu PRIVATE MPI::MPI_CXX) -else() - target_link_libraries(gpu PRIVATE mpi_stubs) -endif() +target_link_libraries(gpu PRIVATE MPI::ANY_CXX) target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES}) set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE}) From f8a4006da7c14eeb0517aa52b2fd7dfd0b550c60 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 08:32:21 -0500 Subject: [PATCH 39/48] must promote imported target to global scope in order to be able to alias it --- cmake/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1778c7b7f2..e2f7d8c90c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -276,6 +276,8 @@ else() option(BUILD_MPI "Build MPI version" OFF) endif() +# configure MPI related settings and define an MPI::ANY_CXX alias target +# which will point to either the imported MPI library or the STUBS lib if(BUILD_MPI) # do not include the (obsolete) MPI C++ bindings which makes # for leaner object files and avoids namespace conflicts @@ -290,6 +292,9 @@ if(BUILD_MPI) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) endif() endif() + if(CMAKE_VERSION VERSION_GREATER 3.11) + set_property(TARGET MPI::MPI_CXX PROPERTY IMPORTED_GOBAL TRUE) + endif() add_library(MPI::ANY_CXX ALIAS MPI::MPI_CXX) else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) From 4b22962ec16c3705dead9ce83beaf54cbc7a18ac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 08:47:46 -0500 Subject: [PATCH 40/48] roll back MPI target alias change one more time. must wait until CMake 3.11 or later is minimum --- cmake/CMakeLists.txt | 16 +++++++--------- cmake/Modules/Packages/GPU.cmake | 6 +++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e2f7d8c90c..7ee4563b6e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -276,8 +276,6 @@ else() option(BUILD_MPI "Build MPI version" OFF) endif() -# configure MPI related settings and define an MPI::ANY_CXX alias target -# which will point to either the imported MPI library or the STUBS lib if(BUILD_MPI) # do not include the (obsolete) MPI C++ bindings which makes # for leaner object files and avoids namespace conflicts @@ -292,17 +290,13 @@ if(BUILD_MPI) target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG) endif() endif() - if(CMAKE_VERSION VERSION_GREATER 3.11) - set_property(TARGET MPI::MPI_CXX PROPERTY IMPORTED_GOBAL TRUE) - endif() - add_library(MPI::ANY_CXX ALIAS MPI::MPI_CXX) + target_link_libraries(lammps PUBLIC MPI::MPI_CXX) else() target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp) add_library(mpi_stubs INTERFACE) target_include_directories(mpi_stubs INTERFACE $) - add_library(MPI::ANY_CXX ALIAS mpi_stubs) + target_link_libraries(lammps PUBLIC mpi_stubs) endif() -target_link_libraries(lammps PUBLIC MPI::ANY_CXX) set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) @@ -583,7 +577,11 @@ if(PKG_ATC) if(LAMMPS_SIZES STREQUAL "BIGBIG") message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG") endif() - target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::ANY_CXX) + if(BUILD_MPI) + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX) + else() + target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs) + endif() target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR}) target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES}) endif() diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index feee45ee68..ee697459d8 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -422,7 +422,11 @@ RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES) RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) -target_link_libraries(gpu PRIVATE MPI::ANY_CXX) +if(BUILD_MPI) + target_link_libraries(gpu PRIVATE MPI::ANY_CXX) +else() + target_link_libraries(gpu PRIVATE mpi_stubs) +endif() target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES}) set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE}) From 65b198f98663cc3a23f9da96a8c609a12ae211e3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 08:48:52 -0500 Subject: [PATCH 41/48] Revert "temporarily switch repo and branch to run on" This reverts commit 213259b732da1fb5d105b50486edb1e6a3f90ae3. --- .github/workflows/compile-msvc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index a099a891f1..e71a2950e6 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -3,12 +3,12 @@ name: "Native Windows Compilation and Unit Tests" on: push: - branches: [mpi-stubs-simplify] + branches: [develop] jobs: build: name: Windows Compilation Test - if: ${{ github.repository == 'akohlmey/lammps' }} + if: ${{ github.repository == 'lammps/lammps' }} runs-on: windows-latest steps: From af8d1bd768dc53d07f53e7b5b493e6309d15334f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 09:00:39 -0500 Subject: [PATCH 42/48] fix typo --- cmake/Modules/Packages/GPU.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index ee697459d8..fe15917f47 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -423,7 +423,7 @@ RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h) get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES) if(BUILD_MPI) - target_link_libraries(gpu PRIVATE MPI::ANY_CXX) + target_link_libraries(gpu PRIVATE MPI::MPI_CXX) else() target_link_libraries(gpu PRIVATE mpi_stubs) endif() From fea41d5458cde75fefb9835240195247c62e0406 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 16:47:17 -0500 Subject: [PATCH 43/48] make windows compatible --- src/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.cpp b/src/utils.cpp index eabe86adbc..ca2a0c4f5b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1028,7 +1028,7 @@ std::vector utils::split_words(const std::string &text) ------------------------------------------------------------------------- */ std::vector utils::split_lines(const std::string &text) { - return Tokenizer(text, "\n").as_vector(); + return Tokenizer(text, "\r\n").as_vector(); } /* ---------------------------------------------------------------------- From 579ac61b5b1c1a19f77ff32384dd23c5ffa67400 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 16:47:52 -0500 Subject: [PATCH 44/48] refactor environment variable settings. make windows compatible --- unittest/force-styles/CMakeLists.txt | 38 +++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index ebad38ed0b..934c110b1f 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -68,6 +68,28 @@ if(FFT_SINGLE) target_compile_definitions(test_pair_style PRIVATE -DFFT_SINGLE) endif() +# prepare environment for testers +if(WIN32) + set(FORCE_TEST_ENVIRONMENT PYTHONPATH=${TEST_INPUT_FOLDER}) +else() + set(FORCE_TEST_ENVIRONMENT PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}) +endif() +list(APPEND FORCE_TEST_ENVIRONMENT "PYTHONUNBUFFERED=1") +list(APPEND FORCE_TEST_ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") +get_property(BUILD_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(BUILD_IS_MULTI_CONFIG) + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) +else() + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}) +endif() +if(APPLE) + list(APPEND FORCE_TEST_ENVIRONMENT "DYLD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{DYLD_LIBRARY_PATH}") +elseif(WIN32) + list(APPEND FORCE_TEST_ENVIRONMENT "LAMMPSDLLPATH=${LAMMPS_LIB_PATH}") +else() + list(APPEND FORCE_TEST_ENVIRONMENT "LD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{LD_LIBRARY_PATH}") +endif() + # tests for molecular systems and related pair styles file(GLOB MOL_PAIR_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/mol-pair-*.yaml) # cannot test MSM with single precision data @@ -82,7 +104,7 @@ foreach(TEST ${MOL_PAIR_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -96,7 +118,7 @@ foreach(TEST ${ATOMIC_PAIR_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -110,7 +132,7 @@ foreach(TEST ${MANYBODY_PAIR_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -127,7 +149,7 @@ foreach(TEST ${BOND_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_bond_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -144,7 +166,7 @@ foreach(TEST ${ANGLE_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_angle_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -162,7 +184,7 @@ foreach(TEST ${KSPACE_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_pair_style ${TEST}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "${FORCE_TEST_ENVIRONMENT}") set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() @@ -183,7 +205,11 @@ foreach(TEST ${FIX_TIMESTEP_TESTS}) continue() endif() add_test(NAME ${TNAME} COMMAND test_fix_timestep ${TEST}) +if(WIN32) + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}\\\;${LAMMPS_PYTHON_DIR}") +else() set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}") +endif() set_tests_properties(${TNAME} PROPERTIES LABELS "${TEST_TAGS}") endforeach() From 2e39971cbcef1d6c1c2cc84a5bc4b33d3d76536f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 16:48:11 -0500 Subject: [PATCH 45/48] re-enable python module tests on windows --- unittest/force-styles/tests/fix-timestep-python_move_nve.yaml | 1 - unittest/force-styles/tests/mol-pair-python_hybrid.yaml | 1 - unittest/force-styles/tests/mol-pair-python_lj.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml index 9b1fe755ca..04bd81670b 100644 --- a/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml +++ b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml @@ -1,7 +1,6 @@ --- lammps_version: 10 Mar 2021 date_generated: Wed Mar 24 18:57:26 2021 -tags: noWindows skip_tests: static epsilon: 9e-12 prerequisites: ! | diff --git a/unittest/force-styles/tests/mol-pair-python_hybrid.yaml b/unittest/force-styles/tests/mol-pair-python_hybrid.yaml index fc55d85304..5383ee113f 100644 --- a/unittest/force-styles/tests/mol-pair-python_hybrid.yaml +++ b/unittest/force-styles/tests/mol-pair-python_hybrid.yaml @@ -1,7 +1,6 @@ --- lammps_version: 8 Apr 2021 date_generated: Mon Apr 19 08:49:08 2021 -tags: noWindows epsilon: 5e-14 prerequisites: ! | atom full diff --git a/unittest/force-styles/tests/mol-pair-python_lj.yaml b/unittest/force-styles/tests/mol-pair-python_lj.yaml index ecdacdedef..ac4fcd9207 100644 --- a/unittest/force-styles/tests/mol-pair-python_lj.yaml +++ b/unittest/force-styles/tests/mol-pair-python_lj.yaml @@ -1,7 +1,6 @@ --- lammps_version: 10 Feb 2021 date_generated: Fri Feb 26 23:08:56 2021 -tags: noWindows epsilon: 5e-14 prerequisites: ! | atom full From a8a76dbbe2c5e1f1b5902564001b16558d6e4eac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 16:48:47 -0500 Subject: [PATCH 46/48] port python module and package tests to be windows compatible. refactor environment processing --- unittest/python/CMakeLists.txt | 52 ++++++++++++++----------- unittest/python/test_python_package.cpp | 10 ++--- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index 0d343582ef..7f9b5e71b2 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -11,18 +11,13 @@ if(NOT BUILD_SHARED_LIBS) return() endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - message(STATUS "Skipping Tests for the LAMMPS Python Module: not yet ported to Windows") - return() -endif() - if(CMAKE_VERSION VERSION_LESS 3.12) - find_package(PythonInterp 3.5) # Deprecated since version 3.12 + find_package(PythonInterp 3.6) # Deprecated since version 3.12 if(PYTHONINTERP_FOUND) set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) endif() else() - find_package(Python3 COMPONENTS Interpreter Development) + find_package(Python3 3.6 COMPONENTS Interpreter Development) endif() add_executable(test_python_package test_python_package.cpp) @@ -34,24 +29,33 @@ if(Python3_Development_FOUND) target_link_libraries(test_python_package PRIVATE Python3::Python) endif() add_test(NAME PythonPackage COMMAND test_python_package) -set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH};PYTHONUNBUFFERED=1") + +# build list of environment variables for testing python functionality +if(WIN32) + set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${LAMMPS_PYTHON_DIR}) +else() + set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}) +endif() +get_property(BUILD_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(BUILD_IS_MULTI_CONFIG) + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) +else() + set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}) +endif() +list(APPEND PYTHON_TEST_ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") +list(APPEND PYTHON_TEST_ENVIRONMENT "PYTHONUNBUFFERED=1") +if(APPLE) + list(APPEND PYTHON_TEST_ENVIRONMENT "DYLD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{DYLD_LIBRARY_PATH}") +elseif(WIN32) + list(APPEND PYTHON_TEST_ENVIRONMENT "LAMMPSDLLPATH=${LAMMPS_LIB_PATH}") +else() + list(APPEND PYTHON_TEST_ENVIRONMENT "LD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{LD_LIBRARY_PATH}") +endif() +set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") 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}) - get_property(BUILD_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - if(BUILD_IS_MULTI_CONFIG) - set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}/$) - else() - set(LAMMPS_LIB_PATH ${CMAKE_BINARY_DIR}) - endif() - list(APPEND PYTHON_TEST_ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") list(APPEND PYTHON_TEST_ENVIRONMENT "TEST_INPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}") - if(APPLE) - list(APPEND PYTHON_TEST_ENVIRONMENT "DYLD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{DYLD_LIBRARY_PATH};LAMMPS_CMAKE_CACHE=${CMAKE_BINARY_DIR}/CMakeCache.txt") - else() - list(APPEND PYTHON_TEST_ENVIRONMENT "LD_LIBRARY_PATH=${LAMMPS_LIB_PATH}:$ENV{LD_LIBRARY_PATH};LAMMPS_CMAKE_CACHE=${CMAKE_BINARY_DIR}/CMakeCache.txt") - endif() + list(APPEND PYTHON_TEST_ENVIRONMENT "LAMMPS_CMAKE_CACHE=${CMAKE_BINARY_DIR}/CMakeCache.txt") if(LAMMPS_MACHINE) # convert from '_machine' to 'machine' string(SUBSTRING ${LAMMPS_MACHINE} 1 -1 LAMMPS_MACHINE_NAME) @@ -94,10 +98,14 @@ if(Python_EXECUTABLE) WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonCapabilities PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + message(STATUS "Skipping Tests for PyLammps Module: not yet ported to Windows") +else() add_test(NAME PythonPyLammps COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-pylammps.py -v WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonPyLammps PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") +endif() add_test(NAME PythonFormats COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-formats.py -v diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 07b9a29f28..82b4704e5f 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -89,7 +89,7 @@ TEST_F(PythonPackageTest, InvokeFunctionFromFile) auto output = CAPTURE_OUTPUT([&]() { command("python printnum invoke"); }); - ASSERT_THAT(output, HasSubstr("2.25\n")); + ASSERT_THAT(output, HasSubstr("2.25")); } #if defined(TEST_HAVE_PYTHON_DEVELOPMENT) @@ -210,7 +210,7 @@ TEST_F(PythonPackageTest, InvokeOtherFunctionFromFile) auto output = CAPTURE_OUTPUT([&] { command("python printtxt invoke"); }); - ASSERT_THAT(output, HasSubstr("sometext\n")); + ASSERT_THAT(output, HasSubstr("sometext")); } TEST_F(PythonPackageTest, InvokeFunctionThatUsesLAMMPSModule) @@ -224,7 +224,7 @@ TEST_F(PythonPackageTest, InvokeFunctionThatUsesLAMMPSModule) auto output = CAPTURE_OUTPUT([&] { command("python getidxvar invoke"); }); - ASSERT_THAT(output, HasSubstr("2.25\n")); + ASSERT_THAT(output, HasSubstr("2.25")); } TEST_F(PythonPackageTest, python_variable) @@ -238,7 +238,7 @@ TEST_F(PythonPackageTest, python_variable) std::string output = CAPTURE_OUTPUT([&] { command("print \"${sq}\""); }); - ASSERT_THAT(output, ContainsRegex("print.*2.25.*")); + ASSERT_THAT(output, ContainsRegex("print.*\n.*2.25.*")); } TEST_F(PythonPackageTest, InlineFunction) @@ -309,7 +309,7 @@ TEST_F(FixPythonInvokeTest, end_of_step) auto output = CAPTURE_OUTPUT([&] { command("run 50"); }); - + fprintf(stderr,"lines: %s\n",output.c_str()); auto lines = utils::split_lines(output); int count = 0; From 3707b327c097db033defa5a2e4e059b6a9d199bd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 16:52:38 -0500 Subject: [PATCH 47/48] improve portability of python result value string conversion --- src/PYTHON/python_impl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 983aafb16b..bc593d5b8a 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -329,9 +329,11 @@ void PythonImpl::invoke_function(int ifunc, char *result) if (pfuncs[ifunc].noutput) { int otype = pfuncs[ifunc].otype; if (otype == INT) { - sprintf(result, "%ld", PY_INT_AS_LONG(pValue)); + auto value = fmt::format("{}", PY_INT_AS_LONG(pValue)); + strncpy(result, value.c_str(), Variable::VALUELENGTH - 1); } else if (otype == DOUBLE) { - sprintf(result, "%.15g", PyFloat_AsDouble(pValue)); + auto value = fmt::format("{:.15g}", PyFloat_AsDouble(pValue)); + strncpy(result, value.c_str(), Variable::VALUELENGTH - 1); } else if (otype == STRING) { const char *pystr = PY_STRING_AS_STRING(pValue); if (pfuncs[ifunc].longstr) From 7ee7d0c57000f4fb461c2bfdc31983df3e187dd1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 30 Jan 2022 17:18:40 -0500 Subject: [PATCH 48/48] apply clang-format --- unittest/c-library/test_library_commands.cpp | 16 +++++++------- unittest/c-library/test_library_config.cpp | 2 +- .../c-library/test_library_properties.cpp | 8 ++++--- .../c-library/test_library_scatter_gather.cpp | 2 +- unittest/commands/test_lattice_region.cpp | 2 +- unittest/commands/test_simple_commands.cpp | 12 ++++++----- unittest/commands/test_variables.cpp | 4 ++-- unittest/cplusplus/test_input_class.cpp | 6 +++--- unittest/cplusplus/test_lammps_class.cpp | 4 ++-- unittest/force-styles/test_angle_style.cpp | 2 +- unittest/force-styles/test_bond_style.cpp | 2 +- unittest/force-styles/test_config_reader.cpp | 2 +- unittest/force-styles/test_dihedral_style.cpp | 2 +- unittest/force-styles/test_fix_timestep.cpp | 4 ++-- unittest/force-styles/test_improper_style.cpp | 2 +- unittest/formats/test_atom_styles.cpp | 2 +- unittest/formats/test_dump_atom.cpp | 4 ++-- unittest/formats/test_dump_custom.cpp | 6 +++--- unittest/formats/test_file_operations.cpp | 4 +++- unittest/formats/test_molecule_file.cpp | 21 +++++++++++-------- unittest/formats/test_text_file_reader.cpp | 2 +- unittest/python/test_python_package.cpp | 2 +- unittest/utils/test_math_eigen_impl.cpp | 14 ++++++------- unittest/utils/test_platform.cpp | 4 ++-- unittest/utils/test_utils.cpp | 16 +++++++------- 25 files changed, 77 insertions(+), 68 deletions(-) diff --git a/unittest/c-library/test_library_commands.cpp b/unittest/c-library/test_library_commands.cpp index 203862c696..f1cc51d8d9 100644 --- a/unittest/c-library/test_library_commands.cpp +++ b/unittest/c-library/test_library_commands.cpp @@ -20,7 +20,7 @@ const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"}; class LibraryCommands : public ::testing::Test { protected: void *lmp; - LibraryCommands() = default; + LibraryCommands() = default; ~LibraryCommands() override = default; void SetUp() override @@ -55,13 +55,13 @@ TEST_F(LibraryCommands, from_file) const char cont_file[] = "in.cont"; fp = fopen(demo_file, "w"); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { fputs(inp, fp); fputc('\n', fp); } fclose(fp); fp = fopen(cont_file, "w"); - for (auto & inp : cont_input) { + for (auto &inp : cont_input) { fputs(inp, fp); fputc('\n', fp); } @@ -85,7 +85,7 @@ TEST_F(LibraryCommands, from_line) { EXPECT_EQ(lammps_get_natoms(lmp), 0); if (!verbose) ::testing::internal::CaptureStdout(); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { lammps_command(lmp, inp); } if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -106,11 +106,11 @@ TEST_F(LibraryCommands, from_string) { std::string cmds(""); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { cmds += inp; cmds += "\n"; } - for (auto & inp : cont_input) { + for (auto &inp : cont_input) { cmds += inp; cmds += "\n"; } @@ -126,11 +126,11 @@ TEST_F(LibraryCommands, from_string) if (!verbose) ::testing::internal::GetCapturedStdout(); cmds.clear(); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { cmds += inp; cmds += "\r\n"; } - for (auto & inp : cont_input) { + for (auto &inp : cont_input) { cmds += inp; cmds += "\r\n"; } diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index 456faff06f..f402ffc2e9 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -22,7 +22,7 @@ protected: void *lmp; std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); - LibraryConfig() = default; + LibraryConfig() = default; ~LibraryConfig() override = default; void SetUp() override diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 754c6df77f..ee0bd1f270 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -23,7 +23,7 @@ protected: void *lmp; std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); - LibraryProperties() = default; + LibraryProperties() = default; ~LibraryProperties() override = default; void SetUp() override @@ -436,8 +436,10 @@ class AtomProperties : public ::testing::Test { protected: void *lmp; - AtomProperties()= default;; - ~AtomProperties() override= default;; + AtomProperties() = default; + ; + ~AtomProperties() override = default; + ; void SetUp() override { diff --git a/unittest/c-library/test_library_scatter_gather.cpp b/unittest/c-library/test_library_scatter_gather.cpp index 7ee1cfc9eb..b070bb4ab7 100644 --- a/unittest/c-library/test_library_scatter_gather.cpp +++ b/unittest/c-library/test_library_scatter_gather.cpp @@ -23,7 +23,7 @@ protected: void *lmp; std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); - GatherProperties() = default; + GatherProperties() = default; ~GatherProperties() override = default; void SetUp() override diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 590180326c..4f314b1669 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -35,8 +35,8 @@ bool verbose = false; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { -using ::testing::ExitedWithCode; using ::testing::ContainsRegex; +using ::testing::ExitedWithCode; using ::testing::StrEq; class LatticeRegionTest : public LAMMPSTest { diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 862c3a8c4a..acbade5ad8 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -39,8 +39,8 @@ bool verbose = false; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { -using ::testing::ExitedWithCode; using ::testing::ContainsRegex; +using ::testing::ExitedWithCode; using ::testing::StrEq; class SimpleCommandsTest : public LAMMPSTest { @@ -412,14 +412,14 @@ TEST_F(SimpleCommandsTest, Plugin) text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, ContainsRegex(".*1: command style plugin hello" - ".*2: fix style plugin nve2.*")); + ".*2: fix style plugin nve2.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "hello")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, ContainsRegex(".*Ignoring load of command style hello: " - "must unload existing hello plugin.*")); + "must unload existing hello plugin.*")); ::testing::internal::CaptureStdout(); lmp->input->one("plugin unload command hello"); @@ -479,7 +479,8 @@ TEST_F(SimpleCommandsTest, Shell) test_var = getenv("TEST_VARIABLE"); ASSERT_NE(test_var, nullptr); #if defined(_WIN32) - // we cannot create empty environment variables on Windows so platform::putenv() sets their value to "1" + // we cannot create empty environment variables on Windows so platform::putenv() sets their + // value to "1" ASSERT_THAT(test_var, StrEq("1")); #else ASSERT_THAT(test_var, StrEq("")); @@ -501,7 +502,8 @@ TEST_F(SimpleCommandsTest, CiteMe) // find the two unique citations, but not the third ASSERT_THAT(text, ContainsRegex("test citation one.\n.*test citation two.*")); - ASSERT_THAT(text, Not(ContainsRegex("test citation one.\n.*test citation two.*\n.*test citation one.*"))); + ASSERT_THAT(text, Not(ContainsRegex( + "test citation one.\n.*test citation two.*\n.*test citation one.*"))); BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 0\n"); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index af52df8e28..57a5d4f0ca 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -36,8 +36,8 @@ using LAMMPS_NS::MathConst::MY_PI; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { -using ::testing::ExitedWithCode; using ::testing::ContainsRegex; +using ::testing::ExitedWithCode; using ::testing::StrEq; class VariableTest : public LAMMPSTest { @@ -317,7 +317,7 @@ TEST_F(VariableTest, Expressions) ASSERT_TRUE(variable->equalstyle(ivar)); ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 2.0); ASSERT_DOUBLE_EQ(variable->compute_equal("v_three"), 3.0); - ASSERT_NEAR(variable->compute_equal("v_four"), MY_PI,1.0e-14); + ASSERT_NEAR(variable->compute_equal("v_four"), MY_PI, 1.0e-14); ASSERT_GE(variable->compute_equal("v_five"), 20210310); ASSERT_DOUBLE_EQ(variable->compute_equal("v_seven"), -1); ASSERT_DOUBLE_EQ(variable->compute_equal("v_eight"), 2.5); diff --git a/unittest/cplusplus/test_input_class.cpp b/unittest/cplusplus/test_input_class.cpp index b1d8af28c6..6595c24695 100644 --- a/unittest/cplusplus/test_input_class.cpp +++ b/unittest/cplusplus/test_input_class.cpp @@ -60,13 +60,13 @@ TEST_F(Input_commands, from_file) const char cont_file[] = "in.cont"; fp = fopen(demo_file, "w"); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { fputs(inp, fp); fputc('\n', fp); } fclose(fp); fp = fopen(cont_file, "w"); - for (auto & inp : cont_input) { + for (auto &inp : cont_input) { fputs(inp, fp); fputc('\n', fp); } @@ -84,7 +84,7 @@ TEST_F(Input_commands, from_file) TEST_F(Input_commands, from_line) { EXPECT_EQ(lmp->atom->natoms, 0); - for (auto & inp : demo_input) { + for (auto &inp : demo_input) { lmp->input->one(inp); } EXPECT_EQ(lmp->atom->natoms, 1); diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 6bbeb385e9..6c733a31e4 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -372,8 +372,8 @@ TEST(LAMMPS_init, NoOpenMP) ::testing::internal::CaptureStdout(); LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(output, - ContainsRegex(".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); + EXPECT_THAT(output, ContainsRegex( + ".*OMP_NUM_THREADS environment is not set.*Defaulting to 1 thread.*")); EXPECT_EQ(lmp->comm->nthreads, 1); ::testing::internal::CaptureStdout(); delete lmp; diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index b4300218b7..8a974a09d2 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -289,7 +289,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->angle->virial; block = fmt::format("{:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e}", stress[0], - stress[1], stress[2], stress[3], stress[4], stress[5]); + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", block); block.clear(); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index f4c151a394..068fee5e82 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -289,7 +289,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->bond->virial; block = fmt::format("{:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e}", stress[0], - stress[1], stress[2], stress[3], stress[4], stress[5]); + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", block); block.clear(); diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index e6cf73f10e..d152b4fcf4 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -374,7 +374,7 @@ void TestConfigReader::tags(const yaml_event_t &event) { std::stringstream data((char *)event.data.scalar.value); config.tags.clear(); - for (std::string tag; std::getline(data, tag, ','); ) { + for (std::string tag; std::getline(data, tag, ',');) { config.tags.push_back(trim(tag)); } } diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 8cae5d5f7c..6f525a07eb 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -292,7 +292,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->dihedral->virial; block = fmt::format("{:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e}", stress[0], - stress[1], stress[2], stress[3], stress[4], stress[5]); + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", block); block.clear(); diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index ac83ff9573..eef928f7e5 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -209,8 +209,8 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) if (fix->thermo_virial) { auto stress = fix->virial; block = fmt::format("{:23.16e} {:23.16e} {:23.16e} " - "{:23.16e} {:23.16e} {:23.16e}", - stress[0], stress[1], stress[2], stress[3], stress[4], stress[5]); + "{:23.16e} {:23.16e} {:23.16e}", + stress[0], stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", block); } diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index b6d6b9a06b..fdbfda8f7a 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -283,7 +283,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // run_stress stress = lmp->force->improper->virial; block = fmt::format("{:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e} {:23.16e}", stress[0], - stress[1], stress[2], stress[3], stress[4], stress[5]); + stress[1], stress[2], stress[3], stress[4], stress[5]); writer.emit_block("run_stress", block); block.clear(); diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 59c0e1350c..ab00efc949 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -2123,7 +2123,7 @@ TEST_F(AtomStyleTest, body_nparticle) "12.0 0.0 12.0 0.0 0.0 0.0\n" "0.0 1.0 0.0\n" "0.0 -3.0 0.0\n"; - FILE *fp = fopen("input_atom_styles.data", "w"); + FILE *fp = fopen("input_atom_styles.data", "w"); fputs(data_file, fp); fclose(fp); BEGIN_HIDE_OUTPUT(); diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index a73204fb92..6303d2c019 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -547,12 +547,12 @@ TEST_F(DumpAtomTest, rerun_bin) command(fmt::format("rerun {} first 1 last 1 every 1 post no dump x y z", dump_file)); }); lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); - ASSERT_NEAR(pe_1, pe_rerun,1.0e-14); + ASSERT_NEAR(pe_1, pe_rerun, 1.0e-14); HIDE_OUTPUT([&] { command(fmt::format("rerun {} first 2 last 2 every 1 post yes dump x y z", dump_file)); }); lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); - ASSERT_NEAR(pe_2, pe_rerun,1.0e-14); + ASSERT_NEAR(pe_2, pe_rerun, 1.0e-14); delete_file(dump_file); } diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index 434acf462c..40e22f5a11 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -346,7 +346,7 @@ TEST_F(DumpCustomTest, rerun) }); lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); ASSERT_DOUBLE_EQ(pe_1, pe_rerun); - + HIDE_OUTPUT([&] { command(fmt::format("rerun {} first 2 last 2 every 1 post yes dump x y z", dump_file)); }); @@ -375,12 +375,12 @@ TEST_F(DumpCustomTest, rerun_bin) command(fmt::format("rerun {} first 1 last 1 every 1 post no dump x y z", dump_file)); }); lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); - ASSERT_NEAR(pe_1, pe_rerun,1.0e-14); + ASSERT_NEAR(pe_1, pe_rerun, 1.0e-14); HIDE_OUTPUT([&] { command(fmt::format("rerun {} first 2 last 2 every 1 post yes dump x y z", dump_file)); }); lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); - ASSERT_NEAR(pe_2, pe_rerun,1.0e-14); + ASSERT_NEAR(pe_2, pe_rerun, 1.0e-14); delete_file(dump_file); } diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index 3ca889b76e..fdb3e1a815 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -334,7 +334,9 @@ TEST_F(FileOperationsTest, write_restart) ASSERT_FILE_EXISTS("multi2-0.restart"); ASSERT_FILE_EXISTS("multi3-base.restart"); ASSERT_FILE_EXISTS("multi3-0.restart"); - if (info->has_package("MPIIO")) { ASSERT_FILE_EXISTS("test.restart.mpiio"); } + if (info->has_package("MPIIO")) { + ASSERT_FILE_EXISTS("test.restart.mpiio"); + } if (!info->has_package("MPIIO")) { TEST_FAILURE(".*ERROR: Writing to MPI-IO filename when MPIIO package is not inst.*", diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 6f24c0f758..17bd30a349 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -189,7 +189,7 @@ TEST_F(MoleculeFileTest, notype) ".*0 fragments.*\n.*1 atoms.*\n.*0 bonds.*")); TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); - } +} TEST_F(MoleculeFileTest, extramass) { @@ -197,12 +197,13 @@ TEST_F(MoleculeFileTest, extramass) command("atom_style atomic"); command("region box block 0 1 0 1 0 1"); command("create_box 1 box"); - run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n" + run_mol_cmd(test_name, "", + "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n" " Types\n\n 1 1\n Masses\n\n 1 1.0\n"); command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546"); auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, ContainsRegex(".*WARNING: Molecule attributes do not match " - "system attributes.*")); + "system attributes.*")); } TEST_F(MoleculeFileTest, twomols) @@ -222,12 +223,14 @@ TEST_F(MoleculeFileTest, twofiles) BEGIN_CAPTURE_OUTPUT(); command("molecule twomols moltest.h2o.mol moltest.co2.mol offset 2 1 1 0 0"); auto output = END_CAPTURE_OUTPUT(); - ASSERT_THAT(output, ContainsRegex(".*Read molecule template twomols:.*\n.*1 molecules.*\n" - ".*0 fragments.*\n.*3 atoms with max type 2.*\n.*2 bonds with max type 1.*\n" - ".*1 angles with max type 1.*\n.*0 dihedrals.*\n.*0 impropers.*\n" - ".*Read molecule template twomols:.*\n.*1 molecules.*\n" - ".*0 fragments.*\n.*3 atoms with max type 4.*\n.*2 bonds with max type 2.*\n" - ".*1 angles with max type 2.*\n.*0 dihedrals.*")); + ASSERT_THAT( + output, + ContainsRegex(".*Read molecule template twomols:.*\n.*1 molecules.*\n" + ".*0 fragments.*\n.*3 atoms with max type 2.*\n.*2 bonds with max type 1.*\n" + ".*1 angles with max type 1.*\n.*0 dihedrals.*\n.*0 impropers.*\n" + ".*Read molecule template twomols:.*\n.*1 molecules.*\n" + ".*0 fragments.*\n.*3 atoms with max type 4.*\n.*2 bonds with max type 2.*\n" + ".*1 angles with max type 2.*\n.*0 dihedrals.*")); } TEST_F(MoleculeFileTest, bonds) diff --git a/unittest/formats/test_text_file_reader.cpp b/unittest/formats/test_text_file_reader.cpp index 6fcc21fb33..4965daab5d 100644 --- a/unittest/formats/test_text_file_reader.cpp +++ b/unittest/formats/test_text_file_reader.cpp @@ -72,7 +72,7 @@ TEST_F(TextFileReaderTest, permissions) { platform::unlink("text_reader_noperms.file"); FILE *fp = fopen("text_reader_noperms.file", "w"); - ASSERT_NE(fp,nullptr); + ASSERT_NE(fp, nullptr); fputs("word\n", fp); fclose(fp); chmod("text_reader_noperms.file", 0); diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 82b4704e5f..db7a7a41b6 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -43,9 +43,9 @@ bool verbose = false; using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { +using ::testing::ContainsRegex; using ::testing::Eq; using ::testing::HasSubstr; -using ::testing::ContainsRegex; using ::testing::StrEq; class PythonPackageTest : public LAMMPSTest { diff --git a/unittest/utils/test_math_eigen_impl.cpp b/unittest/utils/test_math_eigen_impl.cpp index 47ca8d9cca..b38438d1f7 100644 --- a/unittest/utils/test_math_eigen_impl.cpp +++ b/unittest/utils/test_math_eigen_impl.cpp @@ -48,7 +48,7 @@ inline static bool SimilarVec(Vector a, Vector b, int n, Scalar eps = 1.0e-06, Scalar ratio = 1.0e-06, Scalar ratio_denom = 1.0) { for (int i = 0; i < n; i++) - if (! Similar(a[i], b[i], eps, ratio, ratio_denom)) return false; + if (!Similar(a[i], b[i], eps, ratio, ratio_denom)) return false; return true; } @@ -61,7 +61,7 @@ inline static bool SimilarVecUnsigned(Vector a, Vector b, int n, Scalar eps = 1. return true; else { for (int i = 0; i < n; i++) - if (! Similar(a[i], -b[i], eps, ratio, ratio_denom)) return false; + if (!Similar(a[i], -b[i], eps, ratio, ratio_denom)) return false; return true; } } @@ -464,7 +464,7 @@ void TestJacobi(int n, //::SORT_INCREASING_ABS_EVALS); #else ecalc.Diagonalize(M, evals, evecs, - Jacobi::SORT_INCREASING_ABS_EVALS); #endif @@ -488,7 +488,7 @@ void TestJacobi(int n, //::SORT_DECREASING_ABS_EVALS); #else ecalc.Diagonalize(M, evals, evecs, - Jacobi::SORT_DECREASING_ABS_EVALS); #endif @@ -511,7 +511,7 @@ void TestJacobi(int n, //::SORT_INCREASING_EVALS); #else ecalc.Diagonalize(M, evals, evecs, - Jacobi::SORT_INCREASING_EVALS); #endif for (int i = 1; i < n; i++) @@ -533,8 +533,8 @@ void TestJacobi(int n, //::DO_NOT_SORT); #else ecalc.Diagonalize( - M, evals, evecs, - Jacobi::DO_NOT_SORT); + M, evals, evecs, + Jacobi::DO_NOT_SORT); #endif } // if (test_code_coverage) diff --git a/unittest/utils/test_platform.cpp b/unittest/utils/test_platform.cpp index ace546ba90..37e749b9be 100644 --- a/unittest/utils/test_platform.cpp +++ b/unittest/utils/test_platform.cpp @@ -68,10 +68,10 @@ TEST(Platform, putenv_unsetenv) ASSERT_EQ(platform::unsetenv(""), -1); ASSERT_EQ(platform::unsetenv("UNITTEST_VAR3=two"), -1); - var = getenv("UNITTEST_VAR1"); + var = getenv("UNITTEST_VAR1"); ASSERT_NE(var, nullptr); ASSERT_EQ(platform::unsetenv("UNITTEST_VAR1"), 0); - var = getenv("UNITTEST_VAR1"); + var = getenv("UNITTEST_VAR1"); ASSERT_EQ(var, nullptr); } diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 72a90a95a0..dccbdb4118 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -838,15 +838,15 @@ TEST(Utils, date2num) TEST(Utils, current_date) { - auto vals = ValueTokenizer(utils::current_date(),"-"); - int year = vals.next_int(); + auto vals = ValueTokenizer(utils::current_date(), "-"); + int year = vals.next_int(); int month = vals.next_int(); - int day = vals.next_int(); - ASSERT_GT(year,2020); - ASSERT_GE(month,1); - ASSERT_GE(day,1); - ASSERT_LE(month,12); - ASSERT_LE(day,31); + int day = vals.next_int(); + ASSERT_GT(year, 2020); + ASSERT_GE(month, 1); + ASSERT_GE(day, 1); + ASSERT_LE(month, 12); + ASSERT_LE(day, 31); } TEST(Utils, binary_search)