From e3d63c0252bfbd0cccb746d405c7e3cdeb8f75c1 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 4 Jan 2017 18:29:13 -0500 Subject: [PATCH] Allow multiple --module, --test, and --run options to be used for test.pl. --- doc/xml/release.xml | 4 +++ test/lib/pgBackRestTest/Common/ListTest.pm | 30 ++++++++-------- test/lib/pgBackRestTest/Common/RunTest.pm | 5 ++- test/test.pl | 41 ++++++++++++++-------- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 5266a21fb..822129140 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -206,6 +206,10 @@

Split test modules into separate files to make the code more maintainable. Tests are dynamically loaded by name rather than requiring an if-else block.

+ +

Allow multiple --module, --test, and --run options to be used for test.pl.

+
+

Added expect log expression to replace year subdirectories in backup.history.

diff --git a/test/lib/pgBackRestTest/Common/ListTest.pm b/test/lib/pgBackRestTest/Common/ListTest.pm index d585975b5..f0df92593 100644 --- a/test/lib/pgBackRestTest/Common/ListTest.pm +++ b/test/lib/pgBackRestTest/Common/ListTest.pm @@ -46,9 +46,9 @@ use constant TEST_PERL_ARCH_PATH => VMDEF_PER sub testListGet { my $strVm = shift; - my $strModule = shift; - my $strModuleTest = shift; - my $iModuleTestRun = shift; + my $stryModule = shift; + my $stryModuleTest = shift; + my $iyModuleTestRun = shift; my $strDbVersion = shift; my $iProcessMax = shift; @@ -76,11 +76,11 @@ sub testListGet { foreach my $oModule (@{$$oTestDef{&TESTDEF_MODULE}}) { - if ($strModule eq $$oModule{&TESTDEF_MODULE_NAME} || $strModule eq 'all') + if (@{$stryModule} == 0 || grep(/^$$oModule{&TESTDEF_MODULE_NAME}$/i, @{$stryModule})) { foreach my $oTest (@{$$oModule{test}}) { - if ($strModuleTest eq $$oTest{&TESTDEF_TEST_NAME} || $strModuleTest eq 'all') + if (@{$stryModuleTest} == 0 || grep(/^$$oTest{&TESTDEF_TEST_NAME}$/i, @{$stryModuleTest})) { my $iDbVersionMin = -1; my $iDbVersionMax = -1; @@ -112,18 +112,16 @@ sub testListGet my $bTestIndividual = !defined($$oTest{&TESTDEF_TEST_INDIVIDUAL}) || $$oTest{&TESTDEF_TEST_INDIVIDUAL} ? true : false; - my $iTestRunMin = defined($iModuleTestRun) ? $iModuleTestRun : ($bTestIndividual ? 1 : -1); - my $iTestRunMax = - defined($iModuleTestRun) ? $iModuleTestRun : - ($bTestIndividual ? $$oTest{&TESTDEF_TEST_TOTAL} : -1); - - if (defined($$oTest{total}) && $iTestRunMax > $$oTest{total}) - { - confess &log(ERROR, "invalid run - must be >= 1 and <= $$oTest{total}") - } + my $iTestRunMin = $bTestIndividual ? 1 : -1; + my $iTestRunMax = $bTestIndividual ? $$oTest{&TESTDEF_TEST_TOTAL} : -1; for (my $iTestRunIdx = $iTestRunMin; $iTestRunIdx <= $iTestRunMax; $iTestRunIdx++) { + # Skip this run if a list was provided and this test is not in the list + next if ( + $bTestIndividual && @{$iyModuleTestRun} != 0 && + !grep(/^$iTestRunIdx$/i, @{$iyModuleTestRun})); + my $iyProcessMax = [defined($iProcessMax) ? $iProcessMax : 1]; if (defined($$oTest{&TESTDEF_TEST_PROCESS}) && $$oTest{&TESTDEF_TEST_PROCESS} && @@ -156,7 +154,9 @@ sub testListGet &TEST_PERL_ARCH_PATH => $$oyVm{$strTestOS}{&VMDEF_PERL_ARCH_PATH}, &TEST_MODULE => $$oModule{&TESTDEF_MODULE_NAME}, &TEST_NAME => $$oTest{&TESTDEF_TEST_NAME}, - &TEST_RUN => $iTestRunIdx == -1 ? undef : $iTestRunIdx, + &TEST_RUN => + $iTestRunIdx == -1 ? (@{$iyModuleTestRun} == 0 ? undef : $iyModuleTestRun) : + [$iTestRunIdx], &TEST_PROCESS => $iProcessTestMax, &TEST_DB => $strDbVersion }; diff --git a/test/lib/pgBackRestTest/Common/RunTest.pm b/test/lib/pgBackRestTest/Common/RunTest.pm index 0518cd92f..a7be64193 100644 --- a/test/lib/pgBackRestTest/Common/RunTest.pm +++ b/test/lib/pgBackRestTest/Common/RunTest.pm @@ -91,7 +91,7 @@ sub process $self->{strPgVersion}, $self->{strModule}, $self->{strModuleTest}, - $self->{iModuleTestRun}, + $self->{iyModuleTestRun}, $self->{iProcessMax}, $self->{bOutput}, $self->{bDryRun}, @@ -193,7 +193,7 @@ sub begin $self->{iRun}++; # Return if this test should not be run - if (defined($self->moduleTestRun()) && $self->moduleTestRun() != $self->runCurrent()) + if (@{$self->{iyModuleTestRun}} != 0 && !grep(/^$self->{iRun}$/i, @{$self->{iyModuleTestRun}})) { return false; } @@ -379,7 +379,6 @@ sub isDryRun {return shift->{bDryRun}} sub expect {return shift->{oExpect}} sub module {return shift->{strModule}} sub moduleTest {return shift->{strModuleTest}} -sub moduleTestRun {return shift->{iModuleTestRun}} sub pgBinPath {return shift->{strPgBinPath}} sub pgUser {return shift->{strPgUser}} sub pgVersion {return shift->{strPgVersion}} diff --git a/test/test.pl b/test/test.pl index 7dca09f23..8f9e97444 100755 --- a/test/test.pl +++ b/test/test.pl @@ -91,9 +91,9 @@ test.pl [options] #################################################################################################################################### my $strLogLevel = 'info'; my $bVmOut = false; -my $strModule = 'all'; -my $strModuleTest = 'all'; -my $iModuleTestRun = undef; +my @stryModule; +my @stryModuleTest; +my @iyModuleTestRun; my $iProcessMax = undef; my $iVmMax = 1; my $iVmId = undef; @@ -122,9 +122,9 @@ GetOptions ('q|quiet' => \$bQuiet, 'vm-out' => \$bVmOut, 'vm-build' => \$bVmBuild, 'vm-force' => \$bVmForce, - 'module=s' => \$strModule, - 'test=s' => \$strModuleTest, - 'run=s' => \$iModuleTestRun, + 'module=s@' => \@stryModule, + 'test=s@' => \@stryModuleTest, + 'run=s@' => \@iyModuleTestRun, 'process-max=s' => \$iProcessMax, 'vm-id=s' => \$iVmId, 'vm-max=s' => \$iVmMax, @@ -175,14 +175,14 @@ eval logLevelSet(uc($strLogLevel), uc($strLogLevel), OFF); - if ($strModuleTest ne 'all' && $strModule eq 'all') + if (@stryModuleTest != 0 && @stryModule != 1) { - confess "--module must be provided for --test=\"${strModuleTest}\""; + confess "Only one --module can be provided when --test is specified"; } - if (defined($iModuleTestRun) && $strModuleTest eq 'all') + if (@iyModuleTestRun != 0 && @stryModuleTest != 1) { - confess "--test must be provided for --run=\"${iModuleTestRun}\""; + confess "Only one --test can be provided when --run is specified"; } # Check process total @@ -267,6 +267,7 @@ eval # Build the C Library in host #----------------------------------------------------------------------------------------------------------------------- + if (!$bDryRun) { my $bLogDetail = $strLogLevel eq 'detail'; my $strBuildPath = "${strBackRestBase}/test/.vagrant/libc/host"; @@ -309,7 +310,7 @@ eval # Determine which tests to run #----------------------------------------------------------------------------------------------------------------------- - my $oyTestRun = testListGet($strVm, $strModule, $strModuleTest, $iModuleTestRun, $strDbVersion, $iProcessMax); + my $oyTestRun = testListGet($strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strDbVersion, $iProcessMax); if (@{$oyTestRun} == 0) { @@ -343,6 +344,7 @@ eval # Build the C Library in container #----------------------------------------------------------------------------------------------------------------------- + if (!$bDryRun) { my $bLogDetail = $strLogLevel eq 'detail'; my @stryBuildVm = $strVm eq 'all' ? (VM_CO6, VM_U16, VM_D8, VM_CO7, VM_U14, VM_U12) : ($strVm); @@ -463,7 +465,7 @@ eval 'vm=' . $$oTest{&TEST_VM} . ', module=' . $$oTest{&TEST_MODULE} . ', test=' . $$oTest{&TEST_NAME} . - (defined($$oTest{&TEST_RUN}) ? ', run=' . $$oTest{&TEST_RUN} : '') . + (defined($$oTest{&TEST_RUN}) ? ', run=' . join(',', @{$$oTest{&TEST_RUN}}) : '') . (defined($$oTest{&TEST_PROCESS}) ? ', process-max=' . $$oTest{&TEST_PROCESS} : '') . (defined($$oTest{&TEST_DB}) ? ', db=' . $$oTest{&TEST_DB} : ''); @@ -494,6 +496,15 @@ eval } } + # Create run parameters + my $strCommandRunParam = ''; + + foreach my $iRunIdx (@{$$oTest{&TEST_RUN}}) + { + $strCommandRunParam .= ' --run=' . $iRunIdx; + } + + # Create command my $strCommand = ($$oTest{&TEST_CONTAINER} ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') . abs_path($0) . " --test-path=${strVmTestPath}" . @@ -501,7 +512,7 @@ eval " --vm-id=${iVmIdx}" . " --module=" . $$oTest{&TEST_MODULE} . ' --test=' . $$oTest{&TEST_NAME} . - (defined($$oTest{&TEST_RUN}) ? ' --run=' . $$oTest{&TEST_RUN} : '') . + $strCommandRunParam . (defined($$oTest{&TEST_DB}) ? ' --db-version=' . $$oTest{&TEST_DB} : '') . (defined($$oTest{&TEST_PROCESS}) ? ' --process-max=' . $$oTest{&TEST_PROCESS} : '') . ($strLogLevel ne lc(INFO) ? " --log-level=${strLogLevel}" : '') . @@ -572,14 +583,14 @@ eval my $oHostGroup = hostGroupGet(); # Run the test - testRun($strModule, $strModuleTest)->process( + testRun($stryModule[0], $stryModuleTest[0])->process( $strVm, $iVmId, # Vm info $strBackRestBase, # Base backrest directory $strTestPath, # Path where the tests will run "${strBackRestBase}/bin/" . BACKREST_EXE, # Path to the backrest executable $strDbVersion ne 'minimal' ? $strPgSqlBin: undef, # Db bin path $strDbVersion ne 'minimal' ? $strDbVersion: undef, # Db version - $strModule, $strModuleTest, $iModuleTestRun, # Module info + $stryModule[0], $stryModuleTest[0], \@iyModuleTestRun, # Module info $iProcessMax, $bVmOut, $bDryRun, $bNoCleanup, $bLogForce, # Test options TEST_USER, BACKREST_USER, TEST_GROUP); # User/group info