aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--changes/bug182426
-rw-r--r--configure.ac8
-rw-r--r--src/common/util.h7
-rw-r--r--src/test/test_rendcache.c4
5 files changed, 24 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index fc9f7b27ba..1333f368ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,11 @@ EXTRA_DIST+= \
if COVERAGE_ENABLED
TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
+if DISABLE_ASSERTS_IN_UNIT_TESTS
+TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS
+else
TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE
+endif
TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
else
TEST_CFLAGS=
diff --git a/changes/bug18242 b/changes/bug18242
new file mode 100644
index 0000000000..e91f6d5eb3
--- /dev/null
+++ b/changes/bug18242
@@ -0,0 +1,6 @@
+ o Minor bugfixes (testing):
+ - We no longer disable assertions in the unit tests when coverage
+ is enabled. Instead, we require you to say --disable-asserts-in-tests
+ to the configure script if you need assertions disabled in the
+ unit tests (for example, if you want to perform branch coverage).
+ Fixes bug 18242; bugfix on 0.2.7.1-alpha.
diff --git a/configure.ac b/configure.ac
index 85fc500964..1d7e11cf62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,11 +41,19 @@ AC_ARG_ENABLE(unittests,
AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
AC_ARG_ENABLE(coverage,
AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
+AC_ARG_ENABLE(asserts-in-tests,
+ AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
AC_ARG_ENABLE(system-torrc,
AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
+if test x$enable_coverage != xyes -a x$enable_asserts_in_tests = xno ; then
+ AC_MSG_ERROR([Can't disable assertions outside of coverage build])
+fi
+
+
AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
+AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test x$enable_asserts_in_tests = xno)
if test "$enable_static_tor" = "yes"; then
enable_static_libevent="yes";
diff --git a/src/common/util.h b/src/common/util.h
index 165bc0dcb3..d05ffa7d10 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -45,9 +45,10 @@
#error "Sorry; we don't support building with NDEBUG."
#endif
-/* Don't use assertions during coverage. It leads to tons of unreached
- * branches which in reality are only assertions we didn't hit. */
-#ifdef TOR_COVERAGE
+/* Sometimes we don't want to use assertions during branch coverage tests; it
+ * leads to tons of unreached branches which in reality are only assertions we
+ * didn't hit. */
+#if defined(TOR_UNIT_TESTS) && defined(DISABLE_ASSERTS_IN_UNIT_TESTS)
#define tor_assert(a) STMT_BEGIN \
(void)(a); \
STMT_END
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index 77796994b4..7e04799db2 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -128,8 +128,8 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test bad base32 failure
// This causes an assertion failure if we're running with assertions.
- // But when doing coverage, we can test it.
-#ifdef TOR_COVERAGE
+ // But when building without asserts, we can test it.
+#ifdef DISABLE_ASSERTS_IN_UNIT_TESTS
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
"!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
tt_int_op(ret, OP_EQ, RCS_BADDESC);