2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# DefineTest.pm - Defines all tests that can be run
|
|
|
|
####################################################################################################################################
|
|
|
|
package pgBackRestTest::Common::DefineTest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
|
2020-03-10 21:41:56 +02:00
|
|
|
use pgBackRestDoc::Common::Log;
|
|
|
|
use pgBackRestDoc::Common::String;
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2017-06-12 16:52:32 +02:00
|
|
|
use pgBackRestTest::Common::VmTest;
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
################################################################################################################################
|
|
|
|
# Test definition constants
|
2018-04-08 16:19:24 +02:00
|
|
|
#
|
|
|
|
# Documentation for these constants is in test/define.yaml.
|
2016-06-24 14:12:58 +02:00
|
|
|
################################################################################################################################
|
2018-04-24 15:12:25 +02:00
|
|
|
use constant TESTDEF_INTEGRATION => 'integration';
|
|
|
|
push @EXPORT, qw(TESTDEF_INTEGRATION);
|
|
|
|
use constant TESTDEF_PERFORMANCE => 'performance';
|
|
|
|
push @EXPORT, qw(TESTDEF_PERFORMANCE);
|
|
|
|
use constant TESTDEF_UNIT => 'unit';
|
|
|
|
push @EXPORT, qw(TESTDEF_UNIT);
|
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
use constant TESTDEF_MODULE => 'module';
|
|
|
|
push @EXPORT, qw(TESTDEF_MODULE);
|
2017-04-10 18:31:30 +02:00
|
|
|
use constant TESTDEF_NAME => 'name';
|
|
|
|
push @EXPORT, qw(TESTDEF_NAME);
|
2016-06-24 14:12:58 +02:00
|
|
|
use constant TESTDEF_TEST => 'test';
|
|
|
|
push @EXPORT, qw(TESTDEF_TEST);
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
use constant TESTDEF_DB => 'db';
|
|
|
|
push @EXPORT, qw(TESTDEF_DB);
|
|
|
|
use constant TESTDEF_CONTAINER => 'container';
|
|
|
|
push @EXPORT, qw(TESTDEF_CONTAINER);
|
2019-10-08 18:06:30 +02:00
|
|
|
use constant TESTDEF_CONTAINER_REQUIRED => 'containerReq';
|
|
|
|
push @EXPORT, qw(TESTDEF_CONTAINER_REQUIRED);
|
2017-04-10 18:31:30 +02:00
|
|
|
use constant TESTDEF_COVERAGE => 'coverage';
|
|
|
|
push @EXPORT, qw(TESTDEF_COVERAGE);
|
2017-10-12 18:55:48 +02:00
|
|
|
use constant TESTDEF_C => 'c';
|
|
|
|
push @EXPORT, qw(TESTDEF_C);
|
2019-07-26 02:15:06 +02:00
|
|
|
use constant TESTDEF_INCLUDE => 'include';
|
|
|
|
push @EXPORT, qw(TESTDEF_INCLUDE);
|
2017-04-10 18:31:30 +02:00
|
|
|
use constant TESTDEF_INDIVIDUAL => 'individual';
|
|
|
|
push @EXPORT, qw(TESTDEF_INDIVIDUAL);
|
|
|
|
use constant TESTDEF_TOTAL => 'total';
|
|
|
|
push @EXPORT, qw(TESTDEF_TOTAL);
|
2019-09-28 20:02:12 +02:00
|
|
|
use constant TESTDEF_TYPE => 'type';
|
|
|
|
push @EXPORT, qw(TESTDEF_TYPE);
|
2019-12-14 00:55:41 +02:00
|
|
|
use constant TESTDEF_BIN_REQ => 'binReq';
|
|
|
|
push @EXPORT, qw(TESTDEF_BIN_REQ);
|
2017-06-12 16:52:32 +02:00
|
|
|
use constant TESTDEF_VM => 'vm';
|
|
|
|
push @EXPORT, qw(TESTDEF_VM);
|
2017-04-10 18:31:30 +02:00
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
use constant TESTDEF_COVERAGE_FULL => 'full';
|
2017-01-10 03:49:04 +02:00
|
|
|
push @EXPORT, qw(TESTDEF_COVERAGE_FULL);
|
2018-04-08 16:19:24 +02:00
|
|
|
use constant TESTDEF_COVERAGE_NOCODE => 'noCode';
|
2017-10-12 18:55:48 +02:00
|
|
|
push @EXPORT, qw(TESTDEF_COVERAGE_NOCODE);
|
2017-01-10 03:49:04 +02:00
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Process normalized data into a more queryable form
|
|
|
|
####################################################################################################################################
|
|
|
|
my $hTestDefHash; # An easier way to query hash version of the above
|
|
|
|
my @stryModule; # Ordered list of modules
|
|
|
|
my $hModuleTest; # Ordered list of tests for each module
|
|
|
|
my $hCoverageType; # Coverage type for each code module (full/partial)
|
|
|
|
my $hCoverageList; # Tests required for full code module coverage (if type full)
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
sub testDefLoad
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2018-04-08 16:19:24 +02:00
|
|
|
my $strDefineYaml = shift;
|
2017-05-12 22:43:04 +02:00
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
# Load test definitions from yaml
|
2021-03-08 23:01:05 +02:00
|
|
|
require YAML::XS;
|
|
|
|
YAML::XS->import(qw(Load));
|
2018-01-16 20:52:20 +02:00
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
my $hTestDef = Load($strDefineYaml);
|
2017-10-16 16:09:56 +02:00
|
|
|
|
2021-01-27 17:57:42 +02:00
|
|
|
# Keep a list of all harnesses added so far. These will make up the harness list for subsequent tests.
|
2021-05-21 00:47:31 +02:00
|
|
|
my @rhyHarnessFile = ();
|
2021-01-27 17:57:42 +02:00
|
|
|
|
|
|
|
# Keep a list of all modules added for coverage so far. These will make up the core list for subsequent tests.
|
|
|
|
my @stryCoreFile = ();
|
|
|
|
|
|
|
|
# Keep a list of modules that are test before this one so we know what is available
|
|
|
|
my $strTestDefine = '';
|
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Iterate each test type
|
|
|
|
foreach my $strModuleType (TESTDEF_UNIT, TESTDEF_INTEGRATION, TESTDEF_PERFORMANCE)
|
2018-04-08 16:19:24 +02:00
|
|
|
{
|
2018-04-24 15:12:25 +02:00
|
|
|
my $hModuleType = $hTestDef->{$strModuleType};
|
2017-10-16 17:03:06 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
my $bContainer = true; # By default run tests in a single container
|
2019-08-26 18:05:36 +02:00
|
|
|
my $bIndividual = false; # By default runs are all executed in the same container
|
2017-10-16 17:03:06 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
if ($strModuleType eq TESTDEF_INTEGRATION)
|
2017-11-27 01:43:51 +02:00
|
|
|
{
|
2018-04-24 15:12:25 +02:00
|
|
|
$bContainer = false; # Integration tests can run in multiple containers
|
|
|
|
$bIndividual = true; # Integration tests can change containers on each run
|
|
|
|
}
|
2018-01-23 20:34:24 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Iterate each module
|
|
|
|
foreach my $hModule (@{$hModuleType})
|
|
|
|
{
|
|
|
|
# Push the module onto the ordered list
|
|
|
|
my $strModule = $hModule->{&TESTDEF_NAME};
|
|
|
|
push(@stryModule, $strModule);
|
2017-11-17 00:18:51 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Iterate each test
|
|
|
|
my @stryModuleTest;
|
2017-01-05 01:31:16 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
foreach my $hModuleTest (@{$hModule->{&TESTDEF_TEST}})
|
2017-04-05 16:16:16 +02:00
|
|
|
{
|
2018-04-24 15:12:25 +02:00
|
|
|
# Push the test on the order list
|
|
|
|
my $strTest = $hModuleTest->{&TESTDEF_NAME};
|
|
|
|
push(@stryModuleTest, $strTest);
|
2017-01-05 01:31:16 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Resolve variables that can be set in the module or the test
|
2018-11-03 22:34:04 +02:00
|
|
|
foreach my $strVar (
|
2022-07-29 16:31:36 +02:00
|
|
|
TESTDEF_DB, TESTDEF_BIN_REQ, TESTDEF_VM, TESTDEF_CONTAINER_REQUIRED)
|
2017-11-28 18:44:24 +02:00
|
|
|
{
|
2018-04-24 15:12:25 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce(
|
|
|
|
$hModuleTest->{$strVar}, $hModule->{$strVar}, $strVar eq TESTDEF_VM ? undef : false);
|
|
|
|
|
|
|
|
# Make false = 0 for debugging
|
|
|
|
if ($strVar ne TESTDEF_VM && $hTestDefHash->{$strModule}{$strTest}{$strVar} eq '')
|
2017-11-28 18:44:24 +02:00
|
|
|
{
|
2018-04-24 15:12:25 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{$strVar} = false;
|
2018-04-08 16:19:24 +02:00
|
|
|
}
|
2018-04-24 15:12:25 +02:00
|
|
|
}
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Set module type variables
|
2019-09-28 20:02:12 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_TYPE} = $strModuleType;
|
2018-04-24 15:12:25 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_C} =
|
2019-09-28 19:17:21 +02:00
|
|
|
$strModuleType ne TESTDEF_INTEGRATION && $strTest !~ /perl$/ ? true : false;
|
2018-05-22 18:53:08 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INTEGRATION} = $strModuleType eq TESTDEF_INTEGRATION ? true : false;
|
2018-04-24 15:12:25 +02:00
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer;
|
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INDIVIDUAL} = $bIndividual;
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
# Set test count
|
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_TOTAL} = $hModuleTest->{&TESTDEF_TOTAL};
|
|
|
|
|
|
|
|
# If this is a C test then add the test module to coverage
|
|
|
|
if ($hModuleTest->{&TESTDEF_C})
|
|
|
|
{
|
|
|
|
my $strTestFile = "module/${strModule}/${strTest}Test";
|
|
|
|
|
|
|
|
$hModuleTest->{&TESTDEF_COVERAGE}{$strTestFile} = TESTDEF_COVERAGE_FULL;
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:56:51 +02:00
|
|
|
# Concatenate coverage for tests
|
|
|
|
foreach my $xCodeModule (@{$hModuleTest->{&TESTDEF_COVERAGE}})
|
2018-04-24 15:12:25 +02:00
|
|
|
{
|
2021-01-15 17:56:51 +02:00
|
|
|
my $strCodeModule = undef;
|
|
|
|
my $strCoverage = undef;
|
|
|
|
|
|
|
|
if (ref($xCodeModule))
|
|
|
|
{
|
|
|
|
$strCodeModule = (keys(%{$xCodeModule}))[0];
|
|
|
|
$strCoverage = $xCodeModule->{$strCodeModule};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strCodeModule = $xCodeModule;
|
|
|
|
$strCoverage = TESTDEF_COVERAGE_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_COVERAGE}{$strCodeModule} = $strCoverage;
|
|
|
|
|
|
|
|
# Build coverage type hash and make sure coverage type does not change
|
|
|
|
if (!defined($hCoverageType->{$strCodeModule}))
|
2018-04-08 16:19:24 +02:00
|
|
|
{
|
2021-01-15 17:56:51 +02:00
|
|
|
$hCoverageType->{$strCodeModule} = $strCoverage;
|
2018-04-08 16:19:24 +02:00
|
|
|
}
|
2021-01-15 17:56:51 +02:00
|
|
|
elsif ($hCoverageType->{$strCodeModule} ne $strCoverage)
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "cannot mix coverage types for ${strCodeModule}");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add to coverage list
|
|
|
|
push(@{$hCoverageList->{$strCodeModule}}, {strModule=> $strModule, strTest => $strTest});
|
2021-01-27 17:57:42 +02:00
|
|
|
|
|
|
|
# Check if this module is already in the core list
|
|
|
|
if (!$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INTEGRATION} && !grep(/^$strCodeModule$/i, @stryCoreFile))
|
|
|
|
{
|
|
|
|
push(@stryCoreFile, $strCodeModule);
|
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
2019-07-26 02:15:06 +02:00
|
|
|
|
|
|
|
# Set include list
|
2021-01-27 17:57:42 +02:00
|
|
|
@{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE}} = ();
|
|
|
|
|
|
|
|
if (defined($hModuleTest->{&TESTDEF_INCLUDE}))
|
|
|
|
{
|
|
|
|
push(@{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE}}, @{$hModuleTest->{&TESTDEF_INCLUDE}});
|
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 15:12:25 +02:00
|
|
|
$hModuleTest->{$strModule} = \@stryModuleTest;
|
|
|
|
}
|
2018-04-08 16:19:24 +02:00
|
|
|
}
|
2017-04-10 18:31:30 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 16:19:24 +02:00
|
|
|
push @EXPORT, qw(testDefLoad);
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# testDefModuleList
|
2016-06-24 14:12:58 +02:00
|
|
|
####################################################################################################################################
|
2017-04-10 18:31:30 +02:00
|
|
|
sub testDefModuleList
|
2016-06-24 14:12:58 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
return @stryModule;
|
2016-06-24 14:12:58 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
push @EXPORT, qw(testDefModuleList);
|
2016-06-24 14:12:58 +02:00
|
|
|
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-04-10 18:31:30 +02:00
|
|
|
# testDefModule
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-04-10 18:31:30 +02:00
|
|
|
sub testDefModule
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
|
|
|
my $strModule = shift;
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if (!defined($hTestDefHash->{$strModule}))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
confess &log(ASSERT, "unable to find module ${strModule}");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hTestDefHash->{$strModule};
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(testDefModule);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# testDefModuleTestList
|
|
|
|
####################################################################################################################################
|
|
|
|
sub testDefModuleTestList
|
|
|
|
{
|
|
|
|
my $strModule = shift;
|
|
|
|
|
|
|
|
if (!defined($hModuleTest->{$strModule}))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "unable to find module ${strModule}");
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
return @{$hModuleTest->{$strModule}};
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
push @EXPORT, qw(testDefModuleTestList);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2017-04-10 18:31:30 +02:00
|
|
|
# testDefModuleTest
|
2016-12-23 15:22:59 +02:00
|
|
|
####################################################################################################################################
|
2017-04-10 18:31:30 +02:00
|
|
|
sub testDefModuleTest
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
my $strModule = shift;
|
2016-12-23 15:22:59 +02:00
|
|
|
my $strModuleTest = shift;
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
if (!defined($hTestDefHash->{$strModule}{$strModuleTest}))
|
2016-12-23 15:22:59 +02:00
|
|
|
{
|
2017-04-10 18:31:30 +02:00
|
|
|
confess &log(ASSERT, "unable to find module ${strModule}, test ${strModuleTest}");
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
return $hTestDefHash->{$strModule}{$strModuleTest};
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(testDefModuleTest);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# testDefCoverageType
|
|
|
|
####################################################################################################################################
|
|
|
|
sub testDefCoverageType
|
|
|
|
{
|
|
|
|
return $hCoverageType;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(testDefCoverageType);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# testDefCoverageList
|
|
|
|
####################################################################################################################################
|
|
|
|
sub testDefCoverageList
|
|
|
|
{
|
|
|
|
return $hCoverageList;
|
2016-12-23 15:22:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:31:30 +02:00
|
|
|
push @EXPORT, qw(testDefCoverageList);
|
2016-12-23 15:22:59 +02:00
|
|
|
|
2016-06-24 14:12:58 +02:00
|
|
|
1;
|