提交 4eee8b52 编写于 作者: S Sitong Liu

timerdevice: add case to measure guest's time jump

Signed-off-by: NSitong Liu <siliu@redhat.com>
上级 93a7ec6f
......@@ -107,7 +107,7 @@
vcpu_socket = 2
- newer_msrs_support_check:
only Linux
no Host_RHEL.m5 Host_RHEL.m6.u0
no Host_RHEL.m6.u0
no RHEL.6.0 RHEL.6.1 RHEL.6.2 RHEL.6.3
type = timerdevice_kvmclock_newer_msrs_support
rtc_base = utc
......@@ -116,3 +116,12 @@
rtc_drift = slew
msrs = "4b564d01 4b564d00"
msrs_catch_re = "kvm-clock: Using msrs (\w+) and (\w+)"
- measure_time_jump:
only Linux
type = timerdevice_time_jump_check
rtc_base = utc
rtc_clock = host
i386, x86_64:
rtc_drift = slew
check_cmd = "for i in `seq 20`; do date +'%y-%m-%d %H:%M:%S';done"
host_cpu_cnt_cmd = "cat /proc/cpuinfo | grep "physical id" | wc -l"
import logging
import time
from virttest import error_context
from virttest.compat_52lts import decode_to_text
from avocado.utils import process
@error_context.context_aware
def run(test, params, env):
"""
check time jumps in guest (only for Linux guest):
1) boot guest with '-rtc base=utc,clock=host,driftfix=slew'
2) check current clocksource in guest
3) pin all vcpus to specfic host CPUs
4) verify time jump
:param test: QEMU test object.
:param params: Dictionary with test parameters.
:param env: Dictionary with the test environment.
"""
vm = env.get_vm(params["main_vm"])
session = vm.wait_for_login()
error_context.context("Check the clock source currently used on guest",
logging.info)
cmd = "cat /sys/devices/system/clocksource/"
cmd += "clocksource0/current_clocksource"
logging.info("%s is current clocksource." % session.cmd_output(cmd))
error_context.context("Pin every vcpu to physical cpu", logging.info)
host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"]
host_cpu_num = decode_to_text(process.system_output(host_cpu_cnt_cmd,
shell=True)).strip()
host_cpu_list = (_ for _ in range(int(host_cpu_num)))
if len(vm.vcpu_threads) > int(host_cpu_num):
host_cpu_list = []
for _ in range(len(vm.vcpu_threads)):
host_cpu_list.append(_ % int(host_cpu_num))
cpu_pin_list = list(zip(vm.vcpu_threads, host_cpu_list))
for vcpu, pcpu in cpu_pin_list:
process.system("taskset -p -c %s %s" % (pcpu, vcpu))
check_cmd = params["check_cmd"]
output = str(session.cmd_output(check_cmd)).splitlines()
session.close()
time_pattern = "%y-%m-%d %H:%M:%S"
time_list = []
for str_time in output:
time_struct = time.strptime(str_time, time_pattern)
etime = time.mktime(time_struct)
time_list.append(etime)
for idx, _ in enumerate(time_list):
if idx < len(time_list) - 1:
if _ == time_list[idx+1] or (_ + 1) == time_list[idx+1]:
continue
else:
test.fail("Test fail, time jumps backward or forward on guest")
else:
break
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册