Skip to content

Commit

Permalink
gcov: gcov.py, gcov_convert.py scripts merged
Browse files Browse the repository at this point in the history
Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R authored and xiaoxiang781216 committed Dec 21, 2024
1 parent 7d6b2e4 commit e26e8bd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 94 deletions.
52 changes: 52 additions & 0 deletions tools/gcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,59 @@

import argparse
import os
import re
import shutil
import subprocess
import sys


def parse_gcda_data(path):
with open(path, "r") as file:
lines = file.read().strip().splitlines()

started = False
filename = ""
output = ""
size = 0

for line in lines:
if line.startswith("gcov start"):
started = True
match = re.search(r"filename:(.*?)\s+size:\s*(\d+)Byte", line)
if match:
filename = match.group(1)
size = int(match.group(2))
continue

if not started:
continue

if line.startswith("gcov end"):
started = False
if size != len(output) // 2:
print(
f"Size mismatch for {filename}: expected {size} bytes, got {len(output) // 2} bytes"
)

match = re.search(r"checksum:\s*(0x[0-9a-fA-F]+)", line)
if match:
checksum = int(match.group(1), 16)
output = bytearray.fromhex(output)
expected = sum(output) % 65536
if checksum != expected:
print(
f"Checksum mismatch for {filename}: expected {checksum}, got {expected}"
)
continue

with open(filename, "wb") as fp:
fp.write(output)
print(f"write {filename} success")
output = ""
else:
output += line.strip()


def copy_file_endswith(endswith, source_dir, target_dir):
print(f"Collect {endswith} files {source_dir} -> {target_dir}")

Expand All @@ -43,6 +91,7 @@ def arg_parser():
parser = argparse.ArgumentParser(
description="Code coverage generation tool.", add_help=False
)
parser.add_argument("-i", "--input", help="Input dump data")
parser.add_argument("-t", dest="gcov_tool", help="Path to gcov tool")
parser.add_argument("-s", dest="gcno_dir", help="Directory containing gcno files")
parser.add_argument("-a", dest="gcda_dir", help="Directory containing gcda files")
Expand Down Expand Up @@ -79,6 +128,9 @@ def main():
debug_file = os.path.join(gcov_dir, "debug.log")
sys.stdout = open(debug_file, "w+")

if args.input:
parse_gcda_data(os.path.join(root_dir, args.input))

os.makedirs(os.path.join(gcov_dir, "data"), exist_ok=True)

# Collect gcno, gcda files
Expand Down
94 changes: 0 additions & 94 deletions tools/gcov_convert.py

This file was deleted.

0 comments on commit e26e8bd

Please sign in to comment.