Skip to content

Commit

Permalink
gen-coverage works
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Feb 7, 2025
1 parent fffb0da commit 4009d04
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions scripts/tests/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,19 @@ def cli(log_level):
)


def _with_activate(build_cmd: List[str]) -> List[str]:
def _with_activate(build_cmd: List[str], output_path=None) -> List[str]:
"""
Given a bash command list, will generate a new command suitable for subprocess
with an execution of `scripts/activate.sh` prepended to it
"""
cmd = shlex.join(build_cmd);
if output_path:
cmd = cmd + f" >{output_path}"

return [
"bash",
"-c",
";".join(["set -e", "source scripts/activate.sh", shlex.join(build_cmd)]),
";".join(["set -e", "source scripts/activate.sh", cmd])
]


Expand Down Expand Up @@ -543,18 +547,27 @@ def gen_coverage():
logging.warning("No profile file '%s'. Skipping.", path)
continue

data_path = os.path.join("./out", f"{t.target}.profdata")
cmd = [
"llvm-profdata",
"merge",
"-sparse",
path,
"-o",
data_path
]
p = subprocess.run(_with_activate(cmd), check=True, capture_output=True)

cmd = [
"llvm-cov",
"export",
"-format=lcov",
"--instr-profile",
path,
data_path,
os.path.join("./out", t.target, t.binary),
]
p = subprocess.run(_with_activate(cmd), check=True, capture_output=True)
info_path = os.path.join("./out", f"{t.target}.info")
with open(info_path, "wb") as f:
f.write(p.stdout)
p = subprocess.run(_with_activate(cmd, output_path=info_path), check=True)
trace_files.append(info_path)
logging.info("Generated %s", info_path)

Expand All @@ -571,6 +584,12 @@ def gen_coverage():

cmd.append("--output-file")
cmd.append("out/merged.info")
cmd.append("--ignore-errors")
cmd.append("inconsistent")
cmd.append("--ignore-errors")
cmd.append("range")
cmd.append("--ignore-errors")
cmd.append("corrupt")

if os.path.exists("out/merged.info"):
os.unlink("out/merged.info")
Expand Down

0 comments on commit 4009d04

Please sign in to comment.