From nobody Sat Nov 23 23:05:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1731416697; cv=none; d=zohomail.com; s=zohoarc; b=fFFFq+gFZ5MSqaSG4Mwj3eyKhnzKTvg0zN4DnEOWTPpY1ppt0MEGskhksXAqEwf5zmlLpS9AeR0oHMsrAf7l8HjvaSsbxNTZuUIODhmJm/0xCglmFCmK4mPgZvV9HU5XiRULXImmTdzLKrF1C1j99vpS+rxYNQQPWqWiValHJ70= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731416697; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7r9JlPFy+XMoABJs96fi5S295SlSc5Rou8kBzhpJxAw=; b=is4sSuaTgXMX21t54WrIimJ/rmtKN1hSHINxHU5ipwJRM0+IMvatlvAeMX+eNWJ+ifNOBrywS6Im+04vrYZ7chid0HcCbkS7FBB5MA0C+qsv0l1vqIbycj1hDBzW6vBzQ0oGdlP+47fD4YvHtPNte6WXfudK/OoBLDu3eYirb7w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731416697732322.1314747421651; Tue, 12 Nov 2024 05:04:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAqY0-0005aP-MM; Tue, 12 Nov 2024 08:03:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAqXz-0005Zi-RZ for qemu-devel@nongnu.org; Tue, 12 Nov 2024 08:03:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAqXx-0003dY-55 for qemu-devel@nongnu.org; Tue, 12 Nov 2024 08:03:06 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-yaIZ3q02MqKbzmLK-1qh4Q-1; Tue, 12 Nov 2024 08:02:59 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 97FF91955D44; Tue, 12 Nov 2024 13:02:57 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.193.48]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 906FF1956054; Tue, 12 Nov 2024 13:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731416582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7r9JlPFy+XMoABJs96fi5S295SlSc5Rou8kBzhpJxAw=; b=Trb/QGGtoQPL5b9NkDfSGiEca3/CbqaAso5jXUUnzjYH29EeUpJYr/6bW4zZO3M0NHPl67 shlaOImYoJq/UQKFgftTfWkkxg9Q8dnY3JIbe6RZWvPgY9INzT/bw1pM7acA/o/4gFI9Lt 6l5XPVqM9qk/pAltLZxfy3AT0QxsaKg= X-MC-Unique: yaIZ3q02MqKbzmLK-1qh4Q-1 X-Mimecast-MFC-AGG-ID: yaIZ3q02MqKbzmLK-1qh4Q From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: Thomas Huth , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v2 1/4] tests/functional: Introduce _console_read() Date: Tue, 12 Nov 2024 14:02:43 +0100 Message-ID: <20241112130246.970281-2-clg@redhat.com> In-Reply-To: <20241112130246.970281-1-clg@redhat.com> References: <20241112130246.970281-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.122, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.671, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1731416699983116600 Interaction with the console has been a problem in our avocado tests. In some cases, the expected string does not match in the output, causing the test to fail with a timeout. These were worked around by sleeping before reading the console and even with SSH connections in some places. To fix, process the console output char by char and not with readline. This routine was largely inspired by console_wait() in tests/vm/basevm.py. Signed-off-by: C=C3=A9dric Le Goater --- tests/functional/qemu_test/cmd.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test= /cmd.py index cbabb1ceed3c..5bca29d1d721 100644 --- a/tests/functional/qemu_test/cmd.py +++ b/tests/functional/qemu_test/cmd.py @@ -12,6 +12,7 @@ # later. See the COPYING file in the top-level directory. =20 import logging +import re import os import os.path import subprocess @@ -78,6 +79,23 @@ def run_cmd(args): def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK) =20 +def _console_read(vm, expect): + console_logger =3D logging.getLogger('console') + output =3D "" + while True: + data =3D vm.console_socket.recv(1) + if not data: + break + output +=3D data.decode("latin1") + if expect in output: + break + if "\r" in output or "\n" in output: + lines =3D re.split("[\r\n]", output) + if lines[0]: + console_logger.debug(lines[0]) + output =3D lines.pop() + return output + def _console_interaction(test, success_message, failure_message, send_string, keep_sending=3DFalse, vm=3DNone): assert not keep_sending or send_string @@ -98,12 +116,12 @@ def _console_interaction(test, success_message, failur= e_message, continue =20 try: - msg =3D console.readline().decode().strip() + msg =3D _console_read(vm, success_message) except UnicodeDecodeError: msg =3D None if not msg: continue - console_logger.debug(msg) + console_logger.debug('found "%s"', msg) if success_message is None or success_message in msg: break if failure_message and failure_message in msg: --=20 2.47.0