diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 41af42e02..ec5f0833e 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -84,7 +84,7 @@ -

Add ASSERT_DEBUG() macro for debugging and replace all current assert() calls except in tests that can't use the debug code.

+

Improve debugging. Add ASSERT_DEBUG() macro for debugging and replace all current assert() calls except in tests that can't use the debug code. Replace remaining NDEBUG blocks with the more granular DEBUG_UNIT. Remove some debug memset() calls in MemContext since valgrind is more useful for these checks.

diff --git a/src/common/debug.h b/src/common/debug.h index c97762a1b..1f8499dfb 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -15,6 +15,9 @@ NDEBUG indicates to C library routines that debugging is off -- set a more reada /*********************************************************************************************************************************** Assert Macros + +Used for assertions that should only be run when debugging. Ideal for conditions that are not likely to happen in production but +could occur during development. ***********************************************************************************************************************************/ #ifdef DEBUG #define ASSERT_DEBUG(condition) \ @@ -26,4 +29,14 @@ Assert Macros #define ASSERT_DEBUG(condition) #endif +/*********************************************************************************************************************************** +Extern variables that are needed for unit testing +***********************************************************************************************************************************/ +#ifdef DEBUG_UNIT + #define DEBUG_UNIT_EXTERN +#else + #define DEBUG_UNIT_EXTERN \ + static +#endif + #endif diff --git a/src/common/log.c b/src/common/log.c index 592be9bb2..e6bdd20f5 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -18,20 +18,20 @@ Log Handler Module variables ***********************************************************************************************************************************/ // Log levels -LogLevel logLevelStdOut = logLevelError; -LogLevel logLevelStdErr = logLevelError; -LogLevel logLevelFile = logLevelOff; +DEBUG_UNIT_EXTERN LogLevel logLevelStdOut = logLevelError; +DEBUG_UNIT_EXTERN LogLevel logLevelStdErr = logLevelError; +DEBUG_UNIT_EXTERN LogLevel logLevelFile = logLevelOff; // Log file handles -int logHandleStdOut = STDOUT_FILENO; -int logHandleStdErr = STDERR_FILENO; -int logHandleFile = -1; +DEBUG_UNIT_EXTERN int logHandleStdOut = STDOUT_FILENO; +DEBUG_UNIT_EXTERN int logHandleStdErr = STDERR_FILENO; +DEBUG_UNIT_EXTERN int logHandleFile = -1; // Has the log file banner been written yet? -bool logFileBanner = false; +static bool logFileBanner = false; // Is the timestamp printed in the log? -bool logTimestamp = false; +static bool logTimestamp = false; /*********************************************************************************************************************************** Debug Asserts diff --git a/src/common/log.h b/src/common/log.h index 70f116f21..c5b6e8824 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -23,9 +23,9 @@ typedef enum } LogLevel; /*********************************************************************************************************************************** -Expose internal data for debugging/testing +Expose internal data for unit testing/debugging ***********************************************************************************************************************************/ -#ifndef NDEBUG +#ifdef DEBUG_UNIT extern LogLevel logLevelStdOut; extern LogLevel logLevelStdErr; extern LogLevel logLevelFile; @@ -33,8 +33,6 @@ Expose internal data for debugging/testing extern int logHandleStdOut; extern int logHandleStdErr; extern int logHandleFile; - - extern bool logTimestamp; #endif /*********************************************************************************************************************************** diff --git a/src/common/memContext.c b/src/common/memContext.c index 73991e120..b8d401fc6 100644 --- a/src/common/memContext.c +++ b/src/common/memContext.c @@ -325,11 +325,6 @@ memFree(void *buffer) // Find the allocation MemContextAlloc *alloc = &(memContextCurrent()->allocList[memFind(buffer)]); - // DEBUG: zero buffer to make it more obvious that it was freed if there are still references to it - #ifndef NDEBUG - memset(alloc->buffer, 0, alloc->size); - #endif - // Free the buffer memFreeInternal(alloc->buffer); alloc->active = false; @@ -433,14 +428,7 @@ memContextFree(MemContext *this) MemContextAlloc *alloc = &(this->allocList[allocIdx]); if (alloc->active) - { - // DEBUG: zero buffer to make it more obvious that it was freed if there are still references to it - #ifndef NDEBUG - memset(alloc->buffer, 0, alloc->size); - #endif - memFreeInternal(alloc->buffer); - } } memFreeInternal(this->allocList); diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index cc81b6d2f..25f578f53 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -344,7 +344,7 @@ sub run " `perl -MExtUtils::Embed -e ccopts`\n" . "LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) ? " -lgcov" : '') . " `perl -MExtUtils::Embed -e ldopts`\n" . - 'TESTFLAGS=' . ($self->{oTest}->{&TEST_CDEF} ? "$self->{oTest}->{&TEST_CDEF}" : '') . + 'TESTFLAGS=-DDEBUG_UNIT' . ($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') . "\n" . "\nSRCS=" . join(' ', @stryCFile) . "\n" . "OBJS=\$(SRCS:.c=.o)\n" .