2017-02-21 15:59:23 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# CiTest.pm - Create Travis configuration file for continuous integration testing
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRestTest::Common::CiTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
use Cwd qw(abs_path);
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use POSIX qw(ceil);
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
|
|
|
|
use pgBackRest::DbVersion;
|
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::FileCommon;
|
|
|
|
use pgBackRest::Version;
|
|
|
|
|
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
|
|
|
use pgBackRestTest::Common::DefineTest;
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::ListTest;
|
|
|
|
use pgBackRestTest::Common::VmTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# new
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
|
|
|
my $strOperation,
|
|
|
|
$self->{strBackRestBase},
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->new', \@_,
|
|
|
|
{name => 'strBackRestBase'},
|
|
|
|
);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# process
|
|
|
|
####################################################################################################################################
|
|
|
|
sub process
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(my $strOperation) = logDebugParam (__PACKAGE__ . '->process', \@_,);
|
|
|
|
|
|
|
|
# Configure environment
|
|
|
|
my $strConfig =
|
|
|
|
"branches:\n" .
|
|
|
|
" only:\n" .
|
|
|
|
" - master\n" .
|
|
|
|
" - integration\n" .
|
|
|
|
" - /-ci\$/\n" .
|
|
|
|
"\n" .
|
|
|
|
"dist: trusty\n" .
|
|
|
|
"sudo: required\n" .
|
|
|
|
"\n" .
|
|
|
|
"language: c\n" .
|
|
|
|
"\n" .
|
|
|
|
"services:\n" .
|
|
|
|
" - docker\n" .
|
|
|
|
"\n" .
|
|
|
|
"env:\n";
|
|
|
|
|
2017-02-21 19:54:27 +02:00
|
|
|
my $bFirst = true;
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
# Iterate each OS
|
|
|
|
foreach my $strVm (VM_LIST)
|
|
|
|
{
|
|
|
|
my $hVm = vmGet();
|
|
|
|
my @stryModule;
|
2017-04-10 18:31:30 +02:00
|
|
|
my $strFullModule = undef;
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
# Get all modules but full to break up the tests
|
2017-04-10 18:31:30 +02:00
|
|
|
foreach my $strModule (testDefModuleList())
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
|
|
|
if ($strModule ne 'full')
|
|
|
|
{
|
|
|
|
push(@stryModule, $strModule);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strFullModule = $strModule;
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 19:54:27 +02:00
|
|
|
# Add config options for tests that are not the very first one
|
|
|
|
my $strConfigNotFirst = '--no-lint';
|
2017-02-21 21:22:03 +02:00
|
|
|
my $strConfigNotFirstOS = '--no-package';
|
2017-02-21 19:54:27 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
$strConfig .=
|
|
|
|
" - PGB_TEST_VM=\"${strVm}\" PGB_BUILD_PARAM=\"--db=none\" PGB_TEST_PARAM=\"--module=" .
|
2017-02-21 19:54:27 +02:00
|
|
|
join(' --module=', @stryModule) . ($bFirst ? '' : " ${strConfigNotFirst}") . "\"\n";
|
|
|
|
$bFirst = false;
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
# Now generate full tests
|
2017-04-10 18:31:30 +02:00
|
|
|
my $strRealTest = undef;
|
2017-02-21 15:59:23 +02:00
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if (!defined($strFullModule))
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
confess "${strFullModule} module not found, has the name changed?";
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
foreach my $strTest (testDefModuleTestList($strFullModule))
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
|
|
|
if ($strTest eq 'real')
|
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
$strRealTest = $strTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
foreach my $strDbVersion (sort {$b cmp $a} @{$hVm->{$strVm}{&VM_DB_MINIMAL}})
|
|
|
|
{
|
|
|
|
$strConfig .=
|
|
|
|
" - PGB_TEST_VM=\"${strVm}\" PGB_BUILD_PARAM=\"--db=${strDbVersion}\"" .
|
|
|
|
" PGB_TEST_PARAM=\"--module=full --test=real --db=${strDbVersion}" .
|
2017-02-21 21:22:03 +02:00
|
|
|
" --process-max=2 ${strConfigNotFirst} ${strConfigNotFirstOS}\"\n";
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strConfig .=
|
|
|
|
" - PGB_TEST_VM=\"${strVm}\" PGB_BUILD_PARAM=\"--db=none\"" .
|
2017-02-21 21:22:03 +02:00
|
|
|
" PGB_TEST_PARAM=\"--module=full --test=${strTest} ${strConfigNotFirst} ${strConfigNotFirstOS}\"\n";
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if (!defined($strRealTest))
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
confess "${strRealTest} test not found in ${strFullModule} module, has the name changed?";
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Configure install and script
|
|
|
|
$strConfig .=
|
|
|
|
"\n" .
|
|
|
|
"before_install:\n" .
|
|
|
|
" - sudo apt-get -qq update\n" .
|
2017-04-10 18:31:30 +02:00
|
|
|
" - sudo apt-get install libxml-checker-perl libdbd-pg-perl libperl-critic-perl libtemplate-perl libpod-coverage-perl" .
|
|
|
|
" libtest-differences-perl libhtml-parser-perl lintian debhelper txt2man devscripts libjson-perl\n" .
|
|
|
|
" - git clone https://anonscm.debian.org/git/pkg-perl/packages/libdevel-cover-perl.git ~/libdevel-cover-perl\n" .
|
|
|
|
' - cd ~/libdevel-cover-perl && git checkout debian/' . LIB_COVER_VERSION . " && debuild -i -us -uc -b\n" .
|
|
|
|
' - sudo dpkg -i ~/' . LIB_COVER_PACKAGE . "\n" .
|
|
|
|
' - ' . LIB_COVER_EXE . " -v\n" .
|
2017-02-21 15:59:23 +02:00
|
|
|
"\n" .
|
|
|
|
"install:\n" .
|
|
|
|
" - sudo adduser --ingroup=\${USER?} --disabled-password --gecos \"\" " . BACKREST_USER . "\n" .
|
|
|
|
" - umask 0022\n" .
|
|
|
|
" - cd ~ && pwd && whoami && umask && groups\n" .
|
|
|
|
" - mv \${TRAVIS_BUILD_DIR?} " . BACKREST_EXE . "\n" .
|
|
|
|
" - rm -rf \${TRAVIS_BUILD_DIR?}\n" .
|
|
|
|
" - " . BACKREST_EXE . "/test/test.pl --vm-build --vm=\${PGB_TEST_VM?} \${PGB_BUILD_PARAM?}\n" .
|
|
|
|
"\n" .
|
|
|
|
"script:\n" .
|
2017-04-13 13:42:45 +02:00
|
|
|
" - " . BACKREST_EXE . "/test/test.pl --vm-host=u14 --vm-max=2 --vm=\${PGB_TEST_VM?} \${PGB_TEST_PARAM?}\n";
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
fileStringWrite("$self->{strBackRestBase}/.travis.yml", $strConfig, false);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|