Disable report-methods end-to-end test
[gromacs.git] / src / gromacs / tools / tests / report_methods.cpp
blobaae1e2c77930db10e93c7d711dd3d7225bc438a9
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019, 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.
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.
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.
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.
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.
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.
35 /*! \internal \file
36 * \brief
37 * Tests for functionality of the "report" tool to write system information.
39 * \author
41 #include "gmxpre.h"
43 #include "gromacs/tools/report_methods.h"
45 #include "gromacs/fileio/tpxio.h"
46 #include "gromacs/gmxpreprocess/grompp.h"
47 #include "gromacs/mdtypes/state.h"
48 #include "gromacs/utility/exceptions.h"
49 #include "gromacs/utility/stringstream.h"
50 #include "gromacs/utility/textwriter.h"
52 #include "testutils/cmdlinetest.h"
53 #include "testutils/refdata.h"
54 #include "testutils/testfilemanager.h"
55 #include "testutils/textblockmatchers.h"
57 namespace gmx
60 namespace test
63 namespace
66 /*! \brief
67 * Generates a tpr for the test.
69 * Generates the tpr from a sample pdb file using grompp,and returns the path
70 * to the file as std::string for reading it in later.
72 * \param[in] fileManager Filemanager to keep track of the input file.
73 * \param[in] filename Basename of the input and output files.
75 std::string generateTprInput(TestFileManager *fileManager, const std::string &filename)
77 // generate temporary tpr file from test system
78 const std::string mdpInputFileName = fileManager->getTemporaryFilePath(filename + ".mdp");
79 TextWriter::writeFileFromString(mdpInputFileName, "");
80 std::string tprName = fileManager->getTemporaryFilePath(filename + ".tpr");
82 CommandLine caller;
83 caller.append("grompp");
84 caller.addOption("-f", mdpInputFileName);
85 caller.addOption("-p", TestFileManager::getInputFilePath(filename + ".top"));
86 caller.addOption("-c", TestFileManager::getInputFilePath(filename + ".pdb"));
87 caller.addOption("-o", tprName);
88 EXPECT_EQ(0, gmx_grompp(caller.argc(), caller.argv()));
90 return tprName;
93 /*! \brief
94 * Generates and reads a tpr for the test.
96 * Generates a tpr from a sample pdb file using grompp, and reads it in to
97 * have access to the system information for print out.
99 * \param[in] filename Basename of the input and output files.
100 * \param[in] mtop Pointer to topology datastructure to populate.
101 * \param[in] ir Pointer to inputrec to populate.
103 void generateAndReadTprInput(const std::string &filename, gmx_mtop_t *mtop, t_inputrec *ir)
105 TestFileManager fileManager;
106 std::string tprName = generateTprInput(&fileManager, filename);
107 // read tpr into variables needed for output
109 t_state state;
110 read_tpx_state(tprName.c_str(), ir, &state, mtop);
114 TEST(ReportMethodsTest, WritesCorrectHeadersFormated)
116 gmx::StringOutputStream stream;
117 gmx::TextWriter test(&stream);
118 writeHeader(&test, "Test", "Test", true);
120 std::string referenceString = "\\Test{Test}\n";
122 EXPECT_EQ(stream.toString(), referenceString);
124 TEST(ReportMethodsTest, WritesCorrectHeadersUnformatted)
126 gmx::StringOutputStream stream;
127 gmx::TextWriter test(&stream);
128 writeHeader(&test, "Test", "Test", false);
130 std::string referenceString = "Test: Test\n";
132 EXPECT_EQ(stream.toString(), referenceString);
135 TEST(ReportMethodsTest, WritesCorrectInformation)
137 gmx_mtop_t top;
138 t_inputrec ir;
139 EXPECT_NO_THROW(generateAndReadTprInput("lysozyme", &top, &ir));
141 // Test both formatted and unformatted output in the same test
143 gmx::StringOutputStream stream;
144 gmx::TextWriter test(&stream);
146 writeSystemInformation(&test, top, true);
148 std::string referenceString = "\\subsection{Simulation system}\n"
149 "A system of 1 molecules (156 atoms) was simulated.\n";
151 EXPECT_EQ(stream.toString(), referenceString);
155 gmx::StringOutputStream stream;
156 gmx::TextWriter test(&stream);
158 writeSystemInformation(&test, top, false);
160 std::string referenceString = "subsection: Simulation system\n"
161 "A system of 1 molecules (156 atoms) was simulated.\n";
163 EXPECT_EQ(stream.toString(), referenceString);
166 // Test for correct parameter information as well
168 gmx::StringOutputStream stream;
169 gmx::TextWriter test(&stream);
171 writeParameterInformation(&test, ir, true);
173 std::string referenceString = "\\subsection{Simulation settings}\n"
174 "A total of 0 ns were simulated with a time step of 1 fs.\n"
175 "Neighbor searching was performed every 10 steps.\n"
176 "The Cut-off algorithm was used for electrostatic interactions.\n"
177 "with a cut-off of 1 nm.\nA single cut-off of 1.1 nm was used "
178 "for Van der Waals interactions.\n";
180 EXPECT_EQ(stream.toString(), referenceString);
184 // This test sometimes fails for reasons that are not understood, see
185 // Redmine #3804.
186 TEST(ReportMethodsTest, DISABLED_ToolEndToEndTest)
188 TestFileManager fileManager;
189 std::string tprName = generateTprInput(&fileManager, "lysozyme");
190 const char *const command[] = {
191 "report-methods", "-s", tprName.c_str()
193 CommandLine cmdline(command);
194 EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(
195 &gmx::ReportMethodsInfo::create, &cmdline));
199 } // namespace
201 } // namespace test
203 } // namespace gmx