Skip to contentSkip to conversation

KVM test: add simple timedrift test (mainly for Windows)

PATCH Michael Goldish 3 participants 4 messages Jul 21, 2009 – Jul 27, 2009 1 message not in the archive KVM

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 151 lines · ----- "Yolkfull Chow
Quoted 9 lines · Michael Goldish

1) Log into a guest.
2) Take a time reading from the guest and host.
3) Run load on the guest and host.
4) Take a second time reading.
5) Stop the load and rest for a while.
6) Take a third time reading.
7) If the drift immediately after load is higher than a user- specified value (in %), fail.
If the drift after the rest period is higher than a user-specified

value,

Quoted 6 lines

fail.

---
 client/tests/kvm/kvm.py       |    1 +
 client/tests/kvm/kvm_tests.py |  161

++++++++++++++++++++++++++++++++++++++++-

client/tests/kvm/kvm.py class kvm(test.test): · line 55

Quoted 8 lines
 2 files changed, 160 insertions(+), 2 deletions(-)
client/tests/kvm/kvm.py +0 -0
index b18b643..070e463 100644
@@ -55,6 +55,7 @@ class kvm(test.test):
                 "kvm_install":  test_routine("kvm_install",

"run_kvm_install"),

client/tests/kvm/kvm.py class kvm(test.test): · line 56

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                 "linux_s3":     test_routine("kvm_tests",

"run_linux_s3"),

client/tests/kvm/kvm.py class kvm(test.test): · line 57

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                 "stress_boot":  test_routine("kvm_tests",

"run_stress_boot"),

client/tests/kvm/kvm.py class kvm(test.test): · line 58

Quoted 1 line
client/tests/kvm/kvm.py +1 -0
+                "timedrift":    test_routine("kvm_tests",

"run_timedrift"),

client/tests/kvm/kvm.py class kvm(test.test): · line 61

Quoted 3 lines
client/tests/kvm/kvm.py +0 -0
                 }
 
         # Make it possible to import modules from the test's

bindir

Review

Quoted 1 line
(quoted diff) +0 -0

b/client/tests/kvm/kvm_tests.py

Quoted 10 lines

index 5991aed..ca0b8c0 100644

client/tests/kvm/kvm_tests.py +1 -1
@@ -1,4 +1,4 @@
-import time, os, logging
+import time, os, logging, re, commands
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, kvm_subprocess, ppm_utils, scan_results
 

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 533

Quoted 6 lines
client/tests/kvm/kvm_tests.py +0 -1
@@ -529,7 +529,6 @@ def run_stress_boot(tests, params, env):
     """
     # boot the first vm
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-
     if not vm:
         raise error.TestError("VM object not found in

environment")

Quoted 10 lines
client/tests/kvm/kvm_tests.py +5 -0
     if not vm.is_alive():
@@ -586,3 +585,161 @@ def run_stress_boot(tests, params, env):
         for se in sessions:
             se.close()
         logging.info("Total number booted: %d" % (num -1))
+
+
+def run_timedrift(test, params, env):
+    """
+    Time drift test (mainly for Windows guests):

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 602

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+
+    1) Log into a guest.
+    2) Take a time reading from the guest and host.
+    3) Run load on the guest and host.
+    4) Take a second time reading.
+    5) Stop the load and rest for a while.
+    6) Take a third time reading.
+    7) If the drift immediately after load is higher than a user-
+    specified value (in %), fail.
+    If the drift after the rest period is higher than a

user-specified value,

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 611

Quoted 9 lines
client/tests/kvm/kvm_tests.py +9 -0
+    fail.
+
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in

environment")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 613

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a

living VM")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 626

Quoted 13 lines
client/tests/kvm/kvm_tests.py +13 -0
+
+    logging.info("Waiting for guest to be up...")
+
+    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not session:
+        raise error.TestFail("Could not log into guest")
+
+    logging.info("Logged in")
+
+    # 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()

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 631

Quoted 5 lines
client/tests/kvm/kvm_tests.py +5 -0
+    time_filter_re = params.get("time_filter_re")
+    # Time format for time.strptime()
+    time_format = params.get("time_format")
+    guest_load_command = params.get("guest_load_command")
+    guest_load_stop_command =

