Skip to content

Commit 8261ed8

Browse files
committed
Fix 'lcov --list' feature - see issue #335.
Also add MC/DC data to the report. Signed-off-by: Henry Cox <[email protected]>
1 parent b672a74 commit 8261ed8

File tree

4 files changed

+87
-90
lines changed

4 files changed

+87
-90
lines changed

bin/lcov

Lines changed: 57 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,33 +1722,27 @@ sub list()
17221722
my $readSourceFile = ReadCurrentSource->new();
17231723
my $data =
17241724
TraceFile->load($list, $readSourceFile, $lcovutil::verify_checksum);
1725-
my $found;
1726-
my $hit;
1727-
my $entry;
1728-
my $fn_found;
1729-
my $fn_hit;
1730-
my $br_found;
1731-
my $br_hit;
17321725
my $total_found = 0;
17331726
my $total_hit = 0;
17341727
my $fn_total_found = 0;
17351728
my $fn_total_hit = 0;
17361729
my $br_total_found = 0;
17371730
my $br_total_hit = 0;
1731+
my $total_mcdc = 0;
1732+
my $total_mcdc_hit = 0;
17381733
my $strlen = length("Filename");
17391734
my @footer;
1740-
my $rate;
1741-
my $fnrate;
1742-
my $brrate;
17431735
my $lastpath;
17441736
my $F_LN_NUM = 0;
17451737
my $F_LN_RATE = 1;
17461738
my $F_FN_NUM = 2;
17471739
my $F_FN_RATE = 3;
17481740
my $F_BR_NUM = 4;
17491741
my $F_BR_RATE = 5;
1750-
my @fwidth_narrow = (5, 5, 3, 5, 4, 5);
1751-
my @fwidth_wide = (6, 5, 5, 5, 6, 5);
1742+
my $F_MCDC_NUM = 6;
1743+
my $F_MCDC_RATE = 7;
1744+
my @fwidth_narrow = (5, 5, 3, 5, 4, 5, 4, 5);
1745+
my @fwidth_wide = (6, 5, 5, 5, 6, 5, 6, 5);
17521746
my @fwidth = @fwidth_wide;
17531747
my $max_width = $opt_list_width;
17541748
my $max_long = $opt_list_truncate_max;
@@ -1817,39 +1811,24 @@ sub list()
18171811
my $heading1 = sprintf("%*s|", $w, "");
18181812
my $heading2 = sprintf("%-*s|", $w, "Filename");
18191813
my $barlen = $w + 1;
1820-
# Line coverage rate
1821-
$w = $fwidth[$F_LN_RATE];
1822-
$format .= "%${w}s ";
1823-
$heading1 .= sprintf("%-*s |", $w + $fwidth[$F_LN_NUM], "Lines");
1824-
$heading2 .= sprintf("%-*s ", $w, "Rate");
1825-
$barlen += $w + 1;
1826-
# Number of lines
1827-
$w = $fwidth[$F_LN_NUM];
1828-
$format .= "%${w}s|";
1829-
$heading2 .= sprintf("%*s|", $w, "Num");
1830-
$barlen += $w + 1;
1831-
# Function coverage rate
1832-
$w = $fwidth[$F_FN_RATE];
1833-
$format .= "%${w}s ";
1834-
$heading1 .= sprintf("%-*s|", $w + $fwidth[$F_FN_NUM] + 1, "Functions");
1835-
$heading2 .= sprintf("%-*s ", $w, "Rate");
1836-
$barlen += $w + 1;
1837-
# Number of functions
1838-
$w = $fwidth[$F_FN_NUM];
1839-
$format .= "%${w}s|";
1840-
$heading2 .= sprintf("%*s|", $w, "Num");
1841-
$barlen += $w + 1;
1842-
# Branch coverage rate
1843-
$w = $fwidth[$F_BR_RATE];
1844-
$format .= "%${w}s ";
1845-
$heading1 .= sprintf("%-*s", $w + $fwidth[$F_BR_NUM] + 1, "Branches");
1846-
$heading2 .= sprintf("%-*s ", $w, "Rate");
1847-
$barlen += $w + 1;
1848-
# Number of branches
1849-
$w = $fwidth[$F_BR_NUM];
1850-
$format .= "%${w}s";
1851-
$heading2 .= sprintf("%*s", $w, "Num");
1852-
$barlen += $w;
1814+
1815+
foreach my $d (['Lines', $F_LN_NUM, $F_LN_RATE],
1816+
['Functions', $F_FN_NUM, $F_FN_RATE],
1817+
['Branches', $F_BR_NUM, $F_BR_RATE],
1818+
['MC/DC', $F_MCDC_NUM, $F_MCDC_RATE],
1819+
) {
1820+
my ($type, $n, $r) = @$d;
1821+
$w = $fwidth[$r];
1822+
$format .= "%${w}s ";
1823+
$heading1 .= sprintf("%-*s |", $w + $fwidth[$n], $type);
1824+
$heading2 .= sprintf("%-*s ", $w, "Rate");
1825+
$barlen += $w + 1;
1826+
# Number of coverpoints
1827+
$w = $fwidth[$n];
1828+
$format .= "%${w}s|";
1829+
$heading2 .= sprintf("%*s|", $w, "Num");
1830+
$barlen += $w + 1;
1831+
}
18531832
# Line end
18541833
$format .= "\n";
18551834
$heading1 .= "\n";
@@ -1890,20 +1869,16 @@ sub list()
18901869
}
18911870
$print_filename = shorten_filename($print_filename, $strlen);
18921871
}
1893-
1894-
($found, $hit, $br_found, $br_hit, $fn_found, $fn_hit) =
1895-
$entry->get_info();
1896-
1897-
# Assume zero count if there is no function data for this file
1898-
if (!defined($fn_found) || !defined($fn_hit)) {
1899-
$fn_found = 0;
1900-
$fn_hit = 0;
1901-
}
1902-
# Assume zero count if there is no branch data for this file
1903-
if (!defined($br_found) || !defined($br_hit)) {
1904-
$br_found = 0;
1905-
$br_hit = 0;
1906-
}
1872+
my $lineData = $entry->sum();
1873+
my $branchData = $entry->sumbr();
1874+
my $funcData = $entry->func();
1875+
my $mcdcData = $entry->mcdc();
1876+
my ($found, $hit, $br_found, $br_hit, $fn_found, $fn_hit, $mcdc_found,
1877+
$mcdc_hit)
1878+
= ($lineData->found(), $lineData->hit(),
1879+
$branchData->found(), $branchData->hit(),
1880+
$funcData->numFunc(), $funcData->numHit(),
1881+
$mcdcData->found(), $mcdcData->hit());
19071882

