2017-02-21 15:59:23 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# JobTest.pm - Run a test job and monitor progress
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRestTest::Common::JobTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# 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();
|
2017-10-12 18:55:48 +02:00
|
|
|
use File::Basename qw(dirname basename);
|
2017-02-21 15:59:23 +02:00
|
|
|
use POSIX qw(ceil);
|
|
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Exception;
|
|
|
|
use pgBackRestDoc::Common::Log;
|
|
|
|
use pgBackRestDoc::Common::String;
|
2020-03-10 23:57:02 +02:00
|
|
|
use pgBackRestDoc::ProjectInfo;
|
2020-03-10 21:12:44 +02:00
|
|
|
|
2018-11-03 22:34:04 +02:00
|
|
|
use pgBackRestTest::Common::BuildTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
use pgBackRestTest::Common::ContainerTest;
|
2019-05-15 19:04:56 +02:00
|
|
|
use pgBackRestTest::Common::CoverageTest;
|
2020-03-10 21:12:44 +02:00
|
|
|
use pgBackRestTest::Common::DbVersion;
|
2017-10-12 18:55:48 +02:00
|
|
|
use pgBackRestTest::Common::DefineTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::ListTest;
|
2017-02-21 18:47:45 +02:00
|
|
|
use pgBackRestTest::Common::RunTest;
|
2017-04-10 18:31:30 +02:00
|
|
|
use pgBackRestTest::Common::VmTest;
|
2017-02-21 15:59:23 +02:00
|
|
|
|
2018-03-12 16:55:58 +02:00
|
|
|
####################################################################################################################################
|
2018-11-03 22:34:04 +02:00
|
|
|
# Has the C build directory been initialized yet?
|
2018-03-12 16:55:58 +02:00
|
|
|
####################################################################################################################################
|
2018-11-02 17:56:13 +02:00
|
|
|
my $rhBuildInit = undef;
|
2018-03-12 16:55:58 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# 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,
|
2017-06-09 23:51:41 +02:00
|
|
|
$self->{oStorageTest},
|
2017-02-21 15:59:23 +02:00
|
|
|
$self->{strBackRestBase},
|
|
|
|
$self->{strTestPath},
|
|
|
|
$self->{oTest},
|
|
|
|
$self->{bDryRun},
|
2019-10-12 15:45:18 +02:00
|
|
|
$self->{strVmHost},
|
2017-02-21 15:59:23 +02:00
|
|
|
$self->{bVmOut},
|
|
|
|
$self->{iVmIdx},
|
|
|
|
$self->{iVmMax},
|
|
|
|
$self->{iTestIdx},
|
|
|
|
$self->{iTestMax},
|
|
|
|
$self->{strLogLevel},
|
2018-07-21 01:03:46 +02:00
|
|
|
$self->{strLogLevelTest},
|
2019-12-17 22:23:07 +02:00
|
|
|
$self->{strLogLevelTestFile},
|
2020-03-22 16:12:29 +02:00
|
|
|
$self->{bLogTimestamp},
|
2017-02-21 15:59:23 +02:00
|
|
|
$self->{bLogForce},
|
|
|
|
$self->{bShowOutputAsync},
|
|
|
|
$self->{bNoCleanup},
|
2017-02-22 05:10:02 +02:00
|
|
|
$self->{iRetry},
|
2018-05-18 12:45:14 +02:00
|
|
|
$self->{bValgrindUnit},
|
|
|
|
$self->{bCoverageUnit},
|
2019-05-15 19:04:56 +02:00
|
|
|
$self->{bCoverageSummary},
|
2018-05-18 12:45:14 +02:00
|
|
|
$self->{bOptimize},
|
2018-05-18 17:57:32 +02:00
|
|
|
$self->{bBackTrace},
|
2018-05-18 12:45:14 +02:00
|
|
|
$self->{bProfile},
|
2019-09-28 20:02:12 +02:00
|
|
|
$self->{iScale},
|
2019-12-12 05:11:04 +02:00
|
|
|
$self->{strTimeZone},
|
2018-05-18 12:45:14 +02:00
|
|
|
$self->{bDebug},
|
2019-02-27 17:09:19 +02:00
|
|
|
$self->{bDebugTestTrace},
|
2019-04-24 02:52:03 +02:00
|
|
|
$self->{iBuildMax},
|
2017-02-21 15:59:23 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->new', \@_,
|
2017-06-09 23:51:41 +02:00
|
|
|
{name => 'oStorageTest'},
|
2017-02-21 15:59:23 +02:00
|
|
|
{name => 'strBackRestBase'},
|
|
|
|
{name => 'strTestPath'},
|
|
|
|
{name => 'oTest'},
|
|
|
|
{name => 'bDryRun'},
|
2019-10-12 15:45:18 +02:00
|
|
|
{name => 'strVmHost'},
|
2017-02-21 15:59:23 +02:00
|
|
|
{name => 'bVmOut'},
|
|
|
|
{name => 'iVmIdx'},
|
|
|
|
{name => 'iVmMax'},
|
|
|
|
{name => 'iTestIdx'},
|
|
|
|
{name => 'iTestMax'},
|
|
|
|
{name => 'strLogLevel'},
|
2018-07-21 01:03:46 +02:00
|
|
|
{name => 'strLogLevelTest'},
|
2019-12-17 22:23:07 +02:00
|
|
|
{name => 'strLogLevelTestFile'},
|
2020-03-22 16:12:29 +02:00
|
|
|
{name => 'bLogTimestamp'},
|
2017-02-21 15:59:23 +02:00
|
|
|
{name => 'bLogForce'},
|
|
|
|
{name => 'bShowOutputAsync'},
|
|
|
|
{name => 'bNoCleanup'},
|
2017-02-22 05:10:02 +02:00
|
|
|
{name => 'iRetry'},
|
2018-05-18 12:45:14 +02:00
|
|
|
{name => 'bValgrindUnit'},
|
|
|
|
{name => 'bCoverageUnit'},
|
2019-05-15 19:04:56 +02:00
|
|
|
{name => 'bCoverageSummary'},
|
2018-05-18 12:45:14 +02:00
|
|
|
{name => 'bOptimize'},
|
2018-05-18 17:57:32 +02:00
|
|
|
{name => 'bBackTrace'},
|
2018-05-18 12:45:14 +02:00
|
|
|
{name => 'bProfile'},
|
2019-09-28 20:02:12 +02:00
|
|
|
{name => 'iScale'},
|
2019-12-12 05:11:04 +02:00
|
|
|
{name => 'strTimeZone', required => false},
|
2018-05-18 12:45:14 +02:00
|
|
|
{name => 'bDebug'},
|
2019-02-27 17:09:19 +02:00
|
|
|
{name => 'bDebugTestTrace'},
|
2019-04-24 02:52:03 +02:00
|
|
|
{name => 'iBuildMax'},
|
2017-02-21 15:59:23 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Set try to 0
|
|
|
|
$self->{iTry} = 0;
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Setup the path where gcc coverage will be performed
|
2018-03-21 22:08:08 +02:00
|
|
|
$self->{strGCovPath} = "$self->{strTestPath}/gcov-$self->{oTest}->{&TEST_VM}-$self->{iVmIdx}";
|
2019-10-08 18:06:30 +02:00
|
|
|
$self->{strDataPath} = "$self->{strTestPath}/data-$self->{iVmIdx}";
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(my $strOperation) = logDebugParam (__PACKAGE__ . '->run', \@_,);
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Start the test timer
|
|
|
|
my $fTestStartTime = gettimeofday();
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
# Was the job run?
|
|
|
|
my $bRun = false;
|
|
|
|
|
|
|
|
# Should the job be run?
|
|
|
|
$self->{iTry}++;
|
|
|
|
|
2017-02-22 05:10:02 +02:00
|
|
|
if ($self->{iTry} <= ($self->{iRetry} + 1))
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
2017-02-22 05:10:02 +02:00
|
|
|
if ($self->{iTry} != 1 && $self->{iTry} == ($self->{iRetry} + 1))
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
|
|
|
$self->{strLogLevel} = lc(DEBUG);
|
|
|
|
}
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
my $strTest = sprintf(
|
|
|
|
'P%0' . length($self->{iVmMax}) . 'd-T%0' . length($self->{iTestMax}) . 'd/%0' .
|
|
|
|
length($self->{iTestMax}) . "d - ", $self->{iVmIdx} + 1, $self->{iTestIdx} + 1, $self->{iTestMax}) .
|
|
|
|
'vm=' . $self->{oTest}->{&TEST_VM} .
|
|
|
|
', module=' . $self->{oTest}->{&TEST_MODULE} .
|
|
|
|
', test=' . $self->{oTest}->{&TEST_NAME} .
|
|
|
|
(defined($self->{oTest}->{&TEST_RUN}) ? ', run=' . join(',', sort(@{$self->{oTest}->{&TEST_RUN}})) : '') .
|
2020-01-08 18:54:44 +02:00
|
|
|
(defined($self->{oTest}->{&TEST_DB}) ? ', pg-version=' . $self->{oTest}->{&TEST_DB} : '') .
|
2017-10-12 18:55:48 +02:00
|
|
|
($self->{iTry} > 1 ? ' (retry ' . ($self->{iTry} - 1) . ')' : '');
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
my $strImage = 'test-' . $self->{iVmIdx};
|
|
|
|
my $strDbVersion = (defined($self->{oTest}->{&TEST_DB}) ? $self->{oTest}->{&TEST_DB} : PG_VERSION_94);
|
|
|
|
$strDbVersion =~ s/\.//;
|
|
|
|
|
|
|
|
&log($self->{bDryRun} && !$self->{bVmOut} || $self->{bShowOutputAsync} ? INFO : DETAIL, "${strTest}" .
|
2017-05-12 22:27:06 +02:00
|
|
|
(!($self->{bDryRun} || !$self->{bVmOut}) || $self->{bShowOutputAsync} ? "\n" : ''));
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
my $strVmTestPath = '/home/' . TEST_USER . "/test/${strImage}";
|
|
|
|
my $strHostTestPath = "$self->{strTestPath}/${strImage}";
|
|
|
|
|
|
|
|
# Don't create the container if this is a dry run unless output from the VM is required. Ouput can be requested
|
|
|
|
# to get more information about the specific tests that will be run.
|
2017-05-12 22:27:06 +02:00
|
|
|
if (!$self->{bDryRun} || $self->{bVmOut})
|
2017-02-21 15:59:23 +02:00
|
|
|
{
|
|
|
|
# Create host test directory
|
2017-06-09 23:51:41 +02:00
|
|
|
$self->{oStorageTest}->pathCreate($strHostTestPath, {strMode => '0770'});
|
2017-02-21 15:59:23 +02:00
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Create gcov directory
|
2018-01-26 23:41:17 +02:00
|
|
|
my $bGCovExists = true;
|
|
|
|
|
2018-01-29 04:37:09 +02:00
|
|
|
if ($self->{oTest}->{&TEST_C} && !$self->{oStorageTest}->pathExists($self->{strGCovPath}))
|
2018-01-26 23:41:17 +02:00
|
|
|
{
|
|
|
|
$self->{oStorageTest}->pathCreate($self->{strGCovPath}, {strMode => '0770'});
|
|
|
|
$bGCovExists = false;
|
|
|
|
}
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
# Create data directory
|
|
|
|
if ($self->{oTest}->{&TEST_C} && !$self->{oStorageTest}->pathExists($self->{strDataPath}))
|
2018-09-16 21:58:46 +02:00
|
|
|
{
|
2019-10-08 18:06:30 +02:00
|
|
|
$self->{oStorageTest}->pathCreate($self->{strDataPath}, {strMode => '0770'});
|
2018-09-16 21:58:46 +02:00
|
|
|
}
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($self->{oTest}->{&TEST_CONTAINER})
|
|
|
|
{
|
2019-10-08 18:06:30 +02:00
|
|
|
if ($self->{oTest}->{&TEST_VM} ne VM_NONE)
|
|
|
|
{
|
2020-03-15 16:09:27 +02:00
|
|
|
my $strBinPath = $self->{strTestPath} . '/bin/' . $self->{oTest}->{&TEST_VM} . '/' . PROJECT_EXE;
|
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
executeTest(
|
|
|
|
'docker run -itd -h ' . $self->{oTest}->{&TEST_VM} . "-test --name=${strImage}" .
|
|
|
|
" -v ${strHostTestPath}:${strVmTestPath}" .
|
|
|
|
($self->{oTest}->{&TEST_C} ? " -v $self->{strGCovPath}:$self->{strGCovPath}" : '') .
|
|
|
|
($self->{oTest}->{&TEST_C} ? " -v $self->{strDataPath}:$self->{strDataPath}" : '') .
|
2020-03-15 16:09:27 +02:00
|
|
|
" -v $self->{strBackRestBase}:$self->{strBackRestBase}" .
|
|
|
|
($self->{oTest}->{&TEST_BIN_REQ} ? " -v ${strBinPath}:${strBinPath}:ro" : '') .
|
|
|
|
' ' . containerRepo() . ':' . $self->{oTest}->{&TEST_VM} . '-test',
|
2019-10-08 18:06:30 +02:00
|
|
|
{bSuppressStdErr => true});
|
|
|
|
}
|
2017-08-25 22:47:47 +02:00
|
|
|
|
2018-01-26 23:41:17 +02:00
|
|
|
# If testing C code copy source files to the test directory
|
2018-03-12 16:55:58 +02:00
|
|
|
if ($self->{oTest}->{&TEST_C})
|
2018-01-26 23:41:17 +02:00
|
|
|
{
|
2018-11-03 22:34:04 +02:00
|
|
|
# If this is the first build, then rsync files
|
2018-11-02 17:56:13 +02:00
|
|
|
if (!$rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}})
|
2018-03-12 16:55:58 +02:00
|
|
|
{
|
2018-11-02 17:56:13 +02:00
|
|
|
executeTest(
|
2020-03-09 23:41:59 +02:00
|
|
|
'rsync -rt --delete --exclude=*.o --exclude=test.c --exclude=test.gcno ' .
|
2019-07-08 14:29:25 +02:00
|
|
|
' --exclude=test --exclude=buildflags --exclude=testflags --exclude=harnessflags' .
|
|
|
|
' --exclude=build.auto.h --exclude=build.auto.h.in --exclude=Makefile --exclude=Makefile.in' .
|
|
|
|
' --exclude=configure --exclude=configure.ac' .
|
2018-11-03 22:34:04 +02:00
|
|
|
" $self->{strBackRestBase}/src/ $self->{strGCovPath} && " .
|
|
|
|
"rsync -rt --delete --exclude=*.o $self->{strBackRestBase}/test/src/ $self->{strGCovPath}/test");
|
2018-03-12 16:55:58 +02:00
|
|
|
}
|
|
|
|
|
2018-11-03 22:34:04 +02:00
|
|
|
# Build directory has been initialized
|
2018-11-02 17:56:13 +02:00
|
|
|
$rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = true;
|
2018-01-26 23:41:17 +02:00
|
|
|
}
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create run parameters
|
|
|
|
my $strCommandRunParam = '';
|
|
|
|
|
|
|
|
foreach my $iRunIdx (@{$self->{oTest}->{&TEST_RUN}})
|
|
|
|
{
|
|
|
|
$strCommandRunParam .= ' --run=' . $iRunIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create command
|
2017-10-12 18:55:48 +02:00
|
|
|
my $strCommand;
|
|
|
|
|
|
|
|
if ($self->{oTest}->{&TEST_C})
|
|
|
|
{
|
2020-05-07 00:24:48 +02:00
|
|
|
# Build filename for valgrind suppressions
|
|
|
|
my $strValgrindSuppress = $self->{strGCovPath} . '/test/valgrind.suppress.' . $self->{oTest}->{&TEST_VM};
|
|
|
|
|
2017-12-23 01:36:36 +02:00
|
|
|
$strCommand =
|
2019-10-08 18:06:30 +02:00
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_NONE ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') .
|
|
|
|
"bash -l -c '" .
|
2018-04-13 02:42:26 +02:00
|
|
|
"cd $self->{strGCovPath} && " .
|
2020-03-20 19:43:08 +02:00
|
|
|
# Remove coverage data from last run
|
|
|
|
"rm -f test.gcda && " .
|
2019-04-24 02:52:03 +02:00
|
|
|
"make -j $self->{iBuildMax} -s 2>&1 &&" .
|
2020-05-07 00:24:48 +02:00
|
|
|
# Test with valgrind when requested
|
2019-09-28 20:02:12 +02:00
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{bValgrindUnit} &&
|
|
|
|
$self->{oTest}->{&TEST_TYPE} ne TESTDEF_PERFORMANCE ?
|
2020-05-07 00:24:48 +02:00
|
|
|
' valgrind -q --gen-suppressions=all ' .
|
|
|
|
($self->{oStorageTest}->exists($strValgrindSuppress) ? " --suppressions=${strValgrindSuppress}" : '') .
|
2018-09-08 01:50:01 +02:00
|
|
|
" --leak-check=full --leak-resolution=high --error-exitcode=25" : '') .
|
2018-11-03 22:34:04 +02:00
|
|
|
" ./test.bin 2>&1'";
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strCommand =
|
|
|
|
($self->{oTest}->{&TEST_CONTAINER} ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') .
|
2019-07-05 22:55:17 +02:00
|
|
|
abs_path($0) .
|
2017-10-12 18:55:48 +02:00
|
|
|
" --test-path=${strVmTestPath}" .
|
2019-10-12 15:45:18 +02:00
|
|
|
" --vm-host=$self->{strVmHost}" .
|
2017-10-12 18:55:48 +02:00
|
|
|
" --vm=$self->{oTest}->{&TEST_VM}" .
|
|
|
|
" --vm-id=$self->{iVmIdx}" .
|
|
|
|
" --module=" . $self->{oTest}->{&TEST_MODULE} .
|
|
|
|
' --test=' . $self->{oTest}->{&TEST_NAME} .
|
|
|
|
$strCommandRunParam .
|
2018-02-04 01:27:38 +02:00
|
|
|
(defined($self->{oTest}->{&TEST_DB}) ? ' --pg-version=' . $self->{oTest}->{&TEST_DB} : '') .
|
2017-10-12 18:55:48 +02:00
|
|
|
($self->{strLogLevel} ne lc(INFO) ? " --log-level=$self->{strLogLevel}" : '') .
|
2019-12-17 22:23:07 +02:00
|
|
|
($self->{strLogLevelTestFile} ne lc(TRACE) ? " --log-level-test-file=$self->{strLogLevelTestFile}" : '') .
|
2020-03-22 16:12:29 +02:00
|
|
|
($self->{bLogTimestamp} ? '' : ' --no-log-timestamp') .
|
2017-10-12 18:55:48 +02:00
|
|
|
' --pgsql-bin=' . $self->{oTest}->{&TEST_PGSQL_BIN} .
|
2019-12-12 05:11:04 +02:00
|
|
|
($self->{strTimeZone} ? " --tz='$self->{strTimeZone}'" : '') .
|
2017-10-12 18:55:48 +02:00
|
|
|
($self->{bLogForce} ? ' --log-force' : '') .
|
|
|
|
($self->{bDryRun} ? ' --dry-run' : '') .
|
|
|
|
($self->{bDryRun} ? ' --vm-out' : '') .
|
|
|
|
($self->{bNoCleanup} ? " --no-cleanup" : '');
|
|
|
|
}
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
if (!$self->{bDryRun} || $self->{bVmOut})
|
|
|
|
{
|
2017-11-27 01:43:51 +02:00
|
|
|
# If testing C code
|
2017-10-12 18:55:48 +02:00
|
|
|
if ($self->{oTest}->{&TEST_C})
|
|
|
|
{
|
|
|
|
my $hTest = (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME}));
|
|
|
|
my $hTestCoverage = $hTest->{&TESTDEF_COVERAGE};
|
|
|
|
|
|
|
|
my @stryCFile;
|
|
|
|
|
2018-01-26 23:41:17 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$self->{oStorageTest}->manifest($self->{strGCovPath})})))
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2019-07-26 02:15:06 +02:00
|
|
|
my $strFileNoExt = substr($strFile, 0, length($strFile) - 2);
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Skip all files except .c files (including .auto.c)
|
|
|
|
next if $strFile !~ /(?<!\.auto)\.c$/;
|
|
|
|
|
2018-11-14 15:08:26 +02:00
|
|
|
# ??? Skip main for now until the function can be renamed to allow unit testing
|
2017-11-27 01:43:51 +02:00
|
|
|
next if $strFile =~ /main\.c$/;
|
|
|
|
|
2018-01-26 23:41:17 +02:00
|
|
|
# Skip test.c -- it will be added manually at the end
|
|
|
|
next if $strFile =~ /test\.c$/;
|
|
|
|
|
2019-07-26 02:15:06 +02:00
|
|
|
if (!defined($hTestCoverage->{$strFileNoExt}) && !grep(/^$strFileNoExt$/, @{$hTest->{&TESTDEF_INCLUDE}}) &&
|
2018-11-03 22:34:04 +02:00
|
|
|
$strFile !~ /^test\/module\/[^\/]*\/.*Test\.c$/)
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2018-01-26 23:41:17 +02:00
|
|
|
push(@stryCFile, "${strFile}");
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate list of C files to include for testing
|
2018-11-03 22:34:04 +02:00
|
|
|
my $strTestDepend = '';
|
2017-10-12 18:55:48 +02:00
|
|
|
my $strTestFile =
|
2018-11-03 22:34:04 +02:00
|
|
|
"test/module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test.c';
|
2017-10-12 18:55:48 +02:00
|
|
|
my $strCInclude;
|
|
|
|
|
2019-07-26 02:15:06 +02:00
|
|
|
foreach my $strFile (sort(keys(%{$hTestCoverage}), @{$hTest->{&TESTDEF_INCLUDE}}))
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
|
|
|
# Don't include the test file as it is already included below
|
|
|
|
next if $strFile =~ /Test$/;
|
|
|
|
|
|
|
|
# Don't any auto files as they are included in their companion C files
|
|
|
|
next if $strFile =~ /auto$/;
|
|
|
|
|
|
|
|
# Include the C file if it exists
|
|
|
|
my $strCIncludeFile = "${strFile}.c";
|
|
|
|
|
|
|
|
# If the C file does not exist use the header file instead
|
2018-01-26 23:41:17 +02:00
|
|
|
if (!$self->{oStorageTest}->exists("$self->{strGCovPath}/${strCIncludeFile}"))
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
|
|
|
# Error if code was expected
|
|
|
|
if ($hTestCoverage->{$strFile} ne TESTDEF_COVERAGE_NOCODE)
|
|
|
|
{
|
2018-01-26 23:41:17 +02:00
|
|
|
confess &log(ERROR, "unable to find source file '$self->{strGCovPath}/${strCIncludeFile}'");
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$strCIncludeFile = "${strFile}.h";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strCInclude .= (defined($strCInclude) ? "\n" : '') . "#include \"${strCIncludeFile}\"";
|
2018-11-03 22:34:04 +02:00
|
|
|
$strTestDepend .= " ${strCIncludeFile}";
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Update C test file with test module
|
2018-11-03 22:34:04 +02:00
|
|
|
my $strTestC = ${$self->{oStorageTest}->get("$self->{strGCovPath}/test/test.c")};
|
2019-09-28 20:02:12 +02:00
|
|
|
|
|
|
|
if (defined($strCInclude))
|
|
|
|
{
|
|
|
|
$strTestC =~ s/\{\[C\_INCLUDE\]\}/$strCInclude/g;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strTestC =~ s/\{\[C\_INCLUDE\]\}//g;
|
|
|
|
}
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_INCLUDE\]\}/\#include \"$strTestFile\"/g;
|
2018-11-03 22:34:04 +02:00
|
|
|
$strTestDepend .= " ${strTestFile}";
|
|
|
|
|
|
|
|
# Build dependencies for the test file
|
|
|
|
my $rhDependencyTree = {};
|
|
|
|
buildDependencyTreeSub(
|
2019-04-26 14:08:23 +02:00
|
|
|
$self->{oStorageTest}, $rhDependencyTree, $strTestFile, false, $self->{strGCovPath}, ['', 'test']);
|
2018-11-03 22:34:04 +02:00
|
|
|
|
|
|
|
foreach my $strDepend (@{$rhDependencyTree->{$strTestFile}{include}})
|
|
|
|
{
|
|
|
|
$strTestDepend .=
|
|
|
|
' ' . ($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') .
|
|
|
|
$strDepend;
|
|
|
|
}
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
# Determine where the project exe is located
|
2020-03-15 16:09:27 +02:00
|
|
|
my $strProjectExePath = "$self->{strTestPath}/bin/$self->{oTest}->{&TEST_VM}/" . PROJECT_EXE;
|
2019-10-08 18:06:30 +02:00
|
|
|
|
|
|
|
# Is this test running in a container?
|
|
|
|
my $strContainer = $self->{oTest}->{&TEST_VM} eq VM_NONE ? 'false' : 'true';
|
|
|
|
|
2019-10-10 21:09:11 +02:00
|
|
|
# What test path should be passed to C? Containers always have their test path at ~/test but when running with
|
|
|
|
# vm=none it should be in a subdirectory of the current directory.
|
|
|
|
my $strTestPathC = $self->{oTest}->{&TEST_VM} eq VM_NONE ? $strHostTestPath : $strVmTestPath;
|
|
|
|
|
2017-12-23 05:36:01 +02:00
|
|
|
# Set globals
|
2019-10-08 18:06:30 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_CONTAINER\]\}/$strContainer/g;
|
|
|
|
$strTestC =~ s/\{\[C\_TEST\_PROJECT\_EXE\]\}/$strProjectExePath/g;
|
2019-10-10 21:09:11 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_PATH\]\}/$strTestPathC/g;
|
2019-10-08 18:06:30 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_DATA_PATH\]\}/$self->{strDataPath}/g;
|
2019-10-10 22:13:43 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_IDX\]\}/$self->{iVmIdx}/g;
|
2018-11-20 22:48:56 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_REPO_PATH\]\}/$self->{strBackRestBase}/g;
|
2019-09-28 20:02:12 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_SCALE\]\}/$self->{iScale}/g;
|
2017-12-23 05:36:01 +02:00
|
|
|
|
2020-03-22 16:12:29 +02:00
|
|
|
my $strLogTimestampC = $self->{bLogTimestamp} ? 'true' : 'false';
|
|
|
|
$strTestC =~ s/\{\[C\_TEST\_TIMING\]\}/$strLogTimestampC/g;
|
|
|
|
|
2019-12-12 05:11:04 +02:00
|
|
|
# Set timezone
|
|
|
|
if (defined($self->{strTimeZone}))
|
|
|
|
{
|
|
|
|
$strTestC =~ s/\{\[C\_TEST\_TZ\]\}/setenv\("TZ", "$self->{strTimeZone}", true\);/g;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strTestC =~ s/\{\[C\_TEST\_TZ\]\}/\/\/ No timezone specified/g;
|
|
|
|
}
|
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Set default log level
|
2018-07-21 01:03:46 +02:00
|
|
|
my $strLogLevelTestC = "logLevel" . ucfirst($self->{strLogLevelTest});
|
|
|
|
$strTestC =~ s/\{\[C\_LOG\_LEVEL\_TEST\]\}/$strLogLevelTestC/g;
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Initialize tests
|
|
|
|
my $strTestInit;
|
|
|
|
|
|
|
|
for (my $iTestIdx = 1; $iTestIdx <= $hTest->{&TESTDEF_TOTAL}; $iTestIdx++)
|
|
|
|
{
|
|
|
|
my $bSelected = false;
|
|
|
|
|
|
|
|
if (!defined($self->{oTest}->{&TEST_RUN}) || @{$self->{oTest}->{&TEST_RUN}} == 0 ||
|
|
|
|
grep(/^$iTestIdx$/, @{$self->{oTest}->{&TEST_RUN}}))
|
|
|
|
{
|
|
|
|
$bSelected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strTestInit .=
|
|
|
|
(defined($strTestInit) ? "\n " : '') .
|
2019-10-16 15:48:33 +02:00
|
|
|
sprintf("hrnAdd(%3d, %8s);" , $iTestIdx, ($bSelected ? 'true' : 'false'));
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$strTestC =~ s/\{\[C\_TEST\_LIST\]\}/$strTestInit/g;
|
2018-11-03 22:34:04 +02:00
|
|
|
buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/test.c", $strTestC);
|
|
|
|
|
2019-04-26 14:08:23 +02:00
|
|
|
# Create build.auto.h
|
2020-03-10 20:45:27 +02:00
|
|
|
my $strBuildAutoH =
|
2020-04-02 22:58:38 +02:00
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_CO6 ? "#define HAVE_STATIC_ASSERT\n" : '') .
|
|
|
|
"#define HAVE_BUILTIN_TYPES_COMPATIBLE_P\n" .
|
2020-05-04 21:25:27 +02:00
|
|
|
(vmWithLz4($self->{oTest}->{&TEST_VM}) ? '#define HAVE_LIBLZ4' : '') . "\n" .
|
|
|
|
(vmWithZst($self->{oTest}->{&TEST_VM}) ? '#define HAVE_LIBZST' : '') . "\n";
|
2019-04-26 14:08:23 +02:00
|
|
|
|
|
|
|
buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/" . BUILD_AUTO_H, $strBuildAutoH);
|
|
|
|
|
2020-03-26 17:16:35 +02:00
|
|
|
# Disable debug/coverage for performance and profile tests
|
|
|
|
my $bPerformance = $self->{oTest}->{&TEST_TYPE} eq TESTDEF_PERFORMANCE;
|
|
|
|
|
|
|
|
if ($bPerformance || $self->{bProfile})
|
|
|
|
{
|
|
|
|
$self->{bDebug} = false;
|
|
|
|
$self->{bDebugTestTrace} = false;
|
|
|
|
$self->{bCoverageUnit} = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
# When optimization is disabled add -ftree-coalesce-vars to make the compiler faster when available
|
|
|
|
my $strNoOptimizeFlags = '-O0' . ($self->{oTest}->{&TEST_VM} ne VM_U12 ? ' -ftree-coalesce-vars' : '');
|
|
|
|
|
2019-03-26 08:20:55 +02:00
|
|
|
# Determine which warnings are available
|
|
|
|
my $strWarningFlags =
|
2019-05-15 18:55:08 +02:00
|
|
|
'-Werror -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wconversion -Wformat=2' .
|
2019-03-26 08:20:55 +02:00
|
|
|
' -Wformat-nonliteral -Wstrict-prototypes -Wpointer-arith -Wvla' .
|
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_U16 || $self->{oTest}->{&TEST_VM} eq VM_U18 ?
|
|
|
|
' -Wformat-signedness' : '') .
|
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_U18 ?
|
|
|
|
' -Wduplicated-branches -Wduplicated-cond' : '') .
|
2019-09-12 21:55:18 +02:00
|
|
|
# This is theoretically a portability issue but a compiler that does not treat NULL and false as 0 is crazy
|
|
|
|
' -Wno-missing-field-initializers';
|
2019-03-26 08:20:55 +02:00
|
|
|
|
2018-11-03 22:34:04 +02:00
|
|
|
# Flags that are common to all builds
|
|
|
|
my $strCommonFlags =
|
2019-12-14 00:55:41 +02:00
|
|
|
'-I. -Itest -std=c99 -fPIC -g -Wno-clobbered -D_POSIX_C_SOURCE=200809L -D_FILE_OFFSET_BITS=64' .
|
2020-01-24 19:08:05 +02:00
|
|
|
' `pkg-config libxml-2.0 --cflags`' . ($self->{bProfile} ? " -pg" : '') .
|
2019-07-25 20:50:02 +02:00
|
|
|
' -I`pg_config --includedir`' .
|
2018-11-03 22:34:04 +02:00
|
|
|
($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : " -DDEBUG_UNIT") .
|
|
|
|
(vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -DWITH_BACKTRACE' : '') .
|
|
|
|
($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') .
|
2019-05-11 20:51:51 +02:00
|
|
|
(vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? ' -DDEBUG_COVERAGE' : '') .
|
2020-03-26 17:16:35 +02:00
|
|
|
($self->{bDebug} ? '' : ' -DNDEBUG') .
|
2020-02-12 21:17:23 +02:00
|
|
|
($self->{bDebugTestTrace} && $self->{bDebug} ? ' -DDEBUG_TEST_TRACE' : '') .
|
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_CO6 ? ' -DDEBUG_EXEC_TIME' : '');
|
2018-11-03 22:34:04 +02:00
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Flags used to build harness files
|
2018-11-03 22:34:04 +02:00
|
|
|
my $strHarnessFlags =
|
2020-03-26 17:16:35 +02:00
|
|
|
($self->{bOptimize} ? '-O2' : $strNoOptimizeFlags) .
|
2018-11-03 22:34:04 +02:00
|
|
|
($self->{oTest}->{&TEST_CTESTDEF} ? " $self->{oTest}->{&TEST_CTESTDEF}" : '');
|
|
|
|
|
2019-03-26 08:20:55 +02:00
|
|
|
buildPutDiffers(
|
|
|
|
$self->{oStorageTest}, "$self->{strGCovPath}/harnessflags",
|
|
|
|
"${strCommonFlags} ${strWarningFlags} ${strHarnessFlags}");
|
2018-11-03 22:34:04 +02:00
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Flags used to build test.c
|
2018-11-03 22:34:04 +02:00
|
|
|
my $strTestFlags =
|
2020-03-26 17:16:35 +02:00
|
|
|
(($self->{bOptimize} && ($self->{bProfile} || $bPerformance)) ? '-O2' : $strNoOptimizeFlags) .
|
|
|
|
(!$self->{bDebugTestTrace} && $self->{bDebug} ? ' -DDEBUG_TEST_TRACE' : '') .
|
|
|
|
(vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? ' -fprofile-arcs -ftest-coverage' : '') .
|
2020-05-09 15:17:33 +02:00
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_NONE ? '' : " -DTEST_CONTAINER_REQUIRED") .
|
2018-11-03 22:34:04 +02:00
|
|
|
($self->{oTest}->{&TEST_CTESTDEF} ? " $self->{oTest}->{&TEST_CTESTDEF}" : '');
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2018-11-03 22:34:04 +02:00
|
|
|
buildPutDiffers(
|
2019-03-26 08:20:55 +02:00
|
|
|
$self->{oStorageTest}, "$self->{strGCovPath}/testflags",
|
|
|
|
"${strCommonFlags} ${strWarningFlags} ${strTestFlags}");
|
2018-11-02 17:56:13 +02:00
|
|
|
|
2019-08-26 18:05:36 +02:00
|
|
|
# Flags used to build all other files
|
2018-11-03 22:34:04 +02:00
|
|
|
my $strBuildFlags =
|
2020-03-26 17:16:35 +02:00
|
|
|
($self->{bOptimize} ? '-O2' : $strNoOptimizeFlags);
|
2018-11-02 17:56:13 +02:00
|
|
|
|
2019-03-26 08:20:55 +02:00
|
|
|
buildPutDiffers(
|
|
|
|
$self->{oStorageTest}, "$self->{strGCovPath}/buildflags",
|
|
|
|
"${strCommonFlags} ${strWarningFlags} ${strBuildFlags}");
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2018-01-26 23:41:17 +02:00
|
|
|
# Build the Makefile
|
|
|
|
my $strMakefile =
|
|
|
|
"CC=gcc\n" .
|
2018-11-03 22:34:04 +02:00
|
|
|
"COMMONFLAGS=${strCommonFlags}\n" .
|
2019-03-26 08:20:55 +02:00
|
|
|
"WARNINGFLAGS=${strWarningFlags}\n" .
|
2018-11-03 22:34:04 +02:00
|
|
|
"BUILDFLAGS=${strBuildFlags}\n" .
|
|
|
|
"HARNESSFLAGS=${strHarnessFlags}\n" .
|
|
|
|
"TESTFLAGS=${strTestFlags}\n" .
|
2020-05-05 22:49:01 +02:00
|
|
|
"LDFLAGS=-lcrypto -lssl -lxml2 -lz -lbz2" .
|
2020-03-10 20:45:27 +02:00
|
|
|
(vmWithLz4($self->{oTest}->{&TEST_VM}) ? ' -llz4' : '') .
|
2020-05-04 21:25:27 +02:00
|
|
|
(vmWithZst($self->{oTest}->{&TEST_VM}) ? ' -lzstd' : '') .
|
2018-11-03 22:34:04 +02:00
|
|
|
(vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? " -lgcov" : '') .
|
2018-05-18 17:57:32 +02:00
|
|
|
(vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -lbacktrace' : '') .
|
2018-01-26 23:41:17 +02:00
|
|
|
"\n" .
|
2018-11-03 22:34:04 +02:00
|
|
|
"SRCS=" . join(' ', @stryCFile) . "\n" .
|
2018-01-26 23:41:17 +02:00
|
|
|
"OBJS=\$(SRCS:.c=.o)\n" .
|
|
|
|
"\n" .
|
|
|
|
"test: \$(OBJS) test.o\n" .
|
2018-11-03 22:34:04 +02:00
|
|
|
"\t\$(CC) -o test.bin \$(OBJS) test.o" . ($self->{bProfile} ? " -pg" : '') . " \$(LDFLAGS)\n" .
|
2018-01-26 23:41:17 +02:00
|
|
|
"\n" .
|
2018-11-03 22:34:04 +02:00
|
|
|
"test.o: testflags test.c${strTestDepend}\n" .
|
2019-12-19 23:25:46 +02:00
|
|
|
"\t\$(CC) \$(COMMONFLAGS) \$(WARNINGFLAGS) \$(TESTFLAGS) -c test.c\n";
|
2018-11-03 22:34:04 +02:00
|
|
|
|
|
|
|
# Build C file dependencies
|
|
|
|
foreach my $strCFile (@stryCFile)
|
|
|
|
{
|
2019-04-26 14:08:23 +02:00
|
|
|
my $bHarnessFile = $strCFile =~ /^test\// ? true : false;
|
|
|
|
|
2018-11-03 22:34:04 +02:00
|
|
|
buildDependencyTreeSub(
|
2019-04-26 14:08:23 +02:00
|
|
|
$self->{oStorageTest}, $rhDependencyTree, $strCFile, !$bHarnessFile, $self->{strGCovPath}, ['', 'test']);
|
2018-11-03 22:34:04 +02:00
|
|
|
|
|
|
|
$strMakefile .=
|
|
|
|
"\n" . substr($strCFile, 0, length($strCFile) - 2) . ".o:" .
|
2019-04-26 14:08:23 +02:00
|
|
|
($bHarnessFile ? " harnessflags" : " buildflags") . " $strCFile";
|
2018-11-03 22:34:04 +02:00
|
|
|
|
|
|
|
foreach my $strDepend (@{$rhDependencyTree->{$strCFile}{include}})
|
|
|
|
{
|
|
|
|
$strMakefile .=
|
2019-04-26 14:08:23 +02:00
|
|
|
' ' .
|
|
|
|
($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') .
|
2018-11-03 22:34:04 +02:00
|
|
|
$strDepend;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strMakefile .=
|
|
|
|
"\n" .
|
2019-03-26 08:20:55 +02:00
|
|
|
"\t\$(CC) \$(COMMONFLAGS) \$(WARNINGFLAGS)" .
|
2018-11-03 22:34:04 +02:00
|
|
|
($strCFile =~ /^test\// ? " \$(HARNESSFLAGS)" : " \$(BUILDFLAGS)") .
|
|
|
|
" -c $strCFile -o " . substr($strCFile, 0, length($strCFile) - 2) . ".o\n";
|
|
|
|
}
|
2018-01-26 23:41:17 +02:00
|
|
|
|
2019-07-08 14:29:25 +02:00
|
|
|
buildPutDiffers($self->{oStorageTest}, $self->{strGCovPath} . "/Makefile", $strMakefile);
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
my $oExec = new pgBackRestTest::Common::ExecuteTest(
|
2018-04-13 02:42:26 +02:00
|
|
|
$strCommand, {bSuppressError => true, bShowOutputAsync => $self->{bShowOutputAsync}});
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
$oExec->begin();
|
|
|
|
|
|
|
|
$self->{oProcess} =
|
|
|
|
{
|
|
|
|
exec => $oExec,
|
|
|
|
test => $strTest,
|
2017-11-27 01:43:51 +02:00
|
|
|
start_time => $fTestStartTime,
|
2017-02-21 15:59:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$bRun = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'bRun', value => $bRun, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# end
|
|
|
|
####################################################################################################################################
|
|
|
|
sub end
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(my $strOperation) = logDebugParam (__PACKAGE__ . '->run', \@_,);
|
|
|
|
|
|
|
|
# Is the job done?
|
|
|
|
my $bDone = false;
|
|
|
|
my $bFail = false;
|
|
|
|
|
|
|
|
my $oExecDone = $self->{oProcess}{exec};
|
|
|
|
my $strTestDone = $self->{oProcess}{test};
|
|
|
|
my $iTestDoneIdx = $self->{oProcess}{idx};
|
|
|
|
|
2019-12-10 20:16:47 +02:00
|
|
|
my $iExitStatus = $oExecDone->end($self->{iVmMax} == 1);
|
2017-02-21 15:59:23 +02:00
|
|
|
|
|
|
|
if (defined($iExitStatus))
|
|
|
|
{
|
2017-10-12 18:55:48 +02:00
|
|
|
my $strImage = 'test-' . $self->{iVmIdx};
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($self->{bShowOutputAsync})
|
|
|
|
{
|
|
|
|
syswrite(*STDOUT, "\n");
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:45:14 +02:00
|
|
|
# If C code generate profile info
|
|
|
|
if ($iExitStatus == 0 && $self->{oTest}->{&TEST_C} && $self->{bProfile})
|
|
|
|
{
|
|
|
|
executeTest(
|
2019-10-08 18:06:30 +02:00
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_NONE ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') .
|
2018-12-05 16:15:45 +02:00
|
|
|
"gprof $self->{strGCovPath}/test.bin $self->{strGCovPath}/gmon.out > $self->{strGCovPath}/gprof.txt");
|
2018-05-18 12:45:14 +02:00
|
|
|
|
2020-03-14 20:50:36 +02:00
|
|
|
$self->{oStorageTest}->pathCreate(
|
|
|
|
"$self->{strBackRestBase}/test/result/profile", {strMode => '0750', bIgnoreExists => true, bCreateParent => true});
|
2018-05-18 12:45:14 +02:00
|
|
|
$self->{oStorageTest}->copy(
|
2020-03-14 20:50:36 +02:00
|
|
|
"$self->{strGCovPath}/gprof.txt", "$self->{strBackRestBase}/test/result/profile/gprof.txt");
|
2018-05-18 12:45:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# If C code generate coverage info
|
2018-09-15 19:27:06 +02:00
|
|
|
if ($iExitStatus == 0 && $self->{oTest}->{&TEST_C} && vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit})
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2020-03-19 18:07:51 +02:00
|
|
|
coverageExtract(
|
2020-05-09 15:17:33 +02:00
|
|
|
$self->{oStorageTest}, $self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME},
|
|
|
|
$self->{oTest}->{&TEST_VM} ne VM_NONE, $self->{bCoverageSummary},
|
2020-03-19 18:07:51 +02:00
|
|
|
$self->{oTest}->{&TEST_VM} eq VM_NONE ? undef : $strImage, $self->{strTestPath}, "$self->{strTestPath}/temp",
|
|
|
|
$self->{strGCovPath}, $self->{strBackRestBase} . '/test/result');
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Record elapsed time
|
2017-02-21 15:59:23 +02:00
|
|
|
my $fTestElapsedTime = ceil((gettimeofday() - $self->{oProcess}{start_time}) * 100) / 100;
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Output error
|
2017-02-21 15:59:23 +02:00
|
|
|
if ($iExitStatus != 0)
|
|
|
|
{
|
2020-03-22 16:12:29 +02:00
|
|
|
&log(ERROR, "${strTestDone} (err${iExitStatus}" . ($self->{bLogTimestamp} ? "-${fTestElapsedTime}s)" : '') .
|
2017-02-21 15:59:23 +02:00
|
|
|
(defined($oExecDone->{strOutLog}) && !$self->{bShowOutputAsync} ?
|
|
|
|
":\n\n" . trim($oExecDone->{strOutLog}) . "\n" : ''), undef, undef, 4);
|
|
|
|
$bFail = true;
|
|
|
|
}
|
2017-10-12 18:55:48 +02:00
|
|
|
# Output success
|
2017-02-21 15:59:23 +02:00
|
|
|
else
|
|
|
|
{
|
2020-03-22 20:18:16 +02:00
|
|
|
&log(INFO, "${strTestDone}" . ($self->{bLogTimestamp} ? " (${fTestElapsedTime}s)" : '').
|
2017-02-21 15:59:23 +02:00
|
|
|
($self->{bVmOut} && !$self->{bShowOutputAsync} ?
|
|
|
|
":\n\n" . trim($oExecDone->{strOutLog}) . "\n" : ''), undef, undef, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$self->{bNoCleanup})
|
|
|
|
{
|
|
|
|
my $strHostTestPath = "$self->{strTestPath}/${strImage}";
|
|
|
|
|
2019-10-08 18:06:30 +02:00
|
|
|
if ($self->{oTest}->{&TEST_VM} ne VM_NONE)
|
|
|
|
{
|
|
|
|
containerRemove("test-$self->{iVmIdx}");
|
|
|
|
}
|
|
|
|
|
2019-10-12 15:45:18 +02:00
|
|
|
executeTest("rm -rf ${strHostTestPath}");
|
2017-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$bDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'bDone', value => $bDone, trace => true},
|
|
|
|
{name => 'bFail', value => $bFail, trace => true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|