From patchwork Tue Aug 11 12:31:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 40603 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7BCSUAR001471 for ; Tue, 11 Aug 2009 12:28:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752696AbZHKM2Z (ORCPT ); Tue, 11 Aug 2009 08:28:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752660AbZHKM2Y (ORCPT ); Tue, 11 Aug 2009 08:28:24 -0400 Received: from mx2.redhat.com ([66.187.237.31]:58331 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752514AbZHKM2Y (ORCPT ); Tue, 11 Aug 2009 08:28:24 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7BCSO65030945; Tue, 11 Aug 2009 08:28:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7BCSMWC026802; Tue, 11 Aug 2009 08:28:23 -0400 Received: from localhost.localdomain (dhcp-1-31.tlv.redhat.com [10.35.1.31]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7BCSK65032142; Tue, 11 Aug 2009 08:28:21 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH] KVM test: kvm_subprocess: add function kill_tail_thread() Date: Tue, 11 Aug 2009 15:31:05 +0300 Message-Id: X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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