-#if GMX_THREAD_MPI
-# define GMX_MPI_TEST(expectedRankCount) \
- do \
- { \
- ASSERT_EQ(expectedRankCount, ::gmx::test::getNumberOfTestMpiRanks()); \
- using MyTestClass = std::remove_reference_t<decltype(*this)>; \
- if (!::gmx::test::threadMpiTestRunner([this]() { this->MyTestClass::TestBody(); })) \
- { \
- return; \
- } \
- } while (0)
-#else
-# define GMX_MPI_TEST(expectedRankCount) \
- ASSERT_EQ(expectedRankCount, ::gmx::test::getNumberOfTestMpiRanks())
-#endif
+#define GMX_MPI_TEST(RankRequirement) \
+ const int numRanks = ::gmx::test::getNumberOfTestMpiRanks(); \
+ if (!RankRequirement::conditionSatisfied(numRanks)) \
+ { \
+ GTEST_SKIP() << std::string("Test skipped because ") + RankRequirement::s_skipReason; \
+ return; \
+ } \
+ GMX_MPI_TEST_INNER;
+
+//! Helper for GMX_MPI_TEST to permit any rank count
+class AllowAnyRankCount
+{
+public:
+ /*! \brief Function called by GMX_MPI_CONDITIONAL_TEST to see
+ * whether the test conditions are satisifed */
+ static bool conditionSatisfied(const int /* numRanks */) { return true; }
+ //! Reason to echo when skipping the test
+ inline static const char* s_skipReason = "UNUSED - any rank count satisfies";
+};
+
+//! Helper for GMX_MPI_TEST to permit only a specific rank count
+template<int requiredNumRanks>
+class RequireRankCount
+{
+public:
+ //! Function to require a specific number of ranks
+ static bool conditionSatisfied(const int numRanks) { return numRanks == requiredNumRanks; }
+ //! Text to echo when skipping a test that does not satisfy the requirement
+ inline static const std::string s_skipReason =
+ std::to_string(requiredNumRanks) + " ranks are required";
+};
+
+//! Helper for GMX_MPI_TEST to permit only a specific rank count
+template<int minimumNumRanks>
+class RequireMinimumRankCount
+{
+public:
+ //! Function to require at least the minimum number of ranks
+ static bool conditionSatisfied(const int numRanks) { return numRanks >= minimumNumRanks; }
+ //! Text to echo when skipping a test that does not satisfy the requirement
+ inline static const std::string s_skipReason =
+ std::to_string(minimumNumRanks) + " or more ranks are required";
+};
+