From patchwork Wed May 18 17:00:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 623673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3r90pG4tz4z9t6S for ; Thu, 19 May 2016 03:01:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b=0rLQxQML; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 68CEC4BA5C; Wed, 18 May 2016 19:01:08 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gNGbQAA2Wc7P; Wed, 18 May 2016 19:01:08 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D970F4B811; Wed, 18 May 2016 19:01:07 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 437CEA74C5 for ; Wed, 18 May 2016 19:01:02 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ILnL4EF8wtkf for ; Wed, 18 May 2016 19:01:02 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by theia.denx.de (Postfix) with ESMTPS id 0D9E7A7498 for ; Wed, 18 May 2016 19:00:58 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id n129so14460046wmn.1 for ; Wed, 18 May 2016 10:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=YpgesogWWa+G4Yq/esxFin8FH1NPcZWgMvKNlz/BiQo=; b=0rLQxQMLLrSXZX4z+W0ZomSwnB7d9UVUCbkttQRLG0NB7F9uEdHUR/nfhBGUlzNq95 Kqapq8Lv8JbPWN1lyAz0TW7thizRarFxIeNO1pvc7BlevhSdora1lWcqymyLGwXbecUH Cs3Dh3KxUklayHNWjeTGYnjvlWDoyoF3BKgwQ6SxKmeXlbSVY24350dHs/N/8rPfuTKC vXy93IG9kb/i9QeRy7/lFUAa2qGcZaX2GDzPEQDc2tZqzgzSPHV9WmsnuS1SkeXMP31C DrIs2uLqwkJQ0gdBR5mugg3ZHFpyB0zu+lIuad4bqEES83t5vlecymBdLd44hSmAQ8q2 SEHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=YpgesogWWa+G4Yq/esxFin8FH1NPcZWgMvKNlz/BiQo=; b=ZnftB+4FUxHT9Vh9S92jVKOVpfKbR7o7dSzt5uBf9KMoOKx5c6D/MpwFZ9AYdeebR8 mepV562EM36QZ+0UFv2WCj1LGMiaSKhmq1g0vhoftaP1VbyXgcgxbCJ3V2OnZOZCUMkB vlQu4CPOHNQISkGFHIFeH8CovDLIwTzgUPM965ZjCFE3TqW6/J/f25DE9OgEujs+xyq0 VCoR6lVS2cPLrV79lb8S+pfe87Uf49bKX367qFvqhQJQR6YtRe/Mlx0fg1pUt7t2siEJ BUFN+fM1BxsxC2l8eVCOdwnLT+rOE94z0MYHwp6la4w3Xt2zPgTm+QAjTNWPI1HZxRz5 855A== X-Gm-Message-State: AOPr4FWnmQKN34VVPbgRThESOqvX1ab6RSwsRmp6D+YaUsffmMHTfbRbHb/s0jE9m5/y0g== X-Received: by 10.28.144.138 with SMTP id s132mr9178943wmd.102.1463590858336; Wed, 18 May 2016 10:00:58 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id o8sm5149643wjs.19.2016.05.18.10.00.57 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 18 May 2016 10:00:57 -0700 (PDT) From: Michal Simek To: swarren@wwwdotorg.org Date: Wed, 18 May 2016 19:00:56 +0200 Message-Id: <24750597429bfd579c2463bb17e2a1f262f02f83.1463590854.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2] test/py: Support setting up specific timeout X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Large file transfers, flash erasing and more complicated tests requires more time to finish. Provide a way to setup specific timeout directly in test. For example description for 50s test: timeout = 50000 with u_boot_console.temporary_timeout(timeout): u_boot_console.run_command(...) Signed-off-by: Michal Simek Reviewed-by: Stephen Warren --- Changes in v2: - save console.p instead of simple console - Some fixes in comments - Save orig_timeout directly in class - Remove get_spawn call - Test if self.p exists test/py/u_boot_console_base.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/py/u_boot_console_base.py b/test/py/u_boot_console_base.py index f7434363fbcb..dbbdd53b46dc 100644 --- a/test/py/u_boot_console_base.py +++ b/test/py/u_boot_console_base.py @@ -56,6 +56,24 @@ class ConsoleDisableCheck(object): self.console.disable_check_count[self.check_type] -= 1 self.console.eval_bad_patterns() +class ConsoleSetupTimeout(object): + """Context manager (for Python's with statement) that temporarily sets up + timeout for specific command. This is useful when execution time is greater + then default 30s.""" + + def __init__(self, console, timeout): + self.p = console.p + self.orig_timeout = self.p.timeout + self.p.timeout = timeout + + def __enter__(self): + return self + + def __exit__(self, extype, value, traceback): + if not self.p: + return + self.p.timeout = self.orig_timeout + class ConsoleBase(object): """The interface through which test functions interact with the U-Boot console. This primarily involves executing shell commands, capturing their @@ -391,3 +409,18 @@ class ConsoleBase(object): """ return ConsoleDisableCheck(self, check_type) + + def temporary_timeout(self, timeout): + """Temporarily set up different timeout for commands. + + Create a new context manager (for use with the "with" statement) which + temporarily change timeout. + + Args: + timeout: Time in milliseconds. + + Returns: + A context manager object. + """ + + return ConsoleSetupTimeout(self, timeout)