clang-tidy: google tests applicable
[alexxy/gromacs.git] / src / programs / mdrun / tests / multisim.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2013,2014,2015,2016,2018, 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
36 /*! \internal \file
37  * \brief
38  * Tests for the mdrun multi-simulation functionality
39  *
40  * \author Mark Abraham <mark.j.abraham@gmail.com>
41  * \ingroup module_mdrun_integration_tests
42  */
43 #include "gmxpre.h"
44
45 #include "config.h"
46
47 #include <gtest/gtest.h>
48
49 #include "multisimtest.h"
50
51 namespace gmx
52 {
53 namespace test
54 {
55
56 /* This test ensures mdrun can run multi-simulations.  It runs one
57  * simulation per MPI rank.
58  *
59  * TODO Preferably, we could test that mdrun correctly refuses to run
60  * multi-simulation unless compiled with real MPI with more than one
61  * rank available. However, if we just call mdrun blindly, those cases
62  * trigger an error that is currently fatal to mdrun and also to the
63  * test binary. So, in the meantime we must not test those cases. If
64  * there is no MPI, we disable the test, so that there is a reminder
65  * that it is disabled. There's no elegant way to conditionally
66  * disable a test at run time, so currently there is no feedback if
67  * only one rank is available. However, the test harness knows to run
68  * this test with more than one rank.
69  *
70  * Strictly, this test does not need to be parameterized, but
71  * conditionally disabling it with respect to GMX_LIB_MPI is easier if
72  * it is parameterized. */
73 TEST_P(MultiSimTest, ExitsNormally)
74 {
75     runExitsNormallyTest();
76 }
77
78 TEST_P(MultiSimTest, ExitsNormallyWithDifferentNumbersOfStepsPerSimulation)
79 {
80     if (size_ <= 1)
81     {
82         /* Can't test multi-sim without multiple ranks. */
83         return;
84     }
85     SimulationRunner runner(&fileManager_);
86     runner.useTopGroAndNdxFromDatabase("spc2");
87
88     const char *pcoupl = GetParam();
89     // Do some different small numbers of steps in each simulation
90     int         numSteps = rank_ % 4;
91     organizeMdpFile(&runner, pcoupl, numSteps);
92     /* Call grompp on every rank - the standard callGrompp() only runs
93        grompp on rank 0. */
94     EXPECT_EQ(0, runner.callGromppOnThisRank());
95
96     ASSERT_EQ(0, runner.callMdrun(*mdrunCaller_));
97 }
98
99 /* Note, not all preprocessor implementations nest macro expansions
100    the same way / at all, if we would try to duplicate less code. */
101 #if GMX_LIB_MPI
102 INSTANTIATE_TEST_CASE_P(InNvt, MultiSimTest,
103                             ::testing::Values("pcoupl = no"));
104 #else
105 // Test needs real MPI to run
106 INSTANTIATE_TEST_CASE_P(DISABLED_InNvt, MultiSimTest,
107                             ::testing::Values("pcoupl = no"));
108 #endif
109
110 //! Convenience typedef
111 typedef MultiSimTest MultiSimTerminationTest;
112
113 TEST_F(MultiSimTerminationTest, WritesCheckpointAfterMaxhTerminationAndThenRestarts)
114 {
115     runMaxhTest();
116 }
117
118 }  // namespace test
119 }  // namespace gmx