From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFCF2C32771 for ; Sun, 19 Jan 2020 01:06:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 789B1246AE for ; Sun, 19 Jan 2020 01:06:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nMSZsmYT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 789B1246AE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isz34-0002MK-Gj for qemu-devel@archiver.kernel.org; Sat, 18 Jan 2020 20:06:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47080) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1isyoN-00079u-L3 for qemu-devel@nongnu.org; Sat, 18 Jan 2020 19:51:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1isyoM-0008RD-3C for qemu-devel@nongnu.org; Sat, 18 Jan 2020 19:51:31 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:38208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1isyoL-0008Qg-Rz; Sat, 18 Jan 2020 19:51:29 -0500 Received: by mail-wr1-x435.google.com with SMTP id y17so26095080wrh.5; Sat, 18 Jan 2020 16:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ySTKs9tAs68j06j0Ef+8j/MLezzl+CwbmdUNKgUrBaM=; b=nMSZsmYTAHyA6JnaupSLr5kU/FO7EbHwb5VwlT7mOjeX+HVq3Nf6vzHINgBugHrib0 OoKjewcNjzANxkoNkaHIm6Pe948mlhTZZeZN9SfKsVfR7L/T0Y9rqS8Sq+sqfmOUJbb1 6rctgJQ3R+WCRmDVtx+AlUBQpu+FtsUliBHMz59TpcklYgj6uvsKl/N8WWxIow2bDXzx XplQMiRz+kEe5ioqvpKM6TR5cY4vP1qYrMv2aQrRjbxBQik7UbZhPCZLoPJq1mLIlkAp WM6INQomlO406LaUm1RKIsoHn668M9Ung2SsHUEeNylJU63uH7pJ1QMmTFOimfGCI0q0 RtzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ySTKs9tAs68j06j0Ef+8j/MLezzl+CwbmdUNKgUrBaM=; b=Ub9NVCeu/hVa9WvVNR5M3n+MuuOdEWXRNWSCRgV7OrZjR70TyTUrJwXfdFhHG/rOa8 1SEd9YBrmx6ZyTnI6ZXn2sMrnE3bJrXafx2yjtlU9/pzXaobJ7X87p1mSuL2q+JEyElQ 6CqulnB9rWMLZM1SRm1IdxfNaeV7Is43Repp6rCqLnjk3HLRun0OfdPGK+iGxK1Rwxjf gCaJWs6GZWeOEbss6T6lcvx4lhYPOON02pSwJA2wSxgiiDN0qNIplMEqXdn5t5K+mrrM OcwWX53Prm3IyqqXgsSM+AsSq1IB+aHPvxzO2EUH8LT12+MwuVsLiBtRGF5M6PmNL/9f PMlg== X-Gm-Message-State: APjAAAUmlXzPDlndccQi6ESd0Y2pMrx6Bwi+tuBaDKjR9QQVCSNxbGLh FiZIUHq/5FUMfGopdfamMKve1lJkCc8= X-Google-Smtp-Source: APXvYqw/qdZBSc6Mn1g0Vj+ttp0yC8fXZ6vruHXfGDUF0JNFzASxgwNDKPhITKJs5FlZiS4GLXp72g== X-Received: by 2002:a5d:6b47:: with SMTP id x7mr11090966wrw.277.1579395088706; Sat, 18 Jan 2020 16:51:28 -0800 (PST) Received: from pavilion.home ([2a02:a456:6be8:1:8edc:d4ff:fe8b:18b7]) by smtp.gmail.com with ESMTPSA id h2sm41763568wrv.66.2020.01.18.16.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 16:51:28 -0800 (PST) From: Niek Linnenbank To: qemu-devel@nongnu.org Subject: [PATCH v4 17/20] Acceptance tests: Extract _console_interaction() Date: Sun, 19 Jan 2020 01:50:59 +0100 Message-Id: <20200119005102.3847-18-nieklinnenbank@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200119005102.3847-1-nieklinnenbank@gmail.com> References: <20200119005102.3847-1-nieklinnenbank@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::435 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org, jasowang@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , b.galvani@gmail.com, Niek Linnenbank , qemu-arm@nongnu.org, imammedo@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Since we are going to re-use the code shared between wait_for_console_pattern() and exec_command_and_wait_for_pattern(), extract the common part into a local function. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Niek Linnenbank Signed-off-by: Niek Linnenbank --- tests/acceptance/avocado_qemu/__init__.py | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py index 6618ea67c1..0a50fcf2be 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -55,19 +55,14 @@ def pick_default_qemu_bin(arch=None): return qemu_bin_from_src_dir_path -def wait_for_console_pattern(test, success_message, failure_message=None): - """ - Waits for messages to appear on the console, while logging the content - - :param test: an Avocado test containing a VM that will have its console - read and probed for a success or failure message - :type test: :class:`avocado_qemu.Test` - :param success_message: if this message appears, test succeeds - :param failure_message: if this message appears, test fails - """ +def _console_interaction(test, success_message, failure_message, + send_string): console = test.vm.console_socket.makefile() console_logger = logging.getLogger('console') while True: + if send_string: + test.vm.console_socket.sendall(send_string.encode()) + send_string = None # send only once msg = console.readline().strip() if not msg: continue @@ -79,6 +74,17 @@ def wait_for_console_pattern(test, success_message, failure_message=None): fail = 'Failure message found in console: %s' % failure_message test.fail(fail) +def wait_for_console_pattern(test, success_message, failure_message=None): + """ + Waits for messages to appear on the console, while logging the content + + :param test: an Avocado test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`avocado_qemu.Test` + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + """ + _console_interaction(test, success_message, failure_message, None) def exec_command_and_wait_for_pattern(test, command, success_message, failure_message=None): @@ -94,10 +100,7 @@ def exec_command_and_wait_for_pattern(test, command, :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails """ - command += '\r' - test.vm.console_socket.sendall(command.encode()) - wait_for_console_pattern(test, success_message, failure_message) - + _console_interaction(test, success_message, failure_message, command + '\r') class Test(avocado.Test): def _get_unique_tag_val(self, tag_name): -- 2.17.1