Skip to content

Commit

Permalink
env_process: Refactor QEMU coverage report resetter
Browse files Browse the repository at this point in the history
Refactor the piece of code in env_process.preprocess that resetted gcov
before running tests or creating VMs. Don't merge it with the
postprocess step related to gcov as well, as it would break the order
(relative to the process() call) in which they are run.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
  • Loading branch information
bgartzi committed Oct 16, 2024
1 parent 7d009bb commit 4c71f7f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
19 changes: 2 additions & 17 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# lazy imports for dependencies that are not needed in all modes of use
from virttest._wrappers import lazy_import
from virttest.test_setup.core import SetupManager
from virttest.test_setup.gcov import ResetQemuGCov
from virttest.test_setup.libvirt_setup import LibvirtdDebugLogConfig
from virttest.test_setup.migration import MigrationEnvSetup
from virttest.test_setup.networking import (
Expand Down Expand Up @@ -1014,24 +1015,8 @@ def preprocess(test, params, env):
vms = list(set(params.objects("vms") + migrate_vms))
params["vms"] = " ".join(vms)

# Check if code coverage for qemu is enabled and
# if coverage reset is enabled too, reset coverage report
gcov_qemu = params.get("gcov_qemu", "no") == "yes"
gcov_qemu_reset = params.get("gcov_qemu_reset", "no") == "yes"
if gcov_qemu and gcov_qemu_reset:
qemu_builddir = os.path.join(test.bindir, "build", "qemu")
qemu_bin = os.path.join(test.bindir, "bin", "qemu")
if os.path.isdir(qemu_builddir) and os.path.isfile(qemu_bin):
os.chdir(qemu_builddir)
# Looks like libvirt process does not have permissions to write to
# coverage files, hence give write for all files in qemu source
reset_cmd = "make clean-coverage;%s -version;" % qemu_bin
reset_cmd += (
'find %s -name "*.gcda" -exec chmod a=rwx {} \;' % qemu_builddir
)
a_process.system(reset_cmd, shell=True)

_setup_manager.initialize(test, params, env)
_setup_manager.register(ResetQemuGCov)
_setup_manager.register(VerifyHostDMesg)
_setup_manager.register(SwitchSMTOff)
_setup_manager.register(CheckRunningAsRoot)
Expand Down
28 changes: 28 additions & 0 deletions virttest/test_setup/gcov.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os

from avocado.utils import process as a_process

from virttest.test_setup.core import Setuper


class ResetQemuGCov(Setuper):
def setup(self):
# Check if code coverage for qemu is enabled and
# if coverage reset is enabled too, reset coverage report
gcov_qemu = self.params.get("gcov_qemu", "no") == "yes"
gcov_qemu_reset = self.params.get("gcov_qemu_reset", "no") == "yes"
if gcov_qemu and gcov_qemu_reset:
qemu_builddir = os.path.join(self.test.bindir, "build", "qemu")
qemu_bin = os.path.join(self.test.bindir, "bin", "qemu")
if os.path.isdir(qemu_builddir) and os.path.isfile(qemu_bin):
os.chdir(qemu_builddir)
# Looks like libvirt process does not have permissions to write to
# coverage files, hence give write for all files in qemu source
reset_cmd = "make clean-coverage;%s -version;" % qemu_bin
reset_cmd += (
'find %s -name "*.gcda" -exec chmod a=rwx {} \;' % qemu_builddir
)
a_process.system(reset_cmd, shell=True)

def cleanup(self):
pass

0 comments on commit 4c71f7f

Please sign in to comment.