From patchwork Sat Apr 4 21:28:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2120 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775338265; bh=ig/zzcY+gUwLBy1AiV7DW6ebILXixAS4f7nN+qFuEU0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=KInSVekKD4GRquyePWtixJS+i4ZUHkEC4Em0jhD3nOrbQdLNtMyrOFRlmTPBRp7hI dQK/LIxki2kOWhO0LiQwrjXlPv1PtwwoD5+sEetNur+OTgfhVVi41EAxfiQFY7Wfut ouvi0QnVBFMUZlLiLqXBcM2Uh2MyubXG3bvZiOfae9qpIBrRoxiojxPgE+z3ypz0P6 5qLIcEUbFilEUM7syXQ48kuOtmNXrvJuejnnVLK1SjQqcaln8NND4PpdNDZ+SLn85P nsu/Fz0tfEVoyDnse8nMO8uhRoCbdpJCoKWdvSBvZXALCY3pPBv/8YE6cPRQrhEji7 I/mrvkRe0PptQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0012E6A37F for ; Sat, 4 Apr 2026 15:31:05 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 0_u11Xl9mZ00 for ; Sat, 4 Apr 2026 15:31:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775338264; bh=ig/zzcY+gUwLBy1AiV7DW6ebILXixAS4f7nN+qFuEU0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=sCwLLZZti7ZPwqg6YVv/hAdweHg1yf1YhzVtE/B6N6RQ+MKvSOAVgfKXKeMuvO3qg l134tKLb3ZwVRqjKVoXxcf721X4D5B2d5Ps+yx5+8e+bfW+bwu1rIYM7hbM917E2OV QatUV9kgDeI+T/o8h/BUGNcicElsnGrgrYTztlUVL5Nw4SkRsKHKKPifZZ4IahlU74 bpPN23kLvw+N/mhnUsFhVQtzPSBRcO6Ckdxb+Eko/gUTuBfhVP8YkIebiD2mhkt1R2 BMy3xH0D4NL9nZ1lzHxx0QLcqalKCcMf/2d4R1OFhYuf7B3JvGKZwRRPEUmXwfSelJ Suh1x9u9zbWxg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D951A6869D for ; Sat, 4 Apr 2026 15:31:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775338263; bh=PBvxsev1kUWNqHNVlnnKPSXXfE096l11ocXKbgM7VkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pxa9mqae38kU6oPBN4DL/BaGksYZCmsGnaQ/n1/zKG5fJJlYmQ5/AICksgkXj32He v6Ge7cl+YyRCK2XXQ/2u/npAWh83glvqT2Ar7wgqVfnK4Hla0cxR+E8Tb2MzMTkZho xI2WGCR06nz7f7TuaNk5qpltVnksMU0O33Hx/aA9gTlBx0L5ZxhfeFXnViN5fS9mZR FFTaWfwxfodXCbnTsupqwplxbw1rKhQLlRcNHe+zogWkOTTpmku85WIpYIVRszN1GF fe42HVyEHYhPZoVvqepUab+2ZW37s5GRySpB+0TQu8jDor/jAQKlWOuiigMdeOIFWq K9rOT+YFqJ0vQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E40366A375; Sat, 4 Apr 2026 15:31:03 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id mK_UUJH-8l9J; Sat, 4 Apr 2026 15:31:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775338259; bh=Gt9UOHQFSAnRhulopyg/O2OWM5iRS+Z2yLqblQ5jj3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MB2tLQZrnFBhywsuGmK8C5c78lrGq5YGjK3EI0SCvW1rQFOlPiWGE6P2O+mD79XN3 Dm7m448D+QnpUMnww+JGB8KVZDfE4M3Pt6yyKjFNLLGeB+1vrrbHDZlXSqxvQDAIml mRsH5Ibz7CdK6szgv5v1oMJxlqmVPwEFWmge6DtxaJMuke1LcUtbqhfcqyTfZGAspz WfP59QUvd99ZzKDID70e/e2w+QlR5udqDrhd7KO+WPwbW6X3jsEylahlvig3Pi7NVM rxfE9FI/S7n55ToKhgLW3+TnsG2vXxr465szTKGyilwzHznfW5/s3dmT/SaA7FZLRU vvNVHoDFyTyfQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D380D6869D; Sat, 4 Apr 2026 15:30:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 4 Apr 2026 15:28:41 -0600 Message-ID: <20260404213020.372253-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260404213020.372253-1-sjg@u-boot.org> References: <20260404213020.372253-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: F7NEBNPKIBOWB7ULWBFPU6YPN4PM6YGC X-Message-ID-Hash: F7NEBNPKIBOWB7ULWBFPU6YPN4PM6YGC X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/37] u_boot_pylib: Fix cros_subprocess tests for Python 3 List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The cros_subprocess test suite uses str for accumulating output data, but communicate_filter() sends bytes. This causes a TypeError on every test. Change MyOperation to use bytes and update all string comparisons in the tests to use byte literals. Add TestSubprocess to the u_boot_pylib test suite. Signed-off-by: Simon Glass --- tools/u_boot_pylib/__main__.py | 3 ++- tools/u_boot_pylib/cros_subprocess.py | 31 ++++++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/u_boot_pylib/__main__.py b/tools/u_boot_pylib/__main__.py index 5f802bd8d86..5d3dec2c709 100755 --- a/tools/u_boot_pylib/__main__.py +++ b/tools/u_boot_pylib/__main__.py @@ -15,6 +15,7 @@ sys.path.append(os.path.join(our_path, '..')) import argparse +from u_boot_pylib import cros_subprocess from u_boot_pylib import test_util @@ -31,7 +32,7 @@ def run_tests(): result = test_util.run_test_suites( 'u_boot_pylib', False, args.verbose, False, False, None, to_run, None, - ['u_boot_pylib.terminal']) + ['u_boot_pylib.terminal', cros_subprocess.TestSubprocess]) sys.exit(0 if result.wasSuccessful() else 1) diff --git a/tools/u_boot_pylib/cros_subprocess.py b/tools/u_boot_pylib/cros_subprocess.py index cd614f38a64..4ac435b631c 100644 --- a/tools/u_boot_pylib/cros_subprocess.py +++ b/tools/u_boot_pylib/cros_subprocess.py @@ -261,9 +261,9 @@ class TestSubprocess(unittest.TestCase): input_to_send: a text string to send when we first get input. We will add \r\n to the string. """ - self.stdout_data = '' - self.stderr_data = '' - self.combined_data = '' + self.stdout_data = b'' + self.stderr_data = b'' + self.combined_data = b'' self.stdin_pipe = None self._input_to_send = input_to_send if input_to_send: @@ -305,8 +305,8 @@ class TestSubprocess(unittest.TestCase): cmd = 'echo fred >/dev/stderr && false || echo bad' plist = Popen([cmd], shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], 'bad\r\n') - self.assertEqual(plist [1], 'fred\r\n') + self.assertEqual(plist [0], b'bad\r\n') + self.assertEqual(plist [1], b'fred\r\n') def test_shell(self): """Check with and without shell works""" @@ -316,7 +316,7 @@ class TestSubprocess(unittest.TestCase): plist = Popen([cmd], shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) self.assertEqual(len(plist [0]), 0) - self.assertEqual(plist [1], 'test\r\n') + self.assertEqual(plist [1], b'test\r\n') def test_list_args(self): """Check with and without shell works using list arguments""" @@ -324,7 +324,7 @@ class TestSubprocess(unittest.TestCase): cmd = ['echo', 'test', '>/dev/stderr'] plist = Popen(cmd, shell=False).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], ' '.join(cmd[1:]) + '\r\n') + self.assertEqual(plist [0], (' '.join(cmd[1:]) + '\r\n').encode()) self.assertEqual(len(plist [1]), 0) oper = TestSubprocess.MyOperation() @@ -333,7 +333,7 @@ class TestSubprocess(unittest.TestCase): cmd = ['echo', 'test', '>/dev/stderr'] plist = Popen(cmd, shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], '\r\n') + self.assertEqual(plist [0], b'\r\n') def test_cwd(self): """Check we can change directory""" @@ -342,7 +342,7 @@ class TestSubprocess(unittest.TestCase): plist = Popen('pwd', shell=shell, cwd='/tmp').communicate_filter( oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], '/tmp\r\n') + self.assertEqual(plist [0], b'/tmp\r\n') def test_env(self): """Check we can change environment""" @@ -354,7 +354,7 @@ class TestSubprocess(unittest.TestCase): cmd = 'echo $FRED' plist = Popen(cmd, shell=True, env=env).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], add and 'fred\r\n' or '\r\n') + self.assertEqual(plist [0], add and b'fred\r\n' or b'\r\n') def test_extra_args(self): """Check we can't add extra arguments""" @@ -374,7 +374,8 @@ class TestSubprocess(unittest.TestCase): shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) self.assertEqual(len(plist [1]), 0) - self.assertEqual(plist [0], prompt + 'Hello Flash\r\r\n') + self.assertEqual(plist [0], + (prompt + 'Hello Flash\r\r\n').encode()) def test_isatty(self): """Check that ptys appear as terminals to the subprocess""" @@ -386,16 +387,16 @@ class TestSubprocess(unittest.TestCase): both_cmds += cmd % (fd, fd, fd, fd, fd) plist = Popen(both_cmds, shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], 'terminal 1\r\n') - self.assertEqual(plist [1], 'terminal 2\r\n') + self.assertEqual(plist [0], b'terminal 1\r\n') + self.assertEqual(plist [1], b'terminal 2\r\n') # Now try with PIPE and make sure it is not a terminal oper = TestSubprocess.MyOperation() plist = Popen(both_cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate_filter(oper.output) self._basic_check(plist, oper) - self.assertEqual(plist [0], 'not 1\n') - self.assertEqual(plist [1], 'not 2\n') + self.assertEqual(plist [0], b'not 1\n') + self.assertEqual(plist [1], b'not 2\n') if __name__ == '__main__': unittest.main()