params.get("guest_load_stop_command")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 633

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    host_load_command = params.get("host_load_command")
+    guest_load_instances = int(params.get("guest_load_instances",

"1"))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 634

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    host_load_instances = int(params.get("host_load_instances",

"0"))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 640

Quoted 6 lines
client/tests/kvm/kvm_tests.py +6 -0
+    # CPU affinity mask for taskset
+    cpu_mask = params.get("cpu_mask", "0xFF")
+    load_duration = float(params.get("load_duration", "30"))
+    rest_duration = float(params.get("rest_duration", "10"))
+    drift_threshold = float(params.get("drift_threshold", "200"))
+    drift_threshold_after_rest =

float(params.get("drift_threshold_after_rest",

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 647

Quoted 7 lines
client/tests/kvm/kvm_tests.py +7 -0
+                                                  "200"))
+
+    guest_load_sessions = []
+    host_load_sessions = []
+
+    # Remember the VM's previous CPU affinity
+    prev_cpu_mask = commands.getoutput("taskset -p %s" %

vm.get_pid())

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 650

Quoted 3 lines
client/tests/kvm/kvm_tests.py +3 -0
+    prev_cpu_mask = prev_cpu_mask.split()[-1]
+    # Set the VM's CPU affinity
+    commands.getoutput("taskset -p %s %s" % (cpu_mask,

vm.get_pid()))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 658

Quoted 8 lines
client/tests/kvm/kvm_tests.py +8 -0
+
+    try:
+        # Get time before load
+        host_time_0 = time.time()
+        session.sendline(time_command)
+        (match, s) = session.read_up_to_prompt()
+        s = re.findall(time_filter_re, s)[0]
+        guest_time_0 = time.mktime(time.strptime(s, time_format))

Hi Machael, this test looks good for me, but I have a little suggestion:
Why not write a common function to get guest time which really save many
duplicate codes here? It could has four parameters and I would also help
write it for you :-)

Quoted 6 lines

def get_guest_time(session, time_command, filter_re, format):
session.sendline(time_command)
(match, s) = session.read_up_to_prompt()
s = re.findall(filter_re, s)[0]
curr_time = time.mktime(time.strptime(s, format)) return curr_time

Thanks, makes perfect sense. The code seemed quite short already so I didn't bother, but it should save quite a few lines.

While we're at it, maybe the function should return the host time as well:
(host_time_0, guest_time_0) = get_current_time(...)

Anyway, if it's OK with everyone, I think I'll do it in an additional commit rather than re-post this one, because even a small change like that needs to undergo some minimal testing.

Quoted 105 lines
Quoted 9 lines
client/tests/kvm/kvm_tests.py +9 -0
+
+        # Run some load on the guest
+        logging.info("Starting load on guest...")
+        for i in range(guest_load_instances):
+            load_session = vm.ssh_login()
+            if not load_session:
+                raise error.TestFail("Could not log into guest")
+            load_session.set_output_prefix("(guest load %d) " % i)
+            load_session.set_output_func(logging.debug)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 677

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+            load_session.sendline(guest_load_command)
+            guest_load_sessions.append(load_session)
+
+        # Run some load on the host
+        logging.info("Starting load on host...")
+        for i in range(host_load_instances):
+            host_load_sessions.append(
+                kvm_subprocess.run_bg(host_load_command,
+                                      output_func=logging.debug,
+                                      output_prefix="(host load %d)

" % i,

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 679

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+                                      timeout=0.5))
+            # Set the CPU affinity of the shell running the load

process

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 681

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+            pid = host_load_sessions[-1].get_shell_pid()
+            commands.getoutput("taskset -p %s %s" % (cpu_mask,

pid))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 682

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+            # Try setting the CPU affinity of the load process

itself

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 685

Quoted 3 lines
client/tests/kvm/kvm_tests.py +3 -0
+            pid = host_load_sessions[-1].get_pid()
+            if pid:
+                commands.getoutput("taskset -p %s %s" % (cpu_mask,

pid))

