Change testing to be more robust in threaded setups.
Also change on merge test to use real MPI to make sure this works
correctly.
Change-Id: Id78b213291bf7cc225fc2564a23f0d85362467fd
extends:
- .gromacs:base:configure
- .use-clang:base
+ - .use-mpi
- .rules:merge-requests
image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
variables:
image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
variables:
REGRESSIONTEST_DOUBLE: "-double"
+ REGRESSIONTEST_PARALLEL: "-np"
needs:
- job: gromacs:clang-9:build
- job: regressiontests:prepare
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <string>
#include <vector>
+#include "config.h"
+
#include "gromacs/gmxpreprocess/grompp.h"
#include "gromacs/math/vec.h"
#include "gromacs/utility/stringutil.h"
namespace testing
{
+#if GMX_OPENMP || defined(DOXYGEN)
+//! Number of OpenMP threads for child mdrun call.
+static constexpr int g_numOpenMPThreads = 2;
+#endif
+
/*! \brief Helper function to get step size as floating point number.
*
* A step size of 0.002ps is suitable for the simulation.
mdArgs.emplace_back(runner_.edrFileName_);
mdArgs.emplace_back("-cpo");
mdArgs.emplace_back(runner_.cptFileName_);
+#if GMX_THREAD_MPI
+ /* This should be handled through the actual API we have for getting
+ * ranks, but currently this leads to data races right now */
+ mdArgs.emplace_back("-ntmpi");
+ mdArgs.emplace_back("1");
+#endif
+
+#if GMX_OPENMP
+ mdArgs.emplace_back("-ntomp");
+ mdArgs.emplace_back(std::to_string(g_numOpenMPThreads));
+#endif
return mdArgs;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/compat/pointers.h"
+#include "config.h"
+
#include <memory>
#include <vector>
#include <gtest/gtest.h>
+#include "testutils/testasserts.h"
namespace gmx
{
* will not trigger the assert when using the pointer without
* a valid object. This was needed due to an internal error
* being triggered instead with the compiler under this condition.
+ *
+ * Death tests can also not be used safely in a parallel environment.
*/
# if !defined(__INTEL_COMPILER) || !(__INTEL_COMPILER == 1800 && __INTEL_COMPILER_UPDATE == 0)
int* nullPointer = nullptr;
- EXPECT_DEATH_IF_SUPPORTED(not_null<int*> invalidNullPointer(nullPointer), "");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(not_null<int*> invalidNullPointer(nullPointer), "");
# endif
#endif
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
addOptionForSelection(&sel, false);
setSelectionOptionValues(getOption(), &sel, false);
- ASSERT_DEATH_IF_SUPPORTED(adapters.addAdapter(std::make_unique<OutputSelector>(sel),
- CoordinateFileFlags::RequireCoordinateSelection),
- "Need a valid selection out of simple atom indices");
+ GMX_ASSERT_DEATH_IF_SUPPORTED(adapters.addAdapter(std::make_unique<OutputSelector>(sel),
+ CoordinateFileFlags::RequireCoordinateSelection),
+ "Need a valid selection out of simple atom indices");
}
};
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/gmxpreprocess/readir.h"
+#include "config.h"
+
#include <string>
#include <gtest/gtest.h>
#include "gromacs/utility/unique_cptr.h"
#include "testutils/refdata.h"
+#include "testutils/testasserts.h"
#include "testutils/testfilemanager.h"
-
namespace gmx
{
namespace test
TEST_F(GetIrTest, RejectsNonCommentLineWithNoEquals)
{
const char* inputMdpFile = "title simulation";
- EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "No '=' to separate");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "No '=' to separate");
}
TEST_F(GetIrTest, AcceptsKeyWithoutValue)
TEST_F(GetIrTest, RejectsValueWithoutKey)
{
const char* inputMdpFile = "= -I/home/me/stuff";
- EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "No .mdp parameter name was found");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "No .mdp parameter name was found");
}
TEST_F(GetIrTest, RejectsEmptyKeyAndEmptyValue)
{
const char* inputMdpFile = " = ";
- EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "No .mdp parameter name or value was found");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile),
+ "No .mdp parameter name or value was found");
}
TEST_F(GetIrTest, AcceptsDefineParametersWithValuesIncludingAssignment)
TEST_F(GetIrTest, RejectsDuplicateOldAndNewKeys)
{
const char* inputMdpFile[] = { "verlet-buffer-drift = 1.3", "verlet-buffer-tolerance = 2.7" };
- EXPECT_DEATH_IF_SUPPORTED(runTest(joinStrings(inputMdpFile, "\n")),
- "A parameter is present with both");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runTest(joinStrings(inputMdpFile, "\n")),
+ "A parameter is present with both");
}
TEST_F(GetIrTest, AcceptsImplicitSolventNo)
TEST_F(GetIrTest, RejectsImplicitSolventYes)
{
const char* inputMdpFile = "implicit-solvent = yes";
- EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "Invalid enum");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runTest(inputMdpFile), "Invalid enum");
}
TEST_F(GetIrTest, AcceptsMimic)
#include "gromacs/utility/enumerationhelpers.h"
+#include "config.h"
+
#include <iostream>
#include <gtest/gtest.h>
#include "gromacs/utility/arrayref.h"
+#include "testutils/testasserts.h"
+
namespace gmx
{
namespace
#ifndef NDEBUG
// Tests (where possible) that those assertions do fire in a build
// with debug behavior.
- EXPECT_DEATH_IF_SUPPORTED(fooStrings[Foo::Count], "index out of range");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(fooStrings[Foo::Count], "index out of range");
#endif
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*/
#include "gmxpre.h"
+#include "config.h"
+
#include <string>
#include <gmock/gmock.h>
{
runner_.useStringAsMdpFile(mdpMdDensfitYesUnsetValues + mdpEnergyAndDensityfittingIntervalMismatch_);
- EXPECT_DEATH_IF_SUPPORTED(runner_.callGrompp(),
- ".*is not a multiple of density-guided-simulation-nst.*");
+ GMX_EXPECT_DEATH_IF_SUPPORTED(runner_.callGrompp(),
+ ".*is not a multiple of density-guided-simulation-nst.*");
}
/* Fit a subset of three of twelve argon atoms into a reference density
* - exceptions
* - floating-point comparison
* - comparison against NULL
+ * - death tests
*
* \if internal
* \todo
*/
#define ASSERT_NO_THROW_GMX(statement) GMX_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
+/*! \brief
+ * Wrapper around EXPECT_DEATH_IF_SUPPORTED gtest macro for thread safe execution.
+ *
+ * Makes sure that tests that are supposed to trigger an assertion are only executed
+ * in a threadsafe environment, and not when when running under e.g. MPI.
+ *
+ * \hideinitializer
+ */
+#define GMX_EXPECT_DEATH_IF_SUPPORTED(expr, msg) \
+ if (!GMX_LIB_MPI) \
+ { \
+ EXPECT_DEATH_IF_SUPPORTED(expr, msg); \
+ }
+
+/*! \brief
+ * Wrapper around ASSERT_DEATH_IF_SUPPORTED gtest macro for thread safe execution.
+ *
+ * Makes sure that tests that are supposed to trigger an assertion are only executed
+ * in a threadsafe environment when running under e.g. MPI.
+ *
+ * \hideinitializer
+ */
+#define GMX_ASSERT_DEATH_IF_SUPPORTED(expr, msg) \
+ if (!GMX_LIB_MPI) \
+ { \
+ ASSERT_DEATH_IF_SUPPORTED(expr, msg); \
+ }
+
//! \}
/*! \libinternal \brief