From f8b0676fd6edbe915bc23d2f082b4862004ca151 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 25 Jul 2019 20:15:06 -0400 Subject: [PATCH] Allow modules to be included for testing without requiring coverage. Sometimes it is useful to get at the internals of a module that is not being tested for coverage in order to provide coverage for another module that is being tested. The include directive allows this. Update modules that had previously been added to coverage that only need to be included. --- test/define.yaml | 16 ++++++++++++---- test/lib/pgBackRestTest/Common/DefineTest.pm | 5 +++++ test/lib/pgBackRestTest/Common/JobTest.pm | 6 ++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/test/define.yaml b/test/define.yaml index 8755973fe..1d164401d 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -21,6 +21,8 @@ # Some options are unique to tests: # * total - total runs in the test # * vm - VMs that the test will be run on +# * include - modules to include directly into test.c (all files in coverage are automatically included) +# This is useful when a module's internal data needs to be manipulated for testing but no coverage is added by the test. # ********************************************************************************************************************************** # ********************************************************************************************************************************** @@ -427,7 +429,9 @@ unit: storage/cifs/storage: full storage/posix/storage: full storage/helper: full - storage/storage: full + + include: + - storage/storage # ---------------------------------------------------------------------------------------------------------------------------- - name: posix @@ -453,10 +457,12 @@ unit: storage/remote/storage: full storage/remote/write: full storage/helper: full - storage/read: full - storage/write: full storage/storage: full + include: + - storage/read + - storage/write + # ---------------------------------------------------------------------------------------------------------------------------- - name: s3 total: 3 @@ -587,7 +593,9 @@ unit: coverage: command/backup/file: full command/backup/protocol: full - storage/storage: full + + include: + - storage/storage # ---------------------------------------------------------------------------------------------------------------------------- - name: command diff --git a/test/lib/pgBackRestTest/Common/DefineTest.pm b/test/lib/pgBackRestTest/Common/DefineTest.pm index f7ec75b5d..9eb3fa667 100644 --- a/test/lib/pgBackRestTest/Common/DefineTest.pm +++ b/test/lib/pgBackRestTest/Common/DefineTest.pm @@ -53,6 +53,8 @@ use constant TESTDEF_DEFINE_TEST => 'define-t push @EXPORT, qw(TESTDEF_DEFINE_TEST); use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress'; push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS); +use constant TESTDEF_INCLUDE => 'include'; + push @EXPORT, qw(TESTDEF_INCLUDE); use constant TESTDEF_INDIVIDUAL => 'individual'; push @EXPORT, qw(TESTDEF_INDIVIDUAL); use constant TESTDEF_TOTAL => 'total'; @@ -180,6 +182,9 @@ sub testDefLoad push(@{$hCoverageList->{$strCodeModule}}, {strModule=> $strModule, strTest => $strTest}); } } + + # Set include list + $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE} = $hModuleTest->{&TESTDEF_INCLUDE}; } $hModuleTest->{$strModule} = \@stryModuleTest; diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index 1aa9e7deb..42eb4cd91 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -291,6 +291,8 @@ sub run foreach my $strFile (sort(keys(%{$self->{oStorageTest}->manifest($self->{strGCovPath})}))) { + my $strFileNoExt = substr($strFile, 0, length($strFile) - 2); + # Skip all files except .c files (including .auto.c) next if $strFile !~ /(?{substr($strFile, 0, length($strFile) - 2)}) && + if (!defined($hTestCoverage->{$strFileNoExt}) && !grep(/^$strFileNoExt$/, @{$hTest->{&TESTDEF_INCLUDE}}) && $strFile !~ /^test\/module\/[^\/]*\/.*Test\.c$/) { push(@stryCFile, "${strFile}"); @@ -313,7 +315,7 @@ sub run "test/module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test.c'; my $strCInclude; - foreach my $strFile (sort(keys(%{$hTestCoverage}))) + foreach my $strFile (sort(keys(%{$hTestCoverage}), @{$hTest->{&TESTDEF_INCLUDE}})) { # Don't include the test file as it is already included below next if $strFile =~ /Test$/;