Quoted 14 lines
client/tests/kvm/kvm_tests.py +14 -0
+
+        # Sleep for a while (during load)
+        logging.info("Sleeping for %s seconds..." % load_duration)
+        time.sleep(load_duration)
+
+        # Get time delta after load
+        host_time_1 = time.time()
+        session.sendline(time_command)
+        (match, s) = session.read_up_to_prompt()
+        s = re.findall(time_filter_re, s)[0]
+        guest_time_1 = time.mktime(time.strptime(s, time_format))
+
+        # Report results
+        host_delta = host_time_1 - host_time_0

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 709

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+        guest_delta = guest_time_1 - guest_time_0
+        drift = 100.0 * (host_delta - guest_delta) / host_delta
+        logging.info("Host duration: %.2f" % host_delta)
+        logging.info("Guest duration: %.2f" % guest_delta)
+        logging.info("Drift: %.2f%%" % drift)
+
+    finally:
+        logging.info("Cleaning up...")
+        # Restore the VM's CPU affinity
+        commands.getoutput("taskset -p %s %s" % (prev_cpu_mask,

vm.get_pid()))

Quoted 14 lines
client/tests/kvm/kvm_tests.py +14 -0
+        # Stop the guest load
+        if guest_load_stop_command:
+            session.get_command_output(guest_load_stop_command)
+        # Close all load shell sessions
+        for load_session in guest_load_sessions:
+            load_session.close()
+        for load_session in host_load_sessions:
+            load_session.close()
+
+    # Sleep again (rest)
+    logging.info("Sleeping for %s seconds..." % rest_duration)
+    time.sleep(rest_duration)
+
+    # Get time after rest

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 733

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+    host_time_2 = time.time()
+    session.sendline(time_command)
+    (match, s) = session.read_up_to_prompt()
+    s = re.findall(time_filter_re, s)[0]
+    guest_time_2 = time.mktime(time.strptime(s, time_format))
+
+    # Report results
+    host_delta_total = host_time_2 - host_time_0
+    guest_delta_total = guest_time_2 - guest_time_0
+    drift_total = 100.0 * (host_delta_total - guest_delta_total) /

host_delta

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 734

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    logging.info("Total host duration including rest: %.2f" %

host_delta_total)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 735

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    logging.info("Total guest duration including rest: %.2f" %

guest_delta_total)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 740

Quoted 5 lines
client/tests/kvm/kvm_tests.py +5 -0
+    logging.info("Total drift after rest: %.2f%%" % drift_total)
+
+    # Fail the test if necessary
+    if drift > drift_threshold:
+        raise error.TestFail("Time drift too large: %.2f%%" %

drift)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 742

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    if drift > drift_threshold_after_rest:
+        raise error.TestFail("Time drift too large after rest

period: %.2f%%"

Quoted 10 lines
client/tests/kvm/kvm_tests.py +3 -0
+                             % drift_total)
+
+    session.close()
Signature · 6 lines
1.5.4.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
#2 lore raw
Quoted 164 lines · Michael Goldish
Quoted 151 lines · ----- "Yolkfull Chow
Quoted 9 lines · Michael Goldish

1) Log into a guest.
2) Take a time reading from the guest and host.
3) Run load on the guest and host.
4) Take a second time reading.
5) Stop the load and rest for a while.
6) Take a third time reading.
7) If the drift immediately after load is higher than a user- specified value (in %), fail.
If the drift after the rest period is higher than a user-specified

value,

Quoted 6 lines

fail.

---
 client/tests/kvm/kvm.py       |    1 +
 client/tests/kvm/kvm_tests.py |  161

++++++++++++++++++++++++++++++++++++++++-

client/tests/kvm/kvm.py class kvm(test.test): · line 55

Quoted 8 lines
 2 files changed, 160 insertions(+), 2 deletions(-)
client/tests/kvm/kvm.py +0 -0
index b18b643..070e463 100644
@@ -55,6 +55,7 @@ class kvm(test.test):
                 "kvm_install":  test_routine("kvm_install",

"run_kvm_install"),

client/tests/kvm/kvm.py class kvm(test.test): · line 56

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                 "linux_s3":     test_routine("kvm_tests",

"run_linux_s3"),

client/tests/kvm/kvm.py class kvm(test.test): · line 57

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                 "stress_boot":  test_routine("kvm_tests",

"run_stress_boot"),

client/tests/kvm/kvm.py class kvm(test.test): · line 58

Quoted 1 line
client/tests/kvm/kvm.py +1 -0
+                "timedrift":    test_routine("kvm_tests",

"run_timedrift"),

client/tests/kvm/kvm.py class kvm(test.test): · line 61

Quoted 3 lines
client/tests/kvm/kvm.py +0 -0
                 }
 
         # Make it possible to import modules from the test's

