2017-06-25 00:04:02 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
2020-12-09 22:19:01 +02:00
|
|
|
# CI Test Wrapper
|
2017-06-25 00:04:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess longmess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
# Convert die to confess to capture the stack trace
|
|
|
|
$SIG{__DIE__} = sub { Carp::confess @_ };
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Getopt::Long qw(GetOptions);
|
|
|
|
use Cwd qw(abs_path);
|
2019-10-15 17:19:42 +02:00
|
|
|
use Pod::Usage qw(pod2usage);
|
2017-06-25 00:04:02 +02:00
|
|
|
|
|
|
|
use lib dirname($0) . '/lib';
|
|
|
|
use lib dirname(dirname($0)) . '/lib';
|
2020-03-10 21:12:44 +02:00
|
|
|
use lib dirname(dirname($0)) . '/doc/lib';
|
2017-06-25 00:04:02 +02:00
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
|
|
use pgBackRestDoc::Common::Log;
|
2020-03-22 00:45:58 +02:00
|
|
|
use pgBackRestDoc::ProjectInfo;
|
2017-06-25 00:04:02 +02:00
|
|
|
|
2019-10-09 00:56:55 +02:00
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
2017-06-25 00:04:02 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::VmTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Usage
|
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2020-12-09 22:19:01 +02:00
|
|
|
ci.pl - CI Test Wrapper
|
2017-06-25 00:04:02 +02:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
test.pl [options] doc|test
|
|
|
|
|
|
|
|
VM Options:
|
|
|
|
--vm docker container to build/test
|
2019-10-15 17:19:42 +02:00
|
|
|
--param parameters to pass to test.pl
|
|
|
|
--sudo test requires sudo
|
2021-10-02 23:27:33 +02:00
|
|
|
--no-tempfs do not create tempfs mount
|
2017-06-25 00:04:02 +02:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
--help display usage and exit
|
|
|
|
=cut
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Command line parameters
|
|
|
|
####################################################################################################################################
|
2023-05-23 09:58:51 +02:00
|
|
|
my $strVm = "none";
|
2019-10-15 17:19:42 +02:00
|
|
|
my @stryParam;
|
2021-10-02 23:27:33 +02:00
|
|
|
my $bNoTempFs;
|
2019-10-15 17:19:42 +02:00
|
|
|
my $bSudo;
|
2017-06-25 00:04:02 +02:00
|
|
|
my $bHelp;
|
|
|
|
|
|
|
|
GetOptions ('help' => \$bHelp,
|
2019-10-15 17:19:42 +02:00
|
|
|
'param=s@' => \@stryParam,
|
2021-10-02 23:27:33 +02:00
|
|
|
'no-tempfs' => \$bNoTempFs,
|
2019-10-15 17:19:42 +02:00
|
|
|
'sudo' => \$bSudo,
|
2017-06-25 00:04:02 +02:00
|
|
|
'vm=s' => \$strVm)
|
|
|
|
or pod2usage(2);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Begin/end functions to track timing
|
|
|
|
####################################################################################################################################
|
|
|
|
my $lProcessBegin;
|
|
|
|
my $strProcessTitle;
|
|
|
|
|
|
|
|
sub processBegin
|
|
|
|
{
|
|
|
|
$strProcessTitle = shift;
|
|
|
|
|
|
|
|
&log(INFO, "Begin ${strProcessTitle}");
|
|
|
|
$lProcessBegin = time();
|
|
|
|
}
|
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
sub processExec
|
|
|
|
{
|
|
|
|
my $strCommand = shift;
|
|
|
|
my $rhParam = shift;
|
|
|
|
|
|
|
|
&log(INFO, " Exec ${strCommand}");
|
|
|
|
executeTest($strCommand, $rhParam);
|
|
|
|
}
|
|
|
|
|
2017-06-25 00:04:02 +02:00
|
|
|
sub processEnd
|
|
|
|
{
|
2019-10-08 18:06:30 +02:00
|
|
|
&log(INFO, " End ${strProcessTitle} (" . (time() - $lProcessBegin) . 's)');
|
2017-06-25 00:04:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Run in eval block to catch errors
|
|
|
|
####################################################################################################################################
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bHelp)
|
|
|
|
{
|
2020-12-09 22:19:01 +02:00
|
|
|
syswrite(*STDOUT, "CI Test Wrapper\n");
|
2017-06-25 00:04:02 +02:00
|
|
|
|
|
|
|
syswrite(*STDOUT, "\n");
|
|
|
|
pod2usage();
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@ARGV != 1)
|
|
|
|
{
|
|
|
|
syswrite(*STDOUT, "test|doc required\n\n");
|
|
|
|
pod2usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Paths
|
|
|
|
################################################################################################################################
|
|
|
|
my $strBackRestBase = dirname(dirname(abs_path($0)));
|
|
|
|
my $strReleaseExe = "${strBackRestBase}/doc/release.pl";
|
|
|
|
my $strTestExe = "${strBackRestBase}/test/test.pl";
|
|
|
|
|
|
|
|
logLevelSet(INFO, INFO, OFF);
|
|
|
|
|
2019-10-09 00:56:55 +02:00
|
|
|
processBegin('install common packages');
|
|
|
|
processExec('sudo apt-get -qq update', {bSuppressStdErr => true, bSuppressError => true});
|
2021-10-02 23:27:33 +02:00
|
|
|
processExec(
|
2023-10-09 20:03:43 +02:00
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y meson libxml-checker-perl libyaml-perl', {bSuppressStdErr => true});
|
2019-10-09 00:56:55 +02:00
|
|
|
processEnd();
|
|
|
|
|
2021-10-02 23:27:33 +02:00
|
|
|
if (!$bNoTempFs)
|
|
|
|
{
|
|
|
|
processBegin('mount tmpfs');
|
|
|
|
processExec('mkdir -p -m 770 test');
|
|
|
|
processExec('sudo mount -t tmpfs -o size=2048m tmpfs test');
|
|
|
|
processExec('df -h test', {bShowOutputAsync => true});
|
|
|
|
processEnd();
|
|
|
|
}
|
2019-10-14 11:51:14 +02:00
|
|
|
|
2017-06-25 00:04:02 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Build documentation
|
|
|
|
################################################################################################################################
|
2020-12-09 22:19:01 +02:00
|
|
|
my $strUser = getpwuid($UID);
|
|
|
|
|
2017-06-25 00:04:02 +02:00
|
|
|
if ($ARGV[0] eq 'doc')
|
|
|
|
{
|
2024-06-11 07:20:04 +02:00
|
|
|
if ($strVm eq VM_RH8)
|
2019-10-08 18:06:30 +02:00
|
|
|
{
|
|
|
|
processBegin('LaTeX install');
|
|
|
|
processExec(
|
2021-10-02 23:27:33 +02:00
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends texlive-latex-base' .
|
|
|
|
' texlive-latex-extra texlive-fonts-recommended',
|
|
|
|
{bSuppressStdErr => true});
|
|
|
|
processExec(
|
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y texlive-font-utils texlive-latex-recommended',
|
2019-10-08 18:06:30 +02:00
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
2017-06-25 00:04:02 +02:00
|
|
|
|
2019-10-15 17:19:42 +02:00
|
|
|
processBegin('remove sudo');
|
2020-12-09 22:19:01 +02:00
|
|
|
processExec("sudo rm /etc/sudoers.d/${strUser}");
|
2019-10-15 17:19:42 +02:00
|
|
|
processEnd();
|
|
|
|
|
2020-03-22 00:45:58 +02:00
|
|
|
processBegin('create link from home to repo for contributing doc');
|
|
|
|
processExec("ln -s ${strBackRestBase} \${HOME?}/" . PROJECT_EXE);
|
|
|
|
processEnd();
|
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
processBegin('release documentation');
|
|
|
|
processExec("${strReleaseExe} --build --no-gen --vm=${strVm}", {bShowOutputAsync => true, bOutLogOnError => false});
|
2017-06-25 00:04:02 +02:00
|
|
|
processEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Run test
|
|
|
|
################################################################################################################################
|
|
|
|
elsif ($ARGV[0] eq 'test')
|
|
|
|
{
|
2019-10-09 00:56:55 +02:00
|
|
|
# Build list of packages that need to be installed
|
2022-06-03 20:13:56 +02:00
|
|
|
my $strPackage =
|
2024-04-25 11:32:07 +02:00
|
|
|
"gcc ccache python3-distutils git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config uncrustify" .
|
2024-03-09 23:53:31 +02:00
|
|
|
" libssh2-1-dev valgrind";
|
2019-10-09 00:56:55 +02:00
|
|
|
|
2020-03-27 04:20:09 +02:00
|
|
|
# Extra packages required when testing without containers
|
2019-10-08 18:06:30 +02:00
|
|
|
if ($strVm eq VM_NONE)
|
2017-06-25 00:04:02 +02:00
|
|
|
{
|
2024-03-06 00:00:09 +02:00
|
|
|
$strPackage .= " liblz4-dev liblz4-tool zstd libzstd-dev bzip2 libbz2-dev";
|
2019-10-09 00:56:55 +02:00
|
|
|
}
|
2020-03-27 04:20:09 +02:00
|
|
|
# Else packages needed for integration tests on containers
|
2019-10-09 00:56:55 +02:00
|
|
|
else
|
|
|
|
{
|
2019-10-09 20:38:24 +02:00
|
|
|
$strPackage .= " libdbd-pg-perl";
|
2019-10-09 00:56:55 +02:00
|
|
|
}
|
|
|
|
|
2019-10-15 17:19:42 +02:00
|
|
|
processBegin('/tmp/pgbackrest owned by root so tests cannot use it');
|
|
|
|
processExec('sudo mkdir -p /tmp/pgbackrest && sudo chown root:root /tmp/pgbackrest && sudo chmod 700 /tmp/pgbackrest');
|
|
|
|
processEnd();
|
|
|
|
|
2019-10-09 00:56:55 +02:00
|
|
|
processBegin('install test packages');
|
2021-10-02 23:27:33 +02:00
|
|
|
processExec(
|
|
|
|
"sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y ${strPackage}",
|
|
|
|
{bSuppressStdErr => true});
|
2019-10-09 00:56:55 +02:00
|
|
|
processEnd();
|
2017-06-25 00:04:02 +02:00
|
|
|
|
2019-10-15 17:19:42 +02:00
|
|
|
if (!$bSudo)
|
2019-10-09 00:56:55 +02:00
|
|
|
{
|
2019-10-10 17:21:09 +02:00
|
|
|
processBegin('remove sudo');
|
2020-12-09 22:19:01 +02:00
|
|
|
processExec("sudo rm /etc/sudoers.d/${strUser}");
|
2019-10-10 17:21:09 +02:00
|
|
|
processEnd();
|
2019-10-08 18:06:30 +02:00
|
|
|
}
|
2019-10-15 17:19:42 +02:00
|
|
|
|
|
|
|
# Build the container
|
|
|
|
if ($strVm ne VM_NONE)
|
2019-10-08 18:06:30 +02:00
|
|
|
{
|
|
|
|
processBegin("${strVm} build");
|
|
|
|
processExec("${strTestExe} --vm-build --vm=${strVm}", {bShowOutputAsync => true, bOutLogOnError => false});
|
|
|
|
processEnd();
|
|
|
|
}
|
2017-06-25 00:04:02 +02:00
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
processBegin(($strVm eq VM_NONE ? "no container" : $strVm) . ' test');
|
|
|
|
processExec(
|
2021-07-17 17:09:53 +02:00
|
|
|
"${strTestExe} --gen-check --log-level-test-file=off --no-coverage-report --vm-max=2 --vm=${strVm}" .
|
2019-10-15 17:19:42 +02:00
|
|
|
(@stryParam != 0 ? " --" . join(" --", @stryParam) : ''),
|
2019-10-08 18:06:30 +02:00
|
|
|
{bShowOutputAsync => true, bOutLogOnError => false});
|
2017-06-25 00:04:02 +02:00
|
|
|
processEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
# Catch error
|
|
|
|
################################################################################################################################
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'invalid command ' . $ARGV[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "CI Complete");
|
|
|
|
|
|
|
|
# Exit with success
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Check for errors
|
|
|
|
####################################################################################################################################
|
|
|
|
or do
|
|
|
|
{
|
|
|
|
# If a backrest exception then return the code
|
2017-10-16 16:47:31 +02:00
|
|
|
exit $EVAL_ERROR->code() if (isException(\$EVAL_ERROR));
|
2017-06-25 00:04:02 +02:00
|
|
|
|
|
|
|
# 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;
|