1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Define DEBUG in build.auto.c.

Both NDEBUG and DEBUG were used in the code, which was a bit confusing.

Define DEBUG in build.auto.c so it is available in all C and header files and stop using NDEBUG. This is preferable to using NDEBUG everywhere since there are multiple DEBUG* defines, e.g. DEBUG_COVERAGE.

Note that NDEBUG is still required since it is used by the C libraries.
This commit is contained in:
David Steele
2021-04-13 18:06:07 -04:00
parent c1aae434ca
commit c2d4a0286e
20 changed files with 53 additions and 38 deletions

View File

@ -3,9 +3,14 @@ Build Flags Generated by Configure
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "version.h" #include "version.h"
// Are test code and asserts disabled? // Are test code and asserts disabled? NDEBUG can be confusing to work with because, when debugging, #ifndef NDEBUG must be used for
// #defines, so also #define DEBUG in this case to make #ifdefs simpler.
#undef NDEBUG #undef NDEBUG
#ifndef NDEBUG
#define DEBUG
#endif
// Does the compiler provide _Static_assert()? // Does the compiler provide _Static_assert()?
#undef HAVE_STATIC_ASSERT #undef HAVE_STATIC_ASSERT

View File

@ -9,7 +9,7 @@ Assert Routines
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Asserts are used in test code to ensure that certain conditions are true. They are omitted from production builds. Asserts are used in test code to ensure that certain conditions are true. They are omitted from production builds.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifndef NDEBUG #ifdef DEBUG
#define ASSERT(condition) \ #define ASSERT(condition) \
do \ do \
{ \ { \

View File

@ -9,13 +9,6 @@ Debug Routines
#include "common/type/convert.h" #include "common/type/convert.h"
#include "common/type/stringz.h" #include "common/type/stringz.h"
/***********************************************************************************************************************************
NDEBUG indicates to C library routines that debugging is off -- set a more readable flag to use when debugging is on
***********************************************************************************************************************************/
#ifndef NDEBUG
#define DEBUG
#endif
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Extern variables that are needed for unit testing Extern variables that are needed for unit testing
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -296,13 +289,13 @@ Function Test Macros
In debug builds these macros will update the stack trace with function names and parameters but will not log. In production builds In debug builds these macros will update the stack trace with function names and parameters but will not log. In production builds
all test macros are compiled out (except for return statements). all test macros are compiled out (except for return statements).
Ignore DEBUG_TEST_TRACE_MACRO if NDEBUG is defined because the underlying functions that support the macros will not be present. Ignore DEBUG_TEST_TRACE_MACRO if DEBUG is not defined because the underlying functions that support the macros will not be present.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifndef NDEBUG #ifdef DEBUG
#ifdef DEBUG_TEST_TRACE #ifdef DEBUG_TEST_TRACE
#define DEBUG_TEST_TRACE_MACRO #define DEBUG_TEST_TRACE_MACRO
#endif // DEBUG_TEST_TRACE #endif // DEBUG_TEST_TRACE
#endif // NDEBUG #endif // DEBUG
#ifdef DEBUG_TEST_TRACE_MACRO #ifdef DEBUG_TEST_TRACE_MACRO
#define FUNCTION_TEST_BEGIN() \ #define FUNCTION_TEST_BEGIN() \

View File

@ -27,7 +27,7 @@ struct ErrorType
const ErrorType name = {code, #name, &parentType} const ErrorType name = {code, #name, &parentType}
// Define test error // Define test error
#ifndef NDEBUG #ifdef DEBUG
ERROR_DEFINE(1, TestError, RuntimeError); ERROR_DEFINE(1, TestError, RuntimeError);
#endif #endif

View File

@ -54,7 +54,7 @@ typedef struct ErrorType ErrorType;
#include "common/error.auto.h" #include "common/error.auto.h"
// Declare test error // Declare test error
#ifndef NDEBUG #ifdef DEBUG
ERROR_DECLARE(TestError); ERROR_DECLARE(TestError);
#else #else
// Must always be defined since it might be needed to compile (though not used) during profiling // Must always be defined since it might be needed to compile (though not used) during profiling

View File

@ -34,7 +34,7 @@ typedef struct IoFilterGroupPub
bool inputSame; // Same input required again? bool inputSame; // Same input required again?
bool done; // Is processing done? bool done; // Is processing done?
#ifndef NDEBUG #ifdef DEBUG
bool opened; // Has the filter set been opened? bool opened; // Has the filter set been opened?
bool closed; // Has the filter set been closed? bool closed; // Has the filter set been closed?
#endif #endif

View File

@ -43,7 +43,7 @@ typedef struct IoReadPub
IoFilterGroup *filterGroup; // IO filters IoFilterGroup *filterGroup; // IO filters
bool eofAll; // Is the read done (read and filters complete)? bool eofAll; // Is the read done (read and filters complete)?
#ifndef NDEBUG #ifdef DEBUG
bool opened; // Has the io been opened? bool opened; // Has the io been opened?
bool closed; // Has the io been closed? bool closed; // Has the io been closed?
#endif #endif

View File

@ -86,7 +86,7 @@ backTraceCallbackError(void *data, const char *msg, int errnum)
#endif #endif
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
#ifndef NDEBUG #ifdef DEBUG
static struct StackTraceTestLocal static struct StackTraceTestLocal
{ {
@ -259,15 +259,7 @@ stackTraceParamLog(void)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
#ifdef NDEBUG #ifdef DEBUG
void
stackTracePop(void)
{
stackTraceLocal.stackSize--;
}
#else
void void
stackTracePop(const char *fileName, const char *functionName, bool test) stackTracePop(const char *fileName, const char *functionName, bool test)
@ -285,6 +277,14 @@ stackTracePop(const char *fileName, const char *functionName, bool test)
} }
} }
#else
void
stackTracePop(void)
{
stackTraceLocal.stackSize--;
}
#endif #endif
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -20,12 +20,12 @@ Macros to access internal functions
#define STACK_TRACE_PUSH(logLevel) \ #define STACK_TRACE_PUSH(logLevel) \
stackTracePush(__FILE__, __func__, logLevel) stackTracePush(__FILE__, __func__, logLevel)
#ifdef NDEBUG #ifdef DEBUG
#define STACK_TRACE_POP(test) \
stackTracePop();
#else
#define STACK_TRACE_POP(test) \ #define STACK_TRACE_POP(test) \
stackTracePop(__FILE__, __func__, test); stackTracePop(__FILE__, __func__, test);
#else
#define STACK_TRACE_POP(test) \
stackTracePop();
#endif #endif
/*********************************************************************************************************************************** /***********************************************************************************************************************************
@ -36,7 +36,7 @@ Internal Functions
void stackTraceInit(const char *exe); void stackTraceInit(const char *exe);
#endif #endif
#ifndef NDEBUG #ifdef DEBUG
// Enable/disable test function logging // Enable/disable test function logging
void stackTraceTestStart(void); void stackTraceTestStart(void);
void stackTraceTestStop(void); void stackTraceTestStop(void);

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Harness for Loading Test Configurations Harness for Loading Test Configurations
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -16,7 +16,7 @@ C Debug Harness
// Set line numer of the current function in the stack trace. This is used to give more detailed info about which test macro // Set line numer of the current function in the stack trace. This is used to give more detailed info about which test macro
// caused an error. // caused an error.
#ifndef NDEBUG #ifdef DEBUG
#define FUNCTION_HARNESS_STACK_TRACE_LINE_SET(lineNo) \ #define FUNCTION_HARNESS_STACK_TRACE_LINE_SET(lineNo) \
stackTraceTestFileLineSet((unsigned int)lineNo) stackTraceTestFileLineSet((unsigned int)lineNo)
#else #else

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Harness for Loading Test Configurations Harness for Loading Test Configurations
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <string.h> #include <string.h>
#include "common/assert.h" #include "common/assert.h"

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Log Test Harness Log Test Harness
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <regex.h> #include <regex.h>

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Harness for Loading Test Configurations Harness for Loading Test Configurations
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/type/convert.h" #include "common/type/convert.h"
#include "common/type/pack.h" #include "common/type/pack.h"

View File

@ -3,6 +3,8 @@ Pq Test Harness
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifndef HARNESS_PQ_REAL #ifndef HARNESS_PQ_REAL
#include "build.auto.h"
#include <string.h> #include <string.h>
#include <libpq-fe.h> #include <libpq-fe.h>

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Server Test Harness Server Test Harness
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Storage Test Harness Storage Test Harness
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View File

@ -1,6 +1,8 @@
/*********************************************************************************************************************************** /***********************************************************************************************************************************
C Test Harness C Test Harness
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
#include <fcntl.h> #include <fcntl.h>
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
@ -490,7 +492,7 @@ hrnTestResultException(void)
if (harnessTestLocal.result.running) if (harnessTestLocal.result.running)
{ {
THROW_FMT( THROW_FMT(
#ifndef NDEBUG #ifdef DEBUG
TestError, TestError,
#else #else
AssertError, AssertError,
@ -520,7 +522,7 @@ static void hrnTestResultDiff(const char *actual, const char *expected)
if (actual != NULL && expected != NULL && (strstr(actual, "\n") != NULL || strstr(expected, "\n") != NULL)) if (actual != NULL && expected != NULL && (strstr(actual, "\n") != NULL || strstr(expected, "\n") != NULL))
{ {
THROW_FMT( THROW_FMT(
#ifndef NDEBUG #ifdef DEBUG
TestError, TestError,
#else #else
AssertError, AssertError,
@ -531,7 +533,7 @@ static void hrnTestResultDiff(const char *actual, const char *expected)
else else
{ {
THROW_FMT( THROW_FMT(
#ifndef NDEBUG #ifdef DEBUG
TestError, TestError,
#else #else
AssertError, AssertError,

View File

@ -44,7 +44,7 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("stackTraceTestStart(), stackTraceTestStop(), and stackTraceTest()")) if (testBegin("stackTraceTestStart(), stackTraceTestStop(), and stackTraceTest()"))
{ {
#ifndef NDEBUG #ifdef DEBUG
assert(stackTraceTest()); assert(stackTraceTest());
stackTraceTestStop(); stackTraceTestStop();

View File

@ -3,6 +3,7 @@ C Test Wrapper
This wrapper runs the the C unit tests. This wrapper runs the the C unit tests.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#include "build.auto.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
C files to be tested C files to be tested
@ -156,7 +157,7 @@ main(int argListSize, const char *argList[])
CATCH_ANY() CATCH_ANY()
{ {
// If a test was running then throw a detailed result exception // If a test was running then throw a detailed result exception
#ifndef NDEBUG #ifdef DEBUG
if (!errorInstanceOf(&TestError)) if (!errorInstanceOf(&TestError))
#endif #endif
hrnTestResultException(); hrnTestResultException();
@ -186,7 +187,7 @@ main(int argListSize, const char *argList[])
errorName(), errorMessage()); errorName(), errorMessage());
// If not a TestError (which is detailed) then also print the stack trace // If not a TestError (which is detailed) then also print the stack trace
#ifndef NDEBUG #ifdef DEBUG
if (!errorInstanceOf(&TestError)) if (!errorInstanceOf(&TestError))
#endif #endif
fprintf(stderr, "\nTHROWN AT:\n%s\n", errorStackTrace()); fprintf(stderr, "\nTHROWN AT:\n%s\n", errorStackTrace());