bindir

Review

Quoted 1 line
(quoted diff) +0 -0

b/client/tests/kvm/kvm_tests.py

Quoted 10 lines

index 5991aed..ca0b8c0 100644

client/tests/kvm/kvm_tests.py +1 -1
@@ -1,4 +1,4 @@
-import time, os, logging
+import time, os, logging, re, commands
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, kvm_subprocess, ppm_utils, scan_results
 

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 533

Quoted 6 lines
client/tests/kvm/kvm_tests.py +0 -1
@@ -529,7 +529,6 @@ def run_stress_boot(tests, params, env):
     """
     # boot the first vm
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-
     if not vm:
         raise error.TestError("VM object not found in

environment")

Quoted 10 lines
client/tests/kvm/kvm_tests.py +5 -0
     if not vm.is_alive():
@@ -586,3 +585,161 @@ def run_stress_boot(tests, params, env):
         for se in sessions:
             se.close()
         logging.info("Total number booted: %d" % (num -1))
+
+
+def run_timedrift(test, params, env):
+    """
+    Time drift test (mainly for Windows guests):

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 602

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+
+    1) Log into a guest.
+    2) Take a time reading from the guest and host.
+    3) Run load on the guest and host.
+    4) Take a second time reading.
+    5) Stop the load and rest for a while.
+    6) Take a third time reading.
+    7) If the drift immediately after load is higher than a user-
+    specified value (in %), fail.
+    If the drift after the rest period is higher than a

user-specified value,

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 611

Quoted 9 lines
client/tests/kvm/kvm_tests.py +9 -0
+    fail.
+
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in

environment")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 613

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a

living VM")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 626

Quoted 13 lines
client/tests/kvm/kvm_tests.py +13 -0
+
+    logging.info("Waiting for guest to be up...")
+
+    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not session:
+        raise error.TestFail("Could not log into guest")
+
+    logging.info("Logged in")
+
+    # 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()

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 631

Quoted 5 lines
client/tests/kvm/kvm_tests.py +5 -0
+    time_filter_re = params.get("time_filter_re")
+    # Time format for time.strptime()
+    time_format = params.get("time_format")
+    guest_load_command = params.get("guest_load_command")
+    guest_load_stop_command =

params.get("guest_load_stop_command")

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 633

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    host_load_command = params.get("host_load_command")
+    guest_load_instances = int(params.get("guest_load_instances",

"1"))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 634

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    host_load_instances = int(params.get("host_load_instances",

"0"))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 640

Quoted 6 lines
client/tests/kvm/kvm_tests.py +6 -0
+    # CPU affinity mask for taskset
+    cpu_mask = params.get("cpu_mask", "0xFF")
+    load_duration = float(params.get("load_duration", "30"))
+    rest_duration = float(params.get("rest_duration", "10"))
+    drift_threshold = float(params.get("drift_threshold", "200"))
+    drift_threshold_after_rest =

float(params.get("drift_threshold_after_rest",

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 647

Quoted 7 lines
client/tests/kvm/kvm_tests.py +7 -0
+                                                  "200"))
+
+    guest_load_sessions = []
+    host_load_sessions = []
+
+    # Remember the VM's previous CPU affinity
+    prev_cpu_mask = commands.getoutput("taskset -p %s" %

vm.get_pid())

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 650

Quoted 3 lines
client/tests/kvm/kvm_tests.py +3 -0
+    prev_cpu_mask = prev_cpu_mask.split()[-1]
+    # Set the VM's CPU affinity
+    commands.getoutput("taskset -p %s %s" % (cpu_mask,

vm.get_pid()))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 658

Quoted 8 lines
client/tests/kvm/kvm_tests.py +8 -0
+
+    try:
+        # Get time before load
+        host_time_0 = time.time()
+        session.sendline(time_command)
+        (match, s) = session.read_up_to_prompt()
+        s = re.findall(time_filter_re, s)[0]
+        guest_time_0 = time.mktime(time.strptime(s, time_format))

Hi Machael, this test looks good for me, but I have a little suggestion:
Why not write a common function to get guest time which really save many
duplicate codes here? It could has four parameters and I would also help
write it for you :-)

Quoted 6 lines

