1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-11-06 08:49:29 +02:00

Output coverage report on test failure in CI.

This allows analysis of coverage failures that only happen in CI. It is not ideal since the report needs to be copied from the log output into an HTML file where it can be viewed, but better than nothing.
This commit is contained in:
David Steele
2023-11-29 09:31:57 -03:00
parent cb6bceb9f1
commit a14732789b
3 changed files with 33 additions and 13 deletions

View File

@@ -64,6 +64,13 @@ jobs:
- name: Run Test - name: Run Test
run: cd ${HOME?} && ${GITHUB_WORKSPACE?}/pgbackrest/test/ci.pl ${{matrix.param}} --param=build-max=2 run: cd ${HOME?} && ${GITHUB_WORKSPACE?}/pgbackrest/test/ci.pl ${{matrix.param}} --param=build-max=2
# Output the coverage report on failure in case the failure was caused by lack of coverage. This is not ideal since the report
# needs to be copied from the log output into an HTML file where it can be viewed, but better than nothing.
- name: Coverage Report
if: failure()
run: |
cat ${GITHUB_WORKSPACE?}/pgbackrest/test/result/coverage/coverage.html
# Basic tests on other architectures using emulation. The emulation is so slow that running all the unit tests would be too # Basic tests on other architectures using emulation. The emulation is so slow that running all the unit tests would be too
# expensive, but this at least shows that the build works and some of the more complex tests run. In particular, it is good to # expensive, but this at least shows that the build works and some of the more complex tests run. In particular, it is good to
# test on one big-endian architecture to be sure that checksums are correct. # test on one big-endian architecture to be sure that checksums are correct.

View File

@@ -372,17 +372,29 @@ sub coverageValidateAndGenerate
&log(INFO, "tested modules have full coverage"); &log(INFO, "tested modules have full coverage");
} }
if ($bCoverageReport) # Always generate unified coverage report if there was missing coverage. This is useful for CI.
if ($bCoverageReport || $result != 0)
{ {
&log(INFO, 'writing C coverage report'); &log(INFO, 'writing C coverage report');
executeTest( if ($bCoverageReport)
"genhtml ${strLCovFile} --config-file=${strTestResultCoveragePath}/raw/lcov.conf" . {
" --prefix=${strWorkPath}/repo" . executeTest(
" --output-directory=${strTestResultCoveragePath}/lcov"); "genhtml ${strLCovFile} --config-file=${strTestResultCoveragePath}/raw/lcov.conf" .
" --prefix=${strWorkPath}/repo" .
" --output-directory=${strTestResultCoveragePath}/lcov");
}
coverageGenerate( coverageGenerate(
$oStorage, "${strWorkPath}/repo", "${strTestResultCoveragePath}/raw", "${strTestResultCoveragePath}/coverage.html"); $oStorage, "${strWorkPath}/repo", "${strTestResultCoveragePath}/raw", "${strTestResultCoveragePath}/coverage.html",
$bCoverageReport);
}
# Else output report status in the HTML
else
{
$oStorage->put(
"${strTestResultCoveragePath}/coverage.html",
"<center>[ " . ($result == 0 ? "Coverage Complete" : "No Coverage Report") . " ]</center>");
} }
if ($bCoverageSummary) if ($bCoverageSummary)
@@ -394,12 +406,6 @@ sub coverageValidateAndGenerate
} }
} }
# Remove coverage report when no coverage or no report to avoid confusion from looking at an old report
if (!$bCoverageReport || !$oStorage->exists($strLCovFile))
{
executeTest("rm -rf ${strTestResultCoveragePath}");
}
return $result; return $result;
} }
@@ -437,6 +443,7 @@ sub coverageGenerate
my $strBasePath = shift; my $strBasePath = shift;
my $strCoveragePath = shift; my $strCoveragePath = shift;
my $strOutFile = shift; my $strOutFile = shift;
my $bCoverageReport = shift;
# Track missing coverage # Track missing coverage
my $rhCoverage = {}; my $rhCoverage = {};
@@ -446,6 +453,10 @@ sub coverageGenerate
foreach my $strFileCov (sort(keys(%{$rhManifest}))) foreach my $strFileCov (sort(keys(%{$rhManifest})))
{ {
# If a coverage report was not requested then skip coverage of test modules. If we are here it means there was missing
# coverage on CI and we want to keep the report as small as possible.
next if !$bCoverageReport && $strFileCov =~ /Test\.lcov$/;
if ($strFileCov =~ /\.lcov$/) if ($strFileCov =~ /\.lcov$/)
{ {
my $strCoverage = ${$oStorage->get("${strCoveragePath}/${strFileCov}")}; my $strCoverage = ${$oStorage->get("${strCoveragePath}/${strFileCov}")};

View File

@@ -427,7 +427,9 @@ eval
$oStorageTest->pathCreate( $oStorageTest->pathCreate(
"${strBackRestBase}/test/result/coverage", {strMode => '0770', bIgnoreExists => true, bCreateParent => true}); "${strBackRestBase}/test/result/coverage", {strMode => '0770', bIgnoreExists => true, bCreateParent => true});
$oStorageBackRest->put( $oStorageBackRest->put(
"${strBackRestBase}/test/result/coverage/coverage.html", "<center>[ Generating New Report ]</center>"); "${strBackRestBase}/test/result/coverage/coverage.html",
"<center>[ " . ($bNoCoverage ? "No Coverage Testing" : "Generating Coverage Report") . " ]</center>");
executeTest("rm -rf ${strBackRestBase}/test/result/coverage/lcov");
# Copy C code for coverage tests # Copy C code for coverage tests
if (vmCoverageC($strVm) && !$bDryRun) if (vmCoverageC($strVm) && !$bDryRun)