From 5aee4f917ffd93d6beb8c91c155a5c7fa01755ef Mon Sep 17 00:00:00 2001 From: mcasquer Date: Tue, 23 Jul 2024 09:36:43 +0200 Subject: [PATCH] rh_kselftests_vm: kernel selftests execution in guest Creates a new test case that executes the kernel selftests inside the VM through the RPM that has been previously downloaded and installed. Could be expanded with more tests in the future. Signed-off-by: mcasquer --- qemu/tests/cfg/rh_kselftests_vm.cfg | 10 ++++ qemu/tests/rh_kselftests_vm.py | 79 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 qemu/tests/cfg/rh_kselftests_vm.cfg create mode 100644 qemu/tests/rh_kselftests_vm.py diff --git a/qemu/tests/cfg/rh_kselftests_vm.cfg b/qemu/tests/cfg/rh_kselftests_vm.cfg new file mode 100644 index 0000000000..433bc7488d --- /dev/null +++ b/qemu/tests/cfg/rh_kselftests_vm.cfg @@ -0,0 +1,10 @@ +- rh_kselftests_vm: + only RHEL + type = rh_kselftests_vm + virt_test_type = qemu + kernel_path = "/tmp/kernel" + kselftests_path = "/usr/libexec/kselftests" + variants: + - mm: + no s390x + selftests_type = mm diff --git a/qemu/tests/rh_kselftests_vm.py b/qemu/tests/rh_kselftests_vm.py new file mode 100644 index 0000000000..3b0f1052cb --- /dev/null +++ b/qemu/tests/rh_kselftests_vm.py @@ -0,0 +1,79 @@ +from virttest import error_context + + +class KernelSelftests(object): + """ + Class for kernel selftests + """ + + def __init__(self, test, params, env): + """ + Init the default values of KernelSelftests object. + + :param test: QEMU test object + :param params: A dict containing VM preprocessing parameters. + :param env: The environment (a dict-like object). + """ + self.session = None + self.test = test + self.params = params + self.env = env + + def run_test(self, test, params, env): + selftests_type = params["selftests_type"] + mm_test_type = "%s_test" % selftests_type + if hasattr(self, mm_test_type): + func = getattr(self, mm_test_type) + func(params) + else: + test.error("Could not find matching test, check the config file") + + def mm_test(self, params): + kselftests_path = params.get("kselftests_path") + params["tests_execution_cmd"] = ( + "cd %s/mm && sh run_vmtests.sh -t hugetlb" % kselftests_path + ) + params["setup_hugepages"] = "yes" + + +@error_context.context_aware +def run(test, params, env): + """ + rh_kselftests_vm test + 1) Download the current kernel selftests RPM + 2) Install the RPM + 3) Execute the kernel selftests + :param test: QEMU test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment + """ + kself_test = KernelSelftests(test, params, env) + kself_test.run_test(test, params, env) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + session = vm.wait_for_login() + kernel_path = params.get("kernel_path", "/tmp/kernel") + tests_execution_cmd = params.get("tests_execution_cmd") + + session.cmd("mkdir -p %s" % kernel_path) + kernel_version = session.cmd_output("uname -r").strip().split("+")[0] + error_context.base_context("The kernel version: %s" % kernel_version, test.log.info) + + error_context.context("Download the kernel selftests RPM", test.log.debug) + session.cmd("cd %s" % kernel_path) + session.cmd( + "brew download-build --rpm kernel-selftests-internal-%s.rpm" % kernel_version, + 180, + ) + + error_context.context("Install the RPM", test.log.debug) + session.cmd("dnf install -y ./kernel-*") + + error_context.base_context("Execute the selftests", test.log.info) + s, o = session.cmd_status_output(tests_execution_cmd, 180) + if s != 0: + test.fail("Error during selftests execution: %s" % o) + + test.log.info("The selftests results: %s" % o) + error_context.context("Cleaning kernel files", test.log.debug) + session.cmd("rm -rf %s" % kernel_path)