From 15b8b9207da40df3df92ee7464a546c335a5a4d9 Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 21 May 2021 12:51:32 -0400 Subject: [PATCH] Add log shim. This allows DEBUG_UNIT and DEBUG_UNIT_EXTERN to be removed since static log variables can now be exposed by functions in the harness. --- doc/xml/release.xml | 1 + src/common/debug.h | 10 ---- src/common/log.c | 8 +-- test/define.yaml | 16 +++--- test/lib/pgBackRestTest/Common/DefineTest.pm | 5 +- test/lib/pgBackRestTest/Common/JobTest.pm | 1 - test/lib/pgBackRestTest/Common/ListTest.pm | 3 -- test/src/common/harnessLog.c | 55 +++++++++++++++++--- test/src/common/harnessLog.h | 12 +++++ test/src/module/common/debugOffTest.c | 7 --- test/src/module/common/debugOnTest.c | 7 --- test/src/module/config/loadTest.c | 8 +-- test/src/module/config/parseTest.c | 32 ++++++------ 13 files changed, 93 insertions(+), 72 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 329922183..24b3b5536 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -181,6 +181,7 @@ +

Add local processs shim.

diff --git a/src/common/debug.h b/src/common/debug.h index a2a61fcf6..6493bc3ab 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -9,16 +9,6 @@ Debug Routines #include "common/type/convert.h" #include "common/type/stringz.h" -/*********************************************************************************************************************************** -Extern variables that are needed for unit testing -***********************************************************************************************************************************/ -#ifdef DEBUG_UNIT - #define DEBUG_UNIT_EXTERN -#else - #define DEBUG_UNIT_EXTERN \ - static -#endif - /*********************************************************************************************************************************** Base function debugging macros diff --git a/src/common/log.c b/src/common/log.c index ba6638ff8..43b8d3795 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -29,16 +29,16 @@ static LogLevel logLevelAny = logLevelError; // Log file descriptors static int logFdStdOut = STDOUT_FILENO; static int logFdStdErr = STDERR_FILENO; -DEBUG_UNIT_EXTERN int logFdFile = -1; +static int logFdFile = -1; // Has the log file banner been written yet? -DEBUG_UNIT_EXTERN bool logFileBanner = false; +static bool logFileBanner = false; // Is the timestamp printed in the log? static bool logTimestamp = false; // Default process id if none is specified -DEBUG_UNIT_EXTERN unsigned int logProcessId = 0; +static unsigned int logProcessId = 0; // Size of the process id field static int logProcessSize = 2; @@ -114,7 +114,7 @@ logLevelStr(LogLevel logLevel) } /**********************************************************************************************************************************/ -DEBUG_UNIT_EXTERN void +static void logAnySet(void) { FUNCTION_TEST_VOID(); diff --git a/test/define.yaml b/test/define.yaml index dc907eabc..1529224b0 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -10,7 +10,6 @@ # Most options can be set for modules and tests (test option will override module option if both are set): # * db - determines if the test will be run against multiple db versions # * define - defines for C code (will also be applied to the test harness) -# * debugUnitSuppress - don't define DEBUG_UNIT for unit tests -- this is used to test unit test debugging macros # * binReq - is the pgbackrest binary required for this test? # * containerReq - is this test required to run in a container? # @@ -79,16 +78,14 @@ unit: - name: assert-off total: 1 define: -DNDEBUG - debugUnitSuppress: true coverage: - common/assert: noCode # ---------------------------------------------------------------------------------------------------------------------------- - name: debug-off - total: 2 + total: 1 define: -DNDEBUG - debugUnitSuppress: true coverage: - common/debug @@ -182,14 +179,17 @@ unit: - name: log total: 5 feature: log - harness: log + harness: + name: log + shim: + common/log: ~ coverage: - common/log # ---------------------------------------------------------------------------------------------------------------------------- - name: debug-on - total: 4 + total: 3 feature: debug coverage: @@ -456,9 +456,6 @@ unit: - config/parse - config/parse.auto: noCode - include: - - common/log - # ---------------------------------------------------------------------------------------------------------------------------- - name: load total: 4 @@ -467,7 +464,6 @@ unit: - config/load include: - - common/log - common/io/socket/common # ---------------------------------------------------------------------------------------------------------------------------- diff --git a/test/lib/pgBackRestTest/Common/DefineTest.pm b/test/lib/pgBackRestTest/Common/DefineTest.pm index d70296e30..2ab61466d 100644 --- a/test/lib/pgBackRestTest/Common/DefineTest.pm +++ b/test/lib/pgBackRestTest/Common/DefineTest.pm @@ -56,8 +56,6 @@ use constant TESTDEF_DEFINE => 'define'; push @EXPORT, qw(TESTDEF_DEFINE); use constant TESTDEF_FEATURE => 'feature'; push @EXPORT, qw(TESTDEF_FEATURE); -use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress'; - push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS); use constant TESTDEF_HARNESS => 'harness'; push @EXPORT, qw(TESTDEF_HARNESS); # Harness name which must match the harness implementation file name @@ -152,8 +150,7 @@ sub testDefLoad # Resolve variables that can be set in the module or the test foreach my $strVar ( - TESTDEF_DEFINE, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_DB, TESTDEF_BIN_REQ, TESTDEF_VM, - TESTDEF_CONTAINER_REQUIRED) + TESTDEF_DEFINE, TESTDEF_DB, TESTDEF_BIN_REQ, TESTDEF_VM, TESTDEF_CONTAINER_REQUIRED) { $hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce( $hModuleTest->{$strVar}, $hModule->{$strVar}, $strVar eq TESTDEF_VM ? undef : false); diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index 895e5109d..96395dfac 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -295,7 +295,6 @@ sub run ($self->{bProfile} ? " \\\n\t-pg" : '') . (vmArchBits($self->{oTest}->{&TEST_VM}) == 32 ? " \\\n\t-D_FILE_OFFSET_BITS=64" : '') . ($self->{bDebug} ? '' : " \\\n\t-DNDEBUG") . - ($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : " \\\n\t-DDEBUG_UNIT") . ($self->{oTest}->{&TEST_VM} eq VM_CO7 ? " \\\n\t-DDEBUG_EXEC_TIME" : '') . ($bCoverage ? " \\\n\t-DDEBUG_COVERAGE" : '') . ($self->{bDebugTestTrace} && $self->{bDebug} ? " \\\n\t-DDEBUG_TEST_TRACE" : '') . diff --git a/test/lib/pgBackRestTest/Common/ListTest.pm b/test/lib/pgBackRestTest/Common/ListTest.pm index d548fb9ac..2335c45cf 100644 --- a/test/lib/pgBackRestTest/Common/ListTest.pm +++ b/test/lib/pgBackRestTest/Common/ListTest.pm @@ -32,8 +32,6 @@ use constant TEST_CTESTDEF => 'ctestdef push @EXPORT, qw(TEST_CTESTDEF); use constant TEST_CONTAINER => 'container'; push @EXPORT, qw(TEST_CONTAINER); -use constant TEST_DEBUG_UNIT_SUPPRESS => TESTDEF_DEBUG_UNIT_SUPPRESS; - push @EXPORT, qw(TEST_DEBUG_UNIT_SUPPRESS); use constant TEST_MODULE => 'module'; push @EXPORT, qw(TEST_MODULE); use constant TEST_NAME => 'test'; @@ -172,7 +170,6 @@ sub testListGet &TEST_C => coalesce($hTest->{&TESTDEF_C}, $hModule->{&TESTDEF_C}, false), &TEST_CDEF => $hTest->{&TESTDEF_DEFINE}, &TEST_CTESTDEF => $hTest->{&TESTDEF_FEATURE}, - &TEST_DEBUG_UNIT_SUPPRESS => $hTest->{&TEST_DEBUG_UNIT_SUPPRESS}, &TEST_CONTAINER => defined($hTest->{&TESTDEF_CONTAINER}) ? $hTest->{&TESTDEF_CONTAINER} : $hModule->{&TESTDEF_CONTAINER}, &TEST_PGSQL_BIN => $strPgSqlBin, diff --git a/test/src/common/harnessLog.c b/test/src/common/harnessLog.c index 025827a8b..282554e8a 100644 --- a/test/src/common/harnessLog.c +++ b/test/src/common/harnessLog.c @@ -18,13 +18,9 @@ Log Test Harness #include "common/harnessTest.h" /*********************************************************************************************************************************** -Expose log internal data for unit testing/debugging +Include shimmed C modules ***********************************************************************************************************************************/ -extern LogLevel logLevelFile; -extern int logFdFile; -extern bool logFileBanner; -extern unsigned int logProcessId; -extern void logAnySet(void); +{[SHIM_MODULE]} /*********************************************************************************************************************************** Log settings for testing @@ -92,6 +88,53 @@ harnessLogDryRunSet(bool dryRun) logInit(logLevelTestDefault, logLevelOff, logLevelTest, false, logProcessId, 99, logDryRunTest); } +/**********************************************************************************************************************************/ +unsigned int +hrnLogLevelFile(void) +{ + return logLevelFile; +} + +void hrnLogLevelFileSet(unsigned int logLevel) +{ + logLevelFile = logLevel; +} + +unsigned int +hrnLogLevelStdOut(void) +{ + return logLevelStdOut; +} + +void hrnLogLevelStdOutSet(unsigned int logLevel) +{ + logLevelStdOut = logLevel; +} + +unsigned int +hrnLogLevelStdErr(void) +{ + return logLevelStdErr; +} + +void hrnLogLevelStdErrSet(unsigned int logLevel) +{ + logLevelStdErr = logLevel; +} + +/**********************************************************************************************************************************/ +bool +hrnLogTimestamp(void) +{ + return logTimestamp; +} + +void +hrnLogTimestampSet(bool log) +{ + logTimestamp = log; +} + /*********************************************************************************************************************************** Change test log level diff --git a/test/src/common/harnessLog.h b/test/src/common/harnessLog.h index 89d2db4ba..92558aacb 100644 --- a/test/src/common/harnessLog.h +++ b/test/src/common/harnessLog.h @@ -23,6 +23,18 @@ void harnessLogResultRegExp(const char *expression); /*********************************************************************************************************************************** Getters/Setters ***********************************************************************************************************************************/ +// Get/set log levels +unsigned int hrnLogLevelFile(void); +void hrnLogLevelFileSet(unsigned int logLevel); +unsigned int hrnLogLevelStdOut(void); +void hrnLogLevelStdOutSet(unsigned int logLevel); +unsigned int hrnLogLevelStdErr(void); +void hrnLogLevelStdErrSet(unsigned int logLevel); + +// Get/set log timestamp +bool hrnLogTimestamp(void); +void hrnLogTimestampSet(bool log); + void harnessLogLevelReset(void); void harnessLogLevelSet(LogLevel logLevel); diff --git a/test/src/module/common/debugOffTest.c b/test/src/module/common/debugOffTest.c index cc7b6c955..1a83cc185 100644 --- a/test/src/module/common/debugOffTest.c +++ b/test/src/module/common/debugOffTest.c @@ -23,12 +23,5 @@ testRun(void) TEST_RESULT_BOOL(debug, false, "DEBUG is not defined"); } - // ***************************************************************************************************************************** - if (testBegin("DEBUG_UNIT_EXTERN")) - { - const char *debugUnitExtern = STRINGIFY(DEBUG_UNIT_EXTERN); - TEST_RESULT_Z(debugUnitExtern, "static", "DEBUG_UNIT_EXTERN is static"); - } - FUNCTION_HARNESS_RETURN_VOID(); } diff --git a/test/src/module/common/debugOnTest.c b/test/src/module/common/debugOnTest.c index 54264bea4..2afb7c20e 100644 --- a/test/src/module/common/debugOnTest.c +++ b/test/src/module/common/debugOnTest.c @@ -106,13 +106,6 @@ testRun(void) TEST_RESULT_BOOL(debug, true, "DEBUG is defined"); } - // ***************************************************************************************************************************** - if (testBegin("DEBUG_UNIT_EXTERN")) - { - const char *debugUnitExtern = STRINGIFY(DEBUG_UNIT_EXTERN); - TEST_RESULT_Z(debugUnitExtern, "", "DEBUG_UNIT_EXTERN is blank (extern)"); - } - // ***************************************************************************************************************************** if (testBegin("FUNCTION_DEBUG() and FUNCTION_LOG_RETURN()")) { diff --git a/test/src/module/config/loadTest.c b/test/src/module/config/loadTest.c index 2529650f7..2cad3de3d 100644 --- a/test/src/module/config/loadTest.c +++ b/test/src/module/config/loadTest.c @@ -25,10 +25,10 @@ testRun(void) TEST_RESULT_VOID(cfgLoadLogSetting(), "load log settings all defaults"); - TEST_RESULT_INT(logLevelStdOut, logLevelOff, "console logging is off"); - TEST_RESULT_INT(logLevelStdErr, logLevelOff, "stderr logging is off"); - TEST_RESULT_INT(logLevelFile, logLevelOff, "file logging is off"); - TEST_RESULT_BOOL(logTimestamp, true, "timestamp logging is on"); + TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelOff, "console logging is off"); + TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelOff, "stderr logging is off"); + TEST_RESULT_INT(hrnLogLevelFile(), logLevelOff, "file logging is off"); + TEST_RESULT_BOOL(hrnLogTimestamp(), true, "timestamp logging is on"); } // ***************************************************************************************************************************** diff --git a/test/src/module/config/parseTest.c b/test/src/module/config/parseTest.c index 8611eed36..303d67bdd 100644 --- a/test/src/module/config/parseTest.c +++ b/test/src/module/config/parseTest.c @@ -836,15 +836,15 @@ testRun(void) strLstAdd(argList, strNew("--log-level-stderr=info")); strLstAddZ(argList, CFGCMD_BACKUP ":" CONFIG_COMMAND_ROLE_LOCAL); - logLevelStdOut = logLevelError; - logLevelStdErr = logLevelError; + hrnLogLevelStdOutSet(logLevelError); + hrnLogLevelStdErrSet(logLevelError); TEST_RESULT_VOID(configParse(storageTest, strLstSize(argList), strLstPtr(argList), true), "load local config"); TEST_RESULT_STR_Z(cfgOptionStr(cfgOptPgPath), "/path/to/2", "default pg-path"); TEST_RESULT_INT(cfgCommandRole(), cfgCmdRoleLocal, " command role is local"); TEST_RESULT_BOOL(cfgLockRequired(), false, " backup:local command does not require lock"); TEST_RESULT_STR_Z(cfgCommandRoleName(), "backup:local", " command/role name is backup:local"); - TEST_RESULT_INT(logLevelStdOut, logLevelError, "console logging is error"); - TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error"); + TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelError, "console logging is error"); + TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelError, "stderr logging is error"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); @@ -855,13 +855,13 @@ testRun(void) strLstAdd(argList, strNew("--log-level-stderr=info")); strLstAddZ(argList, CFGCMD_BACKUP ":" CONFIG_COMMAND_ROLE_REMOTE); - logLevelStdOut = logLevelError; - logLevelStdErr = logLevelError; + hrnLogLevelStdOutSet(logLevelError); + hrnLogLevelStdErrSet(logLevelError); TEST_RESULT_VOID(configParse(storageTest, strLstSize(argList), strLstPtr(argList), true), "load remote config"); TEST_RESULT_INT(cfgCommandRole(), cfgCmdRoleRemote, " command role is remote"); TEST_RESULT_STR_Z(cfgCommandRoleStr(cfgCmdRoleRemote), "remote", " remote role name"); - TEST_RESULT_INT(logLevelStdOut, logLevelError, "console logging is error"); - TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error"); + TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelError, "console logging is error"); + TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelError, "stderr logging is error"); argList = strLstNew(); strLstAdd(argList, strNew("pgbackrest")); @@ -870,12 +870,12 @@ testRun(void) strLstAdd(argList, strNew("--log-level-stderr=info")); strLstAddZ(argList, CFGCMD_ARCHIVE_GET ":" CONFIG_COMMAND_ROLE_ASYNC); - logLevelStdOut = logLevelError; - logLevelStdErr = logLevelError; + hrnLogLevelStdOutSet(logLevelError); + hrnLogLevelStdErrSet(logLevelError); TEST_RESULT_VOID(configParse(storageTest, strLstSize(argList), strLstPtr(argList), true), "load async config"); TEST_RESULT_INT(cfgCommandRole(), cfgCmdRoleAsync, " command role is async"); - TEST_RESULT_INT(logLevelStdOut, logLevelError, "console logging is error"); - TEST_RESULT_INT(logLevelStdErr, logLevelError, "stderr logging is error"); + TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelError, "console logging is error"); + TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelError, "stderr logging is error"); harnessLogLevelReset(); @@ -1158,13 +1158,13 @@ testRun(void) argList = strLstNew(); strLstAdd(argList, strNew(TEST_BACKREST_EXE)); - logLevelStdOut = logLevelOff; - logLevelStdErr = logLevelOff; + hrnLogLevelStdOutSet(logLevelOff); + hrnLogLevelStdErrSet(logLevelOff); TEST_RESULT_VOID(configParse(storageTest, strLstSize(argList), strLstPtr(argList), true), "no command"); TEST_RESULT_BOOL(cfgCommandHelp(), true, " help is set"); TEST_RESULT_INT(cfgCommand(), cfgCmdNone, " command is none"); - TEST_RESULT_INT(logLevelStdOut, logLevelWarn, "console logging is warn"); - TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is warn"); + TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelWarn, "console logging is warn"); + TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelWarn, "stderr logging is warn"); harnessLogLevelReset(); // -------------------------------------------------------------------------------------------------------------------------