1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
#!/usr/bin/perl
####################################################################################################################################
# CI Test Wrapper
####################################################################################################################################
####################################################################################################################################
# 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);
use Pod::Usage qw(pod2usage);
use lib dirname($0) . '/lib';
use lib dirname(dirname($0)) . '/lib';
use lib dirname(dirname($0)) . '/doc/lib';
use pgBackRestDoc::Common::Exception;
use pgBackRestDoc::Common::Log;
use pgBackRestDoc::ProjectInfo;
use pgBackRestTest::Common::ContainerTest;
use pgBackRestTest::Common::ExecuteTest;
use pgBackRestTest::Common::VmTest;
####################################################################################################################################
# Usage
####################################################################################################################################
=head1 NAME
ci.pl - CI Test Wrapper
=head1 SYNOPSIS
test.pl [options] doc|test
VM Options:
--vm docker container to build/test
--param parameters to pass to test.pl
--sudo test requires sudo
--no-tempfs do not create tempfs mount
General Options:
--help display usage and exit
=cut
####################################################################################################################################
# Command line parameters
####################################################################################################################################
my $strVm = "none";
my @stryParam;
my $bNoTempFs;
my $bSudo;
my $bHelp;
GetOptions ('help' => \$bHelp,
'param=s@' => \@stryParam,
'no-tempfs' => \$bNoTempFs,
'sudo' => \$bSudo,
'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();
}
sub processExec
{
my $strCommand = shift;
my $rhParam = shift;
&log(INFO, " Exec ${strCommand}");
executeTest($strCommand, $rhParam);
}
sub processEnd
{
&log(INFO, " End ${strProcessTitle} (" . (time() - $lProcessBegin) . 's)');
}
####################################################################################################################################
# Run in eval block to catch errors
####################################################################################################################################
eval
{
# Display version and exit if requested
if ($bHelp)
{
syswrite(*STDOUT, "CI Test Wrapper\n");
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);
processBegin('install common packages');
processExec('sudo apt-get -qq update', {bSuppressStdErr => true, bSuppressError => true});
processExec(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y meson libxml-checker-perl libyaml-perl', {bSuppressStdErr => true});
processEnd();
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();
}
################################################################################################################################
# Build documentation
################################################################################################################################
my $strUser = getpwuid($UID);
if ($ARGV[0] eq 'doc')
{
if ($strVm eq VM_RH8)
{
processBegin('LaTeX install');
processExec(
'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',
{bSuppressStdErr => true});
}
processBegin('remove sudo');
processExec("sudo rm /etc/sudoers.d/${strUser}");
processEnd();
processBegin('create link from home to repo for contributing doc');
processExec("ln -s ${strBackRestBase} \${HOME?}/" . PROJECT_EXE);
processEnd();
processBegin('release documentation');
processExec("${strReleaseExe} --build --no-gen --vm=${strVm}", {bShowOutputAsync => true, bOutLogOnError => false});
processEnd();
}
################################################################################################################################
# Run test
################################################################################################################################
elsif ($ARGV[0] eq 'test')
{
# Build list of packages that need to be installed
my $strPackage =
"gcc ccache python3-distutils git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config uncrustify" .
" libssh2-1-dev valgrind";
# Extra packages required when testing without containers
if ($strVm eq VM_NONE)
{
$strPackage .= " liblz4-dev liblz4-tool zstd libzstd-dev bzip2 libbz2-dev";
}
# Else packages needed for integration tests on containers
else
{
$strPackage .= " libdbd-pg-perl";
}
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();
processBegin('install test packages');
processExec(
"sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y ${strPackage}",
{bSuppressStdErr => true});
processEnd();
if (!$bSudo)
{
processBegin('remove sudo');
processExec("sudo rm /etc/sudoers.d/${strUser}");
processEnd();
}
# Build the container
if ($strVm ne VM_NONE)
{
processBegin("${strVm} build");
processExec("${strTestExe} --vm-build --vm=${strVm}", {bShowOutputAsync => true, bOutLogOnError => false});
processEnd();
}
processBegin(($strVm eq VM_NONE ? "no container" : $strVm) . ' test');
processExec(
"${strTestExe} --gen-check --log-level-test-file=off --no-coverage-report --vm-max=2 --vm=${strVm}" .
(@stryParam != 0 ? " --" . join(" --", @stryParam) : ''),
{bShowOutputAsync => true, bOutLogOnError => false});
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
exit $EVAL_ERROR->code() if (isException(\$EVAL_ERROR));
# Else output the unhandled error
print $EVAL_ERROR;
exit ERROR_UNHANDLED;
};
# It shouldn't be possible to get here
&log(ASSERT, 'execution reached invalid location in ' . __FILE__ . ', line ' . __LINE__);
exit ERROR_ASSERT;
|