Skip to content

Commit da1a747

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 76ddf59 commit da1a747

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

app/Http/Submission/Handlers/CoverageLogHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public function startElement($parser, $name, $attributes): void
6969
if ($attributes['COUNT'] >= 0) {
7070
$this->CurrentCoverageFileLog->AddLine($attributes['NUMBER'], $attributes['COUNT']);
7171
}
72+
if (array_key_exists('BRANCHESTESTED', $attributes)) {
73+
if (($attributes['BRANCHESTESTED'] > 0) || ($attributes['BRANCHESUNTESTED'] > 0)) {
74+
$this->CurrentCoverageFileLog->AddBranch($attributes['NUMBER'],
75+
$attributes['BRANCHESTESTED'],
76+
$attributes['BRANCHESTESTED'] + $attributes['BRANCHESUNTESTED']);
77+
}
78+
}
7279
$this->CurrentLine = '';
7380
}
7481
}

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
@@ -363,6 +363,8 @@ add_feature_test(/Feature/Submission/Tests/TestXMLTest)
363363

364364
add_feature_test(/Feature/Submission/Tests/BuildXMLTest)
365365

366+
add_feature_test(/Feature/Submission/Tests/CoverageLogXMLTest)
367+
366368
add_browser_test(/Browser/Pages/SitesIdPageTest)
367369

368370
add_browser_test(/Browser/Pages/ProjectSitesPageTest)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Tests\Feature\Submission\Tests;
4+
5+
use App\Models\Project;
6+
use Illuminate\Testing\Fluent\AssertableJson;
7+
use Tests\TestCase;
8+
use Tests\Traits\CreatesProjects;
9+
use Tests\Traits\CreatesSubmissions;
10+
11+
class CoverageLogXMLTest extends TestCase
12+
{
13+
use CreatesProjects;
14+
use CreatesSubmissions;
15+
16+
private Project $project;
17+
18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
22+
$this->project = $this->makePublicProject();
23+
}
24+
25+
protected function tearDown(): void
26+
{
27+
$this->project->delete();
28+
29+
parent::tearDown();
30+
}
31+
32+
/**
33+
* Test parsing a valid CoverageLog.xml file that contains branch
34+
* coverage information in the attributes of each line
35+
*/
36+
public function testBranchCoverage(): void
37+
{
38+
$this->submitFiles($this->project->name, [
39+
base_path(
40+
'tests/Feature/Submission/Tests/data/with_branchCoverage.xml'
41+
),
42+
base_path(
43+
'tests/Feature/Submission/Tests/data/with_LogBranchCoverage.xml'
44+
),
45+
]);
46+
47+
$this->graphQL('
48+
query build($id: ID) {
49+
build(id: $id) {
50+
coverage {
51+
edges {
52+
node {
53+
branchPercentage
54+
branchesTested
55+
branchesUntested
56+
coveredLines {
57+
branchesHit
58+
totalBranches
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
', [
66+
'id' => $this->project->builds()->firstOrFail()->id,
67+
])->assertJson(function (AssertableJson $json): void {
68+
// This is to check that branch data exists overall
69+
$json->has('data.build.coverage.edges.0.node', function (AssertableJson $json): void {
70+
$json->where('branchesTested', 3)
71+
->where('branchesUntested', 1)
72+
->where('branchPercentage', 75)
73+
->etc();
74+
});
75+
// This is to check that one numbered line has branch data
76+
$json->has('data.build.coverage.edges.0.node.coveredLines.19', function (AssertableJson $json): void {
77+
$json->where('branchesHit', 1)
78+
->where('totalBranches', 2);
79+
});
80+
});
81+
}
82+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
<Line Number="0" Count="-1" BranchesTested="0" BranchesUntested="0">#include &lt;iostream&gt;</Line>
13+
<Line Number="1" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
14+
<Line Number="2" Count="11" BranchesTested="0" BranchesUntested="0">int printMsg(int times) {</Line>
15+
<Line Number="3" Count="66" BranchesTested="2" BranchesUntested="0"> for (int i =0; i &lt; times; i++) {</Line>
16+
<Line Number="4" Count="55" BranchesTested="0" BranchesUntested="0"> std::cout &lt;&lt; i &lt;&lt; ": Hello, World!" &lt;&lt; std::endl;</Line>
17+
<Line Number="5" Count="55" BranchesTested="0" BranchesUntested="0"> }</Line>
18+
<Line Number="6" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
19+
<Line Number="7" Count="11" BranchesTested="0" BranchesUntested="0"> int i = 10;</Line>
20+
<Line Number="8" Count="11" BranchesTested="0" BranchesUntested="0"> return i;</Line>
21+
<Line Number="9" Count="11" BranchesTested="0" BranchesUntested="0">}</Line>
22+
<Line Number="10" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
23+
<Line Number="11" Count="11" BranchesTested="0" BranchesUntested="0">void main1() {}</Line>
24+
<Line Number="12" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
25+
<Line Number="13" Count="11" BranchesTested="0" BranchesUntested="0">int main() {</Line>
26+
<Line Number="14" Count="11" BranchesTested="0" BranchesUntested="0"> printMsg(5);</Line>
27+
<Line Number="15" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
28+
<Line Number="16" Count="11" BranchesTested="0" BranchesUntested="0"> main1();</Line>
29+
<Line Number="17" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
30+
<Line Number="18" Count="11" BranchesTested="1" BranchesUntested="1"> if(false)</Line>
31+
<Line Number="19" Count="0" BranchesTested="0" BranchesUntested="0"> {</Line>
32+
<Line Number="20" Count="-1" BranchesTested="0" BranchesUntested="0"> // go to check</Line>
33+
<Line Number="21" Count="0" BranchesTested="0" BranchesUntested="0"> return 1;</Line>
34+
<Line Number="22" Count="0" BranchesTested="0" BranchesUntested="0"> }</Line>
35+
<Line Number="23" Count="-1" BranchesTested="0" BranchesUntested="0"></Line>
36+
<Line Number="24" Count="11" BranchesTested="0" BranchesUntested="0"> return 0;</Line>
37+
<Line Number="25" Count="0" BranchesTested="0" BranchesUntested="0"> int blah;</Line>
38+
<Line Number="26" Count="0" BranchesTested="0" BranchesUntested="0">}</Line>
39+
</Report>
40+
</File>
41+
<EndDateTime>Apr 01 09:08 EDT</EndDateTime>
42+
<EndTime>1775048903</EndTime>
43+
</CoverageLog>
44+
</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)