commit 58b79263adaaee08a7a913268f36e2f957b330db Author: Jonas Eriksson Date: Fri Mar 21 15:21:18 2014 +0100 tsc_sync tests: Avoid build and parameterize Signed-off-by: Jonas Eriksson Upstream-Status: Pending diff --git a/qemu/tests/timerdevice_clock_drift_with_ntp.py b/qemu/tests/timerdevice_clock_drift_with_ntp.py index 4498519..28f22c0 100644 --- a/qemu/tests/timerdevice_clock_drift_with_ntp.py +++ b/qemu/tests/timerdevice_clock_drift_with_ntp.py @@ -26,9 +26,11 @@ def run(test, params, env): :param params: Dictionary with test parameters. :param env: Dictionary with the test environment. """ + drift_filename = params.get("drift_filename", "/var/lib/ntp/drift") + def _drift_file_exist(): try: - session.cmd("test -f /var/lib/ntp/drift") + session.cmd("test -f %s" % drift_filename) return True except Exception: return False @@ -46,20 +48,25 @@ def run(test, params, env): timeout = int(params.get("login_timeout", 360)) sess_guest_load = vm.wait_for_login(timeout=timeout) - error.context("Copy time-warp-test.c to guest", logging.info) - src_file_name = os.path.join(data_dir.get_deps_dir(), "time_warp", - "time-warp-test.c") - vm.copy_files_to(src_file_name, "/tmp") + time_warp_test_cmd = params.get("time_warp_test_cmd", "/tmp/time-warp-test") + + if sess_guest_load.get_command_status("test -x %s" % time_warp_test_cmd): + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_deps_dir(), "time_warp", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") - error.context("Compile the time-warp-test.c", logging.info) - cmd = "cd /tmp/;" - cmd += " yum install -y popt-devel;" - cmd += " rm -f time-warp-test;" - cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" - sess_guest_load.cmd(cmd) + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + sess_guest_load.cmd(cmd) error.context("Stop ntpd and apply load on guest", logging.info) - sess_guest_load.cmd("yum install -y ntp; service ntpd stop") + default_ntp_stop_cmd = "yum install -y ntp; service ntpd stop; rm -f %s" % drift_filename + ntp_stop_cmd = params.get("ntp_stop_cmd", default_ntp_stop_cmd) + sess_guest_load.cmd(ntp_stop_cmd) load_cmd = "for ((I=0; I<`grep 'processor id' /proc/cpuinfo| wc -l`; I++));" load_cmd += " do taskset -c $I /bin/bash -c 'for ((;;)); do X=1; done &';" load_cmd += " done" @@ -80,12 +87,12 @@ def run(test, params, env): error.context("Run time-warp-test", logging.info) session = vm.wait_for_login(timeout=timeout) - cmd = "/tmp/time-warp-test > /dev/null &" + cmd = "%s > /dev/null &" % time_warp_test_cmd session.sendline(cmd) error.context("Start ntpd on guest", logging.info) - cmd = "service ntpd start; sleep 1; echo" - session.cmd(cmd) + ntp_start_cmd = params.get("ntp_start_cmd", "service ntpd start; sleep 1; echo") + session.cmd(ntp_start_cmd) error.context("Check if the drift file exists on guest", logging.info) test_run_timeout = float(params["test_run_timeout"]) @@ -93,10 +100,12 @@ def run(test, params, env): utils_misc.wait_for(_drift_file_exist, test_run_timeout, step=5) except aexpect.ShellCmdError, detail: raise error.TestError("Failed to wait for the creation of" - " /var/lib/ntp/drift file. Detail: '%s'" % detail) + " %s file. Detail: '%s'" % + (drift_filename, detail)) error.context("Verify the drift file content on guest", logging.info) - output = session.cmd("cat /var/lib/ntp/drift") + output = session.cmd("cat %s" % drift_filename) if int(abs(float(output))) > 20: raise error.TestFail("Failed to check the ntp drift." - " Output: '%s'" % output) + " Output from 'cat %s': '%s'" % + (drift_filename, output)) diff --git a/qemu/tests/timerdevice_tscsync_change_host_clksource.py b/qemu/tests/timerdevice_tscsync_change_host_clksource.py index 5339fce..3ea6cb2 100644 --- a/qemu/tests/timerdevice_tscsync_change_host_clksource.py +++ b/qemu/tests/timerdevice_tscsync_change_host_clksource.py @@ -43,23 +43,27 @@ def run(test, params, env): if not '0' in output: raise error.TestFail("Failed to check vsyscall. Output: '%s'" % output) - error.context("Copy time-warp-test.c to guest", logging.info) - src_file_name = os.path.join(data_dir.get_deps_dir(), "tsc_sync", - "time-warp-test.c") - vm.copy_files_to(src_file_name, "/tmp") - - error.context("Compile the time-warp-test.c", logging.info) - cmd = "cd /tmp/;" - cmd += " yum install -y popt-devel;" - cmd += " rm -f time-warp-test;" - cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" - session.cmd(cmd) - - error.context("Run time-warp-test", logging.info) + time_warp_test_cmd = params.get("time_warp_test_cmd", "/tmp/time-warp-test") + + if session.get_command_status("test -x %s" % time_warp_test_cmd): + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_deps_dir(), "tsc_sync", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") + + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + session.cmd(cmd) + + time_warp_test_cmd = "/tmp/time-warp-test" + + error.context("Run %s" % time_warp_test_cmd, logging.info) test_run_timeout = int(params.get("test_run_timeout", 10)) session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) - cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + _, output = session.cmd_status_output(time_warp_test_cmd, timeout=(test_run_timeout + 60)) re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" fail_cnt = re.findall(re_str, output) @@ -83,8 +87,7 @@ def run(test, params, env): logging.info) cmd = "$(sleep %d; pkill time-warp-test) &" session.sendline(cmd % test_run_timeout) - cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, + _, output = session.cmd_status_output(time_warp_test_cmd, timeout=(test_run_timeout + 60)) fail_cnt = re.findall(re_str, output) diff --git a/qemu/tests/timerdevice_tscsync_longtime.py b/qemu/tests/timerdevice_tscsync_longtime.py index 47cc659..841be62 100644 --- a/qemu/tests/timerdevice_tscsync_longtime.py +++ b/qemu/tests/timerdevice_tscsync_longtime.py @@ -40,23 +40,25 @@ def run(test, params, env): timeout = int(params.get("login_timeout", 360)) session = vm.wait_for_login(timeout=timeout) - error.context("Copy time-warp-test.c to guest", logging.info) - src_file_name = os.path.join(data_dir.get_root_dir(), "shared", "deps", - "time-warp-test.c") - vm.copy_files_to(src_file_name, "/tmp") + time_warp_test_cmd = params.get("time_warp_test_cmd", "/tmp/time-warp-test") - error.context("Compile the time-warp-test.c", logging.info) - cmd = "cd /tmp/;" - cmd += " yum install -y popt-devel;" - cmd += " rm -f time-warp-test;" - cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" - session.cmd(cmd) + if sess_guest_load.get_command_status("test -x %s", time_warp_test_cmd): + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_root_dir(), "shared", "deps", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") + + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + session.cmd(cmd) error.context("Run time-warp-test for minimum 4 hours", logging.info) test_run_timeout = int(params.get("test_run_timeout", 14400)) session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) - cmd = "/tmp/time-warp-test" - _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + _, output = session.cmd_status_output(time_warp_test_cmd, timeout=(test_run_timeout + 60)) re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" fail_cnt = re.findall(re_str, output)