This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit d004e56b11b62ad2f19c8f3c5cdb910b2bf83501
Author: wangmingrong1 <[email protected]>
AuthorDate: Mon Nov 2 16:08:34 2026 +0800

    tools/gcov: skip genhtml when lcov tracefile has no records
    
    Root cause: when the host gcov tool cannot decode any collected .gcda
    file (typically because the build toolchain produced a newer gcov
    version, e.g. 'version B34*' vs 'prefer B31*'), lcov still exits 0
    thanks to --ignore-errors gcov but writes an empty .info tracefile.
    Running genhtml on such a file always fails with
    'genhtml: ERROR: no valid records found in tracefile ...', which makes
    gcov.py exit 1 and breaks the VTF gcov integration test (and any
    CI that wraps this script) for a pure environment mismatch.
    
    Fix: before calling genhtml, scan the .info tracefile for at least one
    'SF:' source record. If none is present, print a clear diagnostic
    pointing at the likely toolchain version mismatch and return cleanly
    from main_gcc (exit 0) instead of running genhtml just to fail.
    Other genhtml failure modes still surface as a non-zero exit.
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 tools/gcov.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/tools/gcov.py b/tools/gcov.py
index 1818bf04629..01b90d22c85 100755
--- a/tools/gcov.py
+++ b/tools/gcov.py
@@ -307,6 +307,26 @@ def get_lcov_major_version():
     return 1
 
 
+def lcov_info_has_records(info_file):
+    """Return True if an lcov .info tracefile contains at least one 'SF:' 
record.
+
+    When the local gcov tool cannot decode any .gcda file (e.g. because the
+    build toolchain produced a newer gcov version than the host tool supports),
+    lcov still exits 0 (due to --ignore-errors gcov) but writes an info file
+    with zero source records. Running genhtml on such a file always fails with
+    'no valid records found in tracefile', which is a pipeline-level symptom
+    of an environment issue, not a real coverage regression.
+    """
+    try:
+        with open(info_file, "r", encoding="utf-8", errors="replace") as f:
+            for line in f:
+                if line.startswith("SF:"):
+                    return True
+    except (IOError, OSError):
+        return False
+    return False
+
+
 def run_genhtml(info, report):
     # 'category' is only supported by lcov >= 2
     ignore_errors = "source"
@@ -572,6 +592,23 @@ def main_gcc(args, gcda_dirs, gcno_dir, result_dir):
     if args.only_copy:
         sys.exit(0)
 
+    # If lcov produced an .info tracefile with no source records, the local
+    # gcov tool could not decode the collected .gcda files - usually a
+    # toolchain version mismatch (look for 'version Bxx*, prefer Byy*'
+    # warnings from lcov above). Running genhtml on an empty tracefile always
+    # fails with 'no valid records found in tracefile' and aborts the whole
+    # pipeline even though there is nothing actionable in the coverage data.
+    # Print a clear diagnostic and skip the HTML step instead of failing.
+    if not lcov_info_has_records(coverage_file):
+        print(
+            "Warning: lcov produced no coverage records in "
+            f"{coverage_file}. This usually means the local gcov tool "
+            "cannot decode the collected .gcda files (toolchain version "
+            "mismatch - see 'version ... prefer ...' warnings above). "
+            "Skipping HTML report generation."
+        )
+        return
+
     try:
         run_genhtml(coverage_file, report_dir)
         print(

Reply via email to