From patchwork Thu Sep 14 20:06:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813930 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV2B0vP0z9s7f for ; Fri, 15 Sep 2017 06:07:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id BAF66C21E68; Thu, 14 Sep 2017 20:07:33 +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=RCVD_IN_DNSWL_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 67B8DC21E26; Thu, 14 Sep 2017 20:07:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5EF22C21DA4; Thu, 14 Sep 2017 20:07:18 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id 18102C21DA4 for ; Thu, 14 Sep 2017 20:07:17 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id F1E6C78475BEC; Thu, 14 Sep 2017 21:07:10 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:07:15 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:27 -0700 Message-ID: <20170914200634.17818-2-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren , =?utf-8?q?Stefan_Br=C3=BCns?= Subject: [U-Boot] [PATCH 1/8] test/py: Make print statements python 3.x safe 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" In python 3.x print must be called as a function rather than used as a statement. Update uses of print to the function call syntax in order to be python 3.x safe. Signed-off-by: Paul Burton --- test/py/conftest.py | 2 +- test/py/test.py | 6 ++++-- test/py/tests/test_fit.py | 12 +++++++----- test/py/u_boot_console_sandbox.py | 2 +- test/py/u_boot_spawn.py | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 65e1d75626..ced96f1006 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -545,7 +545,7 @@ def pytest_runtest_protocol(item, nextitem): # is fixed, if this exception still exists, it will then be logged as # part of the test's stdout. import traceback - print 'Exception occurred while logging runtest status:' + print('Exception occurred while logging runtest status:') traceback.print_exc() # FIXME: Can we force a test failure here? diff --git a/test/py/test.py b/test/py/test.py index 74e560a4d3..215f2651a7 100755 --- a/test/py/test.py +++ b/test/py/test.py @@ -8,6 +8,8 @@ # Wrapper script to invoke pytest with the directory name that contains the # U-Boot tests. +from __future__ import print_function + import os import os.path import sys @@ -27,7 +29,7 @@ except: traceback.print_exc() # Hint to the user that they likely simply haven't installed the required # dependencies. - print >>sys.stderr, ''' + print(''' exec(py.test) failed; perhaps you are missing some dependencies? -See test/py/README.md for the list.''' +See test/py/README.md for the list.''', file=sys.stderr) sys.exit(1) diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 7e6b96dae4..29b2491f89 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -4,6 +4,8 @@ # # Sanity check of the FIT handling in U-Boot +from __future__ import print_function + import os import pytest import struct @@ -153,7 +155,7 @@ def test_fit(u_boot_console): src = make_fname('u-boot.dts') dtb = make_fname('u-boot.dtb') with open(src, 'w') as fd: - print >> fd, base_fdt + print(base_fdt, file=fd) util.run_and_log(cons, ['dtc', src, '-O', 'dtb', '-o', dtb]) return dtb @@ -167,7 +169,7 @@ def test_fit(u_boot_console): """ its = make_fname('test.its') with open(its, 'w') as fd: - print >> fd, base_its % params + print(base_its % params, file=fd) return its def make_fit(mkimage, params): @@ -186,7 +188,7 @@ def test_fit(u_boot_console): its = make_its(params) util.run_and_log(cons, [mkimage, '-f', its, fit]) with open(make_fname('u-boot.dts'), 'w') as fd: - print >> fd, base_fdt + print(base_fdt, file=fd) return fit def make_kernel(filename, text): @@ -202,7 +204,7 @@ def test_fit(u_boot_console): for i in range(100): data += 'this %s %d is unlikely to boot\n' % (text, i) with open(fname, 'w') as fd: - print >> fd, data + print(data, file=fd) return fname def make_ramdisk(filename, text): @@ -216,7 +218,7 @@ def test_fit(u_boot_console): for i in range(100): data += '%s %d was seldom used in the middle ages\n' % (text, i) with open(fname, 'w') as fd: - print >> fd, data + print(data, file=fd) return fname def find_matching(text, match): diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 647e1f879f..9a2fe9cb59 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -42,7 +42,7 @@ class ConsoleSandbox(ConsoleBase): bcfg = self.config.buildconfig config_spl = bcfg.get('config_spl', 'n') == 'y' fname = '/spl/u-boot-spl' if config_spl else '/u-boot' - print fname + print(fname) cmd = [] if self.config.gdbserver: cmd += ['gdbserver', self.config.gdbserver] diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 3a0fbfad90..15ca4ac838 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -59,7 +59,7 @@ class Spawn(object): os.chdir(cwd) os.execvp(args[0], args) except: - print 'CHILD EXECEPTION:' + print('CHILD EXECEPTION:') import traceback traceback.print_exc() finally: From patchwork Thu Sep 14 20:06:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813931 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV3j3wTKz9s78 for ; Fri, 15 Sep 2017 06:09:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 548FFC21D84; Thu, 14 Sep 2017 20:08:19 +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=RCVD_IN_DNSWL_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 42E2CC21C5C; Thu, 14 Sep 2017 20:08:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AFB3EC21DBC; Thu, 14 Sep 2017 20:07:39 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id B1485C21E4C for ; Thu, 14 Sep 2017 20:07:34 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id EB0EFA8CE1F71; Thu, 14 Sep 2017 21:07:28 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:07:33 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:28 -0700 Message-ID: <20170914200634.17818-3-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren Subject: [U-Boot] [PATCH 2/8] test/py: Use range() rather than xrange() 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" In python 3.x the xrange() function has been removed, and range() returns an iterator much like Python 2.x's xrange(). Simply use range() in place of xrange() in order to work on both python 2.x & 3.x. This will mean a small cost on python 2.x since range() will return a list there rather than an iterator, but the cost should be negligible. Signed-off-by: Paul Burton --- test/py/u_boot_console_sandbox.py | 2 +- test/py/u_boot_spawn.py | 6 +++--- test/py/u_boot_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/py/u_boot_console_sandbox.py b/test/py/u_boot_console_sandbox.py index 9a2fe9cb59..5c91d926c5 100644 --- a/test/py/u_boot_console_sandbox.py +++ b/test/py/u_boot_console_sandbox.py @@ -82,7 +82,7 @@ class ConsoleSandbox(ConsoleBase): p = self.p self.p = None - for i in xrange(100): + for i in range(100): ret = not p.isalive() if ret: break diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 15ca4ac838..638c5dd31d 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -135,7 +135,7 @@ class Spawn(object): the expected time. """ - for pi in xrange(len(patterns)): + for pi in range(len(patterns)): if type(patterns[pi]) == type(''): patterns[pi] = re.compile(patterns[pi]) @@ -144,7 +144,7 @@ class Spawn(object): while True: earliest_m = None earliest_pi = None - for pi in xrange(len(patterns)): + for pi in range(len(patterns)): pattern = patterns[pi] m = pattern.search(self.buf) if not m: @@ -199,7 +199,7 @@ class Spawn(object): """ os.close(self.fd) - for i in xrange(100): + for i in range(100): if not self.isalive(): break time.sleep(0.1) diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index 2ba4baed07..264508da4e 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -120,7 +120,7 @@ def wait_until_open_succeeds(fn): An open file handle to the file. """ - for i in xrange(100): + for i in range(100): fh = attempt_to_open_file(fn) if fh: return fh @@ -143,7 +143,7 @@ def wait_until_file_open_fails(fn, ignore_errors): Nothing. """ - for i in xrange(100): + for i in range(100): fh = attempt_to_open_file(fn) if not fh: return From patchwork Thu Sep 14 20:06:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813932 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV4t3LM1z9s78 for ; Fri, 15 Sep 2017 06:10:06 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4A3D2C21E55; Thu, 14 Sep 2017 20:09:24 +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=RCVD_IN_DNSWL_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 6FB9AC21DA4; Thu, 14 Sep 2017 20:09:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 22271C21E52; Thu, 14 Sep 2017 20:07:55 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id 62060C21E24 for ; Thu, 14 Sep 2017 20:07:52 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id E2CE0FC4E4F17; Thu, 14 Sep 2017 21:07:46 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:07:51 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:29 -0700 Message-ID: <20170914200634.17818-4-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren , =?utf-8?q?Stefan_Br=C3=BCns?= Subject: [U-Boot] [PATCH 3/8] test/py: Import 'configparser' lower case to be python 3.x safe 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" In python 3.x the configparser module is named with all lower case. Import it as such in order to avoid errors when running on python 3.x, and fall back to the CamelCase version in order to keep working with python 2.x. Signed-off-by: Paul Burton --- test/py/conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index ced96f1006..dc444cc866 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -19,11 +19,15 @@ import os import os.path import pytest from _pytest.runner import runtestprotocol -import ConfigParser import re import StringIO import sys +try: + import configparser as ConfigParser +except: + import ConfigParser + # Globals: The HTML log file, and the connection to the U-Boot console. log = None console = None From patchwork Thu Sep 14 20:06:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813933 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV5X4tpTz9s7f for ; Fri, 15 Sep 2017 06:10:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 77C11C21EA6; Thu, 14 Sep 2017 20:09:07 +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=RCVD_IN_DNSWL_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 3476EC21E26; Thu, 14 Sep 2017 20:09:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A08F4C21E24; Thu, 14 Sep 2017 20:08:10 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id 72A9CC21DF3 for ; Thu, 14 Sep 2017 20:08:10 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id 03DF3711A021B; Thu, 14 Sep 2017 21:08:05 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:08:09 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:30 -0700 Message-ID: <20170914200634.17818-5-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren , =?utf-8?q?Stefan_Br=C3=BCns?= Subject: [U-Boot] [PATCH 4/8] test/py: Import StringIO from io module for python 3.x 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" In python 3.x the StringIO module is gone, and instead StringIO can be imported from the io module. Do this in order to run on python 3.x, and fall back to importing StringIO as a module in order to continue working with python 2.x. Signed-off-by: Paul Burton --- test/py/conftest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index dc444cc866..98093540fd 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -20,7 +20,6 @@ import os.path import pytest from _pytest.runner import runtestprotocol import re -import StringIO import sys try: @@ -28,6 +27,11 @@ try: except: import ConfigParser +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + # Globals: The HTML log file, and the connection to the U-Boot console. log = None console = None @@ -170,7 +174,7 @@ def pytest_configure(config): with open(dot_config, 'rt') as f: ini_str = '[root]\n' + f.read() - ini_sio = StringIO.StringIO(ini_str) + ini_sio = StringIO(ini_str) parser = ConfigParser.RawConfigParser() parser.readfp(ini_sio) ubconfig.buildconfig.update(parser.items('root')) From patchwork Thu Sep 14 20:06:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813938 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV8R1Y7Lz9s82 for ; Fri, 15 Sep 2017 06:13:11 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E8A89C21DF4; Thu, 14 Sep 2017 20:09: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=RCVD_IN_DNSWL_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 E2AABC21E31; Thu, 14 Sep 2017 20:09:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3A881C21E6F; Thu, 14 Sep 2017 20:08:31 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id 68FCFC21DCE for ; Thu, 14 Sep 2017 20:08:28 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id C05594C838A7C; Thu, 14 Sep 2017 21:08:22 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:08:27 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:31 -0700 Message-ID: <20170914200634.17818-6-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren Subject: [U-Boot] [PATCH 5/8] test/py: Encode/decode strings for stdio 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" When reading stdin python 3.x will give us byte arrays, and when writing stdout or stderr it will expect byte arrays. In order to insulate the rest of the code from this difference, call encode or decode at appropriate points when reading or writing stdio files. This works fine on python 2.x too. Signed-off-by: Paul Burton --- test/py/multiplexed_log.py | 4 ++-- test/py/tests/test_ut.py | 2 +- test/py/u_boot_spawn.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index bf926c3e77..21bdcb7309 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -140,11 +140,11 @@ class RunAndLog(object): if stdout: if stderr: output += 'stdout:\n' - output += stdout + output += stdout.decode('utf8') if stderr: if stdout: output += 'stderr:\n' - output += stderr + output += stderr.decode('utf8') exit_status = p.returncode exception = None except subprocess.CalledProcessError as cpe: diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 5c25a2d465..1f40e2c2d0 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -14,7 +14,7 @@ def test_ut_dm_init(u_boot_console): data = 'this is a test' data += '\x00' * ((4 * 1024 * 1024) - len(data)) with open(fn, 'wb') as fh: - fh.write(data) + fh.write(data.encode('utf-8')) fn = u_boot_console.config.source_dir + '/spi.bin' if not os.path.exists(fn): diff --git a/test/py/u_boot_spawn.py b/test/py/u_boot_spawn.py index 638c5dd31d..751302a529 100644 --- a/test/py/u_boot_spawn.py +++ b/test/py/u_boot_spawn.py @@ -114,7 +114,7 @@ class Spawn(object): Nothing. """ - os.write(self.fd, data) + os.write(self.fd, data.encode('utf8')) def expect(self, patterns): """Wait for the sub-process to emit specific data. @@ -172,7 +172,7 @@ class Spawn(object): events = self.poll.poll(poll_maxwait) if not events: raise Timeout() - c = os.read(self.fd, 1024) + c = os.read(self.fd, 1024).decode('utf8') if not c: raise EOFError() if self.logfile_read: From patchwork Thu Sep 14 20:06:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813936 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV7l1l1Bz9s82 for ; Fri, 15 Sep 2017 06:12:33 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B8167C21EA5; Thu, 14 Sep 2017 20:10:50 +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=RCVD_IN_DNSWL_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 E8632C21EBA; Thu, 14 Sep 2017 20:10:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 66520C21E26; Thu, 14 Sep 2017 20:08:46 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id D8DB2C21DBC for ; Thu, 14 Sep 2017 20:08:45 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id 7C9B120FB066E; Thu, 14 Sep 2017 21:08:40 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:08:44 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:32 -0700 Message-ID: <20170914200634.17818-7-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren Subject: [U-Boot] [PATCH 6/8] test/py: fit: Open files as binary files 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" The read_file() function in test_fit is used with files that are not text files, as well as some that are. It is never used in a way that requires it to decode text files to characters, so open all files in binary mode such that read() doesn't attempt to decode characters for files which are not text files. Without this test_fit fails on python 3.x when reading an FDT in run_fit_test() with: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte Signed-off-by: Paul Burton --- test/py/tests/test_fit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/py/tests/test_fit.py b/test/py/tests/test_fit.py index 29b2491f89..01ecde27d5 100755 --- a/test/py/tests/test_fit.py +++ b/test/py/tests/test_fit.py @@ -143,7 +143,7 @@ def test_fit(u_boot_console): Returns: Contents of file as a string """ - with open(fname, 'r') as fd: + with open(fname, 'rb') as fd: return fd.read() def make_dtb(): From patchwork Thu Sep 14 20:06:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813934 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV6q5xKtz9s7f for ; Fri, 15 Sep 2017 06:11:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 90289C21E55; Thu, 14 Sep 2017 20:10:17 +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=RCVD_IN_DNSWL_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 9C17CC21E55; Thu, 14 Sep 2017 20:10:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7F260C21DDE; Thu, 14 Sep 2017 20:09:03 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id BEA6AC21DA4 for ; Thu, 14 Sep 2017 20:09:03 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id 6BDA97008F9E9; Thu, 14 Sep 2017 21:08:58 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:09:02 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:33 -0700 Message-ID: <20170914200634.17818-8-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren , Michal Simek Subject: [U-Boot] [PATCH 7/8] test/py: hush_if_test: Use open() in place of file() 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" In python 3.x the file() function has been removed. Use open() instead, which works on both python 2.x & 3.x, and is described as the preferred method of opening a file by python 2.x documentation anyway. Signed-off-by: Paul Burton --- test/py/tests/test_hush_if_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/py/tests/test_hush_if_test.py b/test/py/tests/test_hush_if_test.py index c8f4208d31..cdad22b429 100644 --- a/test/py/tests/test_hush_if_test.py +++ b/test/py/tests/test_hush_if_test.py @@ -149,7 +149,7 @@ def test_hush_if_test_host_file_exists(u_boot_console): exec_hush_if(u_boot_console, expr, False) try: - with file(test_file, 'wb'): + with open(test_file, 'wb'): pass assert os.path.exists(test_file) From patchwork Thu Sep 14 20:06:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 813935 X-Patchwork-Delegate: trini@ti.com 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=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xtV6z15qYz9s7f for ; Fri, 15 Sep 2017 06:11:55 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D9E5FC21E8E; Thu, 14 Sep 2017 20:11:08 +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=RCVD_IN_DNSWL_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 36942C21E79; Thu, 14 Sep 2017 20:11:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D55ABC21DDE; Thu, 14 Sep 2017 20:09:22 +0000 (UTC) Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by lists.denx.de (Postfix) with ESMTP id BF652C21D90 for ; Thu, 14 Sep 2017 20:09:21 +0000 (UTC) Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id 4CD99A1373F90; Thu, 14 Sep 2017 21:09:16 +0100 (IST) Received: from localhost (10.20.1.88) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 14 Sep 2017 21:09:20 +0100 From: Paul Burton To: Date: Thu, 14 Sep 2017 13:06:34 -0700 Message-ID: <20170914200634.17818-9-paul.burton@imgtec.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170914200634.17818-1-paul.burton@imgtec.com> References: <20170914200634.17818-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.20.1.88] Cc: Stephen Warren Subject: [U-Boot] [PATCH 8/8] test/py: vboot: Remove stderr redirect from openssl command 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" The openssl command specified in test_with_algo() ultimately ends up being run by RunAndLog::run(), which uses it to construct a Popen object with the default shell=False. The stderr redirect in the command is therefore simply passed to openssl as an argument. With at least openssl 1.1.0f this causes openssl, and therefore test_vboot, to fail with: genpkey: Use -help for summary. Exit code: 1 Any stderr output ought to be captured & stored in the RunAndLog object's output field and returned from run() via run_and_log() to test_with_algo() which then ignores it anyway, so we can drop the shell-like redirection with no ill effects. With this fix test_vboot now passes for me. Signed-off-by: Paul Burton Reviewed-by: Stephen Warren --- test/py/tests/test_vboot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py index 6e62820743..ba86a08e2e 100644 --- a/test/py/tests/test_vboot.py +++ b/test/py/tests/test_vboot.py @@ -174,8 +174,8 @@ def test_vboot(u_boot_console): public_exponent = 65537 util.run_and_log(cons, 'openssl genpkey -algorithm RSA -out %sdev.key ' '-pkeyopt rsa_keygen_bits:2048 ' - '-pkeyopt rsa_keygen_pubexp:%d ' - '2>/dev/null' % (tmpdir, public_exponent)) + '-pkeyopt rsa_keygen_pubexp:%d' + % (tmpdir, public_exponent)) # Create a certificate containing the public key util.run_and_log(cons, 'openssl req -batch -new -x509 -key %sdev.key -out '