public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [KVM-AUTOTEST PATCH] KVM test: kvm_subprocess: add function kill_tail_thread()
@ 2009-08-11 12:31 Michael Goldish
  2009-07-20 15:07 ` [KVM-AUTOTEST PATCH 01/17] Add new module kvm_subprocess Michael Goldish
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Goldish @ 2009-08-11 12:31 UTC (permalink / raw)
  To: autotest, kvm; +Cc: Michael Goldish

Normally all threads are killed when the test process exits.  However, when
running multiple iterations of a test (with iterations=n) the test process
remains alive between iterations, and new threads are started but old threads
are not killed.  This function allow to stop thread execution explicitly.

This patch also makes the postprocessor call the function for all VMs.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_preprocessing.py |    4 ++++
 client/tests/kvm/kvm_subprocess.py    |   12 ++++++++++++
 client/tests/kvm/kvm_vm.py            |    8 ++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py
index 7c16305..ca86221 100644
--- a/client/tests/kvm/kvm_preprocessing.py
+++ b/client/tests/kvm/kvm_preprocessing.py
@@ -288,6 +288,10 @@ def postprocess(test, params, env):
                         int(params.get("post_command_timeout", "600")),
                         params.get("post_command_noncritical") == "yes")
 
+    # Kill the tailing threads of all VMs
+    for vm in kvm_utils.env_get_all_vms(env):
+        vm.kill_tail_thread()
+
     # Terminate tcpdump if no VMs are alive
     living_vms = [vm for vm in kvm_utils.env_get_all_vms(env) if vm.is_alive()]
     if not living_vms and env.has_key("tcpdump"):
diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py
index dcb20cc..07303a8 100644
--- a/client/tests/kvm/kvm_subprocess.py
+++ b/client/tests/kvm/kvm_subprocess.py
@@ -489,6 +489,7 @@ class kvm_tail(kvm_spawn):
         self.output_prefix = output_prefix
 
         # Start the thread in the background
+        self.__thread_kill_requested = False
         self.tail_thread = threading.Thread(None, self._tail)
         self.tail_thread.start()
 
@@ -551,6 +552,15 @@ class kvm_tail(kvm_spawn):
         self.output_prefix = output_prefix
 
 
+    def kill_tail_thread(self):
+        """
+        Stop the tailing thread which calls output_func() and
+        termination_func().
+        """
+        self.__thread_kill_requested = True
+        self._join_thread()
+
+
     def _tail(self):
         def print_line(text):
             # Pre-pend prefix and remove trailing whitespace
@@ -567,6 +577,8 @@ class kvm_tail(kvm_spawn):
         fd = self._get_fd("tail")
         buffer = ""
         while True:
+            if self.__thread_kill_requested:
+                return
             try:
                 # See if there's any data to read from the pipe
                 r, w, x = select.select([fd], [], [], 0.05)
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 9016ed3..edd822b 100644
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -573,6 +573,14 @@ class VM:
         return not self.process or not self.process.is_alive()
 
 
+    def kill_tail_thread(self):
+        """
+        Stop the tailing thread which reports the output of qemu.
+        """
+        if self.process:
+            self.process.kill_tail_thread()
+
+
     def get_params(self):
         """
         Return the VM's params dict. Most modified params take effect only
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-13 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <916351769.31401255352843062.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-10-12 13:07 ` [KVM-AUTOTEST,01/17] Add new module kvm_subprocess Michael Goldish
2009-10-13  1:59   ` Cao, Chen
2009-10-13 11:58     ` Michael Goldish
2009-08-11 12:31 [KVM-AUTOTEST PATCH] KVM test: kvm_subprocess: add function kill_tail_thread() Michael Goldish
2009-07-20 15:07 ` [KVM-AUTOTEST PATCH 01/17] Add new module kvm_subprocess Michael Goldish
2009-10-12  6:55   ` [KVM-AUTOTEST,01/17] " Cao, Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox