Add global directory for simulation test inputs
authorPaul Bauer <paul.bauer.q@gmail.com>
Tue, 6 Nov 2018 16:06:24 +0000 (17:06 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 7 Nov 2018 11:55:00 +0000 (12:55 +0100)
Adds the ability to testfilemanager to use input files from a global
defined directory that is set at CMake time and contains the input files
for tpr file generation in the tests.

When a file is not found in the current directory, the code searches
the global archive for it and finally falls back to the current
directory if no file extension was given.

Example case is given for the tool test that needs a pdb and a top file.

Change-Id: Ic94f4a4d0d451024b435bf2900360aa60cd01b11

src/buildinfo.h.cmakein
src/gromacs/tools/tests/report-methods.cpp
src/testutils/simulationdatabase/lysozyme.pdb [moved from src/gromacs/tools/tests/lysozyme.pdb with 100% similarity]
src/testutils/simulationdatabase/lysozyme.top [moved from src/gromacs/tools/tests/lysozyme.top with 100% similarity]
src/testutils/testfilemanager.cpp
src/testutils/testfilemanager.h
src/testutils/testinit.cpp
src/testutils/testinit.h

index c58bb6ded9797fd7d3283140a464e653867b1cc6..a6f63b07a1fd98afaeba760fa2e01c5805763746 100644 (file)
@@ -57,6 +57,9 @@
 /** Source directory for the build */
 #define CMAKE_SOURCE_DIR        "@CMAKE_SOURCE_DIR@"
 
+/** Directory for test input files */
+#define GMX_TESTSIMULATIONDATABASE_DIR  "@CMAKE_SOURCE_DIR@/src/testutils/simulationdatabase"
+
 /** Binary directory for the build */
 #define CMAKE_BINARY_DIR        "@CMAKE_BINARY_DIR@"
 
index 2afb204d987905c5c81fcf4b6239f9cba47398cd..d84fb3328be1e646dec5ecfd1c08cf80ddae940b 100644 (file)
@@ -82,7 +82,7 @@ std::string generateTprInput(TestFileManager *fileManager, const std::string &fi
         CommandLine caller;
         caller.append("grompp");
         caller.addOption("-f", mdpInputFileName);
-        caller.addOption("-p", TestFileManager::getInputFilePath(filename));
+        caller.addOption("-p", TestFileManager::getInputFilePath(filename + ".top"));
         caller.addOption("-c", TestFileManager::getInputFilePath(filename + ".pdb"));
         caller.addOption("-o", tprName);
         EXPECT_EQ(0, gmx_grompp(caller.argc(), caller.argv()));
index 3e024f55731f5acaf7a8574ddd7038466b934d65..8e83635dc9fadaa0fccd98f4023e8600d9b99472 100644 (file)
@@ -78,6 +78,9 @@ class TestFileManager::Impl
         //! Global test input data path set with setDataInputDirectory().
         static std::string s_inputDirectory;
 
+        //! Global path to simulation input database set with setTestSimulationDataBaseDirectory().
+        static std::string s_simulationDatabaseDirectory;
+
         //! Global temporary output directory for tests, set with setGlobalOutputTempDirectory().
         static const char *s_globalOutputTempDirectory;
 
@@ -112,6 +115,7 @@ class TestFileManager::Impl
 };
 
 std::string TestFileManager::Impl::s_inputDirectory;
+std::string TestFileManager::Impl::s_simulationDatabaseDirectory;
 const char *TestFileManager::Impl::s_globalOutputTempDirectory = nullptr;
 /** Controls whether TestFileManager should delete temporary files
     after the test finishes. */
@@ -195,7 +199,21 @@ std::string TestFileManager::getTestSpecificFileName(const char *suffix)
 
 std::string TestFileManager::getInputFilePath(const char *filename)
 {
-    return Path::join(getInputDataDirectory(), filename);
+    // Check if file is present in local directory.
+    if (File::exists(Path::join(getInputDataDirectory(), filename), File::returnFalseOnError))
+    {
+        return Path::join(getInputDataDirectory(), filename);
+    }
+    else if (File::exists(Path::join(getTestSimulationDatabaseDirectory(), filename), File::returnFalseOnError))
+    {
+        // Assume file is in global directory for simulation input files.
+        return Path::join(getTestSimulationDatabaseDirectory(), filename);
+    }
+    else
+    {
+        // Assume file is present locally without full name (e.g. extension).
+        return Path::join(getInputDataDirectory(), filename);
+    }
 }
 
 std::string TestFileManager::getInputFilePath(const std::string &filename)
@@ -220,6 +238,12 @@ const char *TestFileManager::getOutputTempDirectory() const
     return impl_->outputTempDirectory_.c_str();
 }
 