19081883
# Add line coverage totals
19091884
$total_found += $found;
@@ -1914,46 +1889,41 @@ sub list()
19141889
# Add branch coverage totals
19151890
$br_total_found += $br_found;
19161891
$br_total_hit += $br_hit;
1892+
$total_mcdc += $mcdc_found;
1893+
$total_mcdc_hit += $mcdc_hit;
19171894

1918-
# Determine line coverage rate for this file
1919-
$rate = shorten_rate($hit, $found, $fwidth[$F_LN_RATE]);
1920-
# Determine function coverage rate for this file
1921-
$fnrate = shorten_rate($fn_hit, $fn_found, $fwidth[$F_FN_RATE]);
1922-
# Determine branch coverage rate for this file
1923-
$brrate = shorten_rate($br_hit, $br_found, $fwidth[$F_BR_RATE]);
1924-
1925-
# Assemble line parameters
19261895
my @file_data;
19271896
push(@file_data, $print_filename);
1928-
push(@file_data, $rate);
1929-
push(@file_data, shorten_number($found, $fwidth[$F_LN_NUM]));
1930-
push(@file_data, $fnrate);
1931-
push(@file_data, shorten_number($fn_found, $fwidth[$F_FN_NUM]));
1932-
push(@file_data, $brrate);
1933-
push(@file_data, shorten_number($br_found, $fwidth[$F_BR_NUM]));
1934-
1897+
foreach my $d ([$hit, $found, $F_LN_RATE, $F_LN_NUM],
1898+
[$fn_hit, $fn_found, $F_FN_RATE, $F_FN_NUM],
1899+
[$br_hit, $br_found, $F_BR_RATE, $F_BR_NUM],
1900+
[$mcdc_hit, $mcdc_found, $F_MCDC_RATE, $F_MCDC_NUM],
1901+
) {
1902+
my ($h, $f, $r, $n) = @$d;
1903+
1904+
push(@file_data, shorten_rate($h, $f, $fwidth[$r]));
1905+
push(@file_data, shorten_number($f, $fwidth[$n]));
1906+
}
19351907
# Print assembled line
19361908
printf($format, @file_data);
19371909
}
19381910

