Commit 732eaf77 authored by Christopher Bruns's avatar Christopher Bruns
Browse files

NML plugin loading test passes on Windows.

parent 535710ec
...@@ -50,8 +50,34 @@ if(UNIX) ...@@ -50,8 +50,34 @@ if(UNIX)
set_target_properties(NormalModeLangevin PROPERTIES DEBUG_OUTPUT_NAME NormalModeLangevin_d) set_target_properties(NormalModeLangevin PROPERTIES DEBUG_OUTPUT_NAME NormalModeLangevin_d)
endif(UNIX) endif(UNIX)
target_link_libraries( NormalModeLangevin ${SHARED_TARGET} ) target_link_libraries( NormalModeLangevin ${SHARED_TARGET} )
# Copy plugin to test_plugin_dir
# TODO - move this up to top level CMakeLists.txt
set(test_plugin_dir "${CMAKE_BINARY_DIR}/test_plugin_dir")
file(MAKE_DIRECTORY "${test_plugin_dir}")
if(BUILD_TESTING) if(BUILD_TESTING)
# On Windows we need to copy the correct Release/Debug plugin for testing
if(MSVC)
set(args -E copy $\(TargetPath\) \"${test_plugin_dir}\")
message(${args})
add_custom_command(TARGET NormalModeLangevin POST_BUILD
DEPENDS $(TargetPath)
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy \"$\(TargetPath\)\" \"${test_plugin_dir}\"
COMMENT "Copying normal mode langevin plugin for testing (WIN32)")
else(MSVC)
get_target_property(old_loc NormalModeLangevin LOCATION)
get_filename_component(new_loc ${old_loc} NAME)
set(new_loc "${test_plugin_dir}/${new_loc}")
add_custom_command(
DEPENDS ${old_loc} NormalModeLangevin
OUTPUT ${new_loc}
COMMAND ${CMAKE_COMMAND} -E copy ${old_loc} ${new_loc})
add_custom_target(CopyTestNmlPlugin ALL
DEPENDS "${new_loc}"
COMMENT "Copying normal mode langevin plugin for testing")
endif(MSVC)
add_subdirectory(test) add_subdirectory(test)
endif(BUILD_TESTING) endif(BUILD_TESTING)
......
...@@ -48,4 +48,3 @@ public: ...@@ -48,4 +48,3 @@ public:
} // namespace OpenMM } // namespace OpenMM
#endif /*OPENMM_REFERENCE_NMLKERNELFACTORY_H_*/ #endif /*OPENMM_REFERENCE_NMLKERNELFACTORY_H_*/
...@@ -35,15 +35,14 @@ ...@@ -35,15 +35,14 @@
using namespace OpenMM; using namespace OpenMM;
using namespace std; using namespace std;
extern "C" void registerPlatforms() { extern "C" void OPENMM_EXPORT registerPlatforms() {
cout << "calling NML registerPlatforms()..." << endl; cout << "calling NML registerPlatforms()..." << endl;
} }
extern "C" void registerKernelFactories() { extern "C" void OPENMM_EXPORT registerKernelFactories() {
cout << "Initializing Normal Mode Langevin OpenMM plugin..." << endl; cout << "Initializing Normal Mode Langevin OpenMM plugin..." << endl;
for (int p = 0; p < Platform::getNumPlatforms(); ++p) { for (int p = 0; p < Platform::getNumPlatforms(); ++p) {
cout << "Plugin number " << p << endl;
cout << "Platform " << p << " name = " << Platform::getPlatform(p).getName() << endl; cout << "Platform " << p << " name = " << Platform::getPlatform(p).getName() << endl;
} }
...@@ -54,13 +53,15 @@ extern "C" void registerKernelFactories() { ...@@ -54,13 +53,15 @@ extern "C" void registerKernelFactories() {
cout << "NML found Cuda platform..." << endl; cout << "NML found Cuda platform..." << endl;
// platform.registerKernelFactory("CudaNMLKernelFactory", new CudaNMLKernelFactory()); // platform.registerKernelFactory("CudaNMLKernelFactory", new CudaNMLKernelFactory());
} catch (const std::exception& exc) { // non fatal } catch (const std::exception& exc) { // non fatal
cout << "NML Cuda platform not found. " << exc.what() << endl;
} }
cout << "NML looking for Reference plugin..." << endl; cout << "NML looking for Reference plugin..." << endl;
try { try {
Platform& platform = Platform::getPlatformByName("Reference"); Platform& platform = Platform::getPlatformByName("Reference");
cout << "NML found Reference platform..." << endl; cout << "NML found Reference platform..." << endl;
platform.registerKernelFactory("ReferenceNMLKernelFactory", new ReferenceNMLKernelFactory()); ReferenceNMLKernelFactory* factory = new ReferenceNMLKernelFactory();
platform.registerKernelFactory("IntegrateNMLStep", factory);
} catch (const std::exception& exc) { // non fatal } catch (const std::exception& exc) { // non fatal
cout << "NML Reference platform not found. " << exc.what() << endl; cout << "NML Reference platform not found. " << exc.what() << endl;
} }
......
# Copy plugin to test_plugin_dir
set(test_plugin_dir "${CMAKE_BINARY_DIR}/test_plugin_dir")
file(MAKE_DIRECTORY "${test_plugin_dir}")
get_target_property(old_loc NormalModeLangevin LOCATION)
get_filename_component(new_loc ${old_loc} NAME)
set(new_loc "${test_plugin_dir}/${new_loc}")
add_custom_command(
DEPENDS ${old_loc} NormalModeLangevin
OUTPUT ${new_loc}
COMMAND ${CMAKE_COMMAND} -E copy ${old_loc} ${new_loc})
add_custom_target(CopyTestNmlPlugin ALL
DEPENDS "${new_loc}"
COMMENT "Copying normal mode langevin plugin for testing")
add_executable(TestNormalModeLangevin TestNormalModeLangevin.cpp) add_executable(TestNormalModeLangevin TestNormalModeLangevin.cpp)
target_link_libraries(TestNormalModeLangevin ${SHARED_TARGET}) target_link_libraries(TestNormalModeLangevin ${SHARED_TARGET})
...@@ -24,4 +10,3 @@ add_test(TestNormalModeLangevin ...@@ -24,4 +10,3 @@ add_test(TestNormalModeLangevin
# does not work - nice try - maybe in cmake 2.8 # does not work - nice try - maybe in cmake 2.8
set_tests_properties(TestNormalModeLangevin PROPERTIES set_tests_properties(TestNormalModeLangevin PROPERTIES
ENVIRONMENT "OPENMM_PLUGIN_DIR=${test_plugin_dir}") ENVIRONMENT "OPENMM_PLUGIN_DIR=${test_plugin_dir}")
...@@ -22,10 +22,16 @@ void testLoadNMLPlugin() ...@@ -22,10 +22,16 @@ void testLoadNMLPlugin()
string pluginDir = Platform::getDefaultPluginsDirectory(); string pluginDir = Platform::getDefaultPluginsDirectory();
cout << "Default plugins directory = " << pluginDir << endl; cout << "Default plugins directory = " << pluginDir << endl;
Platform::loadPluginsFromDirectory(pluginDir); Platform::loadPluginsFromDirectory(pluginDir);
// Create a context, just to initialize all plugins
System system;
VerletIntegrator integrator(0.01);
Context context(system, integrator);
// Was NormalModeLangevin plugin loaded?
vector<string> kernelName; vector<string> kernelName;
kernelName.push_back("IntegrateNMLStep"); kernelName.push_back("IntegrateNMLStep");
// Was NormalModeLangevin plugin loaded? cout << "Searching for kernel IntegrateNMLStep" << endl;
cout << "Searching for kernel IntegrateNMLStep = " << pluginDir << endl;
Platform& platform = Platform::findPlatform(kernelName); // throws if no platform with kernel Platform& platform = Platform::findPlatform(kernelName); // throws if no platform with kernel
} }
...@@ -33,9 +39,9 @@ int main(int argc, const char* argv[]) ...@@ -33,9 +39,9 @@ int main(int argc, const char* argv[])
{ {
try try
{ {
// Set OPENMM_PLUGIN_DIR from first command line argument
if (argc > 1) { if (argc > 1) {
const char* plugin_dir = argv[1]; const char* plugin_dir = argv[1];
// 0 => don't set if variable exists
mysetenv("OPENMM_PLUGIN_DIR", plugin_dir); mysetenv("OPENMM_PLUGIN_DIR", plugin_dir);
cout << plugin_dir << endl; cout << plugin_dir << endl;
cout << getenv("OPENMM_PLUGIN_DIR") << endl; cout << getenv("OPENMM_PLUGIN_DIR") << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment