You've already forked pgbackrest
							
							
				mirror of
				https://github.com/pgbackrest/pgbackrest.git
				synced 2025-10-30 23:37:45 +02:00 
			
		
		
		
	Move coverage code to CoverageTest module.
This code needs some work, which will be easier if it is all in one place.
This commit is contained in:
		| @@ -610,134 +610,10 @@ sub end | ||||
|         # If C code generate coverage info | ||||
|         if ($iExitStatus == 0 && $self->{oTest}->{&TEST_C} && vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit}) | ||||
|         { | ||||
|             # Generate a list of files to cover | ||||
|             my $hTestCoverage = | ||||
|                 (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME}))->{&TESTDEF_COVERAGE}; | ||||
|  | ||||
|             my @stryCoveredModule; | ||||
|  | ||||
|             foreach my $strModule (sort(keys(%{$hTestCoverage}))) | ||||
|             { | ||||
|                 push (@stryCoveredModule, $strModule); | ||||
|             } | ||||
|  | ||||
|             push( | ||||
|                 @stryCoveredModule, | ||||
|                 "module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test'); | ||||
|  | ||||
|             # Generate coverage reports for the modules | ||||
|             my $strLCovConf = $self->{strBackRestBase} . '/test/result/coverage/raw/lcov.conf'; | ||||
|             coverageLCovConfigGenerate($self->{oStorageTest}, $strLCovConf, $self->{bCoverageSummary}); | ||||
|  | ||||
|             my $strLCovExeBase = "lcov --config-file=${strLCovConf}"; | ||||
|             my $strLCovOut = $self->{strGCovPath} . '/test.lcov'; | ||||
|             my $strLCovOutTmp = $self->{strGCovPath} . '/test.tmp.lcov'; | ||||
|  | ||||
|             executeTest( | ||||
|                 ($self->{oTest}->{&TEST_VM} ne VM_NONE  ? 'docker exec -i -u ' . TEST_USER . " ${strImage} " : '') . | ||||
|                 "${strLCovExeBase} --capture --directory=$self->{strGCovPath} --o=${strLCovOut}"); | ||||
|  | ||||
|             # Generate coverage report for each module | ||||
|             foreach my $strModule (@stryCoveredModule) | ||||
|             { | ||||
|                 my $strModuleName = testRunName($strModule, false); | ||||
|                 my $strModuleOutName = $strModuleName; | ||||
|                 my $bTest = false; | ||||
|  | ||||
|                 if ($strModuleOutName =~ /^module/mg) | ||||
|                 { | ||||
|                     $strModuleOutName =~ s/^module/test/mg; | ||||
|                     $bTest = true; | ||||
|                 } | ||||
|  | ||||
|                 # Disable branch coverage for test files | ||||
|                 my $strLCovExe = $strLCovExeBase; | ||||
|  | ||||
|                 if ($bTest) | ||||
|                 { | ||||
|                     $strLCovExe .= ' --rc lcov_branch_coverage=0'; | ||||
|                 } | ||||
|  | ||||
|                 # Generate lcov reports | ||||
|                 my $strModulePath = | ||||
|                     $self->{strTestPath} . "/repo/" . | ||||
|                     (${strModuleOutName} =~ /^test\// ? | ||||
|                         'test/src/module/' . substr(${strModuleOutName}, 5) : "src/${strModuleOutName}"); | ||||
|                 my $strLCovFile = $self->{strBackRestBase} . "/test/result/coverage/raw/${strModuleOutName}.lcov"; | ||||
|                 my $strLCovTotal = $self->{strTestPath} . "/temp/all.lcov"; | ||||
|  | ||||
|                 executeTest( | ||||
|                     "${strLCovExe} --extract=${strLCovOut} */${strModuleName}.c --o=${strLCovOutTmp}"); | ||||
|  | ||||
|                 # Combine with prior run if there was one | ||||
|                 if ($self->{oStorageTest}->exists($strLCovFile)) | ||||
|                 { | ||||
|                     my $strCoverage = ${$self->{oStorageTest}->get($strLCovOutTmp)}; | ||||
|                     $strCoverage =~ s/^SF\:.*$/SF:$strModulePath\.c/mg; | ||||
|                     $self->{oStorageTest}->put($strLCovOutTmp, $strCoverage); | ||||
|  | ||||
|                     executeTest( | ||||
|                         "${strLCovExe} --add-tracefile=${strLCovOutTmp} --add-tracefile=${strLCovFile} --o=${strLCovOutTmp}"); | ||||
|                 } | ||||
|  | ||||
|                 # Update source file | ||||
|                 my $strCoverage = ${$self->{oStorageTest}->get($strLCovOutTmp)}; | ||||
|  | ||||
|                 if (defined($strCoverage)) | ||||
|                 { | ||||
|                     if (!$bTest && $hTestCoverage->{$strModule} eq TESTDEF_COVERAGE_NOCODE) | ||||
|                     { | ||||
|                         confess &log(ERROR, "module '${strModule}' is marked 'no code' but has code"); | ||||
|                     } | ||||
|  | ||||
|                     # Get coverage info | ||||
|                     my $iTotalLines = (split(':', ($strCoverage =~ m/^LF:.*$/mg)[0]))[1] + 0; | ||||
|                     my $iCoveredLines = (split(':', ($strCoverage =~ m/^LH:.*$/mg)[0]))[1] + 0; | ||||
|  | ||||
|                     my $iTotalBranches = 0; | ||||
|                     my $iCoveredBranches = 0; | ||||
|  | ||||
|                     if ($strCoverage =~ /^BRF\:/mg && $strCoverage =~ /^BRH\:/mg) | ||||
|                     { | ||||
|                         # If this isn't here the statements below fail -- huh? | ||||
|                         my @match = $strCoverage =~ m/^BRF\:.*$/mg; | ||||
|  | ||||
|                         $iTotalBranches = (split(':', ($strCoverage =~ m/^BRF:.*$/mg)[0]))[1] + 0; | ||||
|                         $iCoveredBranches = (split(':', ($strCoverage =~ m/^BRH:.*$/mg)[0]))[1] + 0; | ||||
|                     } | ||||
|  | ||||
|                     # Report coverage if this is not a test or if the test does not have complete coverage | ||||
|                     if (!$bTest || $iTotalLines != $iCoveredLines || $iTotalBranches != $iCoveredBranches) | ||||
|                     { | ||||
|                         # Fix source file name | ||||
|                         $strCoverage =~ s/^SF\:.*$/SF:$strModulePath\.c/mg; | ||||
|  | ||||
|                         $self->{oStorageTest}->put( | ||||
|                             $self->{oStorageTest}->openWrite($strLCovFile, {bPathCreate => true}), $strCoverage); | ||||
|  | ||||
|                         if ($self->{oStorageTest}->exists($strLCovTotal)) | ||||
|                         { | ||||
|                             executeTest( | ||||
|                                 "${strLCovExe} --add-tracefile=${strLCovFile} --add-tracefile=${strLCovTotal} --o=${strLCovTotal}"); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             $self->{oStorageTest}->copy($strLCovFile, $strLCovTotal) | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         $self->{oStorageTest}->remove($strLCovFile); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     if ($hTestCoverage->{$strModule} ne TESTDEF_COVERAGE_NOCODE) | ||||
|                     { | ||||
|                         confess &log(ERROR, "module '${strModule}' is marked 'code' but has no code"); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             coverageExtract( | ||||
|                 $self->{oStorageTest}, $self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME}, $self->{bCoverageSummary}, | ||||
|                 $self->{oTest}->{&TEST_VM} eq VM_NONE ? undef : $strImage, $self->{strTestPath}, "$self->{strTestPath}/temp", | ||||
|                 $self->{strGCovPath}, $self->{strBackRestBase} . '/test/result'); | ||||
|         } | ||||
|  | ||||
|         # Record elapsed time | ||||
|   | ||||
		Reference in New Issue
	
	Block a user