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: