mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +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:
parent
c1aae434ca
commit
c2d4a0286e
@ -3,9 +3,14 @@ Build Flags Generated by Configure
|
||||
***********************************************************************************************************************************/
|
||||
#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
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define DEBUG
|
||||
#endif
|
||||
|
||||
// Does the compiler provide _Static_assert()?
|
||||
#undef HAVE_STATIC_ASSERT
|
||||
|
||||
|
@ -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.
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
#define ASSERT(condition) \
|
||||
do \
|
||||
{ \
|
||||
|
@ -9,13 +9,6 @@ Debug Routines
|
||||
#include "common/type/convert.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
|
||||
***********************************************************************************************************************************/
|
||||
@ -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
|
||||
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
|
||||
#define DEBUG_TEST_TRACE_MACRO
|
||||
#endif // DEBUG_TEST_TRACE
|
||||
#endif // NDEBUG
|
||||
#endif // DEBUG
|
||||
|
||||
#ifdef DEBUG_TEST_TRACE_MACRO
|
||||
#define FUNCTION_TEST_BEGIN() \
|
||||
|
@ -27,7 +27,7 @@ struct ErrorType
|
||||
const ErrorType name = {code, #name, &parentType}
|
||||
|
||||
// Define test error
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
ERROR_DEFINE(1, TestError, RuntimeError);
|
||||
#endif
|
||||
|
||||
|
@ -54,7 +54,7 @@ typedef struct ErrorType ErrorType;
|
||||
#include "common/error.auto.h"
|
||||
|
||||
// Declare test error
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
ERROR_DECLARE(TestError);
|
||||
#else
|
||||
// Must always be defined since it might be needed to compile (though not used) during profiling
|
||||
|
@ -34,7 +34,7 @@ typedef struct IoFilterGroupPub
|
||||
bool inputSame; // Same input required again?
|
||||
bool done; // Is processing done?
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
bool opened; // Has the filter set been opened?
|
||||
bool closed; // Has the filter set been closed?
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@ typedef struct IoReadPub
|
||||
IoFilterGroup *filterGroup; // IO filters
|
||||
bool eofAll; // Is the read done (read and filters complete)?
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
bool opened; // Has the io been opened?
|
||||
bool closed; // Has the io been closed?
|
||||
#endif
|
||||
|
@ -86,7 +86,7 @@ backTraceCallbackError(void *data, const char *msg, int errnum)
|
||||
#endif
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
|
||||
static struct StackTraceTestLocal
|
||||
{
|
||||
@ -259,15 +259,7 @@ stackTraceParamLog(void)
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
#ifdef NDEBUG
|
||||
|
||||
void
|
||||
stackTracePop(void)
|
||||
{
|
||||
stackTraceLocal.stackSize--;
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
|
||||
void
|
||||
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
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -20,12 +20,12 @@ Macros to access internal functions
|
||||
#define STACK_TRACE_PUSH(logLevel) \
|
||||
stackTracePush(__FILE__, __func__, logLevel)
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define STACK_TRACE_POP(test) \
|
||||
stackTracePop();
|
||||
#else
|
||||
#ifdef DEBUG
|
||||
#define STACK_TRACE_POP(test) \
|
||||
stackTracePop(__FILE__, __func__, test);
|
||||
#else
|
||||
#define STACK_TRACE_POP(test) \
|
||||
stackTracePop();
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -36,7 +36,7 @@ Internal Functions
|
||||
void stackTraceInit(const char *exe);
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
// Enable/disable test function logging
|
||||
void stackTraceTestStart(void);
|
||||
void stackTraceTestStop(void);
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Harness for Loading Test Configurations
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -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
|
||||
// caused an error.
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
#define FUNCTION_HARNESS_STACK_TRACE_LINE_SET(lineNo) \
|
||||
stackTraceTestFileLineSet((unsigned int)lineNo)
|
||||
#else
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Harness for Loading Test Configurations
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Log Test Harness
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <regex.h>
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Harness for Loading Test Configurations
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/type/convert.h"
|
||||
#include "common/type/pack.h"
|
||||
|
@ -3,6 +3,8 @@ Pq Test Harness
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef HARNESS_PQ_REAL
|
||||
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Server Test Harness
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
Storage Test Harness
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -1,6 +1,8 @@
|
||||
/***********************************************************************************************************************************
|
||||
C Test Harness
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
@ -490,7 +492,7 @@ hrnTestResultException(void)
|
||||
if (harnessTestLocal.result.running)
|
||||
{
|
||||
THROW_FMT(
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
TestError,
|
||||
#else
|
||||
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))
|
||||
{
|
||||
THROW_FMT(
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
TestError,
|
||||
#else
|
||||
AssertError,
|
||||
@ -531,7 +533,7 @@ static void hrnTestResultDiff(const char *actual, const char *expected)
|
||||
else
|
||||
{
|
||||
THROW_FMT(
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
TestError,
|
||||
#else
|
||||
AssertError,
|
||||
|
@ -44,7 +44,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("stackTraceTestStart(), stackTraceTestStop(), and stackTraceTest()"))
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
assert(stackTraceTest());
|
||||
|
||||
stackTraceTestStop();
|
||||
|
@ -3,6 +3,7 @@ C Test Wrapper
|
||||
|
||||
This wrapper runs the the C unit tests.
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
C files to be tested
|
||||
@ -156,7 +157,7 @@ main(int argListSize, const char *argList[])
|
||||
CATCH_ANY()
|
||||
{
|
||||
// If a test was running then throw a detailed result exception
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
if (!errorInstanceOf(&TestError))
|
||||
#endif
|
||||
hrnTestResultException();
|
||||
@ -186,7 +187,7 @@ main(int argListSize, const char *argList[])
|
||||
errorName(), errorMessage());
|
||||
|
||||
// If not a TestError (which is detailed) then also print the stack trace
|
||||
#ifndef NDEBUG
|
||||
#ifdef DEBUG
|
||||
if (!errorInstanceOf(&TestError))
|
||||
#endif
|
||||
fprintf(stderr, "\nTHROWN AT:\n%s\n", errorStackTrace());
|
||||
|
Loading…
Reference in New Issue
Block a user