From 9034e757076accf75daec95a49ffabc9a052e267 Mon Sep 17 00:00:00 2001 From: Christian Hopps Date: Wed, 17 Apr 2024 14:24:37 +0000 Subject: [PATCH] coverage checkpoint --- munet/args.py | 11 ++++++++--- munet/native.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/munet/args.py b/munet/args.py index baf5099..49ad891 100644 --- a/munet/args.py +++ b/munet/args.py @@ -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", @@ -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", @@ -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( diff --git a/munet/native.py b/munet/native.py index 2fa02dd..408e808 100644 --- a/munet/native.py +++ b/munet/native.py @@ -11,6 +11,7 @@ import base64 import errno import getpass +import glob import ipaddress import logging import os @@ -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 = [] @@ -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":