Skip to content

Commit b3813bd

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
gcov: Solve the problem of incorrect report generation caused by different compilation and test environments
Due to the makefile, the relative paths of the files are different, and it is impossible to use existing tools such as gcov and lcov to specify a base compilation path for them. The solution for Linux is to copy a copy of the source code from the compilation environment to the test environment, and there is a place that is consistent with the absolute path of the compilation environment. This solution is to pass in the "-b" parameter to directly modify the info file generated by lcov. The search path will be executed in the next step of genhtml Signed-off-by: wangmingrong1 <[email protected]>
1 parent 1cbb718 commit b3813bd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tools/gcov.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ def parse_gcda_data(path):
7373
output += line.strip()
7474

7575

76+
def correct_content_path(file, newpath):
77+
with open(file, "r", encoding="utf-8") as f:
78+
content = f.read()
79+
80+
pattern = r"SF:([^\s]*?)/nuttx/include/nuttx"
81+
matches = re.findall(pattern, content)
82+
83+
if matches:
84+
new_content = content.replace(matches[0], newpath)
85+
86+
with open(file, "w", encoding="utf-8") as f:
87+
f.write(new_content)
88+
89+
7690
def copy_file_endswith(endswith, source_dir, target_dir):
7791
print(f"Collect {endswith} files {source_dir} -> {target_dir}")
7892

@@ -93,6 +107,7 @@ def arg_parser():
93107
)
94108
parser.add_argument("-i", "--input", help="Input dump data")
95109
parser.add_argument("-t", dest="gcov_tool", help="Path to gcov tool")
110+
parser.add_argument("-b", dest="base_dir", help="Compile base directory")
96111
parser.add_argument("-s", dest="gcno_dir", help="Directory containing gcno files")
97112
parser.add_argument("-a", dest="gcda_dir", help="Directory containing gcda files")
98113
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
@@ -171,6 +186,9 @@ def main():
171186
stderr=sys.stdout,
172187
)
173188

189+
if args.base_dir:
190+
correct_content_path(coverage_file, args.base_dir)
191+
174192
# genhtml generate coverage report
175193
subprocess.run(
176194
[

0 commit comments

Comments
 (0)