+const char *TestFileManager::getTestSimulationDatabaseDirectory()
+{
+    GMX_RELEASE_ASSERT(!Impl::s_simulationDatabaseDirectory.empty(), "Path for simulation input database directory is not set");
+    return Impl::s_simulationDatabaseDirectory.c_str();
+}
+
 void TestFileManager::setInputDataDirectory(const std::string &path)
 {
     // There is no need to protect this by a mutex, as this is called in early
@@ -229,6 +253,15 @@ void TestFileManager::setInputDataDirectory(const std::string &path)
     Impl::s_inputDirectory = path;
 }
 
+void TestFileManager::setTestSimulationDatabaseDirectory(const std::string &path)
+{
+    // There is no need to protect this by a mutex, as this is called in early
+    // initialization of the tests.
+    GMX_RELEASE_ASSERT(Directory::exists(path),
+                       "Simulation database directory does not exist");
+    Impl::s_simulationDatabaseDirectory = path;
+}
+
 void TestFileManager::setGlobalOutputTempDirectory(const char *path)
 {
     // There is no need to protect this by a mutex, as this is called in early
index 591af38c9fc593d5f1c5adf9a9f1d656815a5e77..07e8cea987a76200f71441d1529422e863d88250 100644 (file)
@@ -74,7 +74,7 @@ namespace test
  * This is used to provide input files for the tests, and also to
  * store test reference data persistently (see TestReferenceData).
  *
- * Note that setInputDataDirectory() and
+ * Note that setInputDataDirectory(), setTestSimulationDataBaseDirectory() and
  * setGlobalOutputTempDirectory() must be called in setup code, before
  * creating any objects of this class that are used for accessing the
  * paths for these respective directories. Code in tests should avoid
@@ -172,6 +172,13 @@ class TestFileManager
         //! \copydoc TestFileManager::getInputFilePath(const char *)
         static std::string getInputFilePath(const std::string &filename);
 
+        /*! \brief
+         * Returns the path to the simulation input database directory.
+         *
+         * \returns Path to simulation input database directory.
+         */
+        static const char *getTestSimulationDatabaseDirectory();
+
         /*! \brief
          * Returns the path to the test input directory.
          *
@@ -191,6 +198,18 @@ class TestFileManager
          */
         static void setInputDataDirectory(const std::string &path);
 
+        /*! \brief
+         * Sets the input directory for simulation input files.
+         *
+         * \param[in] path Path to look up the directory for simulation input files.
+         *
+         * \p path must name an exisitng directory.
+         *
+         * This function is automatically called by unittest_main.cpp through
+         * initTestUtils().
+         */
+        static void setTestSimulationDatabaseDirectory(const std::string &path);
+
         /*! \brief Returns the path to the global test output
          * temporary directory for future TestFileManager objects.
          *
index ed71926fff1957d7b2f19064b02aecc6dddb22f9..3b33c1e883917982f02132ee905932f9b810bd85 100644 (file)
@@ -203,6 +203,9 @@ void initTestUtils(const char *dataPath, const char *tempPath, bool usesMpi,
         {
             TestFileManager::setGlobalOutputTempDirectory(tempPath);
         }
+        TestFileManager::setTestSimulationDatabaseDirectory(
+                GMX_TESTSIMULATIONDATABASE_DIR);
+
         bool        bHelp = false;
         std::string sourceRoot;
         Options     options;
index 3842434f4979d8ec16ae74f72c6ede7988b9f111..8cbe43c54224bd318a6a4cb4fb9017aefa17a0b0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -58,6 +58,13 @@ namespace test
  *
  * This function is automatically called by unittest_main.cpp.
  *
+ * \param[in] dataPath Filepath to input files.
+ * \param[in] tempPath Filepath to temporary files.
+ * \param[in] usesMpi  If the test is run with MPI or not.
+ * \param[in] usesHardwareDetection If hardwaredetection is enabled.
+ * \param[in] argc Number of cmdline options
+ * \param[in] argv Cmdline options.
+ *
  * \ingroup module_testutils
  */
 void initTestUtils(const char *dataPath, const char *tempPath, bool usesMpi,