1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Improvements to log testing.

Replaced tokens are now numbered to give a more accurate rendition of the logs.
Some formatting improvements.
This commit is contained in:
David Steele
2015-05-29 14:39:43 -04:00
parent 5fce709ae7
commit 5fd4f3bd5b
34 changed files with 8690 additions and 8526 deletions

View File

@@ -76,6 +76,7 @@ my $bFullLog = false;
my $hOut;
my $pId;
my $strCommand;
my $oReplaceHash = {};
# Test globals
my $strTestLog;
@@ -190,6 +191,7 @@ sub BackRestTestCommon_Run
}
$strFullLog = "${strTestLog}\n" . ('=' x length($strTestLog)) . "\n";
$oReplaceHash = {};
$strModule = $strModuleParam;
$strModuleTest = $strModuleTestParam;
@@ -273,24 +275,15 @@ sub BackRestTestCommon_ExecuteBegin
$strOutLog = '';
$hOut = undef;
my $strBinPath = dirname(dirname(abs_path($0))) . '/bin';
$bFullLog = false;
if ($strCommandParam =~ /\/bin\/pg_backrest\.pl/)
{
my $strTestPath = BackRestTestCommon_TestPathGet();
$strCommandParam =~ s/$strBinPath/[BACKREST_BIN_PATH]/g;
$strCommandParam =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/;
if (defined($strTestPath))
{
$strCommandParam =~ s/$strTestPath/[TEST_PATH]/g;
}
$strCommandParam = BackRestTestCommon_ExecuteRegAll($strCommandParam);
if (defined($strComment))
{
$strComment =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/;
$strComment = BackRestTestCommon_ExecuteRegAll($strComment);
$strFullLog .= "\n${strComment}";
}
@@ -304,6 +297,106 @@ sub BackRestTestCommon_ExecuteBegin
$pId = open3(undef, $hOut, $hError, $strCommand);
}
####################################################################################################################################
# BackRestTestCommon_ExecuteRegExp
####################################################################################################################################
sub BackRestTestCommon_ExecuteRegExp
{
my $strLine = shift;
my $strType = shift;
my $strExpression = shift;
my $strToken = shift;
my $bIndex = shift;
my @stryReplace = ($strLine =~ /$strExpression/g);
foreach my $strReplace (@stryReplace)
{
my $iIndex;
my $strTypeReplacement;
if (!defined($bIndex) || $bIndex)
{
if (defined($$oReplaceHash{$strType}{$strReplace}))
{
$iIndex = $$oReplaceHash{$strType}{$strReplace}{index};
}
else
{
if (!defined($$oReplaceHash{$strType}{index}))
{
$$oReplaceHash{$strType}{index} = 1;
}
$iIndex = $$oReplaceHash{$strType}{index}++;
$$oReplaceHash{$strType}{$strReplace}{index} = $iIndex;
}
}
$strTypeReplacement = "[${strType}" . (defined($iIndex) ? "-${iIndex}" : '') . ']';
my $strReplacement;
if (defined($strToken))
{
$strReplacement = $strReplace;
$strReplacement =~ s/$strToken/$strTypeReplacement/;
}
else
{
$strReplacement = $strTypeReplacement;
}
$strLine =~ s/$strReplace/$strReplacement/g;
}
return $strLine;
}
####################################################################################################################################
# BackRestTestCommon_ExecuteRegExpAll
####################################################################################################################################
sub BackRestTestCommon_ExecuteRegAll
{
my $strLine = shift;
my $strBinPath = dirname(dirname(abs_path($0))) . '/bin';
$strLine =~ s/$strBinPath/[BACKREST_BIN_PATH]/g;
my $strTestPath = BackRestTestCommon_TestPathGet();
if (defined($strTestPath))
{
$strLine =~ s/$strTestPath/[TEST_PATH]/g;
}
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'MODIFICATION-TIME', 'modification_time = [0-9]+', '[0-9]+$');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-INCR', '[0-9]{8}\-[0-9]{6}F\_[0-9]{8}\-[0-9]{6}I');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-DIFF', '[0-9]{8}\-[0-9]{6}F\_[0-9]{8}\-[0-9]{6}D');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'BACKUP-FULL', '[0-9]{8}\-[0-9]{6}F');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'GROUP', 'group = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'USER', 'user = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'VERSION', 'version = ' . version_get(), version_get . '$');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'VERSION', '"version" : ' . version_get(), version_get . '$');
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'FORMAT', '"format" : ' . FORMAT, FORMAT . '$');
my $strTimestampRegExp = "[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]";
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP', "\"timestamp-copy-start\" : \"$strTimestampRegExp\"",
$strTimestampRegExp, false);
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP', "\"timestamp-start\" : \"$strTimestampRegExp\"",
$strTimestampRegExp, false);
$strLine = BackRestTestCommon_ExecuteRegExp($strLine, 'TIMESTAMP', "\"timestamp-stop\" : \"$strTimestampRegExp\"",
$strTimestampRegExp, false);
return $strLine;
}
####################################################################################################################################
# BackRestTestCommon_ExecuteEnd
####################################################################################################################################
@@ -318,10 +411,6 @@ sub BackRestTestCommon_ExecuteEnd
$bSuppressError = defined($bSuppressError) ? $bSuppressError : false;
$bShowOutput = defined($bShowOutput) ? $bShowOutput : false;
# Get test path
my $strTestPath = BackRestTestCommon_TestPathGet();
my $strVersion = version_get();
# Create select objects
my $oErrorSelect = IO::Select->new();
$oErrorSelect->add($hError);
@@ -355,21 +444,14 @@ sub BackRestTestCommon_ExecuteEnd
if ($bFullLog)
{
$strLine =~ s/^[^ ]* [^ ]* [^ ]* //;
$strLine =~ s/\r//;
$strLine =~ s/[0-9]{8}\-[0-9]{6}F(\_[0-9]{8}\-[0-9]{6}(D|I)){0,1}/[BACKUP_LABEL]/g;
$strLine =~ s/version = $strVersion/version = [VERSION]/g;
$strLine =~ s/modification_time = [0-9]+/modification_time = [MODIFICATION_TIME]/g;
$strLine =~ s/user = [^ \n,\[\]]+/user = [USER]/g;
$strLine =~ s/group = [^ \n,\[\]]+/group = [GROUP]/g;
$strLine =~ s/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]\.[0-9]{3} T[0-9]{2} //;
if (defined($strTestPath))
if ($strLine !~ /^ TEST/ && $strLine =~ /^ /)
{
$strLine =~ s/$strTestPath/[TEST_PATH]/g;
}
$strLine =~ s/^ //;
$strLine =~ s/^ //;
if ($strLine !~ /^ TEST/)
{
$strLine = BackRestTestCommon_ExecuteRegAll($strLine);
$strFullLog .= $strLine;
}
}