@@ -0,0 +1,51 @@
+import re, string, logging, random, time
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_balloon_check(test, params, env):
+ """
+ Check Memory ballooning:
+ 1) Boot a guest
+ 2) Change the memory between 60% to 95% of memory of guest using ballooning
+ 3) check memory info
+
+ @param test: kvm test object
+ @param params: Dictionary with the test parameters
+ @param env: Dictionary with test environment.
+ """
+
+ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+ session = kvm_test_utils.wait_for_login(vm)
+ fail = 0
+
+ # Check memory size
+ logging.info("Memory size check")
+ expected_mem = int(params.get("mem"))
+ actual_mem = vm.get_memory_size()
+ if actual_mem != expected_mem:
+ logging.error("Memory size mismatch:")
+ logging.error(" Assigned to VM: %s" % expected_mem)
+ logging.error(" Reported by OS: %s" % actual_mem)
+
+
+ #Check if info balloon works or not.
+ status, output = vm.send_monitor_cmd("info balloon")
+ if status != 0:
+ logging.error("qemu monitor command failed: info balloon")
+ fail += 1
+
+ #Reduce memory to random size between 60% to 95% of actual memory
+ percent = random.uniform(0.6, 0.95)
+ new_mem = int(percent*actual_mem)
+ vm.send_monitor_cmd("balloon %s" % new_mem)
+ time.sleep(20)
+ status, output = vm.send_monitor_cmd("info balloon")
+ ballooned_mem = int(re.findall("\d+",output)[0])
+ if ballooned_mem != new_mem:
+ logging.error("memory ballooning failed while changing memory from %s to %s" %actual_mem %new_mem)
+ fail += 1
+
+ #Checking for test result
+ if fail != 0:
+ raise error.TestFail("Memory ballooning test failed ")
+ session.close()
@@ -171,6 +171,10 @@ variants:
drift_threshold = 10
drift_threshold_single = 3
+ - balloon_check: install setup unattended_install
+ type = balloon_check
+ extra_params += "-balloon virtio"
+
- stress_boot: install setup unattended_install
type = stress_boot
max_vms = 5