From 3243651c6332dd87471d6d0f42f1ccda88afd865 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 4 Jun 2020 21:40:40 -0400 Subject: [PATCH] Internals: Fix misc internal coverage holes. No functional change intended. --- .codacy.yml | 1 + nodist/code_coverage | 15 +++++++++++++-- nodist/code_coverage.dat | 4 ++++ src/V3Case.cpp | 4 ++-- src/V3FileLine.cpp | 4 ++-- src/V3Options.cpp | 8 ++++---- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.codacy.yml b/.codacy.yml index 31a95b117..409c852ee 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -3,3 +3,4 @@ exclude_paths: - '.github/**' - 'ci/build_verilator.sh' - 'include/vltstd/**' + - 'nodist/fastcov.py' diff --git a/nodist/code_coverage b/nodist/code_coverage index a96489dce..869027ecf 100755 --- a/nodist/code_coverage +++ b/nodist/code_coverage @@ -18,6 +18,7 @@ use vars qw($Debug); our $Opt_Stop = 1; our $Opt_Fastcov = 1; +our $Exclude_Branch_Regexp; our $Exclude_Line_Regexp; our $Remove_Gcda_Regexp; @@ -312,6 +313,7 @@ sub test { sub clone_sources { my $cc_dir = shift; my $excluded_lines = 0; + my $excluded_br_lines = 0; foreach my $glob (@Source_Globs) { foreach my $infile (glob $glob) { $infile !~ m!^/! @@ -334,10 +336,15 @@ sub clone_sources { elsif ($line =~ /LCOV_EXCL_STOP/) { $line .= " LCOV_EXCL_BR_STOP"; } - elsif ($line !~ m!// LCOV_EXCL_LINE! - && $line =~ /$Exclude_Line_Regexp/) { + elsif ($line =~ /$Exclude_Line_Regexp/) { $line .= " //code_coverage: // LCOV_EXCL_LINE LCOV_EXCL_BR_LINE"; $excluded_lines++; + $excluded_br_lines++; + #print "$infile:$lineno: $line"; + } + elsif ($line =~ /$Exclude_Branch_Regexp/) { + $line .= " //code_coverage: // LCOV_EXCL_BR_LINE"; + $excluded_br_lines++; #print "$infile:$lineno: $line"; } $ofh->print("$line\n"); @@ -345,6 +352,7 @@ sub clone_sources { } } print "Number of source lines automatically LCOV_EXCL_LINE'ed: $excluded_lines\n"; + print "Number of source lines automatically LCOV_EXCL_BR_LINE'ed: $excluded_br_lines\n"; } sub cleanup_abs_paths_info { @@ -388,6 +396,9 @@ sub cleanup_abs_paths_json { ####################################################################### # .dat file callbacks +sub exclude_branch_regexp { + $Exclude_Branch_Regexp = shift; +} sub exclude_line_regexp { $Exclude_Line_Regexp = shift; } diff --git a/nodist/code_coverage.dat b/nodist/code_coverage.dat index 252956799..df768a0ab 100644 --- a/nodist/code_coverage.dat +++ b/nodist/code_coverage.dat @@ -42,6 +42,7 @@ remove_source("*examples/*"); # Would just be removed with remove_source in later step remove_gcda_regexp(qr!test_regress/.*/(Vt_|Vtop_).*\.gcda!); +# Exclude line entirely, also excludes from function and branch coverage exclude_line_regexp(qr/(\bv3fatalSrc\b |\bfatalSrc\b |\bVL_UNCOVERABLE\b @@ -51,4 +52,7 @@ exclude_line_regexp(qr/(\bv3fatalSrc\b |\bV3ERROR_NA |\bUINFO\b)/x); +# Exclude for branch coverage only +exclude_branch_regexp(qr/(\bdebug\(\))/x); + 1; diff --git a/src/V3Case.cpp b/src/V3Case.cpp index e359443fc..01ba0b96d 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -280,13 +280,13 @@ private: // IF(msb-1, 01, 00)) AstNode* cexprp = nodep->exprp()->unlinkFrBack(); - if (debug() >= 9) { + if (debug() >= 9) { // LCOV_EXCL_START for (uint32_t i = 0; i < (1UL << m_caseWidth); ++i) { if (AstNode* itemp = m_valueItem[i]) { UINFO(9, "Value " << std::hex << i << " " << itemp << endl); } } - } + } // LCOV_EXCL_STOP // Handle any assertions replaceCaseParallel(nodep, m_caseNoOverlapsAllCovered); diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index 4c4559e79..23b07c4cd 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -390,14 +390,14 @@ string FileLine::warnOther() const { } string FileLine::source() const { - if (VL_UNCOVERABLE(!m_contentp)) { + if (VL_UNCOVERABLE(!m_contentp)) { // LCOV_EXCL_START if (debug() || v3Global.opt.debugCheck()) { // The newline here is to work around the " | " return "\n%Error: internal tracking of file contents failed"; } else { return ""; } - } + } // LCOV_EXCL_STOP return m_contentp->getLine(m_contentLineno); } string FileLine::prettySource() const { diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 95e8ee583..554168b81 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -329,9 +329,9 @@ void V3Options::fileNfsFlush(const string& filename) { // NFS caches stat() calls so to get up-to-date information must // do a open or opendir on the filename. // Faster to just try both rather than check if a file is a dir. - if (DIR* dirp = opendir(filename.c_str())) { + if (DIR* dirp = opendir(filename.c_str())) { // LCOV_EXCL_BR_LINE closedir(dirp); // LCOV_EXCL_LINE - } else if (int fd = ::open(filename.c_str(), O_RDONLY)) { + } else if (int fd = ::open(filename.c_str(), O_RDONLY)) { // LCOV_EXCL_BR_LINE if (fd > 0) ::close(fd); } } @@ -667,13 +667,13 @@ string V3Options::protectKeyDefaulted() { return m_protectKey; } -void V3Options::throwSigsegv() { +void V3Options::throwSigsegv() { // LCOV_EXCL_START #if !(defined(VL_CPPCHECK) || defined(__clang_analyzer__)) // clang-format off { char* zp = NULL; *zp = 0; } // Intentional core dump, ignore warnings here // clang-format on #endif -} +} // LCOV_EXCL_STOP VTimescale V3Options::timeComputePrec(const VTimescale& flag) const { if (!timeOverridePrec().isNone()) {