From patchwork Fri Jul 6 16:27:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 940614 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41MgT95MT1z9s4Z for ; Sat, 7 Jul 2018 02:40:45 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 573E6C22075; Fri, 6 Jul 2018 16:35:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EC775C220B1; Fri, 6 Jul 2018 16:29:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5C521C22079; Fri, 6 Jul 2018 16:28:48 +0000 (UTC) Received: from mail-it0-f73.google.com (mail-it0-f73.google.com [209.85.214.73]) by lists.denx.de (Postfix) with ESMTPS id EC2ECC2201E for ; Fri, 6 Jul 2018 16:28:43 +0000 (UTC) Received: by mail-it0-f73.google.com with SMTP id i4-v6so4024263ite.3 for ; Fri, 06 Jul 2018 09:28:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=G/sbJ9HqYCCp/E7yPrYJhniK0X9Bou08TN3OPXYMNuE=; b=oAh5eEUSIn6aZYRre/SnlCzetSTC1MI959tBz/3M3XzIqN+XXflVwS5AQ4LR0rfKEU c3i/L4Rv3eX+eDz25nLU+3FDF0SFB7/RQa09N5Z/iahvhrn2DgtuEFzp644ZhRhsDs88 qFPNAg+PjmGmbNIdGRZBS0J6yubAdaMpL9c6LH9kEdt1XJp8+zIFMHs0d8a+GNbH3ZK8 tO2PYGoB6+Lm/dTOsjk+Ck2Ejc91ygFojNqX3WvjPkk2R+aWlqAtiDeq25cRgK7UpLJc cannSeDC74C451QmzTcZ2fUqIHjG98CdfdfXAZCc00yPCh0uKXZshywebx8ql1QLrAPb qivw== X-Gm-Message-State: AOUpUlGvMmjxuK5wV9uZsbYS9l6dMKh/1LS9yLZauCTr96PSiEyxJx6p s7lI0mt8hIiAqLLpPu8ByxhbMhI= X-Google-Smtp-Source: AAOMgpdocKJo2GqzhJjeUDWuuZwfMy8VnINHNwwXbf+7QHE3kE0TqH8ks9ObK371mkYX6w7+fSVUXU4= MIME-Version: 1.0 X-Received: by 2002:a6b:8827:: with SMTP id k39-v6mr4683591iod.129.1530894522987; Fri, 06 Jul 2018 09:28:42 -0700 (PDT) Date: Fri, 6 Jul 2018 10:27:34 -0600 In-Reply-To: <20180706162742.186950-1-sjg@chromium.org> Message-Id: <20180706162742.186950-22-sjg@chromium.org> References: <20180706162742.186950-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini Subject: [U-Boot] [PATCH v2 21/29] binman: Move capture_sys_output() to test_util X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This function is useful in various tests. Move it into the common test utility module. Signed-off-by: Simon Glass --- Changes in v2: None tools/binman/elf_test.py | 22 ++-------------------- tools/binman/image_test.py | 2 +- tools/patman/test_util.py | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index fb6e451cf0..9c8f1feca8 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -4,33 +4,15 @@ # # Test for the elf module -from contextlib import contextmanager import os import sys import unittest -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - import elf +import test_util binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) -# Use this to suppress stdout/stderr output: -# with capture_sys_output() as (stdout, stderr) -# ...do something... -@contextmanager -def capture_sys_output(): - capture_out, capture_err = StringIO(), StringIO() - old_out, old_err = sys.stdout, sys.stderr - try: - sys.stdout, sys.stderr = capture_out, capture_err - yield capture_out, capture_err - finally: - sys.stdout, sys.stderr = old_out, old_err - class FakeEntry: def __init__(self, contents_size): @@ -110,7 +92,7 @@ class TestElf(unittest.TestCase): entry = FakeEntry(20) section = FakeSection() elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms') - with capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as (stdout, stderr): syms = elf.LookupAndWriteSymbols(elf_fname, entry, section) elf.debug = False self.assertTrue(len(stdout.getvalue()) > 0) diff --git a/tools/binman/image_test.py b/tools/binman/image_test.py index 45dd2378c8..3775e1afb0 100644 --- a/tools/binman/image_test.py +++ b/tools/binman/image_test.py @@ -7,7 +7,7 @@ import unittest from image import Image -from elf_test import capture_sys_output +from test_util import capture_sys_output class TestImage(unittest.TestCase): def testInvalidFormat(self): diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py index 1a33c997c4..0e79af871a 100644 --- a/tools/patman/test_util.py +++ b/tools/patman/test_util.py @@ -3,12 +3,19 @@ # Copyright (c) 2016 Google, Inc # +from contextlib import contextmanager import glob import os import sys import command +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + + def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None): """Run tests and check that we get 100% coverage @@ -62,3 +69,17 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None): ok = False if not ok: raise ValueError('Test coverage failure') + + +# Use this to suppress stdout/stderr output: +# with capture_sys_output() as (stdout, stderr) +# ...do something... +@contextmanager +def capture_sys_output(): + capture_out, capture_err = StringIO(), StringIO() + old_out, old_err = sys.stdout, sys.stderr + try: + sys.stdout, sys.stderr = capture_out, capture_err + yield capture_out, capture_err + finally: + sys.stdout, sys.stderr = old_out, old_err