1939-
# Determine total line coverage rate
1940-
$rate = shorten_rate($total_hit, $total_found, $fwidth[$F_LN_RATE]);
1941-
# Determine total function coverage rate
1942-
$fnrate = shorten_rate($fn_total_hit, $fn_total_found, $fwidth[$F_FN_RATE]);
1943-
# Determine total branch coverage rate
1944-
$brrate = shorten_rate($br_total_hit, $br_total_found, $fwidth[$F_BR_RATE]);
1945-
19461911
# Print separator
19471912
print(("=" x $barlen) . "\n");
19481913

19491914
# Assemble line parameters
19501915
push(@footer, sprintf("%*s", $strlen, "Total:"));
1951-
push(@footer, $rate);
1952-
push(@footer, shorten_number($total_found, $fwidth[$F_LN_NUM]));
1953-
push(@footer, $fnrate);
1954-
push(@footer, shorten_number($fn_total_found, $fwidth[$F_FN_NUM]));
1955-
push(@footer, $brrate);
1956-
push(@footer, shorten_number($br_total_found, $fwidth[$F_BR_NUM]));
1916+
1917+
foreach my $d ([$total_hit, $total_found, $F_LN_RATE, $F_LN_NUM],
1918+
[$fn_total_hit, $fn_total_found, $F_FN_RATE, $F_FN_NUM],
1919+
[$br_total_hit, $br_total_found, $F_BR_RATE, $F_BR_NUM],
1920+
[$total_mcdc_hit, $total_mcdc, $F_MCDC_RATE, $F_MCDC_NUM],
1921+
) {
1922+
my ($h, $f, $r, $n) = @$d;
1923+
1924+
push(@footer, shorten_rate($h, $f, $fwidth[$r]));
1925+
push(@footer, shorten_number($f, $fwidth[$n]));
1926+
}
19571927

19581928
# Print assembled line
19591929
printf($format, @footer);

tests/lcov/extract/extract.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ if [ "${VER[0]}" -lt 5 ] ; then
107107
FILTER='--filter branch'
108108
fi
109109
110-
rm -rf *.gcda *.gcno a.out *.info* *.txt* *.json dumper* testRC *.gcov *.gcov.* *.log *.o errs *.msg
110+
rm -rf *.gcda *.gcno a.out *.info* *.txt* *.json dumper* testRC *.gcov *.gcov.* *.log *.o errs *.msg *.dat
111111
rm -rf rcOptBug
112112
113113
if [ -d separate ] ; then
@@ -388,10 +388,23 @@ if [ 0 != $? ] ; then
388388
fi
389389
390390
391-
392391
$COVER $CAPTURE . $LCOV_OPTS --no-external -o internal.info
393392
394-
$COVER $LCOV_TOOL $LCOV_OPTS --list internal.info
393+
# substiture PWD so the test isn't dependent on directory layout.
394+
# quiet, to suppress core count and (empty) message summary
395+
$COVER $LCOV_TOOL $LCOV_OPTS --list internal.info --subst "s#$PWD#.#" -q -q > list.dat
396+
397+
if [ "$ENABLE_MCDC" == 1 ] ; then
398+
diff list.dat list_mcdc.gold
399+
else
400+
diff list.dat list.gold
401+
fi
402+
if [ 0 != $? ] ; then
403+
echo "Error: unexpected list difference"
404+
if [ $KEEP_GOING == 0 ] ; then
405+
exit 1
406+
fi
407+
fi
395408
396409
COUNT=`grep -c SF: internal.info`
397410
if [ $COUNT != '1' ] ; then

tests/lcov/extract/list.gold

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
|Lines |Functions |Branches |MC/DC |
2+
Filename |Rate Num|Rate Num|Rate Num|Rate Num|
3+
====================================================================
4+
[./]
5+
extract.cpp | 100% 13| 100% 3|50.0% 20| - 0|
6+
====================================================================
7+
Total:| 100% 13| 100% 3|50.0% 20| - 0|

tests/lcov/extract/list_mcdc.gold

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
|Lines |Functions |Branches |MC/DC |
2+
Filename |Rate Num|Rate Num|Rate Num|Rate Num|
3+
====================================================================
4+
[./]
5+
extract.cpp | 100% 13| 100% 1|50.0% 16|50.0% 6|
6+
====================================================================
7+
Total:| 100% 13| 100% 1|50.0% 16|50.0% 6|

0 commit comments

Comments
 (0)