diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 15219db3a..11ee01e3c 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -92,6 +92,10 @@

Refactor the common/log tests to not depend on common/harnessLog. common/harnessLog was not ideally suited for general testing and made all the tests quite awkward. Instead, move all code used to test the common/log module into the logTest module and repurpose common/harnessLog to do log expect testing for all other tests in a cleaner way. Add a few exceptions for config testing since the log levels are reset by default in config/parse.

+ + +

Add --log-level-test option. This allows setting the test log level independently from the general test harness setting, but current only works for the C tests. It is useful for seeing log output from functions on the console while a test is running.

+
diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index e6093a22b..42aafad5b 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -62,6 +62,7 @@ sub new $self->{iTestIdx}, $self->{iTestMax}, $self->{strLogLevel}, + $self->{strLogLevelTest}, $self->{bLogForce}, $self->{bShowOutputAsync}, $self->{bNoCleanup}, @@ -88,6 +89,7 @@ sub new {name => 'iTestIdx'}, {name => 'iTestMax'}, {name => 'strLogLevel'}, + {name => 'strLogLevelTest'}, {name => 'bLogForce'}, {name => 'bShowOutputAsync'}, {name => 'bNoCleanup'}, @@ -329,6 +331,10 @@ sub run # Set globals $strTestC =~ s/\{\[C\_TEST\_PATH\]\}/$strVmTestPath/g; + # Set defalt log level + my $strLogLevelTestC = "logLevel" . ucfirst($self->{strLogLevelTest}); + $strTestC =~ s/\{\[C\_LOG\_LEVEL\_TEST\]\}/$strLogLevelTestC/g; + # Initialize tests my $strTestInit; diff --git a/test/src/common/harnessLog.c b/test/src/common/harnessLog.c index 4b2fdcc20..490b6981a 100644 --- a/test/src/common/harnessLog.c +++ b/test/src/common/harnessLog.c @@ -17,11 +17,15 @@ Log Test Harness /*********************************************************************************************************************************** Expose log internal data for unit testing/debugging ***********************************************************************************************************************************/ -extern LogLevel logLevelStdOut; extern LogLevel logLevelFile; extern int logHandleFile; extern bool logFileBanner; +/*********************************************************************************************************************************** +Default log level for testing +***********************************************************************************************************************************/ +LogLevel logLevelTestDefault = logLevelOff; + /*********************************************************************************************************************************** Name of file where logs are stored for testing ***********************************************************************************************************************************/ @@ -62,7 +66,7 @@ harnessLogInit() { FUNCTION_HARNESS_VOID(); - logInit(logLevelOff, logLevelOff, logLevelInfo, false); + logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false); logFileBanner = true; snprintf(logFile, sizeof(logFile), "%s/expect.log", testPath()); @@ -79,7 +83,29 @@ This is info by default but it can sometimes be useful to set the log level to s void harnessLogLevelSet(LogLevel logLevel) { - logInit(logLevelStdOut, logLevelOff, logLevel, false); + logInit(logLevelTestDefault, logLevelOff, logLevel, false); +} + +/*********************************************************************************************************************************** +Reset test log level + +Set back to info +***********************************************************************************************************************************/ +void +harnessLogLevelReset() +{ + logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false); +} + +/*********************************************************************************************************************************** +Change default test log level + +Set the default log level for output to the console (for testing). +***********************************************************************************************************************************/ +void +harnessLogLevelDefaultSet(LogLevel logLevel) +{ + logLevelTestDefault = logLevel; } /*********************************************************************************************************************************** diff --git a/test/src/common/harnessLog.h b/test/src/common/harnessLog.h index 57254d32f..af05dc13f 100644 --- a/test/src/common/harnessLog.h +++ b/test/src/common/harnessLog.h @@ -15,6 +15,7 @@ void harnessLogResultRegExp(const char *expression); /*********************************************************************************************************************************** Setters ***********************************************************************************************************************************/ +void harnessLogLevelReset(); void harnessLogLevelSet(LogLevel logLevel); #endif diff --git a/test/src/module/command/commandTest.c b/test/src/module/command/commandTest.c index c11b6853c..f496b5db4 100644 --- a/test/src/module/command/commandTest.c +++ b/test/src/module/command/commandTest.c @@ -95,7 +95,7 @@ testRun() // Nothing should be logged for command end when the log level is too low // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID(cmdEnd(0, NULL), "command end no logging"); - harnessLogLevelSet(logLevelInfo); + harnessLogLevelReset(); // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID(cmdEnd(25, strNew("aborted with exception [025]")), "command end with error"); diff --git a/test/src/module/common/debugOnTest.c b/test/src/module/common/debugOnTest.c index 1b9f5c7e4..25caaf8b1 100644 --- a/test/src/module/common/debugOnTest.c +++ b/test/src/module/common/debugOnTest.c @@ -120,10 +120,9 @@ testRun() "P00 TRACE: module/common/debugOnTest::testFunction2: (void)\n" "P00 TRACE: module/common/debugOnTest::testFunction2: => void\n" "P00 DEBUG: module/common/debugOnTest::testFunction1: => 1"); - harnessLogLevelSet(logLevelTrace); + harnessLogLevelReset(); // ------------------------------------------------------------------------------------------------------------------------- - harnessLogLevelSet(logLevelInfo); testFunction1(55, true, 0.99, 0755); harnessLogResult(""); diff --git a/test/src/module/common/exitTest.c b/test/src/module/common/exitTest.c index 36c591082..d22540d69 100644 --- a/test/src/module/common/exitTest.c +++ b/test/src/module/common/exitTest.c @@ -87,7 +87,7 @@ testRun() } TRY_END(); - harnessLogLevelSet(logLevelInfo); + harnessLogLevelReset(); // ------------------------------------------------------------------------------------------------------------------------- TRY_BEGIN() diff --git a/test/src/module/config/parseTest.c b/test/src/module/config/parseTest.c index 9718d59b1..8ac156204 100644 --- a/test/src/module/config/parseTest.c +++ b/test/src/module/config/parseTest.c @@ -931,9 +931,7 @@ testRun() 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"); - logLevelStdOut = logLevelOff; - logLevelStdErr = logLevelOff; - logLevelFile = logLevelInfo; + harnessLogLevelReset(); // ------------------------------------------------------------------------------------------------------------------------- argList = strLstNew(); diff --git a/test/src/test.c b/test/src/test.c index 4fb587888..64b85a81d 100644 --- a/test/src/test.c +++ b/test/src/test.c @@ -18,6 +18,7 @@ This wrapper runs the the C unit tests. #ifndef NO_LOG #include "common/harnessLog.h" + void harnessLogLevelDefaultSet(LogLevel logLevel); #endif #ifndef NO_MEM_CONTEXT @@ -73,6 +74,11 @@ main(int argListSize, const char *argList[]) testExeSet(argList[0]); testPathSet("{[C_TEST_PATH]}"); + // Set default test log level +#ifndef NO_LOG + harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]}); +#endif + // Initialize tests // run, selected {[C_TEST_LIST]} diff --git a/test/test.pl b/test/test.pl index 9a6c4b9c2..b6be942d3 100755 --- a/test/test.pl +++ b/test/test.pl @@ -101,7 +101,8 @@ test.pl [options] Configuration Options: --psql-bin path to the psql executables (e.g. /usr/lib/postgresql/9.3/bin/) --test-path path where tests are executed (defaults to ./test) - --log-level log level to use for tests (defaults to INFO) + --log-level log level to use for test harness (and Perl tests) (defaults to INFO) + --log-level-test log level to use for C tests (defaults to OFF) --quiet, -q equivalent to --log-level=off VM Options: @@ -120,6 +121,7 @@ test.pl [options] # Command line parameters #################################################################################################################################### my $strLogLevel = lc(INFO); +my $strLogLevelTest = lc(OFF); my $bVmOut = false; my @stryModule; my @stryModuleTest; @@ -166,6 +168,7 @@ GetOptions ('q|quiet' => \$bQuiet, 'pgsql-bin=s' => \$strPgSqlBin, 'test-path=s' => \$strTestPath, 'log-level=s' => \$strLogLevel, + 'log-level-test=s' => \$strLogLevelTest, 'vm=s' => \$strVm, 'vm-host=s' => \$strVmHost, 'vm-out' => \$bVmOut, @@ -1136,7 +1139,7 @@ eval { my $oJob = new pgBackRestTest::Common::JobTest( $oStorageTest, $strBackRestBase, $strTestPath, $strCoveragePath, $$oyTestRun[$iTestIdx], $bDryRun, $bVmOut, - $iVmIdx, $iVmMax, $iTestIdx, $iTestMax, $strLogLevel, $bLogForce, $bShowOutputAsync, $bNoCleanup, $iRetry, + $iVmIdx, $iVmMax, $iTestIdx, $iTestMax, $strLogLevel, $strLogLevelTest, $bLogForce, $bShowOutputAsync, $bNoCleanup, $iRetry, !$bNoValgrind, !$bNoCoverage, !$bNoOptimize, $bBackTrace, $bProfile, !$bNoDebug); $iTestIdx++;