Refactor mdrun integration tests
[alexxy/gromacs.git] / src / programs / mdrun / tests / moduletest.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \libinternal
36  * \defgroup module_mdrun_integration_tests Integration test utilities
37  * \ingroup group_mdrun
38  *
39  * \brief Functionality for testing mdrun as a whole
40  */
41 #ifndef GMX_MDRUN_TESTS_MODULETEST_H
42 #define GMX_MDRUN_TESTS_MODULETEST_H
43
44 #include <gtest/gtest.h>
45
46 #include "testutils/cmdlinetest.h"
47 #include "testutils/integrationtests.h"
48
49 namespace gmx
50 {
51
52 namespace test
53 {
54
55 /*! \libinternal \brief Helper object for running grompp and mdrun in
56  * integration tests of mdrun functionality
57  *
58  * Objects of this class are intended to be owned by
59  * IntegrationTestFixture objects, and an IntegrationTestFixture
60  * object might own more than one SimulationRunner.
61  *
62  * The setup phase creates various temporary files for input and
63  * output that are common for mdrun tests, using the file manager
64  * object of the fixture that owns this object. Individual tests
65  * should create any extra filenames similarly, so that the test
66  * users's current working directory does not get littered with files
67  * left over from tests.
68  *
69  * Any method in this class may throw std::bad_alloc if out of memory.
70  *
71  * \ingroup module_mdrun_integration_tests
72  */
73 class SimulationRunner
74 {
75     public:
76         /*! \brief Constructor, which establishes the fixture that
77          * will own each object */
78         explicit SimulationRunner(IntegrationTestFixture *fixture_);
79
80         //! Use an empty .mdp file as input to grompp
81         void useEmptyMdpFile();
82         //! Use a given string as input to grompp
83         void useStringAsMdpFile(const char *mdpString);
84         //! Use a given string as input to grompp
85         void useStringAsMdpFile(const std::string &mdpString);
86         //! Use a string as -n input to grompp
87         void useStringAsNdxFile(const char *ndxString);
88         //! Use a standard .top and .gro file as input to grompp
89         void useTopGroAndNdxFromDatabase(const char *name);
90         //! Calls grompp (on rank 0) to prepare for the mdrun test
91         int callGrompp();
92         //! Calls grompp (on this rank) to prepare for the mdrun test
93         int callGromppOnThisRank();
94         //! Calls mdrun for testing with a customized command line
95         int callMdrun(const CommandLine &callerRef);
96         /*! \brief Convenience wrapper for calling mdrun for testing
97          * with default command line */
98         int callMdrun();
99
100     private:
101         //! Provides access to the test fixture, e.g. for the TestFileManager
102         IntegrationTestFixture *fixture_;
103     public:
104         //@{
105         /*! \name Names for frequently used grompp and mdrun output files
106          *
107          * These strings can be set to point to files present in the
108          * source tree, or to temporary files created for the test
109          * fixture. In the latter case,
110          * IntegrationTestFixture::fileManager_ should be used to fill
111          * these strings with paths to files, so that they are created
112          * in a temporary directory and (by default behaviour of
113          * TestFileManager) deleted when the test is complete.
114          */
115         std::string topFileName_;
116         std::string groFileName_;
117         std::string fullPrecisionTrajectoryFileName_;
118         std::string reducedPrecisionTrajectoryFileName_;
119         std::string groOutputFileName_;
120         std::string ndxFileName_;
121         std::string mdpInputFileName_;
122         std::string mdpOutputFileName_;
123         std::string tprFileName_;
124         std::string logFileName_;
125         std::string edrFileName_;
126         std::string cptFileName_;
127         std::string swapFileName_;
128         int         nsteps_;
129         //@}
130 };
131
132 /*! \libinternal \brief Declares test fixture base class for
133  * integration tests of mdrun functionality
134  *
135  * Derived fixture classes (or individual test cases) that might have
136  * specific requirements should assert that behaviour, rather than
137  * hard-code the requirements. A test that (for example) can't run
138  * with more than one thread should report that as a diagnostic, so the
139  * person running the test (or designing the test harness) can get
140  * feedback on what tests need what conditions without having to read
141  * the code of lots of tests.
142  *
143  * Specifying the execution context (such as numbers of threads and
144  * processors) is normally sensible to specify from the test harness
145  * (i.e. when CMake/CTest/the user runs a test executable), because
146  * only there is information about the hardware available. The default
147  * values for such context provided in test fixtures for mdrun should
148  * mirror the defaults for mdrun, but currently mdrun.c hard-codes
149  * those in a gmx_hw_opt_t.
150  *
151  * Any method in this class may throw std::bad_alloc if out of memory.
152  *
153  * \ingroup module_mdrun_integration_tests
154  */
155 class MdrunTestFixtureBase : public IntegrationTestFixture
156 {
157     public:
158         MdrunTestFixtureBase();
159         virtual ~MdrunTestFixtureBase();
160 };
161
162 /*! \libinternal \brief Declares test fixture class for integration
163  * tests of mdrun functionality that use a single call of mdrun
164  *
165  * Any method in this class may throw std::bad_alloc if out of memory.
166  *
167  * \ingroup module_mdrun_integration_tests
168  */
169 class MdrunTestFixture : public IntegrationTestFixture
170 {
171     public:
172         MdrunTestFixture();
173         virtual ~MdrunTestFixture();
174
175         //! Helper object to manage the preparation for and call of mdrun
176         SimulationRunner runner_;
177 };
178
179 /*! \libinternal \brief
180  * Parameterized test fixture for mdrun integration tests
181  */
182 class ParameterizedMdrunTestFixture : public gmx::test::MdrunTestFixture,
183                                       public ::testing::WithParamInterface<const char *>
184 {
185 };
186
187 } // namespace test
188 } // namespace gmx
189
190 #endif