Skip to content

Commit

Permalink
munet: change tar archive when gathering gcov data from qemu kernel
Browse files Browse the repository at this point in the history
Do not include the "/sys/kernel/debug/gcov" path in the tar archive
  • Loading branch information
choppsv1 committed Apr 17, 2024
1 parent 4c6cf07 commit 78bf8dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
47 changes: 34 additions & 13 deletions munet/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# pylint: disable=protected-access
"""A module that defines objects for standalone use."""
import asyncio
import base64
import errno
import getpass
import ipaddress
Expand Down Expand Up @@ -2059,24 +2060,44 @@ async def renumber_interfaces(self):

async def gather_coverage_data(self):
con = self.conrepl
gcda_root = "/sys/kernel/debug/gcov"
dest = "/tmp/gcov-data.tgz"

if gcda_root != "/sys/kernel/debug/gcov":
con.cmd_raises(
rf"cd {gcda_root} && find * -name '*.gc??' "
"| tar -cf - -T - | gzip -c > {dest}"
)
else:
# Some tars dont try and read 0 length files so we need to copy them.
tmpdir = con.cmd_raises("mktemp -d").strip()
con.cmd_raises(
rf"cd {gcda_root} && find -type d -exec mkdir -p {tmpdir}/{{}} \;"
)
con.cmd_raises(
rf"cd {gcda_root} && "
rf"find -name '*.gcda' -exec sh -c 'cat < $0 > {tmpdir}/$0' {{}} \;"
)
con.cmd_raises(
rf"cd {gcda_root} && "
rf"find -name '*.gcno' -exec sh -c 'cp -d $0 {tmpdir}/$0' {{}} \;"
)
con.cmd_raises(
rf"cd {tmpdir} && "
rf"find * -name '*.gc??' | tar -cf - -T - | gzip -c > {dest}"
)
con.cmd_raises(rf"rm -rf {tmpdir}")

gcda = "/sys/kernel/debug/gcov"
tmpdir = con.cmd_raises("mktemp -d").strip()
dest = "/gcov-data.tgz"
con.cmd_raises(rf"find {gcda} -type d -exec mkdir -p {tmpdir}/{{}} \;")
con.cmd_raises(
rf"find {gcda} -name '*.gcda' -exec sh -c 'cat < $0 > {tmpdir}/$0' {{}} \;"
)
con.cmd_raises(
rf"find {gcda} -name '*.gcno' -exec sh -c 'cp -d $0 {tmpdir}/$0' {{}} \;"
)
con.cmd_raises(rf"tar cf - -C {tmpdir} sys | gzip -c > {dest}")
con.cmd_raises(rf"rm -rf {tmpdir}")
self.logger.info("Saved coverage data in VM at %s", dest)
ldest = os.path.join(self.rundir, "gcov-data.tgz")
if self.use_ssh:
ldest = os.path.join(self.rundir, "gcov-data.tgz")
self.cmd_raises(["/bin/cat", dest], stdout=open(ldest, "wb"))
self.logger.info("Saved coverage data on host at %s", ldest)
else:
output = con.cmd_raises(rf"base64 {dest}")
with open(ldest, "wb") as f:
f.write(base64.b64decode(output))
self.logger.info("Saved coverage data on host at %s", ldest)

async def _opencons(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "munet"
version = "0.13.19"
version = "0.13.20"
description = "A package to facilitate network simulations"
authors = ["Christian Hopps <chopps@labn.net>"]
license = "GPL-2.0-or-later"
Expand Down

0 comments on commit 78bf8dc

Please sign in to comment.