mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Add test function to set stack trace function line number.
This is helpful for test macros that know the line number. The line number can now be non-zero below the top of the stack without WITH_BACKTRACE so instead ignore the line number for output when it is zero.
This commit is contained in:
parent
bd461a1899
commit
5a8758cc8a
@ -109,6 +109,13 @@ stackTraceTest(void)
|
||||
{
|
||||
return stackTraceTestFlag;
|
||||
}
|
||||
|
||||
void
|
||||
stackTraceTestFileLineSet(unsigned int fileLine)
|
||||
{
|
||||
stackTrace[stackSize - 1].fileLine = fileLine;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -339,18 +346,12 @@ stackTraceToZ(char *buffer, size_t bufferSize, const char *fileName, const char
|
||||
StackTraceData *data = &stackTrace[stackIdx];
|
||||
|
||||
result += stackTraceFmt(
|
||||
buffer, bufferSize, result, "\n%.*s:%s"
|
||||
buffer, bufferSize, result, "\n%.*s:%s", (int)(strlen(data->fileName) - 2), data->fileName, data->functionName);
|
||||
|
||||
#ifdef WITH_BACKTRACE
|
||||
":%u"
|
||||
#endif
|
||||
":(%s)", (int)(strlen(data->fileName) - 2), data->fileName, data->functionName,
|
||||
if (data->fileLine > 0)
|
||||
result += stackTraceFmt(buffer, bufferSize, result, ":%u", data->fileLine);
|
||||
|
||||
#ifdef WITH_BACKTRACE
|
||||
data->fileLine,
|
||||
#endif
|
||||
|
||||
stackTraceParamIdx(stackIdx));
|
||||
result += stackTraceFmt(buffer, bufferSize, result, ":(%s)", stackTraceParamIdx(stackIdx));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,9 @@ Internal Functions
|
||||
void stackTraceTestStart(void);
|
||||
void stackTraceTestStop(void);
|
||||
bool stackTraceTest(void);
|
||||
|
||||
// Set line number for the current function on the stack
|
||||
void stackTraceTestFileLineSet(unsigned int fileLine);
|
||||
#endif
|
||||
|
||||
LogLevel stackTracePush(const char *fileName, const char *functionName, LogLevel functionLogLevel);
|
||||
|
@ -52,6 +52,11 @@ testRun(void)
|
||||
|
||||
stackTraceTestStart();
|
||||
assert(stackTraceTest());
|
||||
|
||||
stackSize++;
|
||||
stackTraceTestFileLineSet(888);
|
||||
assert(stackTrace[stackSize - 1].fileLine == 888);
|
||||
stackSize--;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -87,21 +92,12 @@ testRun(void)
|
||||
|
||||
stackTraceToZ(buffer, sizeof(buffer), "file1.c", "function2", 99);
|
||||
|
||||
#ifdef WITH_BACKTRACE
|
||||
TEST_RESULT_Z(
|
||||
buffer,
|
||||
"file1:function2:99:(test build required for parameters)\n"
|
||||
" ... function(s) omitted ...\n"
|
||||
"file1:function1:0:(void)",
|
||||
" check stack trace");
|
||||
#else
|
||||
TEST_RESULT_Z(
|
||||
buffer,
|
||||
"file1:function2:99:(test build required for parameters)\n"
|
||||
" ... function(s) omitted ...\n"
|
||||
"file1:function1:(void)",
|
||||
" check stack trace");
|
||||
#endif
|
||||
|
||||
assert(stackTracePush("file1.c", "function2", logLevelTrace) == logLevelTrace);
|
||||
stackTrace[stackSize - 2].fileLine = 7777;
|
||||
@ -152,7 +148,6 @@ testRun(void)
|
||||
|
||||
stackTraceToZ(buffer, sizeof(buffer), "file4.c", "function4", 99);
|
||||
|
||||
#ifdef WITH_BACKTRACE
|
||||
TEST_RESULT_Z(
|
||||
buffer,
|
||||
"file4:function4:99:(buffer full - parameters not available)\n"
|
||||
@ -161,16 +156,6 @@ testRun(void)
|
||||
"file1:function2:7777:(debug log level required for parameters)\n"
|
||||
"file1:function1:7777:(void)",
|
||||
"stack trace");
|
||||
#else
|
||||
TEST_RESULT_Z(
|
||||
buffer,
|
||||
"file4:function4:99:(buffer full - parameters not available)\n"
|
||||
"file3:function3:(param1: value1, param2: value2)\n"
|
||||
"file2:function2:(param1: value1)\n"
|
||||
"file1:function2:(debug log level required for parameters)\n"
|
||||
"file1:function1:(void)",
|
||||
"stack trace");
|
||||
#endif
|
||||
|
||||
stackTracePop("file4.c", "function4", false);
|
||||
assert(stackSize == 4);
|
||||
|
Loading…
Reference in New Issue
Block a user