From 1c4b016764aa59ccfca2bfe94805e33d29367608 Mon Sep 17 00:00:00 2001 From: Yihuang Yu Date: Thu, 15 Jun 2023 10:07:56 +0800 Subject: [PATCH 1/2] KSMController.is_ksm_running: Strip the output to avoid failure The output of `process.run("cat /sys/kernel/mm/ksm/run").stdout_text` is '0\n', which does not match numeric only string, the make the function always returns `True`. Signed-off-by: Yihuang Yu --- virttest/utils_misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virttest/utils_misc.py b/virttest/utils_misc.py index b9bd2d3643..ffe44897fc 100644 --- a/virttest/utils_misc.py +++ b/virttest/utils_misc.py @@ -3084,7 +3084,8 @@ def is_ksm_running(self): Verify whether ksm is running. """ if self.interface == "sysfs": - running = process.run("cat %s" % self.ksm_params["run"]).stdout_text + running = process.run( + "cat %s" % self.ksm_params["run"]).stdout_text.strip() else: output = process.run("ksmctl info").stdout_text try: From a41e37e181d934a71b0f0df9e82e0e4f997f1aad Mon Sep 17 00:00:00 2001 From: Yihuang Yu Date: Thu, 15 Jun 2023 10:19:07 +0800 Subject: [PATCH 2/2] KSMConfig.cleanup: Ensure ksm to be disabled at the end of the case In the `cleanup` function, "start_ksmtuned" will start the ksmtuned.service, it controls and tunes the ksm service, but depends on the KSM_MONITOR_INTERVAL. So ksm is not closed immediately, but at some time in KSM_MONITOR_INTERVAL loop. Without this fix, the next test case may launch the guest with ksm enabled, which is not expected. Signed-off-by: Yihuang Yu --- virttest/test_setup/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/virttest/test_setup/__init__.py b/virttest/test_setup/__init__.py index c845c96534..13952a9e7c 100644 --- a/virttest/test_setup/__init__.py +++ b/virttest/test_setup/__init__.py @@ -638,7 +638,7 @@ def __init__(self, params, env): if self.run == "yes": self.run = "1" elif self.run == "no": - self.run == "0" + self.run = "0" # Get KSM module status if there is one self.ksmctler = utils_misc.KSMController() @@ -695,6 +695,12 @@ def cleanup(self, env): # ksmtuned used to run in host. Start the process # and don't need set up the configures. self.ksmctler.start_ksmtuned() + # Ensure ksm it not enabled before return + if not wait.wait_for(lambda: not self.ksmctler.is_ksm_running(), + timeout=120, step=5, + text="Waiting for ksm to be disabled"): + LOG.warning("KSM is still running, subsequent test may not " + "work as expected") return if default_status == self.default_status: