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);
|
2021-01-24 23:24:14 +02:00
|
|
|
use Time::HiRes qw(gettimeofday usleep);
|
2017-02-21 15:59:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# 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},
|
2021-01-24 22:35:40 +02:00
|
|
|
$self->{strMakeCmd},
|
2017-02-21 15:59:23 +02:00
|
|
|
$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'},
|
2021-01-24 22:35:40 +02:00
|
|
|
{name => 'strMakeCmd'},
|
2017-02-21 15:59:23 +02:00
|
|
|
{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}";
|
2021-01-24 23:24:14 +02:00
|
|
|
$self->{strRepoPath} = "$self->{strTestPath}/repo";
|
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}";
|
|
|
|
|
2021-04-28 16:58:45 +02:00
|
|
|
# Don't create the container if this is a dry run unless output from the VM is required. Output can be requested
|
2017-02-21 15:59:23 +02:00
|
|
|
# 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}" .
|
2021-01-24 23:24:14 +02:00
|
|
|
" -v $self->{strRepoPath}:$self->{strRepoPath}:ro" .
|
2020-03-15 16:09:27 +02:00
|
|
|
($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-02-21 15:59:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create run parameters
|
|
|
|
my $strCommandRunParam = '';
|
|
|
|
|
|
|
|
foreach my $iRunIdx (@{$self->{oTest}->{&TEST_RUN}})
|
|
|
|
{
|
|
|
|
$strCommandRunParam .= ' --run=' . $iRunIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$self->{bDryRun} || $self->{bVmOut})
|
|
|
|
{
|
2021-01-24 23:24:14 +02:00
|
|
|
my $strCommand = undef; # Command to run test
|
|
|
|
|
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})
|
|
|
|
{
|
2021-01-24 23:24:14 +02:00
|
|
|
my $strRepoCopyPath = $self->{strTestPath} . '/repo'; # Path to repo copy
|
|
|
|
my $strRepoCopySrcPath = $strRepoCopyPath . '/src'; # Path to repo copy src
|
|
|
|
my $strRepoCopyTestSrcPath = $strRepoCopyPath . '/test/src'; # Path to repo copy test src
|
2021-05-21 00:47:31 +02:00
|
|
|
my $strShimSrcPath = $self->{strGCovPath} . '/src'; # Path to shim src
|
|
|
|
my $strShimTestSrcPath = $self->{strGCovPath} . '/test/src'; # Path to shim test src
|
2021-01-24 23:24:14 +02:00
|
|
|
|
|
|
|
my $bCleanAll = false; # Do all object files need to be cleaned?
|
|
|
|
my $bConfigure = false; # Does configure need to be run?
|
|
|
|
|
|
|
|
# If the build.processing file exists then wipe the path to start clean
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strBuildProcessingFile = $self->{strGCovPath} . "/build.processing";
|
|
|
|
|
|
|
|
# If the file exists then processing terminated before test.bin was run in the last test and the path might be in a
|
|
|
|
# bad state.
|
|
|
|
if ($self->{oStorageTest}->exists($strBuildProcessingFile))
|
|
|
|
{
|
|
|
|
executeTest("find $self->{strGCovPath} -mindepth 1 -print0 | xargs -0 rm -rf");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Write build.processing to track processing of this test
|
|
|
|
$self->{oStorageTest}->put($strBuildProcessingFile);
|
|
|
|
|
|
|
|
# Create Makefile.in
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strMakefileIn =
|
|
|
|
"CC_CONFIG = \@CC\@\n" .
|
|
|
|
"CFLAGS_CONFIG = \@CFLAGS\@\n" .
|
|
|
|
"CPPFLAGS_CONFIG = \@CPPFLAGS\@\n" .
|
|
|
|
"LDFLAGS_CONFIG = \@LDFLAGS\@\n" .
|
|
|
|
"LIBS_CONFIG = \@LIBS\@\n";
|
|
|
|
|
|
|
|
# If Makefile.in has changed then configure needs to be run and all files cleaned
|
|
|
|
if (buildPutDiffers($self->{oStorageTest}, $self->{strGCovPath} . "/Makefile.in", $strMakefileIn))
|
|
|
|
{
|
|
|
|
$bConfigure = true;
|
|
|
|
$bCleanAll = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create Makefile.param
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Is coverage being tested?
|
|
|
|
my $bCoverage = vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit};
|
|
|
|
|
|
|
|
# Generate Makefile.param
|
|
|
|
my $strMakefileParam =
|
|
|
|
"CFLAGS =" .
|
2021-02-03 00:05:55 +02:00
|
|
|
" \\\n\t-Werror -Wfatal-errors -g" .
|
2021-01-24 23:24:14 +02:00
|
|
|
($self->{bProfile} ? " \\\n\t-pg" : '') .
|
|
|
|
(vmArchBits($self->{oTest}->{&TEST_VM}) == 32 ? " \\\n\t-D_FILE_OFFSET_BITS=64" : '') .
|
|
|
|
($self->{bDebug} ? '' : " \\\n\t-DNDEBUG") .
|
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_CO7 ? " \\\n\t-DDEBUG_EXEC_TIME" : '') .
|
|
|
|
($bCoverage ? " \\\n\t-DDEBUG_COVERAGE" : '') .
|
|
|
|
($self->{bDebugTestTrace} && $self->{bDebug} ? " \\\n\t-DDEBUG_TEST_TRACE" : '') .
|
|
|
|
(vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? " \\\n\t-DWITH_BACKTRACE" : '') .
|
|
|
|
($self->{oTest}->{&TEST_CDEF} ? " \\\n\t$self->{oTest}->{&TEST_CDEF}" : '') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"CFLAGS_TEST =" .
|
|
|
|
" \\\n\t" . (($self->{bOptimize} && ($self->{bProfile} || $bPerformance)) ? '-O2' : '-O0') .
|
|
|
|
" \\\n\t-DDEBUG_MEM" .
|
|
|
|
(!$self->{bDebugTestTrace} && $self->{bDebug} ? " \\\n\t-DDEBUG_TEST_TRACE" : '') .
|
|
|
|
($bCoverage ? " \\\n\t-fprofile-arcs -ftest-coverage" : '') .
|
|
|
|
($self->{oTest}->{&TEST_VM} eq VM_NONE ? '' : " \\\n\t-DTEST_CONTAINER_REQUIRED") .
|
|
|
|
($self->{oTest}->{&TEST_CTESTDEF} ? " \\\n\t$self->{oTest}->{&TEST_CTESTDEF}" : '') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"CFLAGS_HARNESS =" .
|
|
|
|
" \\\n\t" . ($self->{bOptimize} ? '-O2' : '-O0') .
|
|
|
|
($self->{oTest}->{&TEST_CTESTDEF} ? " \\\n\t$self->{oTest}->{&TEST_CTESTDEF}" : '') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"CFLAGS_CORE =" .
|
|
|
|
" \\\n\t" . ($self->{bOptimize} ? '-O2' : '-O0') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"LDFLAGS =" .
|
|
|
|
($self->{bProfile} ? " \\\n\t-pg" : '') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"LIBS =" .
|
|
|
|
($bCoverage ? " \\\n\t-lgcov" : '') .
|
|
|
|
(vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? " \\\n\t-lbacktrace" : '') .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
|
|
|
"INCLUDE =" .
|
2021-05-21 00:47:31 +02:00
|
|
|
" \\\n\t-I\"${strShimSrcPath}\"" .
|
|
|
|
" \\\n\t-I\"${strShimTestSrcPath}\"" .
|
2021-01-24 23:24:14 +02:00
|
|
|
" \\\n\t-I\"${strRepoCopySrcPath}\"" .
|
|
|
|
" \\\n\t-I\"${strRepoCopyTestSrcPath}\"" .
|
|
|
|
"\n" .
|
|
|
|
"\n" .
|
2021-05-21 00:47:31 +02:00
|
|
|
"vpath \%.c ${strShimSrcPath}:${strShimTestSrcPath}:${strRepoCopySrcPath}:${strRepoCopyTestSrcPath}\n";
|
2021-01-24 23:24:14 +02:00
|
|
|
|
|
|
|
# If Makefile.param has changed then clean all files
|
|
|
|
if (buildPutDiffers($self->{oStorageTest}, $self->{strGCovPath} . "/Makefile.param", $strMakefileParam))
|
|
|
|
{
|
|
|
|
$bCleanAll = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate list of harness files
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
2021-01-27 17:57:42 +02:00
|
|
|
my $hTest = (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME}));
|
2021-01-24 23:24:14 +02:00
|
|
|
my $strRepoCopyTestSrcHarnessPath = $strRepoCopyTestSrcPath . '/common';
|
|
|
|
|
2021-05-21 00:47:31 +02:00
|
|
|
# C modules included in harness files that should not be added to the make list
|
|
|
|
my $rhHarnessCModule = {};
|
|
|
|
|
|
|
|
# List of harness files to include in make
|
2021-01-27 17:57:42 +02:00
|
|
|
my @stryHarnessFile = ('common/harnessTest');
|
2021-01-24 23:24:14 +02:00
|
|
|
|
2021-05-21 00:47:31 +02:00
|
|
|
foreach my $rhHarness (@{$hTest->{&TESTDEF_HARNESS}})
|
2021-01-24 23:24:14 +02:00
|
|
|
{
|
2021-05-17 13:20:28 +02:00
|
|
|
my $bFound = false;
|
2021-05-21 00:47:31 +02:00
|
|
|
my $strFile = "common/harness" . ucfirst($rhHarness->{&TESTDEF_HARNESS_NAME});
|
2021-05-17 13:20:28 +02:00
|
|
|
|
|
|
|
# Include harness file if present
|
2021-05-21 00:47:31 +02:00
|
|
|
my $strHarnessSrcFile = "${strRepoCopyTestSrcPath}/${strFile}.c";
|
|
|
|
|
|
|
|
if ($self->{oStorageTest}->exists($strHarnessSrcFile))
|
2021-05-17 13:20:28 +02:00
|
|
|
{
|
|
|
|
$bFound = true;
|
2021-05-21 00:47:31 +02:00
|
|
|
|
|
|
|
if (!defined($hTest->{&TESTDEF_HARNESS_SHIM_DEF}{$rhHarness->{&TESTDEF_HARNESS_NAME}}))
|
|
|
|
{
|
|
|
|
push(@stryHarnessFile, $strFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install shim
|
|
|
|
my $rhShim = $rhHarness->{&TESTDEF_HARNESS_SHIM};
|
|
|
|
|
|
|
|
if (defined($rhShim))
|
|
|
|
{
|
|
|
|
my $strHarnessSrc = ${$self->{oStorageTest}->get($strHarnessSrcFile)};
|
|
|
|
|
|
|
|
# Error if there is no placeholder for the shimmed modules
|
|
|
|
if ($strHarnessSrc !~ /\{\[SHIM\_MODULE\]\}/)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "{[SHIM_MODULE]} tag not found in '${strFile}' harness with shims");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build list of shimmed C modules
|
|
|
|
my $strShimModuleList = undef;
|
|
|
|
|
|
|
|
foreach my $strShimModule (sort(keys(%{$rhShim})))
|
|
|
|
{
|
|
|
|
# If there are shimmed elements the C module will need to be updated and saved to the test path
|
|
|
|
if (defined($rhShim->{$strShimModule}))
|
|
|
|
{
|
|
|
|
my $strShimModuleSrc = ${$self->{oStorageTest}->get(
|
|
|
|
"${strRepoCopySrcPath}/${strShimModule}.c")};
|
|
|
|
my @stryShimModuleSrcRenamed;
|
|
|
|
my $strFunctionDeclaration = undef;
|
|
|
|
my $strFunctionShim = undef;
|
|
|
|
|
|
|
|
foreach my $strLine (split("\n", $strShimModuleSrc))
|
|
|
|
{
|
|
|
|
# Renamed shimmed functions
|
|
|
|
foreach my $strFunction (@{$rhShim->{$strShimModule}{&TESTDEF_HARNESS_SHIM_FUNCTION}})
|
|
|
|
{
|
|
|
|
# If shimmed function declaration construction is in progress
|
|
|
|
if (defined($strFunctionShim))
|
|
|
|
{
|
|
|
|
# When the beginning of the function block is found, output both the constructed
|
|
|
|
# declaration and the renamed implementation.
|
|
|
|
if ($strLine =~ /^{/)
|
|
|
|
{
|
|
|
|
push(@stryShimModuleSrcRenamed, trim($strFunctionDeclaration) . ";");
|
|
|
|
push(@stryShimModuleSrcRenamed, $strFunctionShim);
|
|
|
|
push(@stryShimModuleSrcRenamed, $strLine);
|
|
|
|
|
|
|
|
$strFunctionShim = undef;
|
|
|
|
}
|
|
|
|
# Else keep constructing the declaration and implementation
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strFunctionDeclaration .= "${strLine}\n";
|
|
|
|
$strFunctionShim .= "${strLine}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Else search for shimmed functions
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# If the function to shim is static then we need to create a declaration with the
|
|
|
|
# original name so references to the original name in the C module will compile.
|
|
|
|
# This is not necessary for extern'd functions since they should already have a
|
|
|
|
# declaration in the header file.
|
|
|
|
if ($strLine =~ /^${strFunction}\(/ && $stryShimModuleSrcRenamed[-1] =~ /^static /)
|
|
|
|
{
|
|
|
|
my $strLineLast = pop(@stryShimModuleSrcRenamed);
|
|
|
|
|
|
|
|
$strFunctionDeclaration = "${strLineLast} ${strLine}\n";
|
|
|
|
|
|
|
|
$strLine =~ s/^${strFunction}\(/${strFunction}_SHIMMED\(/;
|
|
|
|
$strFunctionShim = "${strLineLast}\n${strLine}\n";
|
|
|
|
}
|
|
|
|
# Else just append the line
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push(@stryShimModuleSrcRenamed, $strLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildPutDiffers(
|
|
|
|
$self->{oStorageTest}, "${strShimSrcPath}/${strShimModule}.c",
|
|
|
|
join("\n", @stryShimModuleSrcRenamed));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build list to include in the harness
|
|
|
|
if (defined($strShimModuleList))
|
|
|
|
{
|
|
|
|
$strShimModuleList .= "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$rhHarnessCModule->{$strShimModule} = true;
|
|
|
|
$strShimModuleList .= "#include \"${strShimModule}.c\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Replace modules and save
|
|
|
|
$strHarnessSrc =~ s/\{\[SHIM\_MODULE\]\}/${strShimModuleList}/g;
|
|
|
|
buildPutDiffers($self->{oStorageTest}, "${strShimTestSrcPath}/${strFile}.c", $strHarnessSrc);
|
|
|
|
}
|
2021-05-17 13:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Include files in the harness directory if present
|
|
|
|
for my $strFileSub (
|
|
|
|
$self->{oStorageTest}->list("${strRepoCopyTestSrcPath}/${strFile}",
|
|
|
|
{bIgnoreMissing => true, strExpression => '\.c$'}))
|
|
|
|
{
|
|
|
|
push(@stryHarnessFile, "${strFile}/" . substr($strFileSub, 0, length($strFileSub) - 2));
|
|
|
|
$bFound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Error when no harness files were found
|
|
|
|
if (!$bFound)
|
|
|
|
{
|
2021-05-21 00:47:31 +02:00
|
|
|
confess &log(ERROR, "no files found for harness '$rhHarness->{&TESTDEF_HARNESS_NAME}'");
|
2021-05-17 13:20:28 +02:00
|
|
|
}
|
2021-01-24 23:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate list of core files (files to be tested/included in this unit will be excluded)
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
2017-10-12 18:55:48 +02:00
|
|
|
my $hTestCoverage = $hTest->{&TESTDEF_COVERAGE};
|
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
my @stryCoreFile;
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2021-01-27 17:57:42 +02:00
|
|
|
foreach my $strFile (@{$hTest->{&TESTDEF_CORE}})
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2021-01-24 23:24:14 +02:00
|
|
|
# Skip all files except .c files (including .auto.c and .vendor.c)
|
2021-01-27 17:57:42 +02:00
|
|
|
next if $strFile !~ /(?<!\.auto)$/ || $strFile !~ /(?<!\.vendor)$/;
|
2020-05-19 01:11:26 +02:00
|
|
|
|
2021-01-27 17:57:42 +02:00
|
|
|
# Skip if no C file exists
|
|
|
|
next if !$self->{oStorageTest}->exists("${strRepoCopySrcPath}/${strFile}.c");
|
2017-11-27 01:43:51 +02:00
|
|
|
|
2021-05-21 00:47:31 +02:00
|
|
|
# Skip if the C file is included in the harness
|
|
|
|
next if defined($rhHarnessCModule->{$strFile});
|
|
|
|
|
2021-01-27 17:57:42 +02:00
|
|
|
if (!defined($hTestCoverage->{$strFile}) && !grep(/^$strFile$/, @{$hTest->{&TESTDEF_INCLUDE}}))
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2021-01-27 17:57:42 +02:00
|
|
|
push(@stryCoreFile, $strFile);
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Create Makefile
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strMakefile =
|
|
|
|
"include Makefile.config\n" .
|
|
|
|
"include Makefile.param\n" .
|
|
|
|
"\n" .
|
|
|
|
"SRCS = test.c \\\n" .
|
|
|
|
"\t" . join('.c ', @stryHarnessFile) . ".c \\\n" .
|
2021-01-27 17:57:42 +02:00
|
|
|
(@stryCoreFile > 0 ? "\t" . join('.c ', @stryCoreFile) . ".c\n" : '').
|
2021-01-24 23:24:14 +02:00
|
|
|
"\n" .
|
|
|
|
".build/test.o: CFLAGS += \$(CFLAGS_TEST)\n" .
|
|
|
|
"\n" .
|
|
|
|
".build/" . join(".o: CFLAGS += \$(CFLAGS_HARNESS)\n.build/", @stryHarnessFile) .
|
|
|
|
".o: CFLAGS += \$(CFLAGS_HARNESS)\n" .
|
|
|
|
"\n" .
|
|
|
|
".build/" . join(".o: CFLAGS += \$(CFLAGS_CORE)\n.build/", @stryCoreFile) .
|
|
|
|
".o: CFLAGS += \$(CFLAGS_CORE)\n" .
|
|
|
|
"\n" .
|
|
|
|
".build/\%.o : \%.c\n" .
|
|
|
|
" \@if test ! -d \$(\@D); then mkdir -p \$(\@D); fi\n" .
|
|
|
|
" \$(CC_CONFIG) \$(INCLUDE) \$(CFLAGS_CONFIG) \$(CPPFLAGS_CONFIG) \$(CFLAGS)" .
|
|
|
|
" -c -o \$\@ \$< -MMD -MP -MF .build/\$*.dep\n" .
|
|
|
|
"\n" .
|
|
|
|
"OBJS = \$(patsubst \%.c,.build/\%.o,\$(SRCS))\n" .
|
|
|
|
"\n" .
|
|
|
|
"test: \$(OBJS)\n" .
|
|
|
|
" \$(CC_CONFIG) -o test.bin \$(OBJS) \$(LDFLAGS_CONFIG) \$(LDFLAGS) \$(LIBS_CONFIG) \$(LIBS)\n" .
|
|
|
|
"\n" .
|
|
|
|
"rwildcard = \$(wildcard \$1\$2) \$(foreach d,\$(wildcard \$1*),\$(call rwildcard,\$d/,\$2))\n" .
|
|
|
|
"DEP_FILES = \$(call rwildcard,.build,*.dep)\n" .
|
|
|
|
"include \$(DEP_FILES)\n";
|
|
|
|
|
|
|
|
buildPutDiffers($self->{oStorageTest}, $self->{strGCovPath} . "/Makefile", $strMakefile);
|
|
|
|
|
|
|
|
# Create test.c
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
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 =
|
2021-01-24 23:24:14 +02:00
|
|
|
"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$/;
|
|
|
|
|
2020-05-19 01:11:26 +02:00
|
|
|
# Don't include auto files as they are included in their companion C files
|
2017-10-12 18:55:48 +02:00
|
|
|
next if $strFile =~ /auto$/;
|
|
|
|
|
2020-05-19 01:11:26 +02:00
|
|
|
# Don't include vendor files as they are included in regular C files
|
|
|
|
next if $strFile =~ /vendor$/;
|
|
|
|
|
2021-05-21 00:47:31 +02:00
|
|
|
# Skip if the C file is included in the harness
|
|
|
|
next if defined($rhHarnessCModule->{$strFile});
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Include the C file if it exists
|
|
|
|
my $strCIncludeFile = "${strFile}.c";
|
|
|
|
|
|
|
|
# If the C file does not exist use the header file instead
|
2021-01-24 23:24:14 +02:00
|
|
|
if (!$self->{oStorageTest}->exists("${strRepoCopySrcPath}/${strCIncludeFile}"))
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
|
|
|
# Error if code was expected
|
|
|
|
if ($hTestCoverage->{$strFile} ne TESTDEF_COVERAGE_NOCODE)
|
|
|
|
{
|
2021-01-24 23:24:14 +02:00
|
|
|
confess &log(ERROR, "unable to find source file '${strRepoCopySrcPath}/${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
|
|
|
}
|
|
|
|
|
2021-05-21 00:47:31 +02:00
|
|
|
# Add harnesses with shims that are first defined in this module
|
|
|
|
foreach my $strHarness (sort(keys(%{$hTest->{&TESTDEF_HARNESS_SHIM_DEF}})))
|
|
|
|
{
|
|
|
|
$strCInclude .=
|
|
|
|
(defined($strCInclude) ? "\n" : '') . "#include \"common/harness" . ucfirst($strHarness) . ".c\"";
|
|
|
|
}
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
# Update C test file with test module
|
2021-01-24 23:24:14 +02:00
|
|
|
my $strTestC = ${$self->{oStorageTest}->get("${strRepoCopyTestSrcPath}/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}";
|
|
|
|
|
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;
|
2021-01-24 23:24:14 +02:00
|
|
|
$strTestC =~ s/\{\[C\_TEST\_PGB\_PATH\]\}/$strRepoCopyPath/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;
|
2019-04-26 14:08:23 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Save test.c and make sure it gets a new timestamp
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
my $strTestCFile = "$self->{strGCovPath}/test.c";
|
2019-04-26 14:08:23 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
if (buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/test.c", $strTestC))
|
2020-03-26 17:16:35 +02:00
|
|
|
{
|
2021-01-24 23:24:14 +02:00
|
|
|
# Get timestamp for test.bin if it existss
|
|
|
|
my $oTestBinInfo = $self->{oStorageTest}->info("$self->{strGCovPath}/test.bin", {bIgnoreMissing => true});
|
|
|
|
my $iTestBinOriginalTime = defined($oTestBinInfo) ? $oTestBinInfo->mtime : 0;
|
2020-03-26 17:16:35 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Get timestamp for test.c
|
|
|
|
my $iTestCNewTime = $self->{oStorageTest}->info($strTestCFile)->mtime;
|
2019-04-26 14:08:23 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Is the timestamp for test.c newer than test.bin?
|
|
|
|
while ($iTestCNewTime <= $iTestBinOriginalTime)
|
|
|
|
{
|
|
|
|
# If not then sleep until the next second
|
|
|
|
my $iTimeToSleep = ($iTestBinOriginalTime + 1) - gettimeofday();
|
2018-11-03 22:34:04 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
if ($iTimeToSleep > 0)
|
|
|
|
{
|
|
|
|
usleep($iTimeToSleep * 1000000);
|
|
|
|
}
|
2018-11-03 22:34:04 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Save the file again
|
|
|
|
$self->{oStorageTest}->put($self->{oStorageTest}->openWrite($strTestCFile), $strTestC);
|
|
|
|
$iTestCNewTime = $self->{oStorageTest}->info($strTestCFile)->mtime;
|
2018-11-03 22:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-26 23:41:17 +02:00
|
|
|
|
2021-01-24 23:24:14 +02:00
|
|
|
# Create command
|
|
|
|
# ------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Build filename for valgrind suppressions
|
|
|
|
my $strValgrindSuppress = $self->{strRepoPath} . '/test/src/valgrind.suppress.' . $self->{oTest}->{&TEST_VM};
|
|
|
|
|
|
|
|
$strCommand =
|
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_NONE ? "docker exec -i -u ${\TEST_USER} ${strImage} bash -l -c '" : '') .
|
|
|
|
" \\\n" .
|
|
|
|
"cd $self->{strGCovPath} && \\\n" .
|
|
|
|
# Clean build
|
|
|
|
($bCleanAll ? "rm -rf .build && \\\n" : '') .
|
|
|
|
# Remove coverage data
|
|
|
|
(!$bCleanAll && $bCoverage ? "rm -rf .build/test.gcda && \\\n" : '') .
|
|
|
|
# Configure when required
|
|
|
|
($bConfigure ?
|
|
|
|
"mv Makefile Makefile.tmp && ${strRepoCopySrcPath}/configure -q --enable-test" .
|
|
|
|
" && mv Makefile Makefile.config && mv Makefile.tmp Makefile && \\\n" :
|
|
|
|
'') .
|
|
|
|
$self->{strMakeCmd} . " -j $self->{iBuildMax} -s 2>&1 && \\\n" .
|
|
|
|
"rm ${strBuildProcessingFile} && \\\n" .
|
|
|
|
# Test with valgrind when requested
|
|
|
|
($self->{bValgrindUnit} && $self->{oTest}->{&TEST_TYPE} ne TESTDEF_PERFORMANCE ?
|
|
|
|
'valgrind -q --gen-suppressions=all' .
|
|
|
|
($self->{oStorageTest}->exists($strValgrindSuppress) ? " --suppressions=${strValgrindSuppress}" : '') .
|
|
|
|
" --leak-check=full --leak-resolution=high --error-exitcode=25" . ' ' : '') .
|
|
|
|
"./test.bin 2>&1" .
|
|
|
|
($self->{oTest}->{&TEST_VM} ne VM_NONE ? "'" : '');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strCommand =
|
|
|
|
($self->{oTest}->{&TEST_CONTAINER} ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') .
|
|
|
|
abs_path($0) .
|
|
|
|
" --test-path=${strVmTestPath}" .
|
|
|
|
" --vm-host=$self->{strVmHost}" .
|
|
|
|
" --vm=$self->{oTest}->{&TEST_VM}" .
|
|
|
|
" --vm-id=$self->{iVmIdx}" .
|
|
|
|
" --module=" . $self->{oTest}->{&TEST_MODULE} .
|
|
|
|
' --test=' . $self->{oTest}->{&TEST_NAME} .
|
|
|
|
$strCommandRunParam .
|
|
|
|
(defined($self->{oTest}->{&TEST_DB}) ? ' --pg-version=' . $self->{oTest}->{&TEST_DB} : '') .
|
|
|
|
($self->{strLogLevel} ne lc(INFO) ? " --log-level=$self->{strLogLevel}" : '') .
|
|
|
|
($self->{strLogLevelTestFile} ne lc(TRACE) ? " --log-level-test-file=$self->{strLogLevelTestFile}" : '') .
|
|
|
|
($self->{bLogTimestamp} ? '' : ' --no-log-timestamp') .
|
|
|
|
' --pgsql-bin=' . $self->{oTest}->{&TEST_PGSQL_BIN} .
|
|
|
|
($self->{strTimeZone} ? " --tz='$self->{strTimeZone}'" : '') .
|
|
|
|
($self->{bLogForce} ? ' --log-force' : '') .
|
|
|
|
($self->{bDryRun} ? ' --dry-run' : '') .
|
|
|
|
($self->{bDryRun} ? ' --vm-out' : '') .
|
|
|
|
($self->{bNoCleanup} ? " --no-cleanup" : '');
|
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)
|
|
|
|
{
|
2021-01-24 15:23:59 +02:00
|
|
|
# Get stdout
|
|
|
|
my $strOutput = trim($oExecDone->{strOutLog}) ? "STDOUT:\n" . trim($oExecDone->{strOutLog}) : '';
|
|
|
|
|
|
|
|
# Get stderr
|
|
|
|
if (trim($oExecDone->{strSuppressedErrorLog}) ne '')
|
|
|
|
{
|
|
|
|
if ($strOutput ne '')
|
|
|
|
{
|
|
|
|
$strOutput .= "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$strOutput .= "STDERR:\n" . trim($oExecDone->{strSuppressedErrorLog});
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no stdout or stderr output something rather than a blank line
|
|
|
|
if ($strOutput eq '')
|
|
|
|
{
|
|
|
|
$strOutput = 'NO OUTPUT ON STDOUT OR STDERR';
|
|
|
|
}
|
|
|
|
|
2020-03-22 16:12:29 +02:00
|
|
|
&log(ERROR, "${strTestDone} (err${iExitStatus}" . ($self->{bLogTimestamp} ? "-${fTestElapsedTime}s)" : '') .
|
2021-01-24 15:23:59 +02:00
|
|
|
(defined($oExecDone->{strOutLog}) && !$self->{bShowOutputAsync} ? ":\n\n${strOutput}\n" : ''), undef, undef, 4);
|
|
|
|
|
2017-02-21 15:59:23 +02:00
|
|
|
$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}");
|
|
|
|
}
|
|
|
|
|
2021-01-24 22:48:32 +02:00
|
|
|
executeTest("chmod -R 700 ${strHostTestPath}/* 2>&1;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;
|