def get_guest_time(session, time_command, filter_re, format):
session.sendline(time_command)
(match, s) = session.read_up_to_prompt()
s = re.findall(filter_re, s)[0]
curr_time = time.mktime(time.strptime(s, format)) return curr_time

Thanks, makes perfect sense. The code seemed quite short already so I didn't bother, but it should save quite a few lines.

Quoted 7 lines

While we're at it, maybe the function should return the host time as well:
(host_time_0, guest_time_0) = get_current_time(...)

Anyway, if it's OK with everyone, I think I'll do it in an additional commit rather than re-post this one, because even a small change like that needs to undergo some minimal testing.

Yes, return the host time as well is better. Anyway, I have to say this is really a well-designed test for timedrift. :-)

Quoted 106 lines
Quoted 106 lines
Quoted 10 lines
client/tests/kvm/kvm_tests.py +9 -0
+
+        # Run some load on the guest
+        logging.info("Starting load on guest...")
+        for i in range(guest_load_instances):
+            load_session = vm.ssh_login()
+            if not load_session:
+                raise error.TestFail("Could not log into guest")
+            load_session.set_output_prefix("(guest load %d) " % i)
+            load_session.set_output_func(logging.debug)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 677

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+            load_session.sendline(guest_load_command)
+            guest_load_sessions.append(load_session)
+
+        # Run some load on the host
+        logging.info("Starting load on host...")
+        for i in range(host_load_instances):
+            host_load_sessions.append(
+                kvm_subprocess.run_bg(host_load_command,
+                                      output_func=logging.debug,
+                                      output_prefix="(host load %d)

" % i,

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 679

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+                                      timeout=0.5))
+            # Set the CPU affinity of the shell running the load

process

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 681

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+            pid = host_load_sessions[-1].get_shell_pid()
+            commands.getoutput("taskset -p %s %s" % (cpu_mask,

pid))

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 682

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+            # Try setting the CPU affinity of the load process

itself

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 685

Quoted 3 lines
client/tests/kvm/kvm_tests.py +3 -0
+            pid = host_load_sessions[-1].get_pid()
+            if pid:
+                commands.getoutput("taskset -p %s %s" % (cpu_mask,

pid))

Quoted 14 lines
client/tests/kvm/kvm_tests.py +14 -0
+
+        # Sleep for a while (during load)
+        logging.info("Sleeping for %s seconds..." % load_duration)
+        time.sleep(load_duration)
+
+        # Get time delta after load
+        host_time_1 = time.time()
+        session.sendline(time_command)
+        (match, s) = session.read_up_to_prompt()
+        s = re.findall(time_filter_re, s)[0]
+        guest_time_1 = time.mktime(time.strptime(s, time_format))
+
+        # Report results
+        host_delta = host_time_1 - host_time_0

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 709

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+        guest_delta = guest_time_1 - guest_time_0
+        drift = 100.0 * (host_delta - guest_delta) / host_delta
+        logging.info("Host duration: %.2f" % host_delta)
+        logging.info("Guest duration: %.2f" % guest_delta)
+        logging.info("Drift: %.2f%%" % drift)
+
+    finally:
+        logging.info("Cleaning up...")
+        # Restore the VM's CPU affinity
+        commands.getoutput("taskset -p %s %s" % (prev_cpu_mask,

vm.get_pid()))

Quoted 14 lines
client/tests/kvm/kvm_tests.py +14 -0
+        # Stop the guest load
+        if guest_load_stop_command:
+            session.get_command_output(guest_load_stop_command)
+        # Close all load shell sessions
+        for load_session in guest_load_sessions:
+            load_session.close()
+        for load_session in host_load_sessions:
+            load_session.close()
+
+    # Sleep again (rest)
+    logging.info("Sleeping for %s seconds..." % rest_duration)
+    time.sleep(rest_duration)
+
+    # Get time after rest

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 733

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+    host_time_2 = time.time()
+    session.sendline(time_command)
+    (match, s) = session.read_up_to_prompt()
+    s = re.findall(time_filter_re, s)[0]
+    guest_time_2 = time.mktime(time.strptime(s, time_format))
+
+    # Report results
+    host_delta_total = host_time_2 - host_time_0
+    guest_delta_total = guest_time_2 - guest_time_0
+    drift_total = 100.0 * (host_delta_total - guest_delta_total) /

