Merge pull request #2650 from akohlmey/plugin-loader

New PLUGIN package with a LAMMPS plugin loader command
This commit is contained in:
Axel Kohlmeyer
2021-04-02 15:08:44 -04:00
committed by GitHub
60 changed files with 3797 additions and 38 deletions

View File

@ -1,5 +1,31 @@
# build LAMMPS plugins, but not on Windows
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND PKG_PLUGIN)
ExternalProject_Add(plugins
SOURCE_DIR "${LAMMPS_DIR}/examples/plugins"
BINARY_DIR ${CMAKE_BINARY_DIR}/build-plugins
INSTALL_DIR ${CMAKE_BINARY_DIR}
CMAKE_ARGS ${CMAKE_REQUEST_PIC}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
BUILD_BYPRODUCTS <BINARY_DIR>/morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
<BINARY_DIR>/nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
<BINARY_DIR>/helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different
<BINARY_DIR>/morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
<BINARY_DIR>/nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX}
<BINARY_DIR>/helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}
TEST_COMMAND "")
endif()
add_executable(test_simple_commands test_simple_commands.cpp)
if(PKG_PLUGIN)
add_dependencies(test_simple_commands plugins)
endif()
target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock GTest::GTest)
add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

View File

@ -367,6 +367,79 @@ TEST_F(SimpleCommandsTest, Units)
TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown"););
}
#if defined(LMP_PLUGIN)
TEST_F(SimpleCommandsTest, Plugin)
{
#if defined(__APPLE__)
std::string loadfmt("plugin load {}plugin.dylib");
#else
std::string loadfmt("plugin load {}plugin.so");
#endif
::testing::internal::CaptureStdout();
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.*"));
::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.*"));
::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.*"));
::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"
".*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: "
"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.*"));
::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 loaded 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.*"));
::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 loaded 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.*"));
}
#endif
TEST_F(SimpleCommandsTest, Shell)
{
if (!verbose) ::testing::internal::CaptureStdout();