Skip to content

Commit

Permalink
coverage checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
choppsv1 committed Apr 17, 2024
1 parent bb58835 commit 9034e75
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
11 changes: 8 additions & 3 deletions munet/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#
"""Common CLI execute argument."""


def add_launch_args(add_func):

add_func(
"--gdb", metavar="NODE-LIST", help="comma-sep list of hosts to run gdb on"
)
add_func("--gdb", metavar="NODE-LIST", help="comma-sep list of hosts to run gdb on")
add_func(
"--gdb-breakpoints",
metavar="BREAKPOINT-LIST",
Expand Down Expand Up @@ -46,6 +45,7 @@ def add_launch_args(add_func):
help="comma-sep list of nodes to open windows viewing stdout",
)


def add_testing_args(add_func):
add_func(
"--cli-on-error",
Expand All @@ -59,6 +59,11 @@ def add_testing_args(add_func):
help="Enable coverage gathering if supported",
)

add_func(
"--cov-build-dir",
help="Specify the build dir for locating coverage data files",
)

add_launch_args(add_func)

add_func(
Expand Down
34 changes: 34 additions & 0 deletions munet/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import base64
import errno
import getpass
import glob
import ipaddress
import logging
import os
Expand Down Expand Up @@ -2909,6 +2910,36 @@ def add_network(self, name, config=None, **kwargs):
mtu = kwargs.get("mtu", config.get("mtu"))
return super().add_switch(name, cls=cls, config=config, mtu=mtu, **kwargs)

def setup_coverage(self):
bdir = self.cfgopt.getoption("--cov-build-dir")
if not bdir:
# Try and find the build dir using common prefix of gcno files
common = None
cwd = os.getcwd()
for f in glob.iglob(rf"{cwd}/**/*.gcno", recursive=True):
if not common:
common = os.path.dirname(f)
else:
common = os.path.commonprefix(common, f)
if not common:
break
assert (
bdir
), "Can't locate build directory for coverage data, use --cov-build-dir"

bdir = Path(bdir).resolve()
rundir = Path(self.rundir).resolve()
gcdadir = rundir / "gcda"
os.environ["FRR_BUILD_DIR"] = str(bdir)
os.environ["GCOV_PREFIX_STRIP"] = str(len(bdir.parts) - 1)
os.environ["GCOV_PREFIX"] = str(gcdadir)

# commander.cmd_raises(f"find {bdir} -name '*.gc??' -exec chmod o+rw {{}} +")
group_id = bdir.stat().st_gid
commander.cmd_raises(f"mkdir -p {gcdadir}")
commander.cmd_raises(f"chown -R root:{group_id} {gcdadir}")
commander.cmd_raises(f"chmod 2775 {gcdadir}")

async def run(self):
tasks = []

Expand All @@ -2918,6 +2949,9 @@ async def run(self):
run_nodes = [x for x in hosts if x.has_run_cmd()]
ready_nodes = [x for x in hosts if x.has_ready_cmd()]

if self.cfgopt.getoption("--coverage"):
self.setup_coverage()

pcapopt = self.cfgopt.getoption("--pcap")
pcapopt = pcapopt if pcapopt else ""
if pcapopt == "all":
Expand Down

0 comments on commit 9034e75

Please sign in to comment.