host_delta

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 734

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    logging.info("Total host duration including rest: %.2f" %

host_delta_total)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 735

Quoted 1 line
client/tests/kvm/kvm_tests.py +1 -0
+    logging.info("Total guest duration including rest: %.2f" %

guest_delta_total)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 740

Quoted 5 lines
client/tests/kvm/kvm_tests.py +5 -0
+    logging.info("Total drift after rest: %.2f%%" % drift_total)
+
+    # Fail the test if necessary
+    if drift > drift_threshold:
+        raise error.TestFail("Time drift too large: %.2f%%" %

drift)

client/tests/kvm/kvm_tests.py def run_stress_boot(tests, params, env): · line 742

Quoted 2 lines
client/tests/kvm/kvm_tests.py +2 -0
+    if drift > drift_threshold_after_rest:
+        raise error.TestFail("Time drift too large after rest

period: %.2f%%"

Quoted 10 lines
client/tests/kvm/kvm_tests.py +3 -0
+                             % drift_total)
+
+    session.close()
Signature · 6 lines
1.5.4.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
#3 lore raw
In reply to Michael Goldish
Quoted 164 lines · Michael Goldish
Quoted 151 lines · ----- "Yolkfull Chow
Quoted 9 lines · Michael Goldish

1) Log into a guest.
2) Take a time reading from the guest and host.
3) Run load on the guest and host.
4) Take a second time reading.
5) Stop the load and rest for a while.
6) Take a third time reading.
7) If the drift immediately after load is higher than a user- specified value (in %), fail.
If the drift after the rest period is higher than a user-specified

value,

Quoted 6 lines

fail.

---
 client/tests/kvm/kvm.py       |    1 +
 client/tests/kvm/kvm_tests.py |  161

++++++++++++++++++++++++++++++++++++++++-

client/tests/kvm/kvm.py class kvm(test.test): · line 55

Quoted 8 lines
 2 files changed, 160 insertions(+), 2 deletions(-)
client/tests/kvm/kvm.py +0 -0
index b18b643..070e463 100644
@@ -55,6 +55,7 @@ class kvm(test.test):
                  "kvm_install":  test_routine("kvm_install",

"run_kvm_install"),

client/tests/kvm/kvm.py class kvm(test.test): · line 56

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                  "linux_s3":     test_routine("kvm_tests",

"run_linux_s3"),

client/tests/kvm/kvm.py class kvm(test.test): · line 57

Quoted 1 line
client/tests/kvm/kvm.py +0 -0
                  "stress_boot":  test_routine("kvm_tests",

"run_stress_boot"),

client/tests/kvm/kvm.py class kvm(test.test): · line 58

Quoted 1 line
client/tests/kvm/kvm.py +1 -0
+                "timedrift":    test_routine("kvm_tests",

"run_timedrift"),

client/tests/kvm/kvm.py class kvm(test.test): · line 61

Quoted 3 lines
client/tests/kvm/kvm.py +0 -0
                  }
 
          # Make it possible to import modules from the test's

bindir

Review

Quoted 1 line
(quoted diff) +0 -0

b/client/tests/kvm/kvm_tests.py

Quoted 11 lines

index 5991aed..ca0b8c0 100644

client/tests/kvm/kvm_tests.py +1 -1
@@ -1,4 +1,4 @@
-import time, os, logging
+import time, os, logging, re, commands

 from autotest_lib.client.common_lib import utils, error import kvm_utils, kvm_subprocess, ppm_utils, scan_results

client/tests/kvm/kvm_tests.py +0 -0
@@ -529,7 +529,6 @@ def run_stress_boot(tests, params, env):

     """

Quoted 5 lines
     # boot the first vm
     vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
-
     if not vm:
         raise error.TestError("VM object not found in

environment")

Quoted 10 lines

     if not vm.is_alive():

client/tests/kvm/kvm_tests.py +0 -0
@@ -586,3 +585,161 @@ def run_stress_boot(tests, params, env):

         for se in sessions:
             se.close()
         logging.info("Total number booted: %d" % (num -1))

client/tests/kvm/kvm_tests.py +5 -0
+
+
+def run_timedrift(test, params, env):
+    """
+    Time drift test (mainly for Windows guests):

client/tests/kvm/kvm_tests.py

