Skip to content

Commit 3243651

Browse files
committed
Internals: Fix misc internal coverage holes. No functional change intended.
1 parent 8d61cd9 commit 3243651

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

.codacy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ exclude_paths:
33
- '.github/**'
44
- 'ci/build_verilator.sh'
55
- 'include/vltstd/**'
6+
- 'nodist/fastcov.py'

nodist/code_coverage

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use vars qw($Debug);
1818

1919
our $Opt_Stop = 1;
2020
our $Opt_Fastcov = 1;
21+
our $Exclude_Branch_Regexp;
2122
our $Exclude_Line_Regexp;
2223
our $Remove_Gcda_Regexp;
2324

@@ -312,6 +313,7 @@ sub test {
312313
sub clone_sources {
313314
my $cc_dir = shift;
314315
my $excluded_lines = 0;
316+
my $excluded_br_lines = 0;
315317
foreach my $glob (@Source_Globs) {
316318
foreach my $infile (glob $glob) {
317319
$infile !~ m!^/!
@@ -334,17 +336,23 @@ sub clone_sources {
334336
elsif ($line =~ /LCOV_EXCL_STOP/) {
335337
$line .= " LCOV_EXCL_BR_STOP";
336338
}
337-
elsif ($line !~ m!// LCOV_EXCL_LINE!
338-
&& $line =~ /$Exclude_Line_Regexp/) {
339+
elsif ($line =~ /$Exclude_Line_Regexp/) {
339340
$line .= " //code_coverage: // LCOV_EXCL_LINE LCOV_EXCL_BR_LINE";
340341
$excluded_lines++;
342+
$excluded_br_lines++;
343+
#print "$infile:$lineno: $line";
344+
}
345+
elsif ($line =~ /$Exclude_Branch_Regexp/) {
346+
$line .= " //code_coverage: // LCOV_EXCL_BR_LINE";
347+
$excluded_br_lines++;
341348
#print "$infile:$lineno: $line";
342349
}
343350
$ofh->print("$line\n");
344351
}
345352
}
346353
}
347354
print "Number of source lines automatically LCOV_EXCL_LINE'ed: $excluded_lines\n";
355+
print "Number of source lines automatically LCOV_EXCL_BR_LINE'ed: $excluded_br_lines\n";
348356
}
349357

350358
sub cleanup_abs_paths_info {
@@ -388,6 +396,9 @@ sub cleanup_abs_paths_json {
388396
#######################################################################
389397
# .dat file callbacks
390398

399+
sub exclude_branch_regexp {
400+
$Exclude_Branch_Regexp = shift;
401+
}
391402
sub exclude_line_regexp {
392403
$Exclude_Line_Regexp = shift;
393404
}

nodist/code_coverage.dat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ remove_source("*examples/*");
4242
# Would just be removed with remove_source in later step
4343
remove_gcda_regexp(qr!test_regress/.*/(Vt_|Vtop_).*\.gcda!);
4444

45+
# Exclude line entirely, also excludes from function and branch coverage
4546
exclude_line_regexp(qr/(\bv3fatalSrc\b
4647
|\bfatalSrc\b
4748
|\bVL_UNCOVERABLE\b
@@ -51,4 +52,7 @@ exclude_line_regexp(qr/(\bv3fatalSrc\b
5152
|\bV3ERROR_NA
5253
|\bUINFO\b)/x);
5354

55+
# Exclude for branch coverage only
56+
exclude_branch_regexp(qr/(\bdebug\(\))/x);
57+
5458
1;

src/V3Case.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ class CaseVisitor : public AstNVisitor {
280280
// IF(msb-1, 01, 00))
281281
AstNode* cexprp = nodep->exprp()->unlinkFrBack();
282282

283-
if (debug() >= 9) {
283+
if (debug() >= 9) { // LCOV_EXCL_START
284284
for (uint32_t i = 0; i < (1UL << m_caseWidth); ++i) {
285285
if (AstNode* itemp = m_valueItem[i]) {
286286
UINFO(9, "Value " << std::hex << i << " " << itemp << endl);
287287
}
288288
}
289-
}
289+
} // LCOV_EXCL_STOP
290290

291291
// Handle any assertions
292292
replaceCaseParallel(nodep, m_caseNoOverlapsAllCovered);

src/V3FileLine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,14 @@ string FileLine::warnOther() const {
390390
}
391391

392392
string FileLine::source() const {
393-
if (VL_UNCOVERABLE(!m_contentp)) {
393+
if (VL_UNCOVERABLE(!m_contentp)) { // LCOV_EXCL_START
394394
if (debug() || v3Global.opt.debugCheck()) {
395395
// The newline here is to work around the " <line#> | "
396396
return "\n%Error: internal tracking of file contents failed";
397397
} else {
398398
return "";
399399
}
400-
}
400+
} // LCOV_EXCL_STOP
401401
return m_contentp->getLine(m_contentLineno);
402402
}
403403
string FileLine::prettySource() const {

src/V3Options.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ void V3Options::fileNfsFlush(const string& filename) {
329329
// NFS caches stat() calls so to get up-to-date information must
330330
// do a open or opendir on the filename.
331331
// Faster to just try both rather than check if a file is a dir.
332-
if (DIR* dirp = opendir(filename.c_str())) {
332+
if (DIR* dirp = opendir(filename.c_str())) { // LCOV_EXCL_BR_LINE
333333
closedir(dirp); // LCOV_EXCL_LINE
334-
} else if (int fd = ::open(filename.c_str(), O_RDONLY)) {
334+
} else if (int fd = ::open(filename.c_str(), O_RDONLY)) { // LCOV_EXCL_BR_LINE
335335
if (fd > 0) ::close(fd);
336336
}
337337
}
@@ -667,13 +667,13 @@ string V3Options::protectKeyDefaulted() {
667667
return m_protectKey;
668668
}
669669

670-
void V3Options::throwSigsegv() {
670+
void V3Options::throwSigsegv() { // LCOV_EXCL_START
671671
#if !(defined(VL_CPPCHECK) || defined(__clang_analyzer__))
672672
// clang-format off
673673
{ char* zp = NULL; *zp = 0; } // Intentional core dump, ignore warnings here
674674
// clang-format on
675675
#endif
676-
}
676+
} // LCOV_EXCL_STOP
677677

678678
VTimescale V3Options::timeComputePrec(const VTimescale& flag) const {
679679
if (!timeOverridePrec().isNone()) {

0 commit comments

Comments
 (0)