Checks the time drift introduced by several reboots (default 1). Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_tests.cfg.sample | 5 ++ client/tests/kvm/tests/timedrift_with_reboot.py | 88 +++++++++++++++++++++++ 2 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/timedrift_with_reboot.py diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample index 618c21e..e80b645 100644 --- a/client/tests/kvm/kvm_tests.cfg.sample +++ b/client/tests/kvm/kvm_tests.cfg.sample @@ -120,6 +120,11 @@ variants: migration_iterations = 3 drift_threshold = 10 drift_threshold_single = 3 + - with_reboot: + type = timedrift_with_reboot + reboot_iterations = 1 + drift_threshold = 10 + drift_threshold_single = 3 - stress_boot: install setup type = stress_boot diff --git a/client/tests/kvm/tests/timedrift_with_reboot.py b/client/tests/kvm/tests/timedrift_with_reboot.py new file mode 100644 index 0000000..642daaf --- /dev/null +++ b/client/tests/kvm/tests/timedrift_with_reboot.py @@ -0,0 +1,88 @@ +import logging, time, commands, re +from autotest_lib.client.common_lib import error +import kvm_subprocess, kvm_test_utils, kvm_utils + + +def run_timedrift_with_reboot(test, params, env): + """ + Time drift test with reboot: + + 1) Log into a guest. + 2) Take a time reading from the guest and host. + 3) Reboot the guest. + 4) Take a second time reading. + 5) If the drift (in seconds) is higher than a user specified value, fail. + + @param test: KVM test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) + + # Collect test parameters: + # Command to run to get the current time + time_command = params.get("time_command") + # Filter which should match a string to be passed to time.strptime() + time_filter_re = params.get("time_filter_re") + # Time format for time.strptime() + time_format = params.get("time_format") + drift_threshold = float(params.get("drift_threshold", "10")) + drift_threshold_single = float(params.get("drift_threshold_single", "3")) + reboot_iterations = int(params.get("reboot_iterations", 1)) + + try: + # Get initial time + # (ht stands for host time, gt stands for guest time) + (ht0, gt0) = kvm_test_utils.get_time(session, time_command, + time_filter_re, time_format) + + # Reboot + for i in range(reboot_iterations): + # Get time before current iteration + (ht0_, gt0_) = kvm_test_utils.get_time(session, time_command, + time_filter_re, time_format) + # Run current iteration + logging.info("Rebooting: iteration %d of %d..." % + (i + 1, reboot_iterations)) + session = kvm_test_utils.reboot(vm, session) + # Get time after current iteration + (ht1_, gt1_) = kvm_test_utils.get_time(session, time_command, + time_filter_re, time_format) + # Report iteration results + host_delta = ht1_ - ht0_ + guest_delta = gt1_ - gt0_ + drift = abs(host_delta - guest_delta) + logging.info("Host duration (iteration %d): %.2f" % + (i + 1, host_delta)) + logging.info("Guest duration (iteration %d): %.2f" % + (i + 1, guest_delta)) + logging.info("Drift at iteration %d: %.2f seconds" % + (i + 1, drift)) + # Fail if necessary + if drift > drift_threshold_single: + raise error.TestFail("Time drift too large at iteration %d: " + "%.2f seconds" % (i + 1, drift)) + + # Get final time + (ht1, gt1) = kvm_test_utils.get_time(session, time_command, + time_filter_re, time_format) + + finally: + session.close() + + # Report results + host_delta = ht1 - ht0 + guest_delta = gt1 - gt0 + drift = abs(host_delta - guest_delta) + logging.info("Host duration (%d reboots): %.2f" % + (reboot_iterations, host_delta)) + logging.info("Guest duration (%d reboots): %.2f" % + (reboot_iterations, guest_delta)) + logging.info("Drift after %d reboots: %.2f seconds" % + (reboot_iterations, drift)) + + # Fail if necessary + if drift > drift_threshold: + raise error.TestFail("Time drift too large after %d reboots: " + "%.2f seconds" % (reboot_iterations, drift)) -- 1.5.4.1 -- 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