Skip to content

Commit c8dbdf6

Browse files
committed
Add handling for branch coverage information from CTest
When reading the coverage log file, look for incoming "BranchesTested" and "BranchesUntested" attributes on each log line. If either is greater than 0, add a branch entry to that line.
1 parent 5ac804b commit c8dbdf6

File tree

6 files changed

+153
-0
lines changed

6 files changed

+153
-0
lines changed

app/Http/Submission/Handlers/CoverageLogHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public function startElement($parser, $name, $attributes): void
6666
$this->CurrentCoverageFileLog = new CoverageFileLog();
6767
$this->CurrentCoverageFile->FullPath = trim($attributes['FULLPATH']);
6868
} elseif ($name === 'LINE') {
69+
if (array_key_exists('BRANCHESTESTED', $attributes)) {
70+
if (($attributes['BRANCHESTESTED'] > 0) || ($attributes['BRANCHESUNTESTED'] > 0)) {
71+
$this->CurrentCoverageFileLog->AddBranch($attributes['NUMBER'],
72+
$attributes['BRANCHESTESTED'],
73+
$attributes['BRANCHESTESTED'] + $attributes['BRANCHESUNTESTED']);
74+
$this->CurrentLine = '';
75+
return;
76+
}
77+
}
6978
if ($attributes['COUNT'] >= 0) {
7079
$this->CurrentCoverageFileLog->AddLine($attributes['NUMBER'], $attributes['COUNT']);
7180
}

app/Validators/Schemas/CoverageLog.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<xs:extension base="xs:string">
2424
<xs:attribute name="Number" type="xs:int" use="required" />
2525
<xs:attribute name="Count" type="xs:int" use="required" />
26+
<xs:attribute name="BranchesTested" type="xs:int" use="optional"/>
27+
<xs:attribute name="BranchesUntested" type="xs:int" use="optional"/>
2628
</xs:extension>
2729
</xs:simpleContent>
2830
</xs:complexType>

app/cdash/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ add_feature_test(/Feature/Submission/Tests/TestXMLTest)
357357

358358
add_feature_test(/Feature/Submission/Tests/BuildXMLTest)
359359

360+
add_feature_test(/Feature/Submission/Tests/CoverageLogXMLTest)
361+
360362
add_browser_test(/Browser/Pages/SitesIdPageTest)
361363

362364
add_browser_test(/Browser/Pages/ProjectSitesPageTest)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace Tests\Feature\Submission\Tests;
4+
5+
use App\Models\Project;
6+
use Tests\TestCase;
7+
use Tests\Traits\CreatesProjects;
8+
use Tests\Traits\CreatesSubmissions;
9+
10+
class CoverageLogXMLTest extends TestCase
11+
{
12+
use CreatesProjects;
13+
use CreatesSubmissions;
14+
15+
private Project $project;
16+
17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->project = $this->makePublicProject();
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
$this->project->delete();
27+
28+
parent::tearDown();
29+
}
30+
31+
/**
32+
* Test parsing a valid CoverageLog.xml file that contains branch
33+
* coverage information in the attributes of each line
34+
*/
35+
public function testBranchCoverage(): void
36+
{
37+
$this->submitFiles($this->project->name, [
38+
base_path(
39+
'tests/Feature/Submission/Tests/data/with_branchCoverage.xml'
40+
),
41+
base_path(
42+
'tests/Feature/Submission/Tests/data/with_LogBranchCoverage.xml'
43+
),
44+
]);
45+
46+
$this->graphQL('
47+
query build($id: ID) {
48+
build(id: $id) {
49+
coverage {
50+
edges {
51+
node {
52+
branchPercentage
53+
branchesTested
54+
branchesUntested
55+
coveredLines {
56+
branchesHit
57+
totalBranches
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
', [
65+
'id' => $this->project->builds()->firstOrFail()->id,
66+
])->assertExactJson([
67+
'data' => [
68+
'build' => [
69+
'coverage' => [
70+
'edges' => [
71+
[
72+
'node' => [
73+
'branchPercentage' => 75,
74+
'branchesTested' => 3,
75+
'branchesUntested' => 1,
76+
'coveredLines' => [
77+
[
78+
'branchesHit' => 2,
79+
'totalBranches' => 2,
80+
],
81+
[
82+
'branchesHit' => 1,
83+
'totalBranches' => 2,
84+
],
85+
],
86+
],
87+
],
88+
],
89+
],
90+
],
91+
],
92+
]);
93+
}
94+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Site BuildName="dummy_test_name"
3+
BuildStamp="dummy_stamp"
4+
Name="dummy_name"
5+
Generator="dummy_generator"
6+
>
7+
<CoverageLog>
8+
<StartDateTime>Apr 01 09:08 EDT</StartDateTime>
9+
<StartTime>1775048903</StartTime>
10+
<File Name="hello.cxx" FullPath="./hello.cxx">
11+
<Report>
12+
13+
<Line Number="3" Count="66" BranchesTested="2" BranchesUntested="0"> for (int i =0; i &lt; times; i++) {</Line>
14+
<Line Number="18" Count="11" BranchesTested="1" BranchesUntested="1"> if(false)</Line>
15+
</Report>
16+
</File>
17+
<EndDateTime>Apr 01 09:08 EDT</EndDateTime>
18+
<EndTime>1775048903</EndTime>
19+
</CoverageLog>
20+
</Site>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Site BuildName="dummy_test_name"
3+
BuildStamp="dummy_stamp"
4+
Name="dummy_name"
5+
Generator="dummy_generator"
6+
>
7+
<Coverage>
8+
<StartDateTime>Apr 01 09:08 EDT</StartDateTime>
9+
<StartTime>1775048902</StartTime>
10+
<File Name="hello.cxx" FullPath="./hello.cxx" Covered="true">
11+
<LOCTested>13</LOCTested>
12+
<LOCUnTested>5</LOCUnTested>
13+
<BranchesTested>3</BranchesTested>
14+
<BranchesUnTested>1</BranchesUnTested>
15+
<PercentCoverage>72.22</PercentCoverage>
16+
<CoverageMetric>0.82</CoverageMetric>
17+
</File>
18+
<LOCTested>13</LOCTested>
19+
<LOCUntested>5</LOCUntested>
20+
<LOC>18</LOC>
21+
<PercentCoverage>72.22</PercentCoverage>
22+
<EndDateTime>Apr 01 09:08 EDT</EndDateTime>
23+
<EndTime>1775048903</EndTime>
24+
<ElapsedMinutes>0</ElapsedMinutes>
25+
</Coverage>
26+
</Site>

0 commit comments

Comments
 (0)