From: Berk Hess Date: Tue, 21 Sep 2021 10:39:28 +0000 (+0000) Subject: Expanded the GetIrTest behavior to enable efficient testing X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=21a96e1d8669fbd4ae27101e9beb0c33a6eced5a;p=alexxy%2Fgromacs.git Expanded the GetIrTest behavior to enable efficient testing --- diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 28b4184f14..1286c79bf7 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -2482,6 +2482,7 @@ void get_ir(const char* mdparin, ir->userreal4 = get_ereal(&inp, "userreal4", 0, wi); #undef CTYPE + if (mdparout) { gmx::TextOutputFile stream(mdparout); write_inpfile(&stream, mdparout, &inp, FALSE, writeMdpHeader, wi); diff --git a/src/gromacs/gmxpreprocess/tests/readir.cpp b/src/gromacs/gmxpreprocess/tests/readir.cpp index af1b9b967a..de21db7179 100644 --- a/src/gromacs/gmxpreprocess/tests/readir.cpp +++ b/src/gromacs/gmxpreprocess/tests/readir.cpp @@ -82,30 +82,58 @@ public: sfree(opts_.include); sfree(opts_.define); } + + //! Tells whether warnings and/or errors are expected from inputrec parsing and checking, and whether we should compare the output + enum class TestBehavior + { + NoErrorAndCompareOutput, //!< Expect no warnings/error and compare output + ErrorAndCompareOutput, //!< Expect at least one warning/error and compare output + ErrorAndDoNotCompareOutput //!< Expect at least one warning/error and do not compare output + }; + /*! \brief Test mdp reading and writing * * \todo Modernize read_inp and write_inp to use streams, * which will make these tests run faster, because they don't * use disk files. */ - void runTest(const std::string& inputMdpFileContents) + void runTest(const std::string& inputMdpFileContents, + const TestBehavior testBehavior = TestBehavior::NoErrorAndCompareOutput) { - auto inputMdpFilename = fileManager_.getTemporaryFilePath("input.mdp"); - auto outputMdpFilename = fileManager_.getTemporaryFilePath("output.mdp"); + const bool expectError = testBehavior != TestBehavior::NoErrorAndCompareOutput; + const bool compareOutput = testBehavior != TestBehavior::ErrorAndDoNotCompareOutput; + + std::string inputMdpFilename = fileManager_.getTemporaryFilePath("input.mdp"); + std::string outputMdpFilename; + if (compareOutput) + { + outputMdpFilename = fileManager_.getTemporaryFilePath("output.mdp"); + } TextWriter::writeFileFromString(inputMdpFilename, inputMdpFileContents); - get_ir(inputMdpFilename.c_str(), outputMdpFilename.c_str(), &mdModules_, &ir_, &opts_, WriteMdpHeader::no, wi_); + get_ir(inputMdpFilename.c_str(), + outputMdpFilename.empty() ? nullptr : outputMdpFilename.c_str(), + &mdModules_, + &ir_, + &opts_, + WriteMdpHeader::no, + wi_); check_ir(inputMdpFilename.c_str(), mdModules_.notifiers(), &ir_, &opts_, wi_); // Now check - bool failure = warning_errors_exist(wi_); - TestReferenceData data; - TestReferenceChecker checker(data.rootChecker()); - checker.checkBoolean(failure, "Error parsing mdp file"); - warning_reset(wi_); - - auto outputMdpContents = TextReader::readFileToString(outputMdpFilename); - checker.checkString(outputMdpContents, "OutputMdpFile"); + bool failure = warning_errors_exist(wi_); + EXPECT_EQ(failure, expectError); + + if (compareOutput) + { + TestReferenceData data; + TestReferenceChecker checker(data.rootChecker()); + checker.checkBoolean(failure, "Error parsing mdp file"); + warning_reset(wi_); + + auto outputMdpContents = TextReader::readFileToString(outputMdpFilename); + checker.checkString(outputMdpContents, "OutputMdpFile"); + } } TestFileManager fileManager_; @@ -174,6 +202,40 @@ TEST_F(GetIrTest, AcceptsEmptyLines) runTest(inputMdpFile); } +TEST_F(GetIrTest, MtsCheckNstcalcenergy) +{ + const char* inputMdpFile[] = { + "mts = yes", "mts-levels = 2", "mts-level2-factor = 2", "nstcalcenergy = 5" + }; + runTest(joinStrings(inputMdpFile, "\n"), TestBehavior::ErrorAndDoNotCompareOutput); +} + +TEST_F(GetIrTest, MtsCheckNstenergy) +{ + const char* inputMdpFile[] = { + "mts = yes", "mts-levels = 2", "mts-level2-factor = 2", "nstenergy = 5" + }; + runTest(joinStrings(inputMdpFile, "\n"), TestBehavior::ErrorAndDoNotCompareOutput); +} + +TEST_F(GetIrTest, MtsCheckNstpcouple) +{ + const char* inputMdpFile[] = { "mts = yes", + "mts-levels = 2", + "mts-level2-factor = 2", + "pcoupl = Berendsen", + "nstpcouple = 5" }; + runTest(joinStrings(inputMdpFile, "\n"), TestBehavior::ErrorAndDoNotCompareOutput); +} + +TEST_F(GetIrTest, MtsCheckNstdhdl) +{ + const char* inputMdpFile[] = { + "mts = yes", "mts-level2-factor = 2", "free-energy = yes", "nstdhdl = 5" + }; + runTest(joinStrings(inputMdpFile, "\n"), TestBehavior::ErrorAndDoNotCompareOutput); +} + // These tests observe how the electric-field keys behave, since they // are currently the only ones using the new Options-style handling. TEST_F(GetIrTest, AcceptsElectricField)