[PATCH 6/8] KVM test: load/unload kvm module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Suqin Huang <shuang@xxxxxxxxxx>

check whether kvm modules exist, unload them if exist, else load them.

Signed-off-by: Suqin Huang <shuang@xxxxxxxxxx>
---
 client/tests/kvm/tests/module_probe.py |   53 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    6 +++
 2 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/module_probe.py

diff --git a/client/tests/kvm/tests/module_probe.py b/client/tests/kvm/tests/module_probe.py
new file mode 100644
index 0000000..519a916
--- /dev/null
+++ b/client/tests/kvm/tests/module_probe.py
@@ -0,0 +1,53 @@
+import re, commands, logging, os
+from autotest_lib.client.common_lib import error
+import kvm_subprocess, kvm_test_utils, kvm_utils
+
+def run_module_probe(test, params, env):
+    """
+    load/unload kvm modules several times.
+
+    Packet Loss Test:
+    1) check host cpu module
+    2) get module info
+    3) unload modules if they exist, else load them
+
+    @param test: Kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+
+    def module_probe(name_list, arg=""):
+        for name in name_list:
+            cmd = "modprobe %s %s" % (arg, name)
+            logging.debug(cmd)
+            s, o = commands.getstatusoutput(cmd)
+            if s != 0:
+                logging.error("Failed to load/unload modules %s" % o)
+                return False
+        return True
+
+    #Check host cpu module
+    flags = file("/proc/cpuinfo").read()
+    arch_check = re.findall("%s\s" % "vmx", flags)
+    if arch_check:
+        arch = "kvm_intel"
+    else:
+        arch = "kvm_amd"
+
+    #Check whether ksm module exist
+    if os.path.exists("/sys/module/ksm"):
+        mod_list = ["ksm", arch, "kvm"]
+    else:
+        mod_list = [arch, "kvm"]
+
+    logging.debug(mod_list)
+    load_count = int(params.get("load_count", 100))
+
+    try:
+        for i in range(load_count):
+                if not module_probe(mod_list):
+                    raise error.TestFail("Failed to load module %s" % mod_list)
+                if not module_probe(mod_list, "-r"):
+                    raise error.TestFail("Failed to remove module %s" % mod_list)
+    finally:
+        module_probe(mod_list)
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 1a260b4..8b2d752 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -748,6 +748,12 @@ variants:
             - vmexit:
                 case = vmexit
 
+    - module_probe:
+        type = module_probe
+        # You can specify your own module list, though it is not needed usually.
+        # mod_list = kvm
+        load_count = 100
+
     - ioquit:
         type = ioquit
         background_cmd = "for i in 1 2 3 4; do (nohup dd if=/dev/urandom of=/tmp/file bs=102400 count=10000000 &) done"
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux