mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-19 21:07:53 +02:00
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.
This commit is contained in:
parent
58e9f1e50c
commit
8568622a6f
@ -92,6 +92,10 @@
|
|||||||
<release-item>
|
<release-item>
|
||||||
<p>Refactor the <code>common/log</code> tests to not depend on <code>common/harnessLog</code>. <code>common/harnessLog</code> was not ideally suited for general testing and made all the tests quite awkward. Instead, move all code used to test the <code>common/log</code> module into the <code>logTest</code> module and repurpose <code>common/harnessLog</code> 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 <code>config/parse</code>.</p>
|
<p>Refactor the <code>common/log</code> tests to not depend on <code>common/harnessLog</code>. <code>common/harnessLog</code> was not ideally suited for general testing and made all the tests quite awkward. Instead, move all code used to test the <code>common/log</code> module into the <code>logTest</code> module and repurpose <code>common/harnessLog</code> 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 <code>config/parse</code>.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Add <setting>--log-level-test</setting> 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.</p>
|
||||||
|
</release-item>
|
||||||
</release-development-list>
|
</release-development-list>
|
||||||
</release-test-list>
|
</release-test-list>
|
||||||
</release>
|
</release>
|
||||||
|
@ -62,6 +62,7 @@ sub new
|
|||||||
$self->{iTestIdx},
|
$self->{iTestIdx},
|
||||||
$self->{iTestMax},
|
$self->{iTestMax},
|
||||||
$self->{strLogLevel},
|
$self->{strLogLevel},
|
||||||
|
$self->{strLogLevelTest},
|
||||||
$self->{bLogForce},
|
$self->{bLogForce},
|
||||||
$self->{bShowOutputAsync},
|
$self->{bShowOutputAsync},
|
||||||
$self->{bNoCleanup},
|
$self->{bNoCleanup},
|
||||||
@ -88,6 +89,7 @@ sub new
|
|||||||
{name => 'iTestIdx'},
|
{name => 'iTestIdx'},
|
||||||
{name => 'iTestMax'},
|
{name => 'iTestMax'},
|
||||||
{name => 'strLogLevel'},
|
{name => 'strLogLevel'},
|
||||||
|
{name => 'strLogLevelTest'},
|
||||||
{name => 'bLogForce'},
|
{name => 'bLogForce'},
|
||||||
{name => 'bShowOutputAsync'},
|
{name => 'bShowOutputAsync'},
|
||||||
{name => 'bNoCleanup'},
|
{name => 'bNoCleanup'},
|
||||||
@ -329,6 +331,10 @@ sub run
|
|||||||
# Set globals
|
# Set globals
|
||||||
$strTestC =~ s/\{\[C\_TEST\_PATH\]\}/$strVmTestPath/g;
|
$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
|
# Initialize tests
|
||||||
my $strTestInit;
|
my $strTestInit;
|
||||||
|
|
||||||
|
@ -17,11 +17,15 @@ Log Test Harness
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Expose log internal data for unit testing/debugging
|
Expose log internal data for unit testing/debugging
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
extern LogLevel logLevelStdOut;
|
|
||||||
extern LogLevel logLevelFile;
|
extern LogLevel logLevelFile;
|
||||||
extern int logHandleFile;
|
extern int logHandleFile;
|
||||||
extern bool logFileBanner;
|
extern bool logFileBanner;
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Default log level for testing
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
LogLevel logLevelTestDefault = logLevelOff;
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Name of file where logs are stored for testing
|
Name of file where logs are stored for testing
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
@ -62,7 +66,7 @@ harnessLogInit()
|
|||||||
{
|
{
|
||||||
FUNCTION_HARNESS_VOID();
|
FUNCTION_HARNESS_VOID();
|
||||||
|
|
||||||
logInit(logLevelOff, logLevelOff, logLevelInfo, false);
|
logInit(logLevelTestDefault, logLevelOff, logLevelInfo, false);
|
||||||
logFileBanner = true;
|
logFileBanner = true;
|
||||||
|
|
||||||
snprintf(logFile, sizeof(logFile), "%s/expect.log", testPath());
|
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
|
void
|
||||||
harnessLogLevelSet(LogLevel logLevel)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -15,6 +15,7 @@ void harnessLogResultRegExp(const char *expression);
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Setters
|
Setters
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
void harnessLogLevelReset();
|
||||||
void harnessLogLevelSet(LogLevel logLevel);
|
void harnessLogLevelSet(LogLevel logLevel);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -95,7 +95,7 @@ testRun()
|
|||||||
// Nothing should be logged for command end when the log level is too low
|
// Nothing should be logged for command end when the log level is too low
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TEST_RESULT_VOID(cmdEnd(0, NULL), "command end no logging");
|
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");
|
TEST_RESULT_VOID(cmdEnd(25, strNew("aborted with exception [025]")), "command end with error");
|
||||||
|
@ -120,10 +120,9 @@ testRun()
|
|||||||
"P00 TRACE: module/common/debugOnTest::testFunction2: (void)\n"
|
"P00 TRACE: module/common/debugOnTest::testFunction2: (void)\n"
|
||||||
"P00 TRACE: module/common/debugOnTest::testFunction2: => void\n"
|
"P00 TRACE: module/common/debugOnTest::testFunction2: => void\n"
|
||||||
"P00 DEBUG: module/common/debugOnTest::testFunction1: => 1");
|
"P00 DEBUG: module/common/debugOnTest::testFunction1: => 1");
|
||||||
harnessLogLevelSet(logLevelTrace);
|
harnessLogLevelReset();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
harnessLogLevelSet(logLevelInfo);
|
|
||||||
testFunction1(55, true, 0.99, 0755);
|
testFunction1(55, true, 0.99, 0755);
|
||||||
|
|
||||||
harnessLogResult("");
|
harnessLogResult("");
|
||||||
|
@ -87,7 +87,7 @@ testRun()
|
|||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
|
|
||||||
harnessLogLevelSet(logLevelInfo);
|
harnessLogLevelReset();
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TRY_BEGIN()
|
TRY_BEGIN()
|
||||||
|
@ -931,9 +931,7 @@ testRun()
|
|||||||
TEST_RESULT_INT(cfgCommand(), cfgCmdNone, " command is none");
|
TEST_RESULT_INT(cfgCommand(), cfgCmdNone, " command is none");
|
||||||
TEST_RESULT_INT(logLevelStdOut, logLevelWarn, "console logging is warn");
|
TEST_RESULT_INT(logLevelStdOut, logLevelWarn, "console logging is warn");
|
||||||
TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is warn");
|
TEST_RESULT_INT(logLevelStdErr, logLevelWarn, "stderr logging is warn");
|
||||||
logLevelStdOut = logLevelOff;
|
harnessLogLevelReset();
|
||||||
logLevelStdErr = logLevelOff;
|
|
||||||
logLevelFile = logLevelInfo;
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
|
@ -18,6 +18,7 @@ This wrapper runs the the C unit tests.
|
|||||||
|
|
||||||
#ifndef NO_LOG
|
#ifndef NO_LOG
|
||||||
#include "common/harnessLog.h"
|
#include "common/harnessLog.h"
|
||||||
|
void harnessLogLevelDefaultSet(LogLevel logLevel);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NO_MEM_CONTEXT
|
#ifndef NO_MEM_CONTEXT
|
||||||
@ -73,6 +74,11 @@ main(int argListSize, const char *argList[])
|
|||||||
testExeSet(argList[0]);
|
testExeSet(argList[0]);
|
||||||
testPathSet("{[C_TEST_PATH]}");
|
testPathSet("{[C_TEST_PATH]}");
|
||||||
|
|
||||||
|
// Set default test log level
|
||||||
|
#ifndef NO_LOG
|
||||||
|
harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]});
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize tests
|
// Initialize tests
|
||||||
// run, selected
|
// run, selected
|
||||||
{[C_TEST_LIST]}
|
{[C_TEST_LIST]}
|
||||||
|
@ -101,7 +101,8 @@ test.pl [options]
|
|||||||
Configuration Options:
|
Configuration Options:
|
||||||
--psql-bin path to the psql executables (e.g. /usr/lib/postgresql/9.3/bin/)
|
--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)
|
--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
|
--quiet, -q equivalent to --log-level=off
|
||||||
|
|
||||||
VM Options:
|
VM Options:
|
||||||
@ -120,6 +121,7 @@ test.pl [options]
|
|||||||
# Command line parameters
|
# Command line parameters
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
my $strLogLevel = lc(INFO);
|
my $strLogLevel = lc(INFO);
|
||||||
|
my $strLogLevelTest = lc(OFF);
|
||||||
my $bVmOut = false;
|
my $bVmOut = false;
|
||||||
my @stryModule;
|
my @stryModule;
|
||||||
my @stryModuleTest;
|
my @stryModuleTest;
|
||||||
@ -166,6 +168,7 @@ GetOptions ('q|quiet' => \$bQuiet,
|
|||||||
'pgsql-bin=s' => \$strPgSqlBin,
|
'pgsql-bin=s' => \$strPgSqlBin,
|
||||||
'test-path=s' => \$strTestPath,
|
'test-path=s' => \$strTestPath,
|
||||||
'log-level=s' => \$strLogLevel,
|
'log-level=s' => \$strLogLevel,
|
||||||
|
'log-level-test=s' => \$strLogLevelTest,
|
||||||
'vm=s' => \$strVm,
|
'vm=s' => \$strVm,
|
||||||
'vm-host=s' => \$strVmHost,
|
'vm-host=s' => \$strVmHost,
|
||||||
'vm-out' => \$bVmOut,
|
'vm-out' => \$bVmOut,
|
||||||
@ -1136,7 +1139,7 @@ eval
|
|||||||
{
|
{
|
||||||
my $oJob = new pgBackRestTest::Common::JobTest(
|
my $oJob = new pgBackRestTest::Common::JobTest(
|
||||||
$oStorageTest, $strBackRestBase, $strTestPath, $strCoveragePath, $$oyTestRun[$iTestIdx], $bDryRun, $bVmOut,
|
$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);
|
!$bNoValgrind, !$bNoCoverage, !$bNoOptimize, $bBackTrace, $bProfile, !$bNoDebug);
|
||||||
$iTestIdx++;
|
$iTestIdx++;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user