-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_cov.py
39 lines (29 loc) · 1.16 KB
/
generate_cov.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Generates a coverage report for the project using kcov."""
import subprocess
import typing
COV_OUT_DIR = "target_cov/cov"
TEST_DIR = "target_cov"
subprocess.run(f"rm -rf {TEST_DIR}", shell=True)
print("Generating test binaries, this might take a while...")
result = subprocess.run(
["cargo", "test", "--no-run", "--target-dir", f"{TEST_DIR}"],
check=True,
capture_output=True,
text=True
)
result = typing.cast(str, result.stdout + result.stderr) # The output is unexpectedly in stderr
# Finds executables in the lines
lines = (line.strip() for line in result.split("\n"))
binaries = [line.split(" ")[-1].strip(")(") for line in lines if line.startswith("Executable")]
del lines
print("Target executables:\n{}".format("\n - ".join(binaries)))
if len(binaries) == 0:
print("No executables found, aborting...")
exit(1)
print("Running coverage...")
dirs_to_merge = []
for i, binary in enumerate(binaries):
out = COV_OUT_DIR + "_" + str(i)
dirs_to_merge.append(out)
subprocess.run(["kcov", "--verify", "--exclude-pattern=/.cargo,/usr/lib", out, binary], check=True)
subprocess.run(["kcov", "--merge", COV_OUT_DIR, *dirs_to_merge], check=True)