Fix mdrun integration tests
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 13 Dec 2013 10:04:14 +0000 (21:04 +1100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Mon, 13 Jan 2014 16:51:18 +0000 (17:51 +0100)
Earlier code forced callMdrun() to trigger an mdrun -rerun, which was
not intended. Fixed that, and opened a path for code to use the
defaults of callMdrun(), but set up the executable name and prepend
command-line arguments to suit itself.

Ideally, the configurability would be more general, and there would
not be the requirement to specify the executable name, but so far this
is not a problem.

Change-Id: Id69927f9153a400455b728db577537ebc155d0af

src/programs/mdrun/tests/moduletest.cpp
src/programs/mdrun/tests/moduletest.h
src/programs/mdrun/tests/rerun.cpp

index aae01affc6b8e6d2476c72a6b4a5b0d8aaa57847..c9ef7cbb09b3243f81c8de675e7062332250d2d4 100644 (file)
@@ -155,13 +155,14 @@ MdrunTestFixture::callGrompp()
 }
 
 int
-MdrunTestFixture::callMdrun()
+MdrunTestFixture::callMdrun(const CommandLine &callerRef)
 {
-    CommandLine caller;
-    caller.append("mdrun");
-
+    /* Conforming to style guide by not passing a non-const reference
+       to this function. Passing a non-const reference might make it
+       easier to write code that incorrectly re-uses callerRef after
+       the call to this function. */
+    CommandLine caller(callerRef);
     caller.addOption("-s", tprFileName);
-    caller.addOption("-rerun", rerunFileName);
 
     caller.addOption("-g", logFileName);
     caller.addOption("-e", edrFileName);
@@ -178,5 +179,13 @@ MdrunTestFixture::callMdrun()
     return gmx_mdrun(caller.argc(), caller.argv());
 }
 
+int
+MdrunTestFixture::callMdrun()
+{
+    CommandLine caller;
+    caller.append("mdrun");
+    return callMdrun(caller);
+}
+
 } // namespace test
 } // namespace gmx
index 69fce84eba414fcce15bc6bf08748c73fc1debff..51978257566592c3f4f7ff9dac6e51497a5bc8f0 100644 (file)
@@ -43,6 +43,7 @@
 #include "testutils/integrationtests.h"
 
 #include <gtest/gtest.h>
+#include "testutils/cmdlinetest.h"
 
 namespace gmx
 {
@@ -94,7 +95,12 @@ class MdrunTestFixture : public IntegrationTestFixture
         void useTopAndGroFromDatabase(const char *name);
         //! Calls grompp to prepare for the mdrun test
         int callGrompp();
-        //! Calls mdrun for testing
+        //! Calls grompp (on this rank) to prepare for the mdrun test
+        int callGromppOnThisRank();
+        //! Calls mdrun for testing with a customized command line
+        int callMdrun(const CommandLine &callerRef);
+        /*! \brief Convenience wrapper for calling mdrun for testing
+         * with default command line */
         int callMdrun();
 
         //@{
@@ -112,7 +118,6 @@ class MdrunTestFixture : public IntegrationTestFixture
         std::string groFileName;
         std::string trrFileName;
         std::string xtcFileName;
-        std::string rerunFileName;
         std::string mdpInputFileName;
         std::string mdpOutputFileName;
         std::string tprFileName;
index b8ad5e202c6e2541a074e4d4528afcc46129995c..f386ee6810d899eefef4540b61cd91f0227552de 100644 (file)
@@ -43,6 +43,7 @@
 #include <gtest/gtest.h>
 #include "moduletest.h"
 #include "gromacs/options/filenameoption.h"
+#include "testutils/cmdlinetest.h"
 
 namespace
 {
@@ -57,8 +58,12 @@ TEST_F(RerunTest, RerunExitsNormally)
     useTopAndGroFromDatabase("spc2");
     EXPECT_EQ(0, callGrompp());
 
-    rerunFileName = fileManager_.getInputFilePath("spc2.trr");
-    ASSERT_EQ(0, callMdrun());
+    std::string rerunFileName = fileManager_.getInputFilePath("spc2.trr");
+
+    ::gmx::test::CommandLine rerunCaller;
+    rerunCaller.append("mdrun");
+    rerunCaller.addOption("-rerun", rerunFileName);
+    ASSERT_EQ(0, callMdrun(rerunCaller));
 }
 
 /*! \todo Add other tests for mdrun -rerun, e.g.