Merge commit d30f2cb6 from release-2020 into master
[alexxy/gromacs.git] / src / programs / mdrun / tests / outputfiles.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020, 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  * Checks that expected output files are present
39  *
40  * \author Pascal Merz <pascal.merz@me.com>
41  * \ingroup module_mdrun_integration_tests
42  */
43
44 #include "gmxpre.h"
45
46 #include "gromacs/utility/path.h"
47 #include "gromacs/utility/stringutil.h"
48
49 #include "testutils/simulationdatabase.h"
50
51 #include "moduletest.h"
52
53 namespace gmx
54 {
55 namespace test
56 {
57 namespace
58 {
59
60 /*! \brief Test fixture base for presence of output files
61  *
62  * This test checks that some expected output files are actually written
63  * in a very simple mdrun call. Currently, it tests for the presence of
64  * full precision trajectory (.trr), log file (.log), energy trajectory (.edr),
65  * final configuration (.gro) and checkpoint file (.cpt).
66  *
67  * The test only checks whether the files are existing, it does not check
68  * their contents.
69  */
70 using OutputFilesTestParams = std::tuple<std::string, std::string>;
71 class OutputFiles : public MdrunTestFixture, public ::testing::WithParamInterface<OutputFilesTestParams>
72 {
73 };
74
75 TEST_P(OutputFiles, FilesArePresent)
76 {
77     auto params         = GetParam();
78     auto simulationName = std::get<0>(params);
79     auto integrator     = std::get<1>(params);
80
81     SCOPED_TRACE(
82             formatString("Checking for presence of expected output files using "
83                          "simulation '%s' with integrator '%s'",
84                          simulationName.c_str(), integrator.c_str()));
85
86     // Prepare the .tpr file
87     {
88         CommandLine caller;
89         runner_.useTopGroAndNdxFromDatabase(simulationName);
90         runner_.useStringAsMdpFile(prepareMdpFileContents(
91                 prepareMdpFieldValues(simulationName.c_str(), integrator.c_str(), "no", "no")));
92         EXPECT_EQ(0, runner_.callGrompp(caller));
93     }
94     // Do mdrun
95     {
96         CommandLine mdrunCaller;
97         ASSERT_EQ(0, runner_.callMdrun(mdrunCaller));
98     }
99     // Check if expected files are present
100     {
101         for (const auto& file : { runner_.fullPrecisionTrajectoryFileName_, runner_.logFileName_,
102                                   runner_.edrFileName_, fileManager_.getTemporaryFilePath("state.gro"),
103                                   fileManager_.getTemporaryFilePath("state.cpt") })
104         {
105             EXPECT_TRUE(File::exists(file, File::returnFalseOnError))
106                     << "File " << file << " was not found.";
107         }
108     }
109 }
110
111 INSTANTIATE_TEST_CASE_P(Argon12,
112                         OutputFiles,
113                         ::testing::Combine(::testing::Values("argon12"),
114                                            ::testing::Values("md", "md-vv")));
115
116 } // namespace
117 } // namespace test
118 } // namespace gmx