Add an option to disable all asserts for coverage.
authorTeemu Murtola <teemu.murtola@gmail.com>
Wed, 24 Jul 2013 10:08:47 +0000 (13:08 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 2 Aug 2013 13:05:50 +0000 (15:05 +0200)
Related to #1300; see there for rationale.

Change-Id: I76c1a4e676a543922b0e027e6693416175797d76

CMakeLists.txt
src/gromacs/utility/gmxassert.h

index ebbbdc4d5de52d2e7f374399b498d1ba915b3198..0d5d0a59cdb56b9bc3be2db0026bf54314559a75 100644 (file)
@@ -185,6 +185,11 @@ mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
 option(GMX_SKIP_DEFAULT_CFLAGS "Don't automatically add suggested/required Compiler flags." OFF)
 mark_as_advanced(GMX_SKIP_DEFAULT_CFLAGS)
 
+option(GMX_BUILD_FOR_COVERAGE
+       "Tune build for better code coverage metrics (e.g., disable asserts)"
+       OFF)
+mark_as_advanced(GMX_BUILD_FOR_COVERAGE)
+
 ######################################################################
 # Compiler tests
 # These need to be done early (before further tests).
@@ -1221,6 +1226,15 @@ else()
             COMPONENT development)
 endif()
 
+if (GMX_BUILD_FOR_COVERAGE)
+    # Code heavy with asserts makes conditional coverage close to useless metric,
+    # as by design most of the false branches are impossible to trigger in
+    # correctly functioning code.  And the benefit of testing those that could
+    # be triggered by using an API against its specification isn't usually
+    # worth the effort.
+    add_definitions(-DNDEBUG -DBOOST_DISABLE_ASSERTS -DGMX_DISABLE_ASSERTS)
+endif ()
+
 add_subdirectory(doxygen)
 add_subdirectory(share)
 add_subdirectory(src)
index 48a142d7022a0682dce08a07461c2c1f9612e266..9e36299cd2dd5e0903aa14040efda28492ace513 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013, by the GROMACS development team, led by
  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
  * others, as listed in the AUTHORS file in the top-level source
  * directory and at http://www.gromacs.org.
@@ -50,7 +50,8 @@
  * \{
  */
 
-/*! \brief
+/*! \def GMX_RELEASE_ASSERT
+ * \brief
  * Macro for asserts that should also be present in the release version.
  *
  * Regardless of NDEBUG, this macro checks \p condition, and if it is not true,
  * should only be used in a context where it is safe to throw an exception to
  * keep the option open.
  */
+#ifdef GMX_DISABLE_ASSERTS
+#define GMX_RELEASE_ASSERT(condition, msg)
+#else
 #define GMX_RELEASE_ASSERT(condition, msg) \
     ((void) ((condition) ? (void)0 : \
              ::gmx::internal::assertHandler(#condition, msg, \
                                             BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)))
+#endif
 /*! \def GMX_ASSERT
  * \brief
  * Macro for debug asserts.