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';
|
2017-08-25 22:47:47 +02:00
|
|
|
use lib dirname(dirname($0)) . '/build/lib';
|
2017-06-09 23:51:41 +02:00
|
|
|
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::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Common::Wait;
|
2017-06-09 23:51:41 +02:00
|
|
|
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
|
|
|
|
2017-11-02 14:14:13 +02:00
|
|
|
use pgBackRestBuild::Build;
|
|
|
|
use pgBackRestBuild::Build::Common;
|
|
|
|
use pgBackRestBuild::Config::Build;
|
|
|
|
use pgBackRestBuild::Config::BuildDefine;
|
2017-11-29 04:44:05 +02:00
|
|
|
use pgBackRestBuild::Config::BuildParse;
|
2018-05-22 18:53:08 +02:00
|
|
|
use pgBackRestBuild::Embed::Build;
|
2018-02-08 23:11:47 +02:00
|
|
|
use pgBackRestBuild::Error::Build;
|
|
|
|
use pgBackRestBuild::Error::Data;
|
2017-11-02 14:14:13 +02:00
|
|
|
|
2018-03-10 06:00:20 +02:00
|
|
|
use pgBackRestTest::Common::BuildTest;
|
2018-04-16 21:52:17 +02:00
|
|
|
use pgBackRestTest::Common::CodeCountTest;
|
2016-06-24 14:12:58 +02:00
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
2018-11-12 00:32:42 +02:00
|
|
|
use pgBackRestTest::Common::CoverageTest;
|
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
|
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
|
2018-02-04 01:27:38 +02:00
|
|
|
--pg-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
|
2018-05-22 18:53:08 +02:00
|
|
|
--build-only compile the test 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-10-12 18:55:48 +02:00
|
|
|
--c-only only run C tests
|
2017-11-02 14:14:13 +02:00
|
|
|
--gen-only only run auto-generation
|
2018-05-22 18:53:08 +02:00
|
|
|
--no-gen do not run code generation
|
2018-04-16 21:52:17 +02:00
|
|
|
--code-count generate code counts
|
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
|
2018-05-18 12:45:14 +02:00
|
|
|
--dev --no-lint --smart --no-package --no-optimize
|
|
|
|
--dev-test --no-lint --no-package
|
|
|
|
--expect --no-lint --no-package --vm=co7 --db=9.6 --log-force
|
|
|
|
--no-valgrind don't run valgrind on C unit tests (saves time)
|
|
|
|
--no-coverage don't run coverage on C unit tests (saves time)
|
|
|
|
--no-optimize don't do compile optimization for C (saves compile time)
|
2018-05-18 17:57:32 +02:00
|
|
|
--backtrace enable backtrace when available (adds stack trace line numbers -- very slow)
|
2018-05-18 12:45:14 +02:00
|
|
|
--profile generate profile info
|
|
|
|
--no-debug don't generate a debug build
|
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)
|
2018-07-21 01:03:46 +02:00
|
|
|
--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)
|
2015-01-12 16:05:26 +02:00
|
|
|
--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);
|
2018-07-21 01:03:46 +02:00
|
|
|
my $strLogLevelTest = lc(OFF);
|
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 $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;
|
2018-02-04 01:27:38 +02:00
|
|
|
my $strPgVersion = '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;
|
2018-05-18 12:45:14 +02:00
|
|
|
my $bNoCoverage = false;
|
2017-10-12 18:55:48 +02:00
|
|
|
my $bCOnly = false;
|
2017-11-02 14:14:13 +02:00
|
|
|
my $bGenOnly = false;
|
2018-05-22 18:53:08 +02:00
|
|
|
my $bNoGen = false;
|
2018-04-16 21:52:17 +02:00
|
|
|
my $bCodeCount = 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;
|
2018-05-18 12:45:14 +02:00
|
|
|
my $bDevTest = false;
|
2018-05-18 17:57:32 +02:00
|
|
|
my $bBackTrace = false;
|
2018-05-18 12:45:14 +02:00
|
|
|
my $bProfile = false;
|
2017-06-09 23:51:41 +02:00
|
|
|
my $bExpect = false;
|
2018-05-18 12:45:14 +02:00
|
|
|
my $bNoValgrind = false;
|
|
|
|
my $bNoOptimize = false;
|
|
|
|
my $bNoDebug = 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,
|
2018-07-21 01:03:46 +02:00
|
|
|
'log-level-test=s' => \$strLogLevelTest,
|
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-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,
|
2018-02-04 01:27:38 +02:00
|
|
|
'pg-version=s' => \$strPgVersion,
|
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,
|
2018-05-18 12:45:14 +02:00
|
|
|
'no-coverage' => \$bNoCoverage,
|
2017-10-12 18:55:48 +02:00
|
|
|
'c-only' => \$bCOnly,
|
2017-11-02 14:14:13 +02:00
|
|
|
'gen-only' => \$bGenOnly,
|
2018-05-22 18:53:08 +02:00
|
|
|
'no-gen' => \$bNoGen,
|
2018-04-16 21:52:17 +02:00
|
|
|
'code-count' => \$bCodeCount,
|
2017-02-18 05:31:16 +02:00
|
|
|
'smart' => \$bSmart,
|
2017-02-22 05:10:02 +02:00
|
|
|
'dev' => \$bDev,
|
2018-05-18 12:45:14 +02:00
|
|
|
'dev-test' => \$bDevTest,
|
2018-05-18 17:57:32 +02:00
|
|
|
'backtrace' => \$bBackTrace,
|
2018-05-18 12:45:14 +02:00
|
|
|
'profile' => \$bProfile,
|
2017-06-09 23:51:41 +02:00
|
|
|
'expect' => \$bExpect,
|
2018-05-18 12:45:14 +02:00
|
|
|
'no-valgrind' => \$bNoValgrind,
|
|
|
|
'no-optimize' => \$bNoOptimize,
|
|
|
|
'no-debug', => \$bNoDebug,
|
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
|
|
|
{
|
2018-03-10 04:24:30 +02:00
|
|
|
# Record the start time
|
|
|
|
my $lStartTime = time();
|
|
|
|
|
2016-09-06 15:44:50 +02:00
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bVersion || $bHelp)
|
|
|
|
{
|
2018-11-25 02:05:03 +02:00
|
|
|
syswrite(*STDOUT, PROJECT_NAME . ' ' . PROJECT_VERSION . " Test Engine\n");
|
2016-09-06 15:44:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
################################################################################################################################
|
2018-05-18 12:45:14 +02:00
|
|
|
# Update options for --dev and --dev-fast and --dev-test
|
2017-02-18 05:31:16 +02:00
|
|
|
################################################################################################################################
|
2018-05-18 12:45:14 +02:00
|
|
|
if ($bDev && $bDevTest)
|
|
|
|
{
|
|
|
|
confess "cannot combine --dev and --dev-test";
|
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
if ($bDev)
|
|
|
|
{
|
|
|
|
$bNoLint = true;
|
|
|
|
$bSmart = true;
|
|
|
|
$bNoPackage = true;
|
2018-05-18 12:45:14 +02:00
|
|
|
$bNoOptimize = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bDevTest)
|
|
|
|
{
|
|
|
|
$bNoPackage = true;
|
|
|
|
$bNoLint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Update options for --profile
|
|
|
|
################################################################################################################################
|
|
|
|
if ($bProfile)
|
|
|
|
{
|
|
|
|
$bNoValgrind = true;
|
|
|
|
$bNoCoverage = true;
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Update options for --expect
|
|
|
|
################################################################################################################################
|
|
|
|
if ($bExpect)
|
|
|
|
{
|
|
|
|
$bNoLint = true;
|
|
|
|
$bNoPackage = true;
|
2017-11-15 00:16:39 +02:00
|
|
|
$strVm = VM_EXPECT;
|
2018-02-04 01:27:38 +02:00
|
|
|
$strPgVersion = '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);
|
2018-03-10 06:00:20 +02:00
|
|
|
&log(INFO, "test begin - log level ${strLogLevel}");
|
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
|
|
|
# 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
|
|
|
}
|
2018-09-15 19:27:06 +02:00
|
|
|
elsif (!vmCoveragePerl($strVm))
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
|
|
|
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-24 16:59:00 +02:00
|
|
|
containerBuild($oStorageBackRest, $strVm, $bVmForce);
|
2016-09-06 15:44:50 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
2016-01-09 15:21:53 +02:00
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Load test definition
|
|
|
|
################################################################################################################################
|
|
|
|
testDefLoad(${$oStorageBackRest->get("test/define.yaml")});
|
|
|
|
|
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
|
|
|
{
|
2018-11-04 01:52:46 +02:00
|
|
|
# Make a copy of the repo to track which files have been changed. Eventually all builds will be done from this directory.
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strRepoCachePath = "${strTestPath}/repo";
|
|
|
|
my $strRepoCacheManifest = 'repo.manifest';
|
|
|
|
|
|
|
|
# Create the repo path -- this should hopefully prevent obvious rsync errors below
|
|
|
|
$oStorageTest->pathCreate("${strTestPath}/repo", {strMode => '0770', bIgnoreExists => true, bCreateParent => true});
|
|
|
|
|
|
|
|
# Check if there are any files existing already. If none, that means a full copy is happening and we shouldn't report
|
|
|
|
# modified files
|
|
|
|
my @stryExistingList = $oStorageTest->list($strRepoCachePath, {bIgnoreMissing => true});
|
|
|
|
|
|
|
|
# First check if there is an old manifest that has not been cleared. This indicates that an error happened before all new
|
|
|
|
# files could be processed, which means they should be processed again.
|
|
|
|
my @stryModifiedList;
|
|
|
|
my $rstrModifiedList = $oStorageTest->get(
|
|
|
|
$oStorageTest->openRead("${strRepoCachePath}/${strRepoCacheManifest}", {bIgnoreMissing => true}));
|
|
|
|
|
|
|
|
if (defined($rstrModifiedList))
|
|
|
|
{
|
|
|
|
@stryModifiedList = split("\n", trim($$rstrModifiedList));
|
|
|
|
}
|
|
|
|
|
|
|
|
push(
|
|
|
|
@stryModifiedList,
|
|
|
|
split(
|
|
|
|
"\n",
|
|
|
|
trim(
|
|
|
|
executeTest(
|
|
|
|
"git -C ${strBackRestBase} ls-files -c --others --exclude-standard |" .
|
2018-11-04 15:39:48 +02:00
|
|
|
" rsync -rtW --out-format=\"\%n\" --delete --ignore-missing-args --exclude=repo.manifest" .
|
|
|
|
" ${strBackRestBase}/ --files-from=- ${strRepoCachePath}"))));
|
2018-11-04 01:52:46 +02:00
|
|
|
|
|
|
|
if (@stryModifiedList > 0)
|
|
|
|
{
|
|
|
|
$oStorageTest->put("${strRepoCachePath}/${strRepoCacheManifest}", join("\n", @stryModifiedList));
|
|
|
|
|
|
|
|
if (@stryExistingList > 0)
|
|
|
|
{
|
|
|
|
&log(INFO, "modified since last run: " . join(', ', @stryModifiedList));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:52:17 +02:00
|
|
|
# Generate code counts
|
2018-11-04 01:52:46 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2018-04-16 21:52:17 +02:00
|
|
|
if ($bCodeCount)
|
|
|
|
{
|
|
|
|
&log(INFO, "classify code files");
|
|
|
|
|
|
|
|
codeCountScan($oStorageBackRest, $strBackRestBase);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Auto-generate files unless --no-gen specified
|
2017-11-29 04:44:05 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2018-05-22 18:53:08 +02:00
|
|
|
if (!$bNoGen)
|
|
|
|
{
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuiltAll;
|
2018-05-22 18:53:08 +02:00
|
|
|
&log(INFO, "check code autogenerate");
|
2018-03-10 06:00:20 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Auto-generate C files
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-11-04 01:52:46 +02:00
|
|
|
if (!$bSmart || grep(/^build\//, @stryModifiedList))
|
2018-05-22 18:53:08 +02:00
|
|
|
{
|
|
|
|
errorDefineLoad(${$oStorageBackRest->get("build/error.yaml")});
|
2018-03-28 04:48:22 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
my $rhBuild =
|
|
|
|
{
|
|
|
|
'config' =>
|
|
|
|
{
|
|
|
|
&BLD_DATA => buildConfig(),
|
|
|
|
&BLD_PATH => 'config',
|
|
|
|
},
|
2018-03-28 04:48:22 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
'configDefine' =>
|
|
|
|
{
|
|
|
|
&BLD_DATA => buildConfigDefine(),
|
|
|
|
&BLD_PATH => 'config',
|
|
|
|
},
|
|
|
|
|
|
|
|
'configParse' =>
|
|
|
|
{
|
|
|
|
&BLD_DATA => buildConfigParse(),
|
|
|
|
&BLD_PATH => 'config',
|
|
|
|
},
|
|
|
|
|
|
|
|
'error' =>
|
|
|
|
{
|
|
|
|
&BLD_DATA => buildError(),
|
|
|
|
&BLD_PATH => 'common',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuilt = buildAll("${strBackRestBase}/src", $rhBuild);
|
|
|
|
&log(INFO, " autogenerated C code: " . (@stryBuilt ? join(', ', @stryBuilt) : 'no changes'));
|
|
|
|
|
|
|
|
if (@stryBuilt)
|
|
|
|
{
|
|
|
|
push(@stryBuiltAll, @stryBuilt);
|
|
|
|
push(@stryModifiedList, @stryBuilt);
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Auto-generate Perl code
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
use lib dirname(dirname($0)) . '/libc/build/lib';
|
|
|
|
use pgBackRestLibC::Build; ## no critic (Modules::ProhibitConditionalUseStatements)
|
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
if (!$bSmart || grep(/^(build|libc\/build)\//, @stryModifiedList))
|
2017-11-29 04:44:05 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
errorDefineLoad(${$oStorageBackRest->get("build/error.yaml")});
|
2018-02-08 23:11:47 +02:00
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuilt = buildXsAll("${strBackRestBase}/libc");
|
|
|
|
&log(INFO, " autogenerated Perl code: " . (@stryBuilt ? join(', ', @stryBuilt) : 'no changes'));
|
|
|
|
|
|
|
|
if (@stryBuilt)
|
|
|
|
{
|
|
|
|
push(@stryBuiltAll, @stryBuilt);
|
|
|
|
push(@stryModifiedList, @stryBuilt);
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Auto-generate C library code to embed in the binary
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-11-04 01:52:46 +02:00
|
|
|
if (!$bSmart || grep(/^libc\//, @stryModifiedList))
|
2018-05-22 18:53:08 +02:00
|
|
|
{
|
|
|
|
my $strLibC = executeTest(
|
|
|
|
"cd ${strBackRestBase}/libc && " .
|
2018-06-06 21:52:28 +02:00
|
|
|
"perl /usr/share/perl/5.26/ExtUtils/xsubpp -typemap /usr/share/perl/5.26/ExtUtils/typemap" .
|
2018-05-22 18:53:08 +02:00
|
|
|
" -typemap typemap LibC.xs");
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Trim off any trailing LFs
|
|
|
|
$strLibC = trim($strLibC) . "\n";
|
2018-05-18 17:57:32 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Strip out line numbers. These are useful for the LibC build but only cause churn in the binary
|
|
|
|
# build.
|
|
|
|
$strLibC =~ s/^\#line .*\n//mg;
|
2018-03-28 04:48:22 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Save into the bin src dir
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuilt;
|
|
|
|
my $strBuilt = 'src/perl/libc.auto.c';
|
|
|
|
|
|
|
|
if (buildPutDiffers($oStorageBackRest, "${strBackRestBase}/${strBuilt}", $strLibC))
|
|
|
|
{
|
|
|
|
push(@stryBuilt, $strBuilt);
|
|
|
|
push(@stryBuiltAll, @stryBuilt);
|
|
|
|
push(@stryModifiedList, @stryBuilt);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, " autogenerated embedded C code: " . (@stryBuilt ? join(', ', @stryBuilt) : 'no changes'));
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2018-03-28 04:48:22 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Auto-generate embedded Perl code
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-11-04 01:52:46 +02:00
|
|
|
if (!$bSmart || grep(/^lib\//, @stryModifiedList))
|
2018-05-22 18:53:08 +02:00
|
|
|
{
|
|
|
|
my $rhBuild =
|
|
|
|
{
|
|
|
|
'embed' =>
|
|
|
|
{
|
|
|
|
&BLD_DATA => buildEmbed($oStorageBackRest),
|
|
|
|
&BLD_PATH => 'perl',
|
|
|
|
},
|
|
|
|
};
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuilt = buildAll("${strBackRestBase}/src", $rhBuild);
|
|
|
|
&log(INFO, " autogenerated embedded Perl code: " . (@stryBuilt ? join(', ', @stryBuilt) : 'no changes'));
|
|
|
|
|
|
|
|
if (@stryBuilt)
|
|
|
|
{
|
|
|
|
push(@stryBuiltAll, @stryBuilt);
|
|
|
|
push(@stryModifiedList, @stryBuilt);
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 20:57:08 +02:00
|
|
|
# Auto-generate C Makefile
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-11-04 01:52:46 +02:00
|
|
|
if (!$bSmart || grep(/^(src|libc)\//, @stryModifiedList))
|
2018-05-23 20:57:08 +02:00
|
|
|
{
|
2018-11-04 01:52:46 +02:00
|
|
|
my @stryBuilt;
|
|
|
|
my $strBuilt = 'src/Makefile';
|
2018-05-23 20:57:08 +02:00
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
if (buildPutDiffers(
|
|
|
|
$oStorageBackRest,
|
|
|
|
$strBuilt,
|
2018-05-23 20:57:08 +02:00
|
|
|
buildMakefile(
|
|
|
|
$oStorageBackRest,
|
|
|
|
${$oStorageBackRest->get("src/Makefile")},
|
2018-11-04 01:52:46 +02:00
|
|
|
{rhOption => {'postgres/pageChecksum.o' => '-funroll-loops -ftree-vectorize'}})))
|
|
|
|
{
|
|
|
|
push(@stryBuilt, $strBuilt);
|
|
|
|
push(@stryBuiltAll, @stryBuilt);
|
|
|
|
push(@stryModifiedList, @stryBuilt);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, " autogenerated C Makefile: " . (@stryBuilt ? join(', ', @stryBuilt) : 'no changes'));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy all the files that were auto-generate so they won't show as modified in the next run
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
foreach my $strBuilt (@stryBuiltAll)
|
|
|
|
{
|
|
|
|
executeTest("cp -p ${strBackRestBase}/${strBuilt} ${strRepoCachePath}/${strBuilt}");
|
2018-05-23 20:57:08 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bGenOnly)
|
|
|
|
{
|
|
|
|
exit 0;
|
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Build CI config
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-02-26 19:53:41 +02:00
|
|
|
if (!$bNoCiConfig)
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
(new pgBackRestTest::Common::CiTest($oStorageBackRest))->process();
|
2017-02-26 19:53:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
# Check Perl version against release notes and update version in C code if needed
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $bVersionDev = true;
|
|
|
|
my $strVersionBase;
|
2016-05-24 02:04:36 +02:00
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
if (!$bDev)
|
2016-05-24 02:04:36 +02:00
|
|
|
{
|
2018-04-09 22:46:36 +02:00
|
|
|
# Make sure version number matches the latest release
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
&log(INFO, "check version info");
|
|
|
|
|
|
|
|
# Load the doc modules dynamically since they are not supported on all systems
|
|
|
|
require BackRestDoc::Common::Doc;
|
|
|
|
BackRestDoc::Common::Doc->import();
|
|
|
|
require BackRestDoc::Custom::DocCustomRelease;
|
|
|
|
BackRestDoc::Custom::DocCustomRelease->import();
|
|
|
|
|
|
|
|
my $strReleaseFile = dirname(dirname(abs_path($0))) . '/doc/xml/release.xml';
|
|
|
|
my $oRelease =
|
|
|
|
(new BackRestDoc::Custom::DocCustomRelease(new BackRestDoc::Common::Doc($strReleaseFile)))->releaseLast();
|
|
|
|
my $strVersion = $oRelease->paramGet('version');
|
|
|
|
$bVersionDev = false;
|
|
|
|
$strVersionBase = $strVersion;
|
|
|
|
|
|
|
|
if ($strVersion =~ /dev$/)
|
|
|
|
{
|
|
|
|
$bVersionDev = true;
|
|
|
|
$strVersionBase = substr($strVersion, 0, length($strVersion) - 3);
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2018-11-25 02:05:03 +02:00
|
|
|
if (PROJECT_VERSION !~ /dev$/ && $oRelease->nodeTest('release-core-list'))
|
2018-04-09 22:46:36 +02:00
|
|
|
{
|
|
|
|
confess "dev release ${strVersion} must match the program version when core changes have been made";
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 02:05:03 +02:00
|
|
|
elsif ($strVersion ne PROJECT_VERSION)
|
2016-05-26 16:34:10 +02:00
|
|
|
{
|
2018-11-25 02:05:03 +02:00
|
|
|
confess 'unable to find version ' . PROJECT_VERSION . " as the most recent release in ${strReleaseFile}";
|
2016-05-26 16:34:10 +02:00
|
|
|
}
|
2016-05-24 02:04:36 +02:00
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
# Update version for the C code based on the current Perl version
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strCVersionFile = "${strBackRestBase}/src/version.h";
|
|
|
|
my $strCVersionOld = ${$oStorageTest->get($strCVersionFile)};
|
|
|
|
my $strCVersionNew;
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
foreach my $strLine (split("\n", $strCVersionOld))
|
2017-11-29 04:44:05 +02:00
|
|
|
{
|
2018-11-25 02:05:03 +02:00
|
|
|
if ($strLine =~ /^#define PROJECT_VERSION/)
|
2018-04-09 22:46:36 +02:00
|
|
|
{
|
2018-11-25 02:05:03 +02:00
|
|
|
$strLine = '#define PROJECT_VERSION' . (' ' x 45) . '"' . PROJECT_VERSION . '"';
|
2018-04-09 22:46:36 +02:00
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
$strCVersionNew .= "${strLine}\n";
|
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
|
2018-04-09 22:46:36 +02:00
|
|
|
if ($strCVersionNew ne $strCVersionOld)
|
|
|
|
{
|
|
|
|
$oStorageTest->put($strCVersionFile, $strCVersionNew);
|
|
|
|
}
|
2017-11-29 04:44:05 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 05:31:16 +02:00
|
|
|
# Clean up
|
2017-08-19 14:48:13 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-02-18 05:31:16 +02:00
|
|
|
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";
|
2018-03-20 05:33:28 +02:00
|
|
|
my $strCodePath = "${strBackRestBase}/test/.vagrant/code";
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
if (!$bDryRun || $bVmOut)
|
|
|
|
{
|
2018-03-10 06:00:20 +02:00
|
|
|
&log(INFO, "cleanup old data and containers");
|
2017-02-18 05:31:16 +02:00
|
|
|
containerRemove('test-([0-9]+|build)');
|
|
|
|
|
|
|
|
for (my $iVmIdx = 0; $iVmIdx < 8; $iVmIdx++)
|
|
|
|
{
|
|
|
|
push(@{$oyProcess}, undef);
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:56:13 +02:00
|
|
|
executeTest(
|
|
|
|
"sudo rm -rf ${strTestPath}/cover_db ${strTestPath}/test-* ${strTestPath}/expect-*" .
|
|
|
|
($bDev ? '' : " ${strTestPath}/gcov-*"));
|
2018-11-04 01:52:46 +02:00
|
|
|
$oStorageTest->pathCreate($strCoveragePath, {strMode => '0770', bIgnoreExists => true, bCreateParent => true});
|
2018-03-20 05:33:28 +02:00
|
|
|
|
|
|
|
# Remove old coverage dirs -- do it this way so the dirs stay open in finder/explorer, etc.
|
2018-11-02 17:56:13 +02:00
|
|
|
executeTest("rm -rf ${strBackRestBase}/test/coverage/c/* ${strBackRestBase}/test/coverage/perl/*");
|
2018-03-20 05:33:28 +02:00
|
|
|
|
2018-11-12 00:32:42 +02:00
|
|
|
# Overwrite the C coverage report so it will load but not show old coverage
|
|
|
|
$oStorageTest->pathCreate("${strBackRestBase}/test/coverage", {strMode => '0770', bIgnoreExists => true});
|
|
|
|
$oStorageBackRest->put(
|
|
|
|
"${strBackRestBase}/test/coverage/c-coverage.html", "<center>[ Generating New Report ]</center>");
|
|
|
|
|
2018-03-20 05:33:28 +02:00
|
|
|
# Copy C code for coverage tests
|
2018-09-15 19:27:06 +02:00
|
|
|
if (vmCoverageC($strVm) && !$bDryRun)
|
2018-03-20 05:33:28 +02:00
|
|
|
{
|
|
|
|
$oStorageTest->pathCreate("${strCodePath}/test", {strMode => '0770', bIgnoreExists => true, bCreateParent => true});
|
|
|
|
|
2018-11-02 17:56:13 +02:00
|
|
|
executeTest(
|
|
|
|
"rsync -rt --delete --exclude=test ${strBackRestBase}/src/ ${strCodePath} && " .
|
|
|
|
"rsync -rt --delete ${strBackRestBase}/test/src/module/ ${strCodePath}/test");
|
2018-03-20 05:33:28 +02:00
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 04:19:59 +02:00
|
|
|
# Determine which tests to run
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $oyTestRun;
|
2018-05-22 18:53:08 +02:00
|
|
|
my $bBinRequired = $bBuildOnly;
|
|
|
|
my $bLibCHostRequired = $bBuildOnly;
|
|
|
|
my $bLibCVmRequired = $bBuildOnly;
|
2017-11-28 04:19:59 +02:00
|
|
|
|
2018-02-14 17:33:21 +02:00
|
|
|
# Only get the test list when they can run
|
2017-11-28 04:19:59 +02:00
|
|
|
if (!$bBuildOnly)
|
|
|
|
{
|
|
|
|
# Get the test list
|
|
|
|
$oyTestRun = testListGet(
|
2018-02-04 01:27:38 +02:00
|
|
|
$strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strPgVersion, $bCoverageOnly, $bCOnly);
|
2017-11-28 04:19:59 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Determine if the C binary and test library need to be built
|
2017-11-28 04:19:59 +02:00
|
|
|
foreach my $hTest (@{$oyTestRun})
|
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
# Bin build required for all Perl tests or if a C unit test calls Perl
|
2018-02-14 17:33:21 +02:00
|
|
|
if (!$hTest->{&TEST_C} || $hTest->{&TEST_PERL_REQ})
|
2017-11-28 04:19:59 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
$bBinRequired = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Host LibC required if a Perl test
|
|
|
|
if (!$hTest->{&TEST_C})
|
|
|
|
{
|
|
|
|
$bLibCHostRequired = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# VM LibC required if Perl and not an integration test
|
|
|
|
if (!$hTest->{&TEST_C} && !$hTest->{&TEST_INTEGRATION})
|
|
|
|
{
|
|
|
|
$bLibCVmRequired = true;
|
2017-11-28 04:19:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
my $strBuildRequired;
|
|
|
|
|
|
|
|
if ($bBinRequired || $bLibCHostRequired || $bLibCVmRequired)
|
|
|
|
{
|
|
|
|
if ($bBinRequired)
|
|
|
|
{
|
|
|
|
$strBuildRequired = "bin";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bLibCHostRequired)
|
|
|
|
{
|
|
|
|
$strBuildRequired .= ", libc host";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bLibCVmRequired)
|
|
|
|
{
|
|
|
|
$strBuildRequired .= ", libc vm";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strBuildRequired = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "builds required: ${strBuildRequired}");
|
|
|
|
|
2017-11-27 01:43:51 +02:00
|
|
|
# Build the binary, library and packages
|
2017-08-19 14:48:13 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2018-05-22 18:53:08 +02:00
|
|
|
if (!$bDryRun)
|
2016-12-13 01:54:07 +02:00
|
|
|
{
|
2017-11-27 01:43:51 +02:00
|
|
|
my $oVm = vmGet();
|
|
|
|
my $strVagrantPath = "${strBackRestBase}/test/.vagrant";
|
2018-05-22 18:53:08 +02:00
|
|
|
my $lTimestampLast;
|
2018-05-24 20:01:24 +02:00
|
|
|
my @stryBinSrcPath = ('src', 'libc');
|
|
|
|
my $strBinPath = "${strVagrantPath}/bin";
|
|
|
|
my $rhBinBuild = {};
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
# Build the binary
|
2018-05-22 18:53:08 +02:00
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-05-24 20:01:24 +02:00
|
|
|
if ($bBinRequired)
|
2018-05-22 18:53:08 +02:00
|
|
|
{
|
2018-05-24 20:01:24 +02:00
|
|
|
# Find the lastest modified time for dirs that affect the bin build
|
|
|
|
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, \@stryBinSrcPath);
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
# Loop through VMs to do the C bin builds
|
|
|
|
my $bLogDetail = $strLogLevel eq 'detail';
|
|
|
|
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
foreach my $strBuildVM (@stryBuildVm)
|
2017-11-27 01:43:51 +02:00
|
|
|
{
|
2018-05-24 20:01:24 +02:00
|
|
|
my $strBuildPath = "${strBinPath}/${strBuildVM}/src";
|
|
|
|
my $bRebuild = !$bSmart;
|
|
|
|
$rhBinBuild->{$strBuildVM} = true;
|
|
|
|
|
|
|
|
# Rebuild if the modification time of the smart file does equal the last changes in source paths
|
|
|
|
if ($bSmart)
|
2018-05-22 18:53:08 +02:00
|
|
|
{
|
2018-05-24 20:01:24 +02:00
|
|
|
my $strBinSmart = "${strBuildPath}/pgbackrest";
|
|
|
|
|
|
|
|
if (!$oStorageBackRest->exists($strBinSmart) ||
|
|
|
|
$oStorageBackRest->info($strBinSmart)->mtime < $lTimestampLast)
|
|
|
|
{
|
|
|
|
&log(INFO, " bin dependencies have changed for ${strBuildVM}, rebuilding...");
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
$bRebuild = true;
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
if ($bRebuild)
|
|
|
|
{
|
|
|
|
&log(INFO, " build bin for ${strBuildVM} (${strBuildPath})");
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
|
|
|
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
|
|
|
|
foreach my $strBinSrcPath (@stryBinSrcPath)
|
|
|
|
{
|
|
|
|
$oStorageBackRest->pathCreate(
|
|
|
|
"${strBinPath}/${strBuildVM}/${strBinSrcPath}", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
}
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"rsync -rt" . (!$bSmart ? " --delete-excluded" : '') .
|
|
|
|
" --include=" . join('/*** --include=', @stryBinSrcPath) . '/*** --exclude=*' .
|
|
|
|
" ${strBackRestBase}/ ${strBinPath}/${strBuildVM}");
|
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
if (vmLintC($strVm) && !$bNoLint)
|
2018-05-24 20:01:24 +02:00
|
|
|
{
|
|
|
|
&log(INFO, " clang static analyzer ${strBuildVM} (${strBuildPath})");
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strCExtra =
|
|
|
|
"'-g -fPIC -D_FILE_OFFSET_BITS=64" .
|
|
|
|
(vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? ' -DWITH_BACKTRACE' : '') . "'";
|
|
|
|
my $strLdExtra = vmWithBackTrace($strBuildVM) && $bNoLint && $bBackTrace ? '-lbacktrace' : '';
|
|
|
|
my $strCDebug = vmDebugIntegration($strBuildVM) ? 'CDEBUG=' : '';
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
'docker exec -i test-build' .
|
2018-09-15 19:27:06 +02:00
|
|
|
(vmLintC($strVm) && !$bNoLint ? ' scan-build-6.0' : '') .
|
2018-05-24 20:01:24 +02:00
|
|
|
" make --silent --directory ${strBuildPath} CEXTRA=${strCExtra} LDEXTRA=${strLdExtra} ${strCDebug}",
|
|
|
|
{bShowOutputAsync => $bLogDetail});
|
|
|
|
|
|
|
|
executeTest("docker rm -f test-build");
|
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2018-05-24 20:01:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build the C Library
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
if ($bLibCHostRequired || $bLibCVmRequired)
|
|
|
|
{
|
|
|
|
my $strLibCPath = "${strVagrantPath}/bin";
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Loop through VMs to do the C Library builds
|
|
|
|
my $bLogDetail = $strLogLevel eq 'detail';
|
|
|
|
my @stryBuildVm = ();
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($strVm eq VM_ALL)
|
|
|
|
{
|
|
|
|
@stryBuildVm = $bLibCVmRequired ? VM_LIST : ($strVmHost);
|
|
|
|
}
|
|
|
|
else
|
2017-11-27 01:43:51 +02:00
|
|
|
{
|
2018-05-23 01:53:25 +02:00
|
|
|
@stryBuildVm = $bLibCVmRequired && $strVmHost ne $strVm ? ($strVmHost, $strVm) : ($strVmHost);
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
foreach my $strBuildVM (@stryBuildVm)
|
|
|
|
{
|
|
|
|
my $strBuildPath = "${strLibCPath}/${strBuildVM}/libc";
|
|
|
|
my $bContainerExists = $strBuildVM ne $strVmHost;
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
my $strLibCSmart = "${strBuildPath}/blib/arch/auto/pgBackRest/LibC/LibC.so";
|
|
|
|
my $bRebuild = !$bSmart;
|
|
|
|
|
|
|
|
# Rebuild if the modification time of the smart file does equal the last changes in source paths
|
|
|
|
if ($bSmart)
|
|
|
|
{
|
|
|
|
if (!$oStorageBackRest->exists($strLibCSmart) ||
|
|
|
|
$oStorageBackRest->info($strLibCSmart)->mtime < $lTimestampLast)
|
|
|
|
{
|
2018-06-11 20:52:26 +02:00
|
|
|
&log(INFO, " libc dependencies have changed for ${strBuildVM}, rebuilding...");
|
2018-05-24 20:01:24 +02:00
|
|
|
|
|
|
|
$bRebuild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Delete old libc files from the host
|
|
|
|
if ($bRebuild)
|
|
|
|
{
|
|
|
|
executeTest('sudo rm -rf ' . $oVm->{$strBuildVM}{&VMDEF_PERL_ARCH_PATH} . '/auto/pgBackRest/LibC');
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bRebuild)
|
2017-11-27 01:43:51 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
&log(INFO, " build test library for ${strBuildVM} (${strBuildPath})");
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-24 20:01:24 +02:00
|
|
|
if (!$rhBinBuild->{$strBuildVM})
|
|
|
|
{
|
|
|
|
foreach my $strBinSrcPath (@stryBinSrcPath)
|
|
|
|
{
|
|
|
|
$oStorageBackRest->pathCreate(
|
|
|
|
"${strBinPath}/${strBuildVM}/${strBinSrcPath}", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
}
|
|
|
|
|
|
|
|
executeTest(
|
|
|
|
"rsync -rt" . (!$bSmart ? " --delete-excluded" : '') .
|
|
|
|
" --include=" . join('/*** --include=', @stryBinSrcPath) . '/*** --exclude=*' .
|
|
|
|
" ${strBackRestBase}/ ${strBinPath}/${strBuildVM}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Can't reuse any object files in the libc dir because it does not have proper dependencies
|
|
|
|
executeTest(
|
|
|
|
"rsync -rt --exclude=Makefile --delete ${strBackRestBase}/libc/ ${strLibCPath}/${strBuildVM}/libc");
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# It's very expensive to rebuild the Makefile so make sure it has actually changed
|
|
|
|
my $bMakeRebuild =
|
|
|
|
!$oStorageBackRest->exists("${strBuildPath}/Makefile") ||
|
|
|
|
($oStorageBackRest->info("${strBackRestBase}/libc/Makefile.PL")->mtime >
|
|
|
|
$oStorageBackRest->info("${strBuildPath}/Makefile.PL")->mtime);
|
2018-03-18 19:32:19 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bContainerExists)
|
|
|
|
{
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
|
|
|
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
2018-05-18 12:45:14 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bMakeRebuild)
|
|
|
|
{
|
2018-05-24 20:01:24 +02:00
|
|
|
&log(INFO, " rebuild test library Makefile for ${strBuildVM}");
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
executeTest(
|
|
|
|
($bContainerExists ? "docker exec -i test-build bash -c '" : '') .
|
2018-07-10 21:39:03 +02:00
|
|
|
"cd ${strBuildPath} && perl ${strBuildPath}/Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none" .
|
2018-05-22 18:53:08 +02:00
|
|
|
($bContainerExists ? "'" : ''),
|
|
|
|
{bSuppressStdErr => true, bShowOutputAsync => $bLogDetail});
|
|
|
|
}
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
executeTest(
|
|
|
|
($bContainerExists ? 'docker exec -i test-build ' : '') .
|
|
|
|
"make --silent --directory ${strBuildPath}",
|
|
|
|
{bShowOutputAsync => $bLogDetail});
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bContainerExists)
|
|
|
|
{
|
|
|
|
executeTest("docker rm -f test-build");
|
|
|
|
}
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($strBuildVM eq $strVmHost)
|
|
|
|
{
|
|
|
|
executeTest("sudo make -C ${strBuildPath} install", {bSuppressStdErr => true});
|
2018-05-24 20:01:24 +02:00
|
|
|
buildLoadLibC();
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-10 04:24:30 +02:00
|
|
|
}
|
2018-05-22 18:53:08 +02:00
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Build the package
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (!$bNoPackage)
|
|
|
|
{
|
|
|
|
my $strPackagePath = "${strVagrantPath}/package";
|
|
|
|
my $strPackageSmart = "${strPackagePath}/build.timestamp";
|
|
|
|
my @stryPackageSrcPath = ('lib');
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Find the lastest modified time for additional dirs that affect the package build
|
|
|
|
foreach my $strPackageSrcPath (@stryPackageSrcPath)
|
|
|
|
{
|
|
|
|
my $hManifest = $oStorageBackRest->manifest($strPackageSrcPath);
|
2017-02-18 05:31:16 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$hManifest})))
|
|
|
|
{
|
|
|
|
if ($hManifest->{$strFile}{type} eq 'f' && $hManifest->{$strFile}{modification_time} > $lTimestampLast)
|
2017-02-18 05:31:16 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
$lTimestampLast = $hManifest->{$strFile}{modification_time};
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 20:12:53 +02:00
|
|
|
}
|
2017-08-19 14:48:13 +02:00
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Rebuild if the modification time of the smart file does not equal the last changes in source paths
|
|
|
|
if ((!$bSmart || !$oStorageBackRest->exists($strPackageSmart) ||
|
|
|
|
$oStorageBackRest->info($strPackageSmart)->mtime < $lTimestampLast))
|
2017-08-19 14:48:13 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
if ($bSmart)
|
2017-08-19 14:48:13 +02:00
|
|
|
{
|
2018-05-22 18:53:08 +02:00
|
|
|
&log(INFO, 'package dependencies have changed, rebuilding...');
|
2017-08-19 14:48:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
executeTest("sudo rm -rf ${strPackagePath}");
|
2017-08-19 14:48:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
# Loop through VMs to do the package builds
|
2017-02-18 05:31:16 +02:00
|
|
|
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
|
|
|
|
2018-05-22 18:53:08 +02:00
|
|
|
foreach my $strBuildVM (@stryBuildVm)
|
2017-02-18 05:31:16 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-08-19 14:48:13 +02:00
|
|
|
&log(INFO, "build package for ${strBuildVM} (${strBuildPath})");
|
2017-02-18 05:31:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-11-27 01:43:51 +02:00
|
|
|
# Patch files in debian package builds
|
|
|
|
#
|
|
|
|
# Use these commands to create a new patch (may need to modify first line):
|
2018-06-06 21:52:28 +02:00
|
|
|
# BRDIR=/backrest;BRVM=u18;BRPATCHFILE=${BRDIR?}/test/patch/debian-package.patch
|
2017-11-27 01:43:51 +02:00
|
|
|
# DBDIR=${BRDIR?}/test/.vagrant/package/${BRVM}/src/debian
|
|
|
|
# diff -Naur ${DBDIR?}.old ${DBDIR}.new > ${BRPATCHFILE?}
|
|
|
|
my $strDebianPackagePatch = "${strBackRestBase}/test/patch/debian-package.patch";
|
|
|
|
|
|
|
|
if ($oStorageBackRest->exists($strDebianPackagePatch))
|
|
|
|
{
|
|
|
|
executeTest("cp -r ${strBuildPath}/debian ${strBuildPath}/debian.old");
|
|
|
|
executeTest("patch -d ${strBuildPath}/debian < ${strDebianPackagePatch}");
|
|
|
|
executeTest("cp -r ${strBuildPath}/debian ${strBuildPath}/debian.new");
|
|
|
|
}
|
|
|
|
|
2017-06-24 16:59:00 +02:00
|
|
|
# If dev build then disable static release date used for reproducibility
|
2017-02-18 05:31:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-22 18:37:21 +02:00
|
|
|
# Remove patches that should be applied to core code
|
2017-07-25 18:44:38 +02:00
|
|
|
$oStorageBackRest->remove("${strBuildPath}/debian/patches", {bRecurse => true, bIgnoreExists => true});
|
2017-06-22 18:37:21 +02:00
|
|
|
|
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");
|
|
|
|
}
|
2018-02-27 02:32:27 +02:00
|
|
|
|
|
|
|
if (!$oStorageBackRest->pathExists($strBuildPath) && $oVm->{$strBuildVM}{&VM_OS_BASE} eq VM_OS_BASE_RHEL)
|
|
|
|
{
|
|
|
|
&log(INFO, "build package for ${strBuildVM} (${strBuildPath})");
|
|
|
|
|
|
|
|
# Create build container
|
|
|
|
executeTest(
|
|
|
|
"docker run -itd -h test-build --name=test-build" .
|
|
|
|
" -v ${strBackRestBase}:${strBackRestBase} " . containerRepo() . ":${strBuildVM}-build",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
|
|
|
|
# Create build directories
|
|
|
|
$oStorageBackRest->pathCreate($strBuildPath, {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
$oStorageBackRest->pathCreate("${strBuildPath}/SOURCES", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
$oStorageBackRest->pathCreate("${strBuildPath}/SPECS", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
$oStorageBackRest->pathCreate("${strBuildPath}/RPMS", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
$oStorageBackRest->pathCreate("${strBuildPath}/BUILD", {bIgnoreExists => true, bCreateParent => true});
|
|
|
|
|
|
|
|
# Copy source files
|
|
|
|
executeTest(
|
|
|
|
"tar --transform='s_^_pgbackrest-release-${strVersionBase}/_'" .
|
|
|
|
" -czf ${strBuildPath}/SOURCES/${strVersionBase}.tar.gz -C ${strBackRestBase}" .
|
|
|
|
" lib libc src LICENSE");
|
|
|
|
|
|
|
|
# Copy package files
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build bash -c '" .
|
|
|
|
"ln -s ${strBuildPath} /root/rpmbuild && " .
|
|
|
|
"cp /root/package-src/pgbackrest.spec ${strBuildPath}/SPECS && " .
|
|
|
|
"cp /root/package-src/*.patch ${strBuildPath}/SOURCES && " .
|
|
|
|
"sudo chown -R " . TEST_USER . " ${strBuildPath}'");
|
|
|
|
|
|
|
|
# Patch files in RHEL package builds
|
|
|
|
#
|
|
|
|
# Use these commands to create a new patch (may need to modify first line):
|
|
|
|
# BRDIR=/backrest;BRVM=co7;BRPATCHFILE=${BRDIR?}/test/patch/rhel-package.patch
|
|
|
|
# PKDIR=${BRDIR?}/test/.vagrant/package/${BRVM}/src/SPECS
|
|
|
|
# diff -Naur ${PKDIR?}.old ${PKDIR}.new > ${BRPATCHFILE?}
|
|
|
|
my $strPackagePatch = "${strBackRestBase}/test/patch/rhel-package.patch";
|
|
|
|
|
|
|
|
if ($oStorageBackRest->exists($strPackagePatch))
|
|
|
|
{
|
|
|
|
executeTest("cp -r ${strBuildPath}/SPECS ${strBuildPath}/SPECS.old");
|
|
|
|
executeTest("patch -d ${strBuildPath}/SPECS < ${strPackagePatch}");
|
|
|
|
executeTest("cp -r ${strBuildPath}/SPECS ${strBuildPath}/SPECS.new");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Update version number to match current version
|
|
|
|
my $strSpec = ${$oStorageBackRest->get("${strBuildPath}/SPECS/pgbackrest.spec")};
|
|
|
|
$strSpec =~ s/^Version\:.*$/Version\:\t${strVersionBase}/gm;
|
|
|
|
$oStorageBackRest->put("${strBuildPath}/SPECS/pgbackrest.spec", $strSpec);
|
|
|
|
|
|
|
|
# Build package
|
|
|
|
executeTest(
|
|
|
|
"docker exec -i test-build rpmbuild -v -bb --clean root/rpmbuild/SPECS/pgbackrest.spec",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
|
|
|
|
# Remove build container
|
|
|
|
executeTest("docker rm -f test-build");
|
|
|
|
}
|
2017-02-18 05:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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-08-19 14:48:13 +02:00
|
|
|
utime($lTimestampLast, $lTimestampLast, $strPackageSmart) or
|
2017-02-18 05:31:16 +02:00
|
|
|
confess "unable to set time for ${strPackageSmart}" . (defined($!) ? ":$!" : '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Exit if only testing builds
|
|
|
|
exit 0 if $bBuildOnly;
|
|
|
|
}
|
|
|
|
|
2018-11-04 01:52:46 +02:00
|
|
|
# Remove repo.manifest now that all processing that depends on modified files has been completed
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$oStorageTest->remove("${strRepoCachePath}/${strRepoCacheManifest}");
|
|
|
|
|
2017-08-19 14:48:13 +02:00
|
|
|
# Perform static source code analysis
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (!$bDryRun)
|
|
|
|
{
|
|
|
|
# Run Perl critic
|
|
|
|
if (!$bNoLint && !$bBuildOnly)
|
|
|
|
{
|
|
|
|
my $strBasePath = dirname(dirname(abs_path($0)));
|
|
|
|
|
|
|
|
&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\"" .
|
2017-11-27 01:43:51 +02:00
|
|
|
" ${strBasePath}/lib/*" .
|
2017-08-19 14:48:13 +02:00
|
|
|
" ${strBasePath}/test/test.pl ${strBasePath}/test/lib/*" .
|
|
|
|
" ${strBasePath}/doc/doc.pl ${strBasePath}/doc/lib/*");
|
|
|
|
}
|
|
|
|
|
|
|
|
logFileSet($oStorageTest, cwd() . "/test");
|
|
|
|
}
|
|
|
|
|
2017-11-28 04:19:59 +02:00
|
|
|
# Run the tests
|
2017-08-19 14:48:13 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
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");
|
|
|
|
|
2017-11-28 04:19:59 +02:00
|
|
|
# Don't allow --no-cleanup when more than one test will run. How would the prior results be preserved?
|
2017-02-18 05:31:16 +02:00
|
|
|
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-11-28 04:19:59 +02:00
|
|
|
# Only use one vm for dry run so results are printed in order
|
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};
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-24 16:35:42 +02:00
|
|
|
# Only wait when all VMs are running or all tests have been assigned. Otherwise, there is something to do.
|
|
|
|
if ($iVmTotal == $iVmMax || $iTestIdx == @{$oyTestRun})
|
2016-01-09 15:21:53 +02:00
|
|
|
{
|
2017-10-24 16:35:42 +02:00
|
|
|
waitHiRes(.05);
|
2016-01-09 15:21:53 +02:00
|
|
|
}
|
|
|
|
}
|
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,
|
2018-07-21 01:03:46 +02:00
|
|
|
$iVmIdx, $iVmMax, $iTestIdx, $iTestMax, $strLogLevel, $strLogLevelTest, $bLogForce, $bShowOutputAsync, $bNoCleanup, $iRetry,
|
2018-05-18 17:57:32 +02:00
|
|
|
!$bNoValgrind, !$bNoCoverage, !$bNoOptimize, $bBackTrace, $bProfile, !$bNoDebug);
|
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-08-19 14:48:13 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-04-10 18:31:30 +02:00
|
|
|
my $iUncoveredCodeModuleTotal = 0;
|
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
if ((vmCoverageC($strVm) || vmCoveragePerl($strVm)) && !$bNoCoverage && !$bDryRun && $iTestFail == 0)
|
2017-01-10 03:49:04 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
# Determine which modules were covered (only check coverage if all tests were successful)
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
2018-09-15 19:27:06 +02:00
|
|
|
my $hModuleTest; # Everything that was run
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
# 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);
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
# Get coverage for the test
|
|
|
|
my $strTest = $hTestRun->{&TEST_NAME};
|
|
|
|
my $hTest = testDefModuleTest($strModule, $strTest);
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
# If no tests are listed it means all of them were run
|
|
|
|
if (@{$hTestRun->{&TEST_RUN}} == 0)
|
|
|
|
{
|
|
|
|
$hModuleTest->{$strModule}{$strTest} = true;
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
2018-09-15 19:27:06 +02:00
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
# Now compare against code modules that should have full coverage
|
|
|
|
my $hCoverageList = testDefCoverageList();
|
|
|
|
my $hCoverageType = testDefCoverageType();
|
|
|
|
my $hCoverageActual;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
foreach my $strCodeModule (sort(keys(%{$hCoverageList})))
|
|
|
|
{
|
|
|
|
if (@{$hCoverageList->{$strCodeModule}} > 0)
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
2018-09-15 19:27:06 +02:00
|
|
|
my $iCoverageTotal = 0;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
foreach my $hTest (@{$hCoverageList->{$strCodeModule}})
|
|
|
|
{
|
|
|
|
if (!defined($hModuleTest->{$hTest->{strModule}}{$hTest->{strTest}}))
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
2018-09-15 19:27:06 +02:00
|
|
|
next;
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
$iCoverageTotal++;
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-15 19:27:06 +02:00
|
|
|
if (@{$hCoverageList->{$strCodeModule}} == $iCoverageTotal)
|
|
|
|
{
|
|
|
|
$hCoverageActual->{testRunName($strCodeModule, false)} = $hCoverageType->{$strCodeModule};
|
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
2018-09-15 19:27:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keys(%{$hCoverageActual}) == 0)
|
|
|
|
{
|
|
|
|
&log(INFO, 'no code modules had all tests run required for coverage');
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate Perl coverage report
|
|
|
|
#-----------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (vmCoveragePerl($strVm))
|
|
|
|
{
|
|
|
|
&log(INFO, 'writing Perl coverage report');
|
|
|
|
|
|
|
|
executeTest("cp -rp ${strCoveragePath} ${strCoveragePath}_temp");
|
|
|
|
executeTest(
|
|
|
|
"cd ${strCoveragePath}_temp && " .
|
|
|
|
LIB_COVER_EXE . " -report json -outputdir ${strBackRestBase}/test/coverage/perl ${strCoveragePath}_temp",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
executeTest("sudo rm -rf ${strCoveragePath}_temp");
|
|
|
|
executeTest("sudo cp -rp ${strCoveragePath} ${strCoveragePath}_temp");
|
|
|
|
executeTest(
|
|
|
|
"cd ${strCoveragePath}_temp && " .
|
|
|
|
LIB_COVER_EXE . " -outputdir ${strBackRestBase}/test/coverage/perl ${strCoveragePath}_temp",
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
executeTest("sudo rm -rf ${strCoveragePath}_temp");
|
|
|
|
|
|
|
|
# Load the results of coverage testing from JSON
|
|
|
|
my $oJSON = JSON::PP->new()->allow_nonref();
|
|
|
|
my $hCoverageResult = $oJSON->decode(${$oStorageBackRest->get('test/coverage/perl/cover.json')});
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
foreach my $strCodeModule (sort(keys(%{$hCoverageActual})))
|
|
|
|
{
|
2018-03-20 05:33:28 +02:00
|
|
|
# If the first char of the module is lower case then it's a c module
|
2017-10-12 18:55:48 +02:00
|
|
|
if (substr($strCodeModule, 0, 1) eq lc(substr($strCodeModule, 0, 1)))
|
|
|
|
{
|
2018-03-20 05:33:28 +02:00
|
|
|
next;
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-20 05:33:28 +02:00
|
|
|
# Create code module path -- where the file is located on disk
|
2018-11-25 02:05:03 +02:00
|
|
|
my $strCodeModulePath = "${strBackRestBase}/lib/" . PROJECT_NAME . "/${strCodeModule}.pm";
|
2018-03-20 05:33:28 +02:00
|
|
|
|
2018-02-14 23:46:52 +02:00
|
|
|
# Get summary results
|
2017-10-12 18:55:48 +02:00
|
|
|
my $hCoverageResultAll = $hCoverageResult->{'summary'}{$strCodeModulePath}{total};
|
|
|
|
|
|
|
|
# Try an extra / if the module is not found
|
|
|
|
if (!defined($hCoverageResultAll))
|
|
|
|
{
|
|
|
|
$strCodeModulePath = "/${strCodeModulePath}";
|
|
|
|
$hCoverageResultAll = $hCoverageResult->{'summary'}{$strCodeModulePath}{total};
|
|
|
|
}
|
|
|
|
|
|
|
|
# If module is marked as having no code
|
|
|
|
if ($hCoverageActual->{$strCodeModule} eq TESTDEF_COVERAGE_NOCODE)
|
|
|
|
{
|
|
|
|
# Error if it really does have coverage
|
|
|
|
if ($hCoverageResultAll)
|
|
|
|
{
|
2018-03-20 05:33:28 +02:00
|
|
|
confess &log(ERROR, "perl module ${strCodeModule} is marked 'no code' but has code");
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Skip to next module
|
|
|
|
next;
|
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
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);
|
2017-10-12 18:55:48 +02:00
|
|
|
my $iCoverageCovered = coalesce($hCoverageResultAll->{covered}, 0);
|
2017-04-14 02:10:28 +02:00
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
if ($hCoverageActual->{$strCodeModule} eq TESTDEF_COVERAGE_FULL)
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
2017-04-14 02:10:28 +02:00
|
|
|
my $iUncoveredLines = $iCoverageTotal - $iCoverageCovered - $iCoverageUncoverable;
|
2017-04-10 18:31:30 +02:00
|
|
|
|
|
|
|
if ($iUncoveredLines != 0)
|
|
|
|
{
|
2018-03-20 05:33:28 +02:00
|
|
|
&log(ERROR, "perl module ${strCodeModule} is not fully covered");
|
2017-04-10 18:31:30 +02:00
|
|
|
$iUncoveredCodeModuleTotal++;
|
2018-02-15 00:13:18 +02:00
|
|
|
|
2018-03-20 05:33:28 +02:00
|
|
|
&log(ERROR, ('-' x 80));
|
|
|
|
executeTest(
|
|
|
|
"/usr/bin/cover -report text ${strCoveragePath} --select ${strBackRestBase}/lib/" .
|
2018-11-25 02:05:03 +02:00
|
|
|
PROJECT_NAME . "/${strCodeModule}.pm",
|
2018-03-20 05:33:28 +02:00
|
|
|
{bShowOutputAsync => true});
|
|
|
|
&log(ERROR, ('-' x 80));
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 18:55:48 +02:00
|
|
|
# Else test how much partial coverage there was
|
|
|
|
elsif ($hCoverageActual->{$strCodeModule} eq TESTDEF_COVERAGE_PARTIAL)
|
2017-04-10 18:31:30 +02:00
|
|
|
{
|
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)
|
|
|
|
{
|
2018-04-13 02:42:26 +02:00
|
|
|
&log(ERROR, "perl module ${strCodeModule} has 100% coverage but is not marked fully covered");
|
|
|
|
$iUncoveredCodeModuleTotal++;
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 19:27:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate C coverage report
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
if (vmCoverageC($strVm))
|
|
|
|
{
|
|
|
|
&log(INFO, 'writing C coverage report');
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2018-03-20 05:33:28 +02:00
|
|
|
my $strLCovFile = "${strBackRestBase}/test/.vagrant/code/all.lcov";
|
|
|
|
|
|
|
|
if ($oStorageBackRest->exists($strLCovFile))
|
|
|
|
{
|
|
|
|
executeTest(
|
2018-03-20 15:47:51 +02:00
|
|
|
"genhtml ${strLCovFile} --config-file=${strBackRestBase}/test/src/lcov.conf" .
|
2018-03-20 22:01:38 +02:00
|
|
|
" --prefix=${strBackRestBase}/test/.vagrant/code" .
|
2018-03-20 15:47:51 +02:00
|
|
|
" --output-directory=${strBackRestBase}/test/coverage/c");
|
2018-03-20 05:33:28 +02:00
|
|
|
|
|
|
|
foreach my $strCodeModule (sort(keys(%{$hCoverageActual})))
|
|
|
|
{
|
|
|
|
# If the first char of the module is upper case then it's a Perl module
|
|
|
|
if (substr($strCodeModule, 0, 1) eq uc(substr($strCodeModule, 0, 1)))
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strCoverageFile = $strCodeModule;
|
|
|
|
$strCoverageFile =~ s/^module/test/mg;
|
|
|
|
$strCoverageFile = "${strBackRestBase}/test/.vagrant/code/${strCoverageFile}.lcov";
|
|
|
|
|
|
|
|
my $strCoverage = $oStorageBackRest->get(
|
|
|
|
$oStorageBackRest->openRead($strCoverageFile, {bIgnoreMissing => true}));
|
|
|
|
|
|
|
|
if (defined($strCoverage) && defined($$strCoverage))
|
|
|
|
{
|
2018-05-05 17:50:11 +02:00
|
|
|
my $iTotalLines = (split(':', ($$strCoverage =~ m/^LF\:.*$/mg)[0]))[1] + 0;
|
|
|
|
my $iCoveredLines = (split(':', ($$strCoverage =~ m/^LH\:.*$/mg)[0]))[1] + 0;
|
|
|
|
|
|
|
|
my $iTotalBranches = 0;
|
|
|
|
my $iCoveredBranches = 0;
|
|
|
|
|
|
|
|
if ($$strCoverage =~ /^BRF\:/mg && $$strCoverage =~ /^BRH\:/mg)
|
|
|
|
{
|
|
|
|
# If this isn't here the statements below fail -- huh?
|
|
|
|
my @match = $$strCoverage =~ m/^BRF\:.*$/mg;
|
|
|
|
|
|
|
|
$iTotalBranches = (split(':', ($$strCoverage =~ m/^BRF\:.*$/mg)[0]))[1] + 0;
|
|
|
|
$iCoveredBranches = (split(':', ($$strCoverage =~ m/^BRH\:.*$/mg)[0]))[1] + 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate detail if there is missing coverage
|
|
|
|
my $strDetail = undef;
|
2018-03-20 05:33:28 +02:00
|
|
|
|
|
|
|
if ($iCoveredLines != $iTotalLines)
|
|
|
|
{
|
2018-05-05 17:50:11 +02:00
|
|
|
$strDetail .= "$iCoveredLines/$iTotalLines lines";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($iTotalBranches != $iCoveredBranches)
|
|
|
|
{
|
|
|
|
$strDetail .= (defined($strDetail) ? ', ' : '') . "$iCoveredBranches/$iTotalBranches branches";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($strDetail))
|
|
|
|
{
|
|
|
|
&log(ERROR, "c module ${strCodeModule} is not fully covered ($strDetail)");
|
2018-03-20 05:33:28 +02:00
|
|
|
$iUncoveredCodeModuleTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 00:32:42 +02:00
|
|
|
|
|
|
|
$oStorageBackRest->remove("${strBackRestBase}/test/.vagrant/code/all.lcov", {bIgnoreMissing => true});
|
|
|
|
coverageGenerate(
|
|
|
|
$oStorageBackRest, "${strBackRestBase}/test/.vagrant/code", "${strBackRestBase}/test/coverage/c-coverage.html");
|
2018-03-20 05:33:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
executeTest("rm -rf ${strBackRestBase}/test/coverage/c");
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
2017-01-10 03:49:04 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
# Print test info and exit
|
2017-08-19 14:48:13 +02:00
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
|
################################################################################################################################
|
2018-05-24 20:01:24 +02:00
|
|
|
buildLoadLibC();
|
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
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
|
2018-11-25 02:05:03 +02:00
|
|
|
'/usr/bin/' . PROJECT_EXE, # Path to the backrest executable
|
|
|
|
"${strBackRestBase}/bin/" . PROJECT_EXE, # Path to the backrest Perl helper
|
2018-02-04 01:27:38 +02:00
|
|
|
$strPgVersion ne 'minimal' ? $strPgSqlBin: undef, # Pg bin path
|
|
|
|
$strPgVersion ne 'minimal' ? $strPgVersion: undef, # Pg version
|
2017-01-05 01:29:13 +02:00
|
|
|
$stryModule[0], $stryModuleTest[0], \@iyModuleTestRun, # Module info
|
2017-06-22 01:21:16 +02:00
|
|
|
$bVmOut, $bDryRun, $bNoCleanup, $bLogForce, # Test options
|
2016-12-23 15:22:59 +02:00
|
|
|
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
|
2018-03-15 17:03:28 +02:00
|
|
|
if (isException(\$EVAL_ERROR))
|
|
|
|
{
|
|
|
|
syswrite(*STDOUT, $EVAL_ERROR->message() . "\n" . $EVAL_ERROR->trace());
|
|
|
|
exit $EVAL_ERROR->code();
|
|
|
|
}
|
2016-09-06 15:44:50 +02:00
|
|
|
|
|
|
|
# Else output the unhandled error
|
2017-08-25 22:47:47 +02:00
|
|
|
syswrite(*STDOUT, $EVAL_ERROR);
|
2016-09-06 15:44:50 +02:00
|
|
|
exit ERROR_UNHANDLED;
|
|
|
|
};
|
|
|
|
|
|
|
|
# It shouldn't be possible to get here
|
|
|
|
&log(ASSERT, 'execution reached invalid location in ' . __FILE__ . ', line ' . __LINE__);
|
|
|
|
exit ERROR_ASSERT;
|