From patchwork Tue May 11 09:03:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 98652 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4B8x6x4015624 for ; Tue, 11 May 2010 08:59:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757503Ab0EKI7B (ORCPT ); Tue, 11 May 2010 04:59:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3591 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757501Ab0EKI7A (ORCPT ); Tue, 11 May 2010 04:59:00 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4B8wxKl005197 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 May 2010 04:58:59 -0400 Received: from localhost.localdomain ([10.66.91.25]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4B8wuN4031795; Tue, 11 May 2010 04:58:57 -0400 Subject: [PATCH v2 05/10] KVM test: Log the content from guest serial console To: lmr@redhat.com, autotest@test.kernel.org From: Jason Wang Cc: kvm@vger.kernel.org Date: Tue, 11 May 2010 17:03:50 +0800 Message-ID: <20100511090350.19914.96243.stgit@localhost.localdomain> In-Reply-To: <20100511083338.19914.7719.stgit@localhost.localdomain> References: <20100511083338.19914.7719.stgit@localhost.localdomain> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 11 May 2010 08:59:06 +0000 (UTC) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 4b9290c..0a33d24 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -1,4 +1,5 @@ import sys, os, time, commands, re, logging, signal, glob, threading, shutil +import socket, select from autotest_lib.client.bin import test, utils from autotest_lib.client.common_lib import error import kvm_vm, kvm_utils, kvm_subprocess, ppm_utils @@ -13,7 +14,8 @@ except ImportError: _screendump_thread = None _screendump_thread_termination_event = None - +_serialdump_thread = None +_serialdump_thread_termination_event = None def preprocess_image(test, params): """ @@ -267,6 +269,16 @@ def preprocess(test, params, env): args=(test, params, env)) _screendump_thread.start() + # Start the serial dump thread + if params.get("serial_mode") == "dump": + logging.debug("Starting serialdump thread") + global _serialdump_thread, _serialdump_thread_termination_event + _serialdump_thread_termination_event = threading.Event() + _serialdump_thread = threading.Thread(target=_dump_serial_console, + args=(test, params, env)) + _serialdump_thread.start() + + def postprocess(test, params, env): """ @@ -286,6 +298,13 @@ def postprocess(test, params, env): _screendump_thread_termination_event.set() _screendump_thread.join(10) + # Terminate the serialdump thread + global _serialdump_thread, _serialdump_thread_termination_event + if _serialdump_thread: + logging.debug("Terminating serialdump thread...") + _serialdump_thread_termination_event.set() + _serialdump_thread.join(10) + # Warn about corrupt PPM files for f in glob.glob(os.path.join(test.debugdir, "*.ppm")): if not ppm_utils.image_verify_ppm_file(f): @@ -450,3 +469,41 @@ def _take_screendumps(test, params, env): if _screendump_thread_termination_event.isSet(): break _screendump_thread_termination_event.wait(delay) + +def _dump_serial_console(test, params, env): + global _serialdump_thread_termination_event + rs = [] + files = {} + + while True: + for vm in kvm_utils.env_get_all_vms(env): + if not vm in files and not vm.is_dead(): + try: + serial_socket = socket.socket(socket.AF_UNIX, + socket.SOCK_STREAM) + serial_socket.setblocking(False) + serial_socket.connect(vm.serial_file_name) + except: + logging.debug("Could not connect to serial socket for %s" % + vm.name) + continue + rs.append(serial_socket) + serial_dump_filename = os.path.join(test.debugdir, + "serial-%s" % vm.name) + files[vm] = [serial_socket, file(serial_dump_filename, "a+")] + + r, w, x = select.select(rs, [], [], 0.5) + for vm in files.keys(): + (s ,d) = files[vm] + if s in r: + data = s.recv(16384) + if not data: + rs.remove(s) + files.pop(vm) + else: + d.write(data) + + if _serialdump_thread_termination_event.isSet(): + break + + diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 9f82ffb..169a69e 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -13,6 +13,7 @@ start_vm = yes kill_vm = no kill_vm_gracefully = yes kill_unresponsive_vms = yes +serial_mode = dump # Screendump specific stuff convert_ppm_files_to_png_on_error = yes