wsd: test: support logging passing test assertions

By configuring with --enable-logging-test-asserts,
which is enabled by default, passing assertions
in tests will be logged.

Can be disabled with --disable-logging-test-asserts
and enabled for individual translation-units via
    #define LOK_LOG_ASSERTIONS 1

This should help with debugging failures that
happen at some arbitrary point in a test.
Logs should now be more readable, as in most cases
extra logs aren't needed to trace the test progression.
That is, the assertions become self-documenting.

Change-Id: I5498331cac63bfe6ab09566697ca324a064c4dbf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2021-11-12 09:42:16 -05:00 committed by Jan Holesovsky
parent 2ff5c2d1ab
commit de78487758
2 changed files with 43 additions and 3 deletions

View file

@ -304,6 +304,10 @@ AC_ARG_WITH([sanitizer],
AS_HELP_STRING([--with-sanitizer],
[Enable one or more compatible sanitizers. E.g. --with-sanitizer=address,undefined,leak]))
AC_ARG_ENABLE([logging-test-asserts],
AS_HELP_STRING([--enable-logging-test-asserts],
[Enable logging of passing test assertions.]))
AC_ARG_WITH([compiler-plugins],
AS_HELP_STRING([--with-compiler-plugins=<path>],
[Experimental! Unlikely to work for anyone except Noel! Enable compiler plugins that will perform additional checks during
@ -366,6 +370,8 @@ BROWSER_LOGGING="false"
debug_msg="secure mode: product build"
anonym_msg=""
bundle_msg="using uglified bundled JS and CSS"
LOK_LOG_ASSERTIONS=0
log_asserts_msg="disabled"
if test "$enable_debug" = "yes"; then
AC_DEFINE([ENABLE_DEBUG],1,[Whether to compile in some extra debugging support code and disable some security pieces])
ENABLE_DEBUG=true
@ -381,6 +387,11 @@ if test "$enable_debug" = "yes"; then
ENABLE_BUNDLE=false
bundle_msg="using individual JS and CSS files"
fi
if test "$enable_logging_test_asserts" != "no"; then
LOK_LOG_ASSERTIONS=1
log_asserts_msg="enabled"
AC_MSG_RESULT([Enabling logging of passing test assertions in debug build (default), override with --disable-logging-test-asserts])
fi
else
AC_DEFINE([ENABLE_DEBUG],0,[Whether to compile in some extra debugging support code and disable some security pieces])
fi
@ -421,6 +432,13 @@ fi
AC_DEFINE_UNQUOTED([COOLWSD_ANONYMIZE_USER_DATA],[$COOLWSD_ANONYMIZE_USER_DATA],[Enable permanent anonymization in logs])
AC_SUBST(COOLWSD_ANONYMIZE_USER_DATA)
if test "$enable_logging_test_asserts" = "yes" ; then
LOK_LOG_ASSERTIONS=1
log_asserts_msg="enabled"
fi
AC_DEFINE_UNQUOTED([LOK_LOG_ASSERTIONS],[$LOK_LOG_ASSERTIONS],[Enable logging of test assertions])
AC_SUBST(LOK_LOG_ASSERTIONS)
if test -z "$anonym_msg"; then
anonym_msg="anonymization of user-data is disabled"
fi
@ -1489,6 +1507,7 @@ Configuration:
LO integration tests ${lo_msg}
SSL support $ssl_msg
Debug & low security $debug_msg
Test assertion logging $log_asserts_msg
Uglification and bundling $bundle_msg
Anonymization $anonym_msg
Set capabilities $setcap_msg

View file

@ -66,6 +66,21 @@ std::string inline lokFormatAssertEq(const std::string& expected, const std::str
#define LOK_ASSERT_IMPL(X)
#endif //LOK_ABORT_ON_ASSERTION
// When enabled, assertions that pass will be logged.
// configure with --enable-logging-test-assert
#if LOK_LOG_ASSERTIONS
#define LOK_TRACE(X) \
do \
{ \
TST_LOG_NAME("unittest", X); \
} while (false)
#else
#define LOK_TRACE(X) \
do \
{ \
} while (false)
#endif
/// Assert the truth of a condition. WARNING: Multiple evaluations!
#define LOK_ASSERT(condition) \
do \
@ -76,6 +91,8 @@ std::string inline lokFormatAssertEq(const std::string& expected, const std::str
LOK_ASSERT_IMPL(condition); \
CPPUNIT_ASSERT(condition); \
} \
else \
LOK_TRACE("PASS: " << (#condition)); \
} while (false)
/// Assert the equality of two expressions. WARNING: Multiple evaluations!
@ -99,6 +116,8 @@ std::string inline lokFormatAssertEq(const std::string& expected, const std::str
LOK_ASSERT_IMPL((expected) == (actual)); \
CPPUNIT_ASSERT_EQUAL_MESSAGE(msg##__LINE__, (expected), (actual)); \
} \
else \
LOK_TRACE("PASS: [" << (expected) << "] == [" << (actual) << ']'); \
} while (false)
/// Assert the equality of two expressions, and a custom message, with guaranteed single evaluation.
@ -131,17 +150,19 @@ std::string inline lokFormatAssertEq(const std::string& expected, const std::str
{ \
if (!(condition)) \
{ \
TST_LOG_NAME("unittest", "ERROR: Assertion failure: " << (message) << ". Condition: " \
<< (#condition)); \
TST_LOG_NAME("unittest", "ERROR: Assertion failure: [" \
<< (message) << "] Condition: " << (#condition)); \
LOK_ASSERT_IMPL(condition); \
CPPUNIT_ASSERT_MESSAGE((message), (condition)); \
} \
else \
LOK_TRACE("PASS: " << (#condition)); \
} while (false)
#define LOK_ASSERT_FAIL(message) \
do \
{ \
TST_LOG_NAME("unittest", "ERROR: Forced failure: " << (message)); \
LOK_ASSERT_IMPL(!"Forced failure"); \
LOK_ASSERT_IMPL(!"Forced failure: " #message); \
CPPUNIT_FAIL((message)); \
} while (false)