Quoted 10 lines
client/tests/kvm/kvm_tests.py +10 -0
+
+    1) Log into a guest.
+    2) Take a time reading from the guest and host.
+    3) Run load on the guest and host.
+    4) Take a second time reading.
+    5) Stop the load and rest for a while.
+    6) Take a third time reading.
+    7) If the drift immediately after load is higher than a user-
+    specified value (in %), fail.
+    If the drift after the rest period is higher than a

user-specified value,

Quoted 9 lines

+    fail.
+
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in

environment")

Quoted 2 lines

+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a

living VM")

client/tests/kvm/kvm_tests.py

Quoted 13 lines
client/tests/kvm/kvm_tests.py +13 -0
+
+    logging.info("Waiting for guest to be up...")
+
+    session = kvm_utils.wait_for(vm.ssh_login, 240, 0, 2)
+    if not session:
+        raise error.TestFail("Could not log into guest")
+
+    logging.info("Logged in")
+
+    # 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()

Quoted 5 lines

+    time_filter_re = params.get("time_filter_re")
+    # Time format for time.strptime()
+    time_format = params.get("time_format")
+    guest_load_command = params.get("guest_load_command")
+    guest_load_stop_command =

params.get("guest_load_stop_command")

Quoted 2 lines

+    host_load_command = params.get("host_load_command")
+    guest_load_instances = int(params.get("guest_load_instances",

"1"))

Quoted 1 line

+    host_load_instances = int(params.get("host_load_instances",

"0"))

Quoted 6 lines

+    # CPU affinity mask for taskset
+    cpu_mask = params.get("cpu_mask", "0xFF")
+    load_duration = float(params.get("load_duration", "30"))
+    rest_duration = float(params.get("rest_duration", "10"))
+    drift_threshold = float(params.get("drift_threshold", "200"))
+    drift_threshold_after_rest =

float(params.get("drift_threshold_after_rest",

client/tests/kvm/kvm_tests.py

Quoted 7 lines

+                                                  "200"))

client/tests/kvm/kvm_tests.py +6 -0
+
+    guest_load_sessions = []
+    host_load_sessions = []
+
+    # Remember the VM's previous CPU affinity
+    prev_cpu_mask = commands.getoutput("taskset -p %s" %

vm.get_pid())

Quoted 3 lines

+    prev_cpu_mask = prev_cpu_mask.split()[-1]
+    # Set the VM's CPU affinity
+    commands.getoutput("taskset -p %s %s" % (cpu_mask,

vm.get_pid()))

Quoted 8 lines

+
+    try:
+        # Get time before load
+        host_time_0 = time.time()
+        session.sendline(time_command)
+        (match, s) = session.read_up_to_prompt()
+        s = re.findall(time_filter_re, s)[0]
+        guest_time_0 = time.mktime(time.strptime(s, time_format))

Hi Machael, this test looks good for me, but I have a little suggestion:
Why not write a common function to get guest time which really save many
duplicate codes here? It could has four parameters and I would also help
write it for you :-)

Quoted 6 lines

def get_guest_time(session, time_command, filter_re, format):
    session.sendline(time_command)
    (match, s) = session.read_up_to_prompt()
    s = re.findall(filter_re, s)[0]
    curr_time = time.mktime(time.strptime(s, format)) return curr_time

Thanks, makes perfect sense. The code seemed quite short already so I didn't bother, but it should save quite a few lines.

Quoted 6 lines

While we're at it, maybe the function should return the host time as well:
(host_time_0, guest_time_0) = get_current_time(...)

Anyway, if it's OK with everyone, I think I'll do it in an additional commit rather than re-post this one, because even a small change like that needs to undergo some minimal testing.

Yes, I am OK with it. I am currently trying the test here on my test box. Code looks good.

#4 lore raw
Quoted 14 lines · Lucas Meneghel Rodrigues
Quoted 13 lines · Michael Goldish
Quoted 10 lines · ----- "Yolkfull Chow
Quoted 9 lines · Michael Goldish

1) Log into a guest.
2) Take a time reading from the guest and host.
3) Run load on the guest and host.
4) Take a second time reading.
5) Stop the load and rest for a while.
6) Take a third time reading.
7) If the drift immediately after load is higher than a user- specified value (in %), fail.
If the drift after the rest period is higher than a user-specified

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

value,

Quoted 1 line

fail.

Ok, looks good to me, test and config file applied. Thanks!