From patchwork Thu Jun 29 02:45:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Martincoski X-Patchwork-Id: 782001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wykfK3cvNz9s0m for ; Thu, 29 Jun 2017 12:50:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oerjMxF7"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E272530605; Thu, 29 Jun 2017 02:49:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KCnrJKmUydGo; Thu, 29 Jun 2017 02:49:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id D1B40300CC; Thu, 29 Jun 2017 02:49:58 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id AC9A91C0521 for ; Thu, 29 Jun 2017 02:49:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A891C8122F for ; Thu, 29 Jun 2017 02:49:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7skQGkiYkKYk for ; Thu, 29 Jun 2017 02:49:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f172.google.com (mail-qk0-f172.google.com [209.85.220.172]) by whitealder.osuosl.org (Postfix) with ESMTPS id 26D1D8012A for ; Thu, 29 Jun 2017 02:49:57 +0000 (UTC) Received: by mail-qk0-f172.google.com with SMTP id 16so66319588qkg.2 for ; Wed, 28 Jun 2017 19:49:57 -0700 (PDT) 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; bh=D/e5bRdfZic5f22aCMRI9ZjXZ++7gSbZu0V1Ywjku1k=; b=oerjMxF7Aj6ysV4I6AdSO9Zm8FAulPZbhnrun+hnHTksQABiP7sSHQdgi1MnOteKcb p1+5cKuRRxA32Higu1xAeAak0u+BH55Dt+OdxUFQFBEYzgsPJLYW7PouIFatfJ3bd2FO odDKpIMLCAm4WrHzKEylAceleOw2jMzYnckICnLosRMG0XgCGsIU3mY/+NmBlAn2NPSq jJtWjKa0z5SM7HAsbIfCD9H9sDONPQt+3zf09TB+G5Fr9sA7IOYPYOOgL92zPudgZ0XC AGD6H4YhIfLtZaLVnduP7ns8Udm3PDjuE0Fk1P3SJGR69zSHJPqFZyCYmhhFdvSQPc0l MKJQ== 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; bh=D/e5bRdfZic5f22aCMRI9ZjXZ++7gSbZu0V1Ywjku1k=; b=btxY8pFb3Gvufud7xe+wPVd8NSLEXnUVW8ZWyKXAJ8AEGeznFvgjhDw3RnYojmJkia XKHGsgK4PG+7TYltgqQnriNvjjQ+8KjpkBQ5xWXxaQy9xsDhX+gVXCExT7LzvPv4SacU zLD24V677r4QLYpPMDbc5nplnvQTOZo4FH+VTpPPblCNZVxT7tAh1qne1ID4JbOnF+k6 PrwRhRKj9lQuiR8qNJorKGaFGTa8lFyY2y7pSpzaSjoubckG9+0nRf1PZdTL+j+RZZzE 0HPRbzZ33KEUiNsIahKNU15uCjlgcyCz++jDyJpAMl0xOmWxJ44iCbq/pnjUSPtw05fr kaqw== X-Gm-Message-State: AKS2vOwnOWb+wAVbfg6nOMMjkpQzOCnI9kBdRrYUelqPPQUF3OG8/+fZ 6ejpzKKUUup+/l5j X-Received: by 10.55.26.150 with SMTP id l22mr15260464qkh.4.1498704596081; Wed, 28 Jun 2017 19:49:56 -0700 (PDT) Received: from ultri3.home (189.27.146.107.dynamic.adsl.gvt.net.br. [189.27.146.107]) by smtp.gmail.com with ESMTPSA id g34sm3230750qta.46.2017.06.28.19.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Jun 2017 19:49:55 -0700 (PDT) From: Ricardo Martincoski To: buildroot@buildroot.org Date: Wed, 28 Jun 2017 23:45:45 -0300 Message-Id: <20170629024549.30484-6-ricardo.martincoski@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170629024549.30484-1-ricardo.martincoski@gmail.com> References: <20170629024549.30484-1-ricardo.martincoski@gmail.com> Cc: Ricardo Martincoski Subject: [Buildroot] [PATCH 5/9] support/testing: use pexpect.expect directly X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" When using pexpect there is no need for a helper function. Just use expect() directly everywhere. Signed-off-by: Ricardo Martincoski --- support/testing/infra/emulator.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index e488d8ac6c..7407309a29 100644 --- a/support/testing/infra/emulator.py +++ b/support/testing/infra/emulator.py @@ -8,7 +8,6 @@ class Emulator(object): def __init__(self, builddir, downloaddir, logtofile): self.qemu = None self.downloaddir = downloaddir - self.log = "" self.logfile = infra.open_log_file(builddir, "run", logtofile) # Start Qemu to boot the system @@ -66,34 +65,25 @@ class Emulator(object): qemu_cmd += ["-append", " ".join(kernel_cmdline)] self.logfile.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) - self.qemu = pexpect.spawn(qemu_cmd[0], qemu_cmd[1:]) + self.qemu = pexpect.spawn(qemu_cmd[0], qemu_cmd[1:], timeout=5) # We want only stdout into the log to avoid double echo self.qemu.logfile_read = self.logfile - def __read_until(self, waitstr, timeout=5): - index = self.qemu.expect([waitstr, pexpect.TIMEOUT], timeout=timeout) - data = self.qemu.before - if index == 0: - data += self.qemu.after - self.log += data - # Remove double carriage return from qemu stdout so str.splitlines() - # works as expected. - return data.replace("\r\r", "\r") - # Wait for the login prompt to appear, and then login as root with # the provided password, or no password if not specified. def login(self, password=None): - self.__read_until("buildroot login:", 10) - if "buildroot login:" not in self.log: + index = self.qemu.expect(["buildroot login:", pexpect.TIMEOUT], + timeout=10) + if index != 0: self.logfile.write("==> System does not boot") raise SystemError("System does not boot") self.qemu.sendline("root") if password: - self.__read_until("Password:") + self.qemu.expect("Password:") self.qemu.sendline(password) - self.__read_until("# ") - if "# " not in self.log: + index = self.qemu.expect(["# ", pexpect.TIMEOUT]) + if index != 0: raise SystemError("Cannot login") self.run("dmesg -n 1") @@ -101,13 +91,14 @@ class Emulator(object): # return a tuple (output, exit_code) def run(self, cmd): self.qemu.sendline(cmd) - output = self.__read_until("# ") - output = output.strip().splitlines() - output = output[1:len(output)-1] + self.qemu.expect("# ") + # Remove double carriage return from qemu stdout so str.splitlines() + # works as expected. + output = self.qemu.before.replace("\r\r", "\r").splitlines()[1:] self.qemu.sendline("echo $?") - exit_code = self.__read_until("# ") - exit_code = exit_code.strip().splitlines()[1] + self.qemu.expect("# ") + exit_code = self.qemu.before.splitlines()[2] exit_code = int(exit_code) return output, exit_code