2013-11-17 21:58:21 +03:00
|
|
|
#!/usr/bin/perl
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
# test.pl - pgBackRest Unit Tests
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
2015-04-19 23:27:40 +02:00
|
|
|
use warnings FATAL => qw(all);
|
2015-06-14 00:25:49 +02:00
|
|
|
use Carp qw(confess longmess);
|
2016-09-06 15:44:50 +02:00
|
|
|
use English '-no_match_vars';
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Convert die to confess to capture the stack trace
|
2015-06-14 00:25:49 +02:00
|
|
|
$SIG{__DIE__} = sub { Carp::confess @_ };
|
2014-04-03 00:25:37 +03:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Getopt::Long qw(GetOptions);
|
2016-01-15 02:37:06 +02:00
|
|
|
use Cwd qw(abs_path cwd);
|
2017-04-10 18:31:30 +02:00
|
|
|
use JSON::PP;
|
2015-08-29 20:20:46 +02:00
|
|
|
use Pod::Usage qw(pod2usage);
|
2017-02-18 05:31:16 +02:00
|
|
|
use POSIX qw(ceil strftime);
|
2016-01-09 15:21:53 +02:00
|
|
|
use Time::HiRes qw(gettimeofday);
|
2014-04-03 00:25:37 +03:00
|
|
|
|
2016-11-04 13:56:26 +02:00
|
|
|
use lib dirname($0) . '/lib';
|
2017-06-09 23:51:41 +02:00
|
|
|
use lib dirname(dirname($0)) . '/lib';
|
|
|
|
use lib dirname(dirname($0)) . '/doc/lib';
|
2016-11-04 13:56:26 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Common::Wait;
|
2016-09-06 15:35:02 +02:00
|
|
|
use pgBackRest::Config::Config;
|
2016-08-12 04:35:24 +02:00
|
|
|
use pgBackRest::DbVersion;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Storage::Helper;
|
|
|
|
use pgBackRest::Storage::Posix::Driver;
|
|
|
|
use pgBackRest::Storage::Local;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Version;
|
2014-06-22 17:30:17 +03:00
|
|
|
|
2016-06-28 02:37:25 +02:00
|
|
|
use BackRestDoc::Custom::DocCustomRelease;
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
use pgBackRestTest::Common::CiTest;
|
2017-04-10 18:31:30 +02:00
|
|
|
use pgBackRestTest::Common::DefineTest;
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::HostGroupTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
use pgBackRestTest::Common::JobTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::ListTest;
|
2016-12-23 15:22:59 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2016-12-13 01:54:07 +02:00
|
|
|
use pgBackRestTest::Common::VmTest;
|
2014-04-03 00:25:37 +03:00
|
|
|
|
2015-01-11 18:52:16 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Usage
|
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
test.pl - pgBackRest Unit Tests
|
2015-01-11 18:52:16 +02:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
test.pl [options]
|
|
|
|
|
|
|
|
Test Options:
|
2016-01-09 15:21:53 +02:00
|
|
|
--module test module to execute
|
2015-06-27 17:12:44 +02:00
|
|
|
--test execute the specified test in a module
|
|
|
|
--run execute only the specified test run
|
2016-09-06 15:35:02 +02:00
|
|
|
--process-max max processes to run for compression/transfer (default 1)
|
2015-01-12 16:05:26 +02:00
|
|
|
--dry-run show only the tests that would be executed but don't execute them
|
|
|
|
--no-cleanup don't cleaup after the last test is complete - useful for debugging
|
2016-05-11 14:59:34 +02:00
|
|
|
--db-version version of postgres to test (all, defaults to minimal)
|
2015-05-05 19:08:48 +02:00
|
|
|
--log-force force overwrite of current test log files
|
2017-01-10 03:49:04 +02:00
|
|
|
--no-lint disable static source code analysis
|
2017-02-18 05:31:16 +02:00
|
|
|
--build-only compile the C library / packages and run tests only
|
2017-04-10 18:31:30 +02:00
|
|
|
--coverage-only only run coverage tests (as a subset of selected tests)
|
2017-02-18 05:31:16 +02:00
|
|
|
--smart perform libc/package builds only when source timestamps have changed
|
|
|
|
--no-package do not build packages
|
2017-02-26 19:53:41 +02:00
|
|
|
--no-ci-config don't overwrite the current continuous integration config
|
2017-06-09 23:51:41 +02:00
|
|
|
--dev --no-lint --smart --no-package --process-max=1
|
2017-06-21 22:07:13 +02:00
|
|
|
--expect --no-lint --smart --no-package --process-max=1 --vm=co7 --db=9.6 --log-force
|
2015-01-11 18:52:16 +02:00
|
|
|
|
|
|
|
Configuration Options:
|
2015-01-12 16:05:26 +02:00
|
|
|
--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)
|
|
|
|
--quiet, -q equivalent to --log-level=off
|
2015-01-11 18:52:16 +02:00
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
VM Options:
|
2016-04-14 00:47:29 +02:00
|
|
|
--vm docker container to build/test (u12, u14, co6, co7)
|
2016-01-09 15:21:53 +02:00
|
|
|
--vm-build build Docker containers
|
2016-04-14 00:47:29 +02:00
|
|
|
--vm-force force a rebuild of Docker containers
|
2016-01-09 15:21:53 +02:00
|
|
|
--vm-out Show VM output (default false)
|
2016-09-06 15:35:02 +02:00
|
|
|
--vm-max max VMs to run in parallel (default 1)
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2015-01-11 18:52:16 +02:00
|
|
|
General Options:
|
2015-01-12 16:05:26 +02:00
|
|
|
--version display version and exit
|
|
|
|
--help display usage and exit
|
2015-01-11 18:52:16 +02:00
|
|
|
=cut
|
|
|
|
|
2014-04-03 00:25:37 +03:00
|
|
|
####################################################################################################################################
|
2014-06-04 04:22:07 +03:00
|
|
|
# Command line parameters
|
|
|
|
####################################################################################################################################
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strLogLevel = lc(INFO);
|
2016-01-09 15:21:53 +02:00
|
|
|
my $bVmOut = false;
|
2017-01-05 01:29:13 +02:00
|
|
|
my @stryModule;
|
|
|
|
my @stryModuleTest;
|
|
|
|
my @iyModuleTestRun;
|
2016-09-06 15:35:02 +02:00
|
|
|
my $iProcessMax = undef;
|
|
|
|
my $iVmMax = 1;
|
|
|
|
my $iVmId = 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;
|
2015-01-11 18:52:16 +02:00
|
|
|
my $bVersion = false;
|
|
|
|
my $bHelp = false;
|
|
|
|
my $bQuiet = false;
|
2016-05-11 14:59:34 +02:00
|
|
|
my $strDbVersion = 'minimal';
|
2015-05-05 19:08:48 +02:00
|
|
|
my $bLogForce = false;
|
2017-04-10 18:31:30 +02:00
|
|
|
my $strVm;
|
2017-02-21 15:59:23 +02:00
|
|
|
my $strVmHost = VM_HOST_DEFAULT;
|
2016-01-09 15:21:53 +02:00
|
|
|
my $bVmBuild = false;
|
2016-04-14 00:47:29 +02:00
|
|
|
my $bVmForce = false;
|
2016-02-23 16:25:22 +02:00
|
|
|
my $bNoLint = false;
|
2017-02-18 05:31:16 +02:00
|
|
|
my $bBuildOnly = false;
|
2017-04-10 18:31:30 +02:00
|
|
|
my $bCoverageOnly = false;
|
2017-02-18 05:31:16 +02:00
|
|
|
my $bSmart = false;
|
|
|
|
my $bNoPackage = false;
|
2017-02-26 19:53:41 +02:00
|
|
|
my $bNoCiConfig = false;
|
2017-02-18 05:31:16 +02:00
|
|
|
my $bDev = false;
|
2017-06-09 23:51:41 +02:00
|
|
|
my $bExpect = false;
|
2017-02-23 01:43:10 +02:00
|
|
|
my $iRetry = 0;
|
2015-01-11 18:52:16 +02:00
|
|
|
|
|
|
|
GetOptions ('q|quiet' => \$bQuiet,
|
|
|
|
'version' => \$bVersion,
|
|
|
|
'help' => \$bHelp,
|
|
|
|
'pgsql-bin=s' => \$strPgSqlBin,
|
2014-09-16 18:22:55 +03:00
|
|
|
'test-path=s' => \$strTestPath,
|
|
|
|
'log-level=s' => \$strLogLevel,
|
2016-04-14 00:47:29 +02:00
|
|
|
'vm=s' => \$strVm,
|
2017-02-21 15:59:23 +02:00
|
|
|
'vm-host=s' => \$strVmHost,
|
2016-01-09 15:21:53 +02:00
|
|
|
'vm-out' => \$bVmOut,
|
|
|
|
'vm-build' => \$bVmBuild,
|
2016-04-14 00:47:29 +02:00
|
|
|
'vm-force' => \$bVmForce,
|
2017-01-05 01:29:13 +02:00
|
|
|
'module=s@' => \@stryModule,
|
|
|
|
'test=s@' => \@stryModuleTest,
|
|
|
|
'run=s@' => \@iyModuleTestRun,
|
2016-01-09 15:21:53 +02:00
|
|
|
'process-max=s' => \$iProcessMax,
|
2016-09-06 15:35:02 +02:00
|
|
|
'vm-id=s' => \$iVmId,
|
2016-09-30 00:26:32 +02:00
|
|
|
'vm-max=s' => \$iVmMax,
|
2014-09-16 18:22:55 +03:00
|
|
|
'dry-run' => \$bDryRun,
|
2015-02-28 06:31:39 +02:00
|
|
|
'no-cleanup' => \$bNoCleanup,
|
2015-05-05 19:08:48 +02:00
|
|
|
'db-version=s' => \$strDbVersion,
|
2016-02-23 16:25:22 +02:00
|
|
|
'log-force' => \$bLogForce,
|
2016-12-13 01:54:07 +02:00
|
|
|
'no-lint' => \$bNoLint,
|
2017-02-18 05:31:16 +02:00
|
|
|
'build-only' => \$bBuildOnly,
|
|
|
|
'no-package' => \$bNoPackage,
|
2017-02-26 19:53:41 +02:00
|
|
|
'no-ci-config' => \$bNoCiConfig,
|
2017-04-10 18:31:30 +02:00
|
|
|
'coverage-only' => \$bCoverageOnly,
|
2017-02-18 05:31:16 +02:00
|
|
|
'smart' => \$bSmart,
|
2017-02-22 05:10:02 +02:00
|
|
|
'dev' => \$bDev,
|
2017-06-09 23:51:41 +02:00
|
|
|
'expect' => \$bExpect,
|
2017-02-22 05:10:02 +02:00
|
|
|
'retry=s' => \$iRetry)
|
2015-01-11 18:52:16 +02:00
|
|
|
or pod2usage(2);
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Run in eval block to catch errors
|
|
|
|
####################################################################################################################################
|
|
|
|
eval
|
2015-01-11 18:52:16 +02:00
|
|
|
{
|
2016-09-06 15:44:50 +02:00
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bVersion || $bHelp)
|
|
|
|
{
|
|
|
|
syswrite(*STDOUT, BACKREST_NAME . ' ' . BACKREST_VERSION . " Test Engine\n");
|
|
|
|
|
|
|
|
if ($bHelp)
|
|
|
|
{
|
|
|
|
syswrite(*STDOUT, "\n");
|
|
|
|
pod2usage();
|
|
|
|
}
|
2015-01-11 18:52:16 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@ARGV > 0)
|
2015-01-11 18:52:16 +02:00
|
|
|
{
|
2016-09-06 15:44:50 +02:00
|
|
|
syswrite(*STDOUT, "invalid parameter\n\n");
|
2015-01-11 18:52:16 +02:00
|
|
|
pod2usage();
|
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Update options for --dev
|
|
|
|
################################################################################################################################
|
|
|
|
if ($bDev)
|
|
|
|
{
|
|
|
|
$bNoLint = true;
|
|
|
|
$bSmart = true;
|
|
|
|
$bNoPackage = true;
|
2017-02-21 15:59:23 +02:00
|
|
|
$iProcessMax = 1;
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Update options for --expect
|
|
|
|
################################################################################################################################
|
|
|
|
if ($bExpect)
|
|
|
|
{
|
|
|
|
$bNoLint = true;
|
|
|
|
$bSmart = true;
|
|
|
|
$bNoPackage = true;
|
|
|
|
$iProcessMax = 1;
|
|
|
|
$strVm = VM_CO7;
|
2017-06-21 22:07:13 +02:00
|
|
|
$strDbVersion = '9.6';
|
2017-06-09 23:51:41 +02:00
|
|
|
$bLogForce = true;
|
|
|
|
}
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Setup
|
|
|
|
################################################################################################################################
|
|
|
|
# Set a neutral umask so tests work as expected
|
|
|
|
umask(0);
|
2014-06-04 04:22:07 +03:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Set console log level
|
|
|
|
if ($bQuiet)
|
|
|
|
{
|
|
|
|
$strLogLevel = 'off';
|
|
|
|
}
|
2015-01-11 18:52:16 +02:00
|
|
|
|
2016-10-05 15:09:30 +02:00
|
|
|
logLevelSet(uc($strLogLevel), uc($strLogLevel), OFF);
|
2014-06-04 04:22:07 +03:00
|
|
|
|
2017-01-05 01:29:13 +02:00
|
|
|
if (@stryModuleTest != 0 && @stryModule != 1)
|
2016-09-06 15:44:50 +02:00
|
|
|
{
|
2017-01-05 01:29:13 +02:00
|
|
|
confess "Only one --module can be provided when --test is specified";
|
2016-09-06 15:44:50 +02:00
|
|
|
}
|
2014-06-05 17:20:03 +03:00
|
|
|
|
2017-01-05 01:29:13 +02:00
|
|
|
if (@iyModuleTestRun != 0 && @stryModuleTest != 1)
|
2016-09-06 15:44:50 +02:00
|
|
|
{
|
2017-01-05 01:29:13 +02:00
|
|
|
confess "Only one --test can be provided when --run is specified";
|
2016-09-06 15:44:50 +02:00
|
|
|
}
|
2014-06-22 17:54:31 +03:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Check process total
|
|
|
|
if (defined($iProcessMax) && ($iProcessMax < 1 || $iProcessMax > OPTION_DEFAULT_PROCESS_MAX_MAX))
|
|
|
|
{
|
|
|
|
confess 'process-max must be between 1 and ' . OPTION_DEFAULT_PROCESS_MAX_MAX;
|
|
|
|
}
|
2015-02-28 17:21:36 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Set test path if not expicitly set
|
|
|
|
if (!defined($strTestPath))
|
|
|
|
{
|
|
|
|
$strTestPath = cwd() . '/test';
|
|
|
|
}
|
2016-05-11 00:12:37 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
my $oStorageTest = new pgBackRest::Storage::Local(
|
|
|
|
$strTestPath, new pgBackRest::Storage::Posix::Driver({bFileSync => false, bPathSync => false}));
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if ($bCoverageOnly)
|
2017-01-10 03:49:04 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
if (!defined($strVm))
|
2017-01-10 03:49:04 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
&log(INFO, "Set --vm=${strVmHost} for coverage testing");
|
|
|
|
$strVm = $strVmHost;
|
2017-01-10 03:49:04 +02:00
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
elsif ($strVm eq VM_ALL)
|
2017-01-10 03:49:04 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
confess &log(ERROR, "select a single Debian-based VM for coverage testing");
|
2017-01-10 03:49:04 +02:00
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
elsif (!vmCoverage($strVm))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "only Debian-based VMs can be used for coverage testing");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# If VM is not defined then set it to all
|
|
|
|
if (!defined($strVm))
|
|
|
|
{
|
|
|
|
$strVm = VM_ALL;
|
2017-01-10 03:49:04 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Get the base backrest path
|
|
|
|
my $strBackRestBase = dirname(dirname(abs_path($0)));
|
2016-06-02 15:32:56 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
my $oStorageBackRest = new pgBackRest::Storage::Local(
|
|
|
|
$strBackRestBase, new pgBackRest::Storage::Posix::Driver({bFileSync => false, bPathSync => false}));
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Build Docker containers
|
|
|
|
################################################################################################################################
|
|
|
|
if ($bVmBuild)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
containerBuild($oStorageBackRest, $strVm, $bVmForce, $strDbVersion);
|
2016-09-06 15:44:50 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Start VM and run
|
|
|
|
################################################################################################################################
|
2016-09-06 15:35:02 +02:00
|
|
|
if (!defined($iVmId))
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-26 19:53:41 +02:00
|
|
|
# Build CI configuration
|
|
|
|
if (!$bNoCiConfig)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
(new pgBackRestTest::Common::CiTest($oStorageBackRest))->process();
|
2017-02-26 19:53:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 02:04:36 +02:00
|
|
|
# Load the doc module dynamically since it is not supported on all systems
|
|
|
|
require BackRestDoc::Common::Doc;
|
|
|
|
BackRestDoc::Common::Doc->import();
|
|
|
|
|
|
|
|
# Make sure version number matches the latest release
|
2016-06-02 15:32:56 +02:00
|
|
|
my $strReleaseFile = dirname(dirname(abs_path($0))) . '/doc/xml/release.xml';
|
2016-06-28 02:37:25 +02:00
|
|
|
my $oRelease = (new BackRestDoc::Custom::DocCustomRelease(new BackRestDoc::Common::Doc($strReleaseFile)))->releaseLast();
|
|
|
|
my $strVersion = $oRelease->paramGet('version');
|
2017-02-18 05:31:16 +02:00
|
|
|
my $bVersionDev = false;
|
|
|
|
my $strVersionBase = $strVersion;
|
2016-05-24 02:04:36 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
if ($strVersion =~ /dev$/)
|
2016-05-24 02:04:36 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
$bVersionDev = true;
|
|
|
|
$strVersionBase = substr($strVersion, 0, length($strVersion) - 3);
|
|
|
|
|
|
|
|
if (BACKREST_VERSION !~ /dev$/ && $oRelease->nodeTest('release-core-list'))
|
2016-05-26 16:34:10 +02:00
|
|
|
{
|
2016-06-28 02:37:25 +02:00
|
|
|
confess "dev release ${strVersion} must match the program version when core changes have been made";
|
2016-05-26 16:34:10 +02:00
|
|
|
}
|
2016-06-28 02:37:25 +02:00
|
|
|
}
|
2016-07-19 21:22:20 +02:00
|
|
|
elsif ($strVersion ne BACKREST_VERSION)
|
2016-06-28 02:37:25 +02:00
|
|
|
{
|
|
|
|
confess 'unable to find version ' . BACKREST_VERSION . " as the most recent release in ${strReleaseFile}";
|
2016-05-24 02:04:36 +02:00
|
|
|
}
|
|
|
|
|
2016-01-15 02:37:06 +02:00
|
|
|
if (!$bDryRun)
|
|
|
|
{
|
2016-02-23 16:25:22 +02:00
|
|
|
# Run Perl critic
|
2017-02-18 05:31:16 +02:00
|
|
|
if (!$bNoLint && !$bBuildOnly)
|
2016-02-23 16:25:22 +02:00
|
|
|
{
|
|
|
|
my $strBasePath = dirname(dirname(abs_path($0)));
|
|
|
|
|
2016-05-26 22:57:35 +02:00
|
|
|
&log(INFO, "Performing static code analysis using perl -cw");
|
2016-02-23 16:25:22 +02:00
|
|
|
|
|
|
|
# Check the exe for warnings
|
2016-05-26 22:57:35 +02:00
|
|
|
my $strWarning = trim(executeTest("perl -cw ${strBasePath}/bin/pgbackrest 2>&1"));
|
2016-02-23 16:25:22 +02:00
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
if ($strWarning ne "${strBasePath}/bin/pgbackrest syntax OK")
|
2016-02-23 16:25:22 +02:00
|
|
|
{
|
2016-04-14 15:30:54 +02:00
|
|
|
confess &log(ERROR, "${strBasePath}/bin/pgbackrest failed syntax check:\n${strWarning}");
|
2016-02-23 16:25:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "Performing static code analysis using perlcritic");
|
|
|
|
|
|
|
|
executeTest('perlcritic --quiet --verbose=8 --brutal --top=10' .
|
|
|
|
' --verbose "[%p] %f: %m at line %l, column %c. %e. (Severity: %s)\n"' .
|
|
|
|
" \"--profile=${strBasePath}/test/lint/perlcritic.policy\"" .
|
2016-04-14 15:30:54 +02:00
|
|
|
" ${strBasePath}/bin/pgbackrest ${strBasePath}/lib/*" .
|
2016-02-23 16:25:22 +02:00
|
|
|
" ${strBasePath}/test/test.pl ${strBasePath}/test/lib/*" .
|
|
|
|
" ${strBasePath}/doc/doc.pl ${strBasePath}/doc/lib/*");
|
|
|
|
}
|
|
|
|
|
2016-01-15 02:37:06 +02:00
|
|
|
logFileSet(cwd() . "/test");
|
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Clean up
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $iTestFail = 0;
|
2017-02-21 15:59:23 +02:00
|
|
|
my $iTestRetry = 0;
|
2017-02-18 05:31:16 +02:00
|
|
|
my $oyProcess = [];
|
|
|
|
my $strCoveragePath = "${strTestPath}/cover_db";
|
|
|
|
|
|
|
|
if (!$bDryRun || $bVmOut)
|
|
|
|
{
|
|
|
|
containerRemove('test-([0-9]+|build)');
|
|
|
|
|
|
|
|
for (my $iVmIdx = 0; $iVmIdx < 8; $iVmIdx++)
|
|
|
|
{
|
|
|
|
push(@{$oyProcess}, undef);
|
|
|
|
}
|
|
|
|
|
|
|
|
executeTest("sudo rm -rf ${strTestPath}/*");
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageTest->pathCreate($strCoveragePath, {strMode => '0770', bIgnoreMissing => true, bCreateParent => true});
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build the C Library and Packages
|
2016-12-13 01:54:07 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2017-01-05 01:29:13 +02:00
|
|
|
if (!$bDryRun)
|
2016-12-13 01:54:07 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
# Paths
|
|
|
|
my $strVagrantPath = "${strBackRestBase}/test/.vagrant";
|
|
|
|
my $strPackagePath = "${strVagrantPath}/package";
|
|
|
|
my $strPackageSmart = "${strPackagePath}/build.timestamp";
|
|
|
|
my $strLibCPath = "${strVagrantPath}/libc";
|
|
|
|
my $strLibCSmart = "${strLibCPath}/build.timestamp";
|
|
|
|
|
|
|
|
# VM Info
|
|
|
|
my $oVm = vmGet();
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-01-10 20:12:53 +02:00
|
|
|
# Find the lastest modified time in the libc dir
|
2017-02-18 05:31:16 +02:00
|
|
|
my $lTimestampLibCLast = 0;
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
my $hManifest = $oStorageBackRest->manifest('libc');
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-01-10 20:12:53 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$hManifest})))
|
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampLibCLast)
|
2017-01-10 20:12:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
$lTimestampLibCLast = $hManifest->{$strFile}{modification_time};
|
2017-01-10 20:12:53 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-01-10 20:12:53 +02:00
|
|
|
# Rebuild if the modification time of the makefile does not equal the latest file in libc
|
2017-06-09 23:51:41 +02:00
|
|
|
if (!$bSmart || !$oStorageBackRest->exists($strLibCSmart) ||
|
|
|
|
$oStorageBackRest->info($strLibCSmart)->mtime != $lTimestampLibCLast)
|
2017-01-10 20:12:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
if ($bSmart)
|
|
|
|
{
|
|
|
|
&log(INFO, 'libC code has changed, library will be rebuilt');
|
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
executeTest("sudo rm -rf ${strLibCPath}");
|
2017-02-21 15:59:23 +02:00
|
|
|
executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC');
|
|
|
|
executeTest('sudo rm -rf ' . $oVm->{$strVmHost}{&VMDEF_PERL_ARCH_PATH} . '/pgBackRest');
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Find the lastest modified time in the bin, lib dirs
|
|
|
|
my $lTimestampPackageLast = $lTimestampLibCLast;
|
2017-01-10 20:12:53 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$hManifest = $oStorageBackRest->manifest('bin');
|
2017-01-10 20:12:53 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$hManifest})))
|
|
|
|
{
|
|
|
|
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampPackageLast)
|
2017-01-10 20:12:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
$lTimestampPackageLast = $hManifest->{$strFile}{modification_time};
|
2017-01-10 20:12:53 +02:00
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$hManifest = $oStorageBackRest->manifest('lib');
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$hManifest})))
|
|
|
|
{
|
|
|
|
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampPackageLast)
|
2017-01-10 20:12:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
$lTimestampPackageLast = $hManifest->{$strFile}{modification_time};
|
2017-01-10 20:12:53 +02:00
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Rebuild if the modification time of the makefile does not equal the latest file in libc
|
|
|
|
if (!$bNoPackage &&
|
2017-06-09 23:51:41 +02:00
|
|
|
(!$bSmart || !$oStorageBackRest->exists($strPackageSmart) ||
|
|
|
|
$oStorageBackRest->info($strPackageSmart)->mtime != $lTimestampPackageLast))
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
if ($bSmart)
|
|
|
|
{
|
|
|
|
&log(INFO, 'libC or Perl code has changed, packages will be rebuilt');
|
|
|
|
}
|
2016-05-11 00:12:37 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
executeTest("sudo rm -rf ${strPackagePath}");
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Loop through VMs to do the C Library builds
|
2016-12-13 01:54:07 +02:00
|
|
|
my $bLogDetail = $strLogLevel eq 'detail';
|
2017-02-21 15:59:23 +02:00
|
|
|
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm eq $strVmHost ? ($strVm) : ($strVm, $strVmHost));
|
2016-12-13 01:54:07 +02:00
|
|
|
|
|
|
|
foreach my $strBuildVM (sort(@stryBuildVm))
|
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
my $strBuildPath = "${strLibCPath}/${strBuildVM}";
|
2017-02-21 15:59:23 +02:00
|
|
|
my $bContainerExists = $strVm eq VM_ALL || $strBuildVM ne $strVmHost;
|
2016-12-13 01:54:07 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
if (!$oStorageBackRest->pathExists($strBuildPath))
|
2017-01-10 20:12:53 +02:00
|
|
|
{
|
2017-02-18 05:31:16 +02:00
|
|
|
&log(INFO, "Build/test C library for ${strBuildVM} (${strBuildPath})");
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($bContainerExists)
|
|
|
|
{
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
|
|
|
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
2017-01-10 20:12:53 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->pathCreate($strBuildPath, {bIgnoreExists => true, bCreateParent => true});
|
2017-01-30 21:00:40 +02:00
|
|
|
executeTest("cp -r ${strBackRestBase}/libc/* ${strBuildPath}");
|
2017-01-10 20:12:53 +02:00
|
|
|
|
|
|
|
executeTest(
|
2017-02-21 15:59:23 +02:00
|
|
|
($bContainerExists ? "docker exec -i test-build bash -c '" : '') .
|
|
|
|
"cd ${strBuildPath} && perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none" .
|
|
|
|
($bContainerExists ? "'" : ''),
|
2017-04-10 23:20:21 +02:00
|
|
|
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
|
2017-01-10 20:12:53 +02:00
|
|
|
executeTest(
|
2017-02-21 15:59:23 +02:00
|
|
|
($bContainerExists ? 'docker exec -i test-build ' : '') .
|
|
|
|
"make -C ${strBuildPath}",
|
|
|
|
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
|
2017-01-10 20:12:53 +02:00
|
|
|
executeTest(
|
2017-02-21 15:59:23 +02:00
|
|
|
($bContainerExists ? 'docker exec -i test-build ' : '') .
|
2017-04-10 23:20:21 +02:00
|
|
|
"make -C ${strBuildPath} test",
|
|
|
|
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
|
2017-01-10 20:12:53 +02:00
|
|
|
executeTest(
|
2017-02-21 15:59:23 +02:00
|
|
|
($bContainerExists ? 'docker exec -i test-build ' : 'sudo ') .
|
2017-04-10 23:20:21 +02:00
|
|
|
"make -C ${strBuildPath} install",
|
|
|
|
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
|
2017-01-10 20:12:53 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($bContainerExists)
|
|
|
|
{
|
|
|
|
executeTest("docker rm -f test-build");
|
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($strBuildVM eq $strVmHost)
|
2017-02-18 05:31:16 +02:00
|
|
|
{
|
2017-04-10 23:20:21 +02:00
|
|
|
executeTest("sudo make -C ${strBuildPath} install", {bSuppressStdErr => true});
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
# Load the module dynamically
|
|
|
|
require pgBackRest::LibC;
|
|
|
|
pgBackRest::LibC->import(qw(:debug));
|
|
|
|
|
|
|
|
# Do a basic test to make sure it installed correctly
|
|
|
|
if (&UVSIZE != 8)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'UVSIZE in C library does not equal 8');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Also check the version number
|
|
|
|
my $strLibCVersion =
|
|
|
|
BACKREST_VERSION =~ /dev$/ ?
|
|
|
|
substr(BACKREST_VERSION, 0, length(BACKREST_VERSION) - 3) . '.999' : BACKREST_VERSION;
|
|
|
|
|
|
|
|
if (libCVersion() ne $strLibCVersion)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, $strLibCVersion . ' was expected for LibC version but found ' . libCVersion());
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 20:12:53 +02:00
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
# Write files to indicate the last time a build was successful
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->put($strLibCSmart);
|
2017-02-18 05:31:16 +02:00
|
|
|
utime($lTimestampLibCLast, $lTimestampLibCLast, $strLibCSmart) or
|
|
|
|
confess "unable to set time for ${strLibCSmart}" . (defined($!) ? ":$!" : '');
|
|
|
|
|
|
|
|
# Loop through VMs to do the package builds
|
|
|
|
if (!$bNoPackage)
|
|
|
|
{
|
|
|
|
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->pathCreate($strPackagePath, {bIgnoreExists => true, bCreateParent => true});
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
foreach my $strBuildVM (sort(@stryBuildVm))
|
|
|
|
{
|
|
|
|
my $strBuildPath = "${strPackagePath}/${strBuildVM}/src";
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
if (!$oStorageBackRest->pathExists($strBuildPath) && $oVm->{$strBuildVM}{&VM_OS_BASE} eq VM_OS_BASE_DEBIAN)
|
2017-02-18 05:31:16 +02:00
|
|
|
{
|
|
|
|
&log(INFO, "Build package for ${strBuildVM} (${strBuildPath})");
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
2017-02-21 15:59:23 +02:00
|
|
|
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
|
|
|
|
{bSuppressStdErr => true});
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->pathCreate($strBuildPath, {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
executeTest("rsync -r --exclude .vagrant --exclude .git ${strBackRestBase}/ ${strBuildPath}/");
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build " .
|
2017-02-21 15:59:23 +02:00
|
|
|
"bash -c 'cp -r /root/package-src/debian ${strBuildPath}' && sudo chown -R " . TEST_USER .
|
|
|
|
" ${strBuildPath}");
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
# If dev build then override then disable static release date used for reproducibility.
|
|
|
|
if ($bVersionDev)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
my $strRules = ${$oStorageBackRest->get("${strBuildPath}/debian/rules")};
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2017-02-21 21:22:03 +02:00
|
|
|
$strRules =~ s/\-\-var\=release-date-static\=y/\-\-var\=release-date-static\=n/g;
|
|
|
|
$strRules =~ s/\-\-out\=html \-\-cache\-only/\-\-out\=html \-\-no\-exe/g;
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->put("${strBuildPath}/debian/rules", $strRules);
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Update changelog to add experimental version
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->put("${strBuildPath}/debian/changelog",
|
2017-03-01 19:22:47 +02:00
|
|
|
"pgbackrest (${strVersionBase}-0." . ($bVersionDev ? 'D' : 'P') . strftime("%Y%m%d%H%M%S", gmtime) .
|
2017-02-18 05:31:16 +02:00
|
|
|
") experimental; urgency=medium\n" .
|
|
|
|
"\n" .
|
|
|
|
' * Automated experimental ' . ($bVersionDev ? 'development' : 'production') . " build.\n" .
|
|
|
|
"\n" .
|
|
|
|
' -- David Steele <david@pgbackrest.org> ' . strftime("%a, %e %b %Y %H:%M:%S %z", gmtime) . "\n\n" .
|
2017-06-09 23:51:41 +02:00
|
|
|
${$oStorageBackRest->get("${strBuildPath}/debian/changelog")});
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build " .
|
|
|
|
"bash -c 'cd ${strBuildPath} && debuild -i -us -uc -b'");
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build " .
|
|
|
|
"bash -c 'rm -f ${strPackagePath}/${strBuildVM}/*.build ${strPackagePath}/${strBuildVM}/*.changes" .
|
|
|
|
" ${strPackagePath}/${strBuildVM}/pgbackrest-doc*'");
|
|
|
|
|
|
|
|
executeTest("docker rm -f test-build");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Write files to indicate the last time a build was successful
|
|
|
|
if (!$bNoPackage)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageBackRest->put($strPackageSmart);
|
2017-02-18 05:31:16 +02:00
|
|
|
utime($lTimestampPackageLast, $lTimestampPackageLast, $strPackageSmart) or
|
|
|
|
confess "unable to set time for ${strPackageSmart}" . (defined($!) ? ":$!" : '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Exit if only testing builds
|
|
|
|
exit 0 if $bBuildOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Determine which tests to run
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $oyTestRun = testListGet(
|
2017-04-10 18:31:30 +02:00
|
|
|
$strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strDbVersion, $iProcessMax, $bCoverageOnly);
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
if (@{$oyTestRun} == 0)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'no tests were selected');
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, @{$oyTestRun} . ' test' . (@{$oyTestRun} > 1 ? 's': '') . " selected\n");
|
|
|
|
|
|
|
|
if ($bNoCleanup && @{$oyTestRun} > 1)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, '--no-cleanup is not valid when more than one test will run')
|
2016-12-13 01:54:07 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Excecute tests
|
2016-01-14 05:43:26 +02:00
|
|
|
if ($bDryRun)
|
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
$iVmMax = 1;
|
2016-01-14 05:43:26 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
my $iTestIdx = 0;
|
2016-09-06 15:35:02 +02:00
|
|
|
my $iVmTotal;
|
2016-01-09 15:21:53 +02:00
|
|
|
my $iTestMax = @{$oyTestRun};
|
|
|
|
my $lStartTime = time();
|
2016-09-06 15:35:02 +02:00
|
|
|
my $bShowOutputAsync = $bVmOut && (@{$oyTestRun} == 1 || $iVmMax == 1) && ! $bDryRun ? true : false;
|
2016-01-09 15:21:53 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
$iVmTotal = 0;
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
for (my $iVmIdx = 0; $iVmIdx < $iVmMax; $iVmIdx++)
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
if (defined($$oyProcess[$iVmIdx]))
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
my ($bDone, $bFail) = $$oyProcess[$iVmIdx]->end();
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($bDone)
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($bFail)
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($oyProcess->[$iVmIdx]->run())
|
|
|
|
{
|
|
|
|
$iTestRetry++;
|
|
|
|
$iVmTotal++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$iTestFail++;
|
|
|
|
$$oyProcess[$iVmIdx] = undef;
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
$$oyProcess[$iVmIdx] = undef;
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
$iVmTotal++;
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
if ($iVmTotal == $iVmMax)
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
|
|
|
waitHiRes(.1);
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 15:35:02 +02:00
|
|
|
while ($iVmTotal == $iVmMax);
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
for (my $iVmIdx = 0; $iVmIdx < $iVmMax; $iVmIdx++)
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2016-09-06 15:35:02 +02:00
|
|
|
if (!defined($$oyProcess[$iVmIdx]) && $iTestIdx < @{$oyTestRun})
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
my $oJob = new pgBackRestTest::Common::JobTest(
|
2017-06-09 23:51:41 +02:00
|
|
|
$oStorageTest, $strBackRestBase, $strTestPath, $strCoveragePath, $$oyTestRun[$iTestIdx], $bDryRun, $bVmOut,
|
|
|
|
$iVmIdx, $iVmMax, $iTestIdx, $iTestMax, $strLogLevel, $bLogForce, $bShowOutputAsync, $bNoCleanup, $iRetry);
|
2016-01-09 15:21:53 +02:00
|
|
|
$iTestIdx++;
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($oJob->run())
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-02-21 15:59:23 +02:00
|
|
|
$$oyProcess[$iVmIdx] = $oJob;
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
$iVmTotal++;
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-06 15:35:02 +02:00
|
|
|
while ($iVmTotal > 0);
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
# Write out coverage info and test coverage
|
2017-01-10 03:49:04 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2017-04-10 18:31:30 +02:00
|
|
|
my $iUncoveredCodeModuleTotal = 0;
|
|
|
|
|
|
|
|
if (vmCoverage($strVm) && !$bDryRun)
|
2017-01-10 03:49:04 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
&log(INFO, 'writing coverage report');
|
2017-01-10 03:49:04 +02:00
|
|
|
executeTest("rm -rf ${strBackRestBase}/test/coverage");
|
|
|
|
executeTest("cp -rp ${strCoveragePath} ${strCoveragePath}_temp");
|
2017-04-10 18:31:30 +02:00
|
|
|
executeTest(
|
|
|
|
LIB_COVER_EXE . " -report json -outputdir ${strBackRestBase}/test/coverage ${strCoveragePath}_temp",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
executeTest("sudo rm -rf ${strCoveragePath}_temp");
|
|
|
|
executeTest("sudo cp -rp ${strCoveragePath} ${strCoveragePath}_temp");
|
|
|
|
executeTest(
|
|
|
|
LIB_COVER_EXE . " -outputdir ${strBackRestBase}/test/coverage ${strCoveragePath}_temp",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
executeTest("sudo rm -rf ${strCoveragePath}_temp");
|
|
|
|
|
|
|
|
# Determine which modules were covered (only check coverage if all tests were successful)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($iTestFail == 0)
|
|
|
|
{
|
|
|
|
my $hModuleTest; # Everything that was run
|
|
|
|
|
|
|
|
# Build a hash of all modules, tests, and runs that were executed
|
|
|
|
foreach my $hTestRun (@{$oyTestRun})
|
|
|
|
{
|
|
|
|
# Get coverage for the module
|
|
|
|
my $strModule = $hTestRun->{&TEST_MODULE};
|
|
|
|
my $hModule = testDefModule($strModule);
|
|
|
|
|
|
|
|
# Get coverage for the test
|
|
|
|
my $strTest = $hTestRun->{&TEST_NAME};
|
|
|
|
my $hTest = testDefModuleTest($strModule, $strTest);
|
|
|
|
|
|
|
|
# If no tests are listed it means all of them were run
|
|
|
|
if (@{$hTestRun->{&TEST_RUN}} == 0)
|
|
|
|
{
|
|
|
|
$hModuleTest->{$strModule}{$strTest} = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load the results of coverage testing from JSON
|
|
|
|
my $oJSON = JSON::PP->new()->allow_nonref();
|
2017-06-09 23:51:41 +02:00
|
|
|
my $hCoverageResult = $oJSON->decode(${$oStorageBackRest->get('test/coverage/cover.json')});
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
# Now compare against code modules that should have full coverage
|
|
|
|
my $hCoverageList = testDefCoverageList();
|
|
|
|
my $hCoverageType = testDefCoverageType();
|
|
|
|
my $hCoverageActual;
|
|
|
|
|
|
|
|
foreach my $strCodeModule (sort(keys(%{$hCoverageList})))
|
|
|
|
{
|
|
|
|
if (@{$hCoverageList->{$strCodeModule}} > 0)
|
|
|
|
{
|
|
|
|
my $iCoverageTotal = 0;
|
|
|
|
|
|
|
|
foreach my $hTest (@{$hCoverageList->{$strCodeModule}})
|
|
|
|
{
|
|
|
|
if (!defined($hModuleTest->{$hTest->{strModule}}{$hTest->{strTest}}))
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$iCoverageTotal++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@{$hCoverageList->{$strCodeModule}} == $iCoverageTotal)
|
|
|
|
{
|
|
|
|
$hCoverageActual->{$strCodeModule} = $hCoverageType->{$strCodeModule};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keys(%{$hCoverageActual}) > 0)
|
|
|
|
{
|
|
|
|
&log(INFO, 'test coverage for: ' . join(', ', sort(keys(%{$hCoverageActual}))));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&log(INFO, 'no code modules had all tests run required for coverage');
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $strCodeModule (sort(keys(%{$hCoverageActual})))
|
|
|
|
{
|
|
|
|
# Get summary results (??? Need to fix this for coverage testing on bin/pgbackrest since .pm is required)
|
|
|
|
my $hCoverageResultAll =
|
|
|
|
$hCoverageResult->{'summary'}
|
|
|
|
{"${strBackRestBase}/lib/" . BACKREST_NAME . "/${strCodeModule}.pm"}{total};
|
|
|
|
|
|
|
|
if (!defined($hCoverageResultAll))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to find coverage results for ${strCodeModule}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that all code has been covered
|
2017-04-14 02:10:28 +02:00
|
|
|
my $iCoverageTotal = $hCoverageResultAll->{total};
|
|
|
|
my $iCoverageUncoverable = coalesce($hCoverageResultAll->{uncoverable}, 0);
|
|
|
|
my $iCoverageCovered = $hCoverageResultAll->{covered};
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if ($hCoverageActual->{$strCodeModule} == TESTDEF_COVERAGE_FULL)
|
|
|
|
{
|
2017-04-14 02:10:28 +02:00
|
|
|
my $iUncoveredLines = $iCoverageTotal - $iCoverageCovered - $iCoverageUncoverable;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
if ($iUncoveredLines != 0)
|
|
|
|
{
|
|
|
|
&log(ERROR, "code module ${strCodeModule} is not fully covered");
|
|
|
|
$iUncoveredCodeModuleTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Else test how much partial coverage where was
|
|
|
|
else
|
|
|
|
{
|
2017-04-14 02:10:28 +02:00
|
|
|
my $iCoveragePercent = int(($iCoverageCovered + $iCoverageUncoverable) * 100 / $iCoverageTotal);
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
if ($iCoveragePercent == 100)
|
|
|
|
{
|
|
|
|
&log(ERROR, "code module ${strCodeModule} has 100% coverage but is not marked fully covered");
|
|
|
|
$iUncoveredCodeModuleTotal++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&log(INFO, "code module ${strCodeModule} has (expected) partial coverage of ${iCoveragePercent}%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 03:49:04 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
# Print test info and exit
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2017-05-12 22:27:06 +02:00
|
|
|
&log(INFO,
|
|
|
|
($bDryRun ? 'DRY RUN COMPLETED' : 'TESTS COMPLETED') . ($iTestFail == 0 ? ' SUCCESSFULLY' .
|
|
|
|
($iUncoveredCodeModuleTotal == 0 ? '' : " WITH ${iUncoveredCodeModuleTotal} MODULE(S) MISSING COVERAGE") :
|
|
|
|
" WITH ${iTestFail} FAILURE(S)") . ($iTestRetry == 0 ? '' : ", ${iTestRetry} RETRY(IES)") .
|
|
|
|
' (' . (time() - $lStartTime) . 's)');
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2017-05-12 22:27:06 +02:00
|
|
|
exit 1 if ($iTestFail > 0 || $iUncoveredCodeModuleTotal > 0);
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
exit 0;
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Runs tests
|
|
|
|
################################################################################################################################
|
|
|
|
my $iRun = 0;
|
2014-07-17 06:38:38 +03:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Create host group for containers
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oHostGroup = hostGroupGet();
|
2015-09-08 18:58:13 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
# Run the test
|
2017-01-05 01:29:13 +02:00
|
|
|
testRun($stryModule[0], $stryModuleTest[0])->process(
|
2016-12-23 15:22:59 +02:00
|
|
|
$strVm, $iVmId, # Vm info
|
|
|
|
$strBackRestBase, # Base backrest directory
|
|
|
|
$strTestPath, # Path where the tests will run
|
|
|
|
"${strBackRestBase}/bin/" . BACKREST_EXE, # Path to the backrest executable
|
|
|
|
$strDbVersion ne 'minimal' ? $strPgSqlBin: undef, # Db bin path
|
|
|
|
$strDbVersion ne 'minimal' ? $strDbVersion: undef, # Db version
|
2017-01-05 01:29:13 +02:00
|
|
|
$stryModule[0], $stryModuleTest[0], \@iyModuleTestRun, # Module info
|
2016-12-23 15:22:59 +02:00
|
|
|
$iProcessMax, $bVmOut, $bDryRun, $bNoCleanup, $bLogForce, # Test options
|
|
|
|
TEST_USER, BACKREST_USER, TEST_GROUP); # User/group info
|
2015-09-09 21:40:54 +02:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
if (!$bNoCleanup)
|
|
|
|
{
|
|
|
|
if ($oHostGroup->removeAll() > 0)
|
|
|
|
{
|
|
|
|
executeTest("sudo rm -rf ${strTestPath}");
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
2015-02-28 06:31:39 +02:00
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
if (!$bDryRun && !$bVmOut)
|
2015-04-08 00:36:59 +02:00
|
|
|
{
|
2016-09-06 15:44:50 +02:00
|
|
|
&log(INFO, 'TESTS COMPLETED SUCCESSFULLY (DESPITE ANY ERROR MESSAGES YOU SAW)');
|
2015-04-08 00:36:59 +02:00
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Exit with success
|
|
|
|
exit 0;
|
2014-06-22 18:56:01 +03:00
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Check for errors
|
|
|
|
####################################################################################################################################
|
|
|
|
or do
|
2014-07-16 05:32:41 +03:00
|
|
|
{
|
2016-09-06 15:44:50 +02:00
|
|
|
# If a backrest exception then return the code
|
|
|
|
exit $EVAL_ERROR->code() if (isException($EVAL_ERROR));
|
|
|
|
|
|
|
|
# Else output the unhandled error
|
|
|
|
print $EVAL_ERROR;
|
|
|
|
exit ERROR_UNHANDLED;
|
|
|
|
};
|
|
|
|
|
|
|
|
# It shouldn't be possible to get here
|
|
|
|
&log(ASSERT, 'execution reached invalid location in ' . __FILE__ . ', line ' . __LINE__);
|
|
|
|
exit ERROR_ASSERT;
|