Skip to content

Use grcov html output #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 22 additions & 58 deletions report/firefox_code_coverage/codecoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,19 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
i += 1
time.sleep(60)
mod_env["PATH"] = one_click_loaner_gcc + ":" + mod_env["PATH"]
fout = open(output_path, "w")
cmd = [grcov_path, "-t", output_format, "-p", "/home/worker/workspace/build/src/"]
cmd = [
grcov_path,
"-t",
output_format,
"-p",
"/home/worker/workspace/build/src/",
"-o",
output_path,
]
if output_format in ["coveralls", "coveralls+"]:
cmd += ["--token", "UNUSED", "--commit-sha", "UNUSED"]
cmd.extend(artifact_paths)
proc = subprocess.Popen(cmd, stdout=fout, stderr=subprocess.PIPE, env=mod_env)
proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, env=mod_env)
i = 0
while proc.poll() is None:
if i % 60 == 0:
Expand All @@ -265,40 +272,6 @@ def generate_report(grcov_path, output_format, output_path, artifact_paths):
raise Exception("Error while running grcov: {}\n".format(proc.stderr.read()))


def generate_html_report(
src_dir,
info_file=os.path.join(os.getcwd(), "output.info"),
output_dir=os.path.join(os.getcwd(), "report"),
silent=False,
style_file=None,
):
cwd = os.getcwd()
os.chdir(src_dir)

with open(os.devnull, "w") as fnull:
command = [
os.path.join(cwd, "lcov-bin/usr/local/bin/genhtml"),
"-o",
output_dir,
"--show-details",
"--highlight",
"--ignore-errors",
"source",
"--legend",
info_file,
]
if style_file is not None:
command += ["--css-file", style_file]
ret = subprocess.call(
command, stdout=fnull if silent else None, stderr=fnull if silent else None
)

if ret != 0:
raise Exception("Error while running genhtml.")

os.chdir(cwd)


def download_grcov():
local_path = "grcov"
local_version = "grcov_ver"
Expand Down Expand Up @@ -337,21 +310,6 @@ def download_grcov():
return local_path


def download_genhtml():
if os.path.isdir("lcov"):
os.chdir("lcov")
subprocess.check_call(["git", "pull"])
else:
subprocess.check_call(
["git", "clone", "https://github.com/linux-test-project/lcov.git"]
)
os.chdir("lcov")

subprocess.check_call(["make", "install", "DESTDIR=../lcov-bin"])

os.chdir("..")


def main():
parser = argparse.ArgumentParser()

Expand Down Expand Up @@ -418,8 +376,16 @@ def main():
action="store_true",
help="Only generate high-level stats, not a full HTML report",
)
parser.add_argument(
"-o",
"--output-dir",
help="The output directory for generated report",
default=os.path.join(os.getcwd(), "ccov-report"),
)
args = parser.parse_args()

os.makedirs(args.output_dir, exist_ok=True)

if (args.branch is None) != (args.commit is None):
parser.print_help()
return
Expand All @@ -444,9 +410,10 @@ def main():
grcov_path = download_grcov()

if args.stats:
generate_report(grcov_path, "coveralls", "output.json", artifact_paths)
output = os.path.join(args.output_dir, "output.json")
generate_report(grcov_path, "coveralls", output, artifact_paths)

with open("output.json", "r") as f:
with open(output, "r") as f:
report = json.load(f)

total_lines = 0
Expand All @@ -468,10 +435,7 @@ def main():
)
)
else:
generate_report(grcov_path, "lcov", "output.info", artifact_paths)

download_genhtml()
generate_html_report(os.path.abspath(args.src_dir))
generate_report(grcov_path, "html", args.output_dir, artifact_paths)


if __name__ == "__main__":
Expand Down
14 changes: 4 additions & 10 deletions report/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ def test(self):
codecoverage.generate_report("./grcov", "lcov", "output.info", artifact_paths)
self.assertTrue(os.path.exists("output.info"))

codecoverage.download_genhtml()
codecoverage.generate_html_report("tests", silent=True)
self.assertTrue(os.path.isdir("report"))
codecoverage.generate_report("./grcov", "html", "report_html", artifact_paths)
self.assertTrue(os.path.isdir("report_html"))
self.assertTrue(os.path.exists("report_html/index.html"))
self.assertTrue(os.path.exists("report_html/grcov.css"))

def test_suite_name_from_task_name(self):
cases = [
Expand Down Expand Up @@ -142,13 +143,6 @@ def test_download_grcov(self):
with open("grcov_ver", "r") as f:
self.assertEqual(ver, f.read())

def test_download_genhtml(self):
codecoverage.download_genhtml()
self.assertTrue(os.path.exists("./lcov-bin/usr/local/bin/genhtml"))

codecoverage.download_genhtml()
self.assertTrue(os.path.exists("./lcov-bin/usr/local/bin/genhtml"))


if __name__ == "__main__":
unittest.main()