2013-11-17 21:58:21 +03:00
|
|
|
#!/usr/bin/perl
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
2014-06-08 00:29:11 +03:00
|
|
|
# test.pl - BackRest Unit Tests
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2014-08-11 04:22:17 +03:00
|
|
|
use Carp;
|
2014-04-03 00:25:37 +03:00
|
|
|
|
|
|
|
use File::Basename;
|
|
|
|
use Getopt::Long;
|
2014-08-11 04:22:17 +03:00
|
|
|
use Cwd 'abs_path';
|
|
|
|
use Cwd;
|
2014-04-03 00:25:37 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
use lib dirname($0) . '/../lib';
|
2014-06-22 17:30:17 +03:00
|
|
|
use BackRest::Utility;
|
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
use lib dirname($0) . '/lib';
|
2014-06-22 17:30:17 +03:00
|
|
|
use BackRestTest::CommonTest;
|
2014-07-17 06:38:38 +03:00
|
|
|
use BackRestTest::UtilityTest;
|
2014-05-14 22:07:37 +03:00
|
|
|
use BackRestTest::FileTest;
|
2014-06-22 18:56:01 +03:00
|
|
|
use BackRestTest::BackupTest;
|
2014-04-03 00:25:37 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2014-06-04 04:22:07 +03:00
|
|
|
# Command line parameters
|
|
|
|
####################################################################################################################################
|
2014-06-05 17:20:03 +03:00
|
|
|
my $strLogLevel = 'off'; # Log level for tests
|
|
|
|
my $strModule = 'all';
|
|
|
|
my $strModuleTest = 'all';
|
2014-06-22 17:54:31 +03:00
|
|
|
my $iModuleTestRun = undef;
|
2014-07-16 05:32:41 +03:00
|
|
|
my $bDryRun = false;
|
|
|
|
my $bNoCleanup = false;
|
2014-08-11 04:22:17 +03:00
|
|
|
my $strPgSqlBin;
|
|
|
|
my $strTestPath;
|
2014-06-04 04:22:07 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
GetOptions ('pgsql-bin=s' => \$strPgSqlBin,
|
|
|
|
'test-path=s' => \$strTestPath,
|
|
|
|
'log-level=s' => \$strLogLevel,
|
|
|
|
'module=s' => \$strModule,
|
|
|
|
'module-test=s' => \$strModuleTest,
|
|
|
|
'module-test-run=s' => \$iModuleTestRun,
|
|
|
|
'dry-run' => \$bDryRun,
|
|
|
|
'no-cleanup' => \$bNoCleanup)
|
|
|
|
or die 'error in command line arguments';
|
2014-06-04 04:22:07 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Setup
|
|
|
|
####################################################################################################################################
|
|
|
|
# Set a neutral umask so tests work as expected
|
|
|
|
umask(0);
|
|
|
|
|
|
|
|
# Set console log level to trace for testing
|
|
|
|
log_level_set(undef, uc($strLogLevel));
|
|
|
|
|
2014-06-05 17:20:03 +03:00
|
|
|
if ($strModuleTest ne 'all' && $strModule eq 'all')
|
|
|
|
{
|
|
|
|
confess "--module must be provided for test \"${strModuleTest}\"";
|
|
|
|
}
|
|
|
|
|
2014-06-22 17:54:31 +03:00
|
|
|
if (defined($iModuleTestRun) && $strModuleTest eq 'all')
|
|
|
|
{
|
|
|
|
confess "--module-test must be provided for run \"${iModuleTestRun}\"";
|
|
|
|
}
|
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
# Make sure PG bin has been defined
|
|
|
|
if (!defined($strPgSqlBin))
|
|
|
|
{
|
2014-09-16 18:22:55 +03:00
|
|
|
confess 'pgsql-bin was not defined';
|
2014-08-11 04:22:17 +03:00
|
|
|
}
|
2014-06-08 00:29:11 +03:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Make sure version number matches in README.md and VERSION
|
|
|
|
####################################################################################################################################
|
|
|
|
my $hReadMe;
|
|
|
|
my $strLine;
|
|
|
|
my $bMatch = false;
|
|
|
|
my $strVersion = version_get();
|
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
if (!open($hReadMe, '<', dirname($0) . '/../README.md'))
|
2014-06-08 00:29:11 +03:00
|
|
|
{
|
2014-09-16 18:22:55 +03:00
|
|
|
confess 'unable to open README.md';
|
2014-06-08 00:29:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while ($strLine = readline($hReadMe))
|
|
|
|
{
|
|
|
|
if ($strLine =~ /^\#\#\# v/)
|
|
|
|
{
|
|
|
|
$bMatch = substr($strLine, 5, length($strVersion)) eq $strVersion;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$bMatch)
|
|
|
|
{
|
|
|
|
confess "unable to find version ${strVersion} as last revision in README.md";
|
|
|
|
}
|
|
|
|
|
2014-08-11 04:22:17 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# Clean whitespace only if test.pl is being run from the test directory in the backrest repo
|
|
|
|
####################################################################################################################################
|
|
|
|
my $hVersion;
|
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
if (-e './test.pl' && -e '../bin/pg_backrest.pl' && open($hVersion, '<', '../VERSION'))
|
2014-08-11 04:22:17 +03:00
|
|
|
{
|
|
|
|
my $strTestVersion = readline($hVersion);
|
|
|
|
|
|
|
|
if (defined($strTestVersion) && $strVersion eq trim($strTestVersion))
|
|
|
|
{
|
|
|
|
BackRestTestCommon_Execute(
|
|
|
|
"find .. -type f -not -path \"../.git/*\" -not -path \"*.DS_Store\" -not -path \"../test/test/*\" " .
|
|
|
|
"-not -path \"../test/data/*\" " .
|
|
|
|
"-exec sh -c 'for i;do echo \"\$i\" && sed 's/[[:space:]]*\$//' \"\$i\">/tmp/.\$\$ && cat /tmp/.\$\$ " .
|
|
|
|
"> \"\$i\";done' arg0 {} + > /dev/null", false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
close($hVersion);
|
|
|
|
}
|
|
|
|
|
2014-06-04 04:22:07 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
# Runs tests
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
2014-08-11 04:22:17 +03:00
|
|
|
BackRestTestCommon_Setup($strTestPath, $strPgSqlBin, $iModuleTestRun, $bDryRun, $bNoCleanup);
|
2014-07-16 05:32:41 +03:00
|
|
|
|
|
|
|
# &log(INFO, "Testing with test_path = " . BackRestTestCommon_TestPathGet() . ", host = {strHost}, user = {strUser}, " .
|
|
|
|
# "group = {strGroup}");
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
if ($strModule eq 'all' || $strModule eq 'utility')
|
2014-07-17 06:38:38 +03:00
|
|
|
{
|
|
|
|
BackRestTestUtility_Test($strModuleTest);
|
|
|
|
}
|
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
if ($strModule eq 'all' || $strModule eq 'file')
|
2014-06-05 17:20:03 +03:00
|
|
|
{
|
2014-07-16 05:32:41 +03:00
|
|
|
BackRestTestFile_Test($strModuleTest);
|
2014-06-05 17:20:03 +03:00
|
|
|
}
|
2014-05-14 22:07:37 +03:00
|
|
|
|
2014-09-16 18:22:55 +03:00
|
|
|
if ($strModule eq 'all' || $strModule eq 'backup')
|
2014-06-22 18:56:01 +03:00
|
|
|
{
|
2014-07-16 05:32:41 +03:00
|
|
|
BackRestTestBackup_Test($strModuleTest);
|
2014-06-22 18:56:01 +03:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:32:41 +03:00
|
|
|
if (!$bDryRun)
|
|
|
|
{
|
2014-09-16 18:22:55 +03:00
|
|
|
&log(ASSERT, 'TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)');
|
2014-07-16 05:32:41 +03:00
|
|
|
}
|