Skip to contentSkip to conversation

KVM test: kvm_subprocess: use read_nonblocking(0) instead of read_nonblocking (0.1)

PATCH In review Michael Goldish 2 participants 7 messages Sep 29, 2009 – Oct 5, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 KVM test: kvm_subprocess: use read_nonblocking(0) instead of read_nonblocking (0.1)

In get_command_status_output() and is_responsive() use read_nonblocking(0) to read the unread output before sending input (e.g. a command).
The timeout is currently 0.1 because theoretically it should help if the guest still produces output when the function is called, but in practice there's no guarantee that a value of 0.1 will suffice. Therefore, it is be the user's responsibility to make sure the guest stopped producing output before get_command_status_output() is called. This can be guaranteed (in most cases) by using get_command_status_output() and friends instead of sendline() to send commands (because the former waits for the prompt to return, whereas the latter returns immediately).

---
 client/tests/kvm/kvm_subprocess.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_subprocess.py +2 -2
index 424c801..730f20e 100755
@@ -1028,7 +1028,7 @@ class kvm_shell_session(kvm_expect):
         """
         # Read all output that's waiting to be read, to make sure the output
         # we read next is in response to the newline sent
-        self.read_nonblocking(timeout=0.1)
+        self.read_nonblocking(timeout=0)
         # Send a newline
         self.sendline()
         # Wait up to timeout seconds for some output from the child
@@ -1095,7 +1095,7 @@ class kvm_shell_session(kvm_expect):
         logging.debug("Sending command: %s" % command)
 
         # Read everything that's waiting to be read
-        self.read_nonblocking(0.1)
+        self.read_nonblocking(timeout=0)
 
         # Send the command and get its output
         self.sendline(command)
Signature · 1 line
1.5.4.1
#1 lore raw

PATCH 2/6 KVM test: AutoIt and Autotest wrappers: use get_command_output() instead of sendline()

get_command_output() is safer because it waits for the prompt to return. sendline() returns immediately, and the output generated in response to the command can appear later and interfere with the test.
For example, the prompt can appear while the Autotest wrapper waits for an Autotest test to complete, and this will make the wrapper exit as if the test has completed.

---
 client/tests/kvm/tests/autoit.py   |    7 +++----
 client/tests/kvm/tests/autotest.py |    9 ++++-----
 2 files changed, 7 insertions(+), 9 deletions(-)
client/tests/kvm/tests/autoit.py +3 -4
index fd2a2cb..9435d7c 100644
@@ -30,18 +30,17 @@ def run_autoit(test, params, env):
 
         # Send AutoIt script to guest (this code will be replaced once we
         # support sending files to Windows guests)
-        session.sendline("del script.au3")
+        session.get_command_output("del script.au3", internal_timeout=0)
         file = open(kvm_utils.get_path(test.bindir, script))
         for line in file.readlines():
             # Insert a '^' before each character
             line = "".join("^" + c for c in line.rstrip())
             if line:
                 # Append line to the file
-                session.sendline("echo %s>>script.au3" % line)
+                session.get_command_output("echo %s>>script.au3" % line,
+                                           internal_timeout=0)
         file.close()
 
-        session.read_up_to_prompt()
-
         command = "cmd /c %s script.au3 %s" % (binary, script_params)
 
         logging.info("---------------- Script output ----------------")
client/tests/kvm/tests/autotest.py +4 -5
index 5c9b2aa..798217d 100644
@@ -85,7 +85,7 @@ def run_autotest(test, params, env):
     extract(vm, "autotest.tar.bz2")
 
     # mkdir autotest/tests
-    session.sendline("mkdir autotest/tests")
+    session.get_command_output("mkdir autotest/tests")
 
     # Extract <test_name>.tar.bz2 into autotest/tests
     extract(vm, test_name + ".tar.bz2", "autotest/tests")
@@ -99,10 +99,9 @@ def run_autotest(test, params, env):
 
     # Run the test
     logging.info("Running test '%s'..." % test_name)
-    session.sendline("cd autotest")
-    session.sendline("rm -f control.state")
-    session.sendline("rm -rf results/*")
-    session.read_up_to_prompt()
+    session.get_command_output("cd autotest")
+    session.get_command_output("rm -f control.state")
+    session.get_command_output("rm -rf results/*")
     logging.info("---------------- Test output ----------------")
     status = session.get_command_status("bin/autotest control",
                                         timeout=test_timeout,
Signature · 1 line
1.5.4.1
#2 lore raw

PATCH 3/6 KVM test: kvm_vm.py: change qemu-img timeout to 120 seconds

The timeout of qemu-img commands is currently 30 seconds.
This may not suffice under heavy load (e.g. when multiple tests run in parallel and use the same physical disk).

---
 client/tests/kvm/kvm_vm.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_vm.py +1 -1
index 07ceb6d..ff6c044 100755
@@ -55,7 +55,7 @@ def create_image(params, root_dir):
 
     logging.debug("Running qemu-img command:\n%s" % qemu_img_cmd)
     (status, output) = kvm_subprocess.run_fg(qemu_img_cmd, logging.debug,
-                                             "(qemu-img) ", timeout=30)
+                                             "(qemu-img) ", timeout=120)
 
     if status is None:
         logging.error("Timeout elapsed while waiting for qemu-img command "
Signature · 1 line
1.5.4.1
#3 lore raw

PATCH 4/6 KVM test: step file tests: add parameter timeout_multiplier

This parameter multiplies the timeout values of all the barriers in a step file test.
It is useful for slower hosts, under load (e.g. when executing multiple tests in parallel) and for testing QEMU without KVM. In any of these cases, the multiplier should be greater than 1 in order to give the test more time to complete.

In addition to modifying tests/steps.py, this patch adds a usage example to control and control.parallel.

---
 client/tests/kvm/control          |    1 +
 client/tests/kvm/control.parallel |    1 +
 client/tests/kvm/tests/steps.py   |   22 +++++++++++++++-------
 3 files changed, 17 insertions(+), 7 deletions(-)
client/tests/kvm/control +1 -0
index 72658f1..491870a 100644
@@ -140,6 +140,7 @@ filename = os.path.join(pwd, "kvm_tests.cfg")
 cfg = kvm_config.config(filename)
 
 # If desirable, make changes to the test configuration here.  For example:
+# cfg.parse_string("install|setup: timeout_multiplier = 2")
 # cfg.parse_string("only fc8_quick")
 # cfg.parse_string("display = sdl")
 
client/tests/kvm/control.parallel +1 -0
index cf268ea..fac0176 100644
@@ -136,6 +136,7 @@ filename = os.path.join(pwd, "kvm_tests.cfg")
 cfg = kvm_config.config(filename)
 
 # If desirable, make changes to the test configuration here.  For example:
+# cfg.parse_string("install|setup: timeout_multiplier = 2")
 # cfg.parse_string("only fc8_quick")
 # cfg.parse_string("display = sdl")
 
client/tests/kvm/tests/steps.py +15 -7
index 8bc85f2..d0b7dbd 100644
@@ -33,6 +33,21 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
     cmd, dx, dy, x1, y1, md5sum, timeout = words[:7]
     dx, dy, x1, y1, timeout = map(int, [dx, dy, x1, y1, timeout])
 
+    scrdump_filename = os.path.join(debug_dir, "scrdump.ppm")
+    cropped_scrdump_filename = os.path.join(debug_dir, "cropped_scrdump.ppm")
+    expected_scrdump_filename = os.path.join(debug_dir, "scrdump_expected.ppm")
+    expected_cropped_scrdump_filename = os.path.join(debug_dir,
+                                                 "cropped_scrdump_expected.ppm")
+    comparison_filename = os.path.join(debug_dir, "comparison.ppm")
+
+    # Multiply timeout by the timeout multiplier
+    timeout_multiplier = params.get("timeout_multiplier")
+    if timeout_multiplier:
+        timeout_multiplier = float(timeout_multiplier)
+    else:
+        timeout_multiplier = 1.0
+    timeout *= timeout_multiplier
+
     # Timeout/5 is the time it took stepmaker to complete this step.
     # Divide that number by 10 to poll 10 times, just in case
     # current machine is stronger then the "stepmaker machine".
@@ -41,13 +56,6 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
     if sleep_duration < 1.0: sleep_duration = 1.0
     if sleep_duration > 10.0: sleep_duration = 10.0
 
-    scrdump_filename = os.path.join(debug_dir, "scrdump.ppm")
-    cropped_scrdump_filename = os.path.join(debug_dir, "cropped_scrdump.ppm")
-    expected_scrdump_filename = os.path.join(debug_dir, "scrdump_expected.ppm")
-    expected_cropped_scrdump_filename = os.path.join(debug_dir,
-                                                 "cropped_scrdump_expected.ppm")
-    comparison_filename = os.path.join(debug_dir, "comparison.ppm")
-
     fail_if_stuck_for = params.get("fail_if_stuck_for")
     if fail_if_stuck_for:
         fail_if_stuck_for = float(fail_if_stuck_for)
Signature · 1 line
1.5.4.1
#4 lore raw

PATCH 5/6 KVM test: tests/steps.py: simplify barrier_2()

Add a few comments, group similar lines and replace some blocks with one-liners.

Note: the weird form
timeout_multiplier = float(params.get("timeout_multiplier") or 1) allows the user to fall back to the default value by setting timeout_multiplier to "".
The more common form
timeout_multiplier = float(params.get("timeout_multiplier", 1)) will raise an exception if timeout_multiplier is "".

---
 client/tests/kvm/tests/steps.py |   32 ++++++++++----------------------
 1 files changed, 10 insertions(+), 22 deletions(-)
client/tests/kvm/tests/steps.py +10 -22
index d0b7dbd..11b2ae1 100644
@@ -30,22 +30,27 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
         logging.error("Bad barrier_2 command line")
         return False
 
+    # Parse barrier command line
     cmd, dx, dy, x1, y1, md5sum, timeout = words[:7]
     dx, dy, x1, y1, timeout = map(int, [dx, dy, x1, y1, timeout])
 
+    # Define some paths
     scrdump_filename = os.path.join(debug_dir, "scrdump.ppm")
     cropped_scrdump_filename = os.path.join(debug_dir, "cropped_scrdump.ppm")
     expected_scrdump_filename = os.path.join(debug_dir, "scrdump_expected.ppm")
     expected_cropped_scrdump_filename = os.path.join(debug_dir,
                                                  "cropped_scrdump_expected.ppm")
     comparison_filename = os.path.join(debug_dir, "comparison.ppm")
+    history_dir = os.path.join(debug_dir, "barrier_history")
+
+    # Collect a few parameters
+    timeout_multiplier = float(params.get("timeout_multiplier") or 1)
+    fail_if_stuck_for = float(params.get("fail_if_stuck_for") or 1e308)
+    stuck_detection_history = int(params.get("stuck_detection_history") or 2)
+    keep_screendump_history = params.get("keep_screendump_history") == "yes"
+    keep_all_history = params.get("keep_all_history") == "yes"
 
     # Multiply timeout by the timeout multiplier
-    timeout_multiplier = params.get("timeout_multiplier")
-    if timeout_multiplier:
-        timeout_multiplier = float(timeout_multiplier)
-    else:
-        timeout_multiplier = 1.0
     timeout *= timeout_multiplier
 
     # Timeout/5 is the time it took stepmaker to complete this step.
@@ -56,23 +61,6 @@ def barrier_2(vm, words, params, debug_dir, data_scrdump_filename,
     if sleep_duration < 1.0: sleep_duration = 1.0
     if sleep_duration > 10.0: sleep_duration = 10.0
 
-    fail_if_stuck_for = params.get("fail_if_stuck_for")
-    if fail_if_stuck_for:
-        fail_if_stuck_for = float(fail_if_stuck_for)
-    else:
-        fail_if_stuck_for = 1e308
-
-    stuck_detection_history = params.get("stuck_detection_history")
-    if stuck_detection_history:
-        stuck_detection_history = int(stuck_detection_history)
-    else:
-        stuck_detection_history = 2
-
-    keep_screendump_history = params.get("keep_screendump_history") == "yes"
-    if keep_screendump_history:
-        keep_all_history = params.get("keep_all_history") == "yes"
-        history_dir = os.path.join(debug_dir, "barrier_history")
-
     end_time = time.time() + timeout
     end_time_stuck = time.time() + fail_if_stuck_for
     start_time = time.time()
Signature · 1 line
1.5.4.1
#5 lore raw

PATCH 6/6 KVM test: kvm_subprocess: use select() in read_until_output_matches()

Currently read_nonblocking() is called repeatedly until a match is found. This is fine as long as internal_timeout, the timeout parameter passed to read_nonblocking(), is greater than zero. If it equals zero the loop will keep the CPU busy and stress the host.
To avoid this, use select() to wait until there's output to read from the child process.

---
 client/tests/kvm/kvm_subprocess.py |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_subprocess.py +7 -2
index 730f20e..2ac062a 100755
@@ -848,8 +848,12 @@ class kvm_expect(kvm_tail):
         match = None
         data = ""
 
+        fd = self._get_fd("expect")
         end_time = time.time() + timeout
-        while time.time() < end_time:
+        while True:
+            r, w, x = select.select([fd], [], [],
+                                    max(0, end_time - time.time()))
+            if fd not in r: break
             # Read data from child
             newdata = self.read_nonblocking(internal_timeout)
             # Print it if necessary
@@ -868,7 +872,8 @@ class kvm_expect(kvm_tail):
                 done = True
             # Check if child has died
             if not self.is_alive():
-                logging.debug("Process terminated with status %s" % self.get_status())
+                logging.debug("Process terminated with status %s" %
+                              self.get_status())
                 done = True
             # Are we done?
             if done: break
Signature · 1 line
1.5.4.1
#6 lore raw
In reply to Michael Goldish

Patchset applied!

Quoted 46 lines · Michael Goldish

In get_command_status_output() and is_responsive() use read_nonblocking(0) to read the unread output before sending input (e.g. a command).
The timeout is currently 0.1 because theoretically it should help if the guest still produces output when the function is called, but in practice there's no guarantee that a value of 0.1 will suffice.  Therefore, it is be the user's responsibility to make sure the guest stopped producing output before get_command_status_output() is called.  This can be guaranteed (in most cases) by using get_command_status_output() and friends instead of sendline() to send commands (because the former waits for the prompt to return, whereas the latter returns immediately).

---
 client/tests/kvm/kvm_subprocess.py |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
client/tests/kvm/kvm_subprocess.py +0 -0
index 424c801..730f20e 100755
@@ -1028,7 +1028,7 @@ class kvm_shell_session(kvm_expect):

        """
        # Read all output that's waiting to be read, to make sure the output

        # we read next is in response to the newline sent
-        self.read_nonblocking(timeout=0.1)
+        self.read_nonblocking(timeout=0)
        # Send a newline
        self.sendline()
        # Wait up to timeout seconds for some output from the child
client/tests/kvm/kvm_subprocess.py +1 -2
@@ -1095,7 +1095,7 @@ class kvm_shell_session(kvm_expect):
         logging.debug("Sending command: %s" % command)
 
         # Read everything that's waiting to be read
-        self.read_nonblocking(0.1)
+        self.read_nonblocking(timeout=0)
 
         # Send the command and get its output
         self.sendline(command)
--

1.5.4.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Signature · 1 line
Lucas