From patchwork Mon Mar 13 09:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172128 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBBE023A7 for ; Mon, 13 Mar 2023 09:44:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65184C4339E; Mon, 13 Mar 2023 09:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700680; bh=1YJ/aFxJnduaOgWIQBgiyP8hO979tvs7YeoZ9myLRVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V7rd3eBv5MzWBZmgiYoTHumjmxnUfEla2f/RSujWTpOZWsEjfXsB9qxLqUOuoXVUz wNZr38OUa0LuY30rXt1WFV27/T6sR8n5efW8nriJa7bv2Rnl5lWZSJuB4sTjHpS91q vLPhPBv+RDioWqnUpejx0kBZdgbGpzBIHxG/zwwhnZduwIXYWMA6rmi5L1Mvs4cieQ lHVXZyPRx0oEagWBXnWSXb3SKXMVA37D1FdFcYUswyMKl8R3J/A44p3gZHWaLE4ns6 W2m49X2rHrwM1HJuHlDyforeblceiiQCPhsVm+I+4GmwhzObkppdABAG2IorFf7jug 2C5DG4aaAZ7TA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 01/14] lava_runner: rename to LavaTestResult Date: Mon, 13 Mar 2023 17:44:18 +0800 Message-Id: <20230313094431.507952-2-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To simplify, rename from LavaTextTestResult to LavaTestResult. Signed-off-by: Tzung-Bi Shih --- cros/runners/lava_runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py index 8a570dda064f..2e8b1c42bdeb 100755 --- a/cros/runners/lava_runner.py +++ b/cros/runners/lava_runner.py @@ -13,7 +13,7 @@ from cros.tests.cros_ec_power import * from cros.tests.cros_ec_extcon import * -class LavaTextTestResult(unittest.TestResult): +class LavaTestResult(unittest.TestResult): def __init__(self, runner): unittest.TestResult.__init__(self) self.runner = runner @@ -56,7 +56,7 @@ class LavaTestRunner: self.stream.write(message) def run(self, test): - result = LavaTextTestResult(self) + result = LavaTestResult(self) test(result) result.testsRun return result From patchwork Mon Mar 13 09:44:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172129 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E24F23A7 for ; Mon, 13 Mar 2023 09:44:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0BF2C433A0; Mon, 13 Mar 2023 09:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700682; bh=7Ud0iz+jD0RCvRNaZ5p6F4jFZT8VE/n4iw3+XZ+5Lek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/zHS+/W7LLr67m5Jt8wKUXuVjY+jO2fEu40Xz7tOzWzmE4MwlHLtIlezYDUegOww RZo1BOpNQD3UnSDgbu9Mqw2lIs9mHXrqSh/fs+cq+GQGO4Qt8zDw8MKsy6/f8nyhW3 UmHfY+6ffSxGiBVxxlbwXZMpMmuvBrFFTyHB7LGe9K7KasNSlW9OzR55fRcwDauWLE DmzpLVgY7G8id1Soixkq8sozzRHiXzhhyA1HxXtdniA9+fO1WY+TgZusdI5c34V2St cr/0DJPITmaVt/cK4NPifAVihLtXjexvRuqoMiFuzFhqpePsZauiGLoo8wOMKA0jSo 2+DJQjwqo7UXw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 02/14] lava_runner: use TextTestRunner Date: Mon, 13 Mar 2023 17:44:19 +0800 Message-Id: <20230313094431.507952-3-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To simplify, eliminate LavaTestRunner but use TextTestRunner directly. Also change the constructor of LavaTestResult per [1]. As a side-effect result, it starts to show the following summary: > Ran 18 tests in 0.010s > > FAILED (failures=1, errors=3, skipped=10) [1]: https://docs.python.org/3/library/unittest.html#unittest.TextTestRunner._makeResult Signed-off-by: Tzung-Bi Shih --- cros/runners/lava_runner.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py index 2e8b1c42bdeb..7524f65dcd39 100755 --- a/cros/runners/lava_runner.py +++ b/cros/runners/lava_runner.py @@ -14,57 +14,42 @@ from cros.tests.cros_ec_extcon import * class LavaTestResult(unittest.TestResult): - def __init__(self, runner): + def __init__(self, stream, descriptions, verbosity): unittest.TestResult.__init__(self) - self.runner = runner + self.stream = stream def addSuccess(self, test): unittest.TestResult.addSuccess(self, test) - self.runner.writeUpdate( + self.stream.write( "\n" % test.id().rsplit(".")[-1] ) def addError(self, test, err): unittest.TestResult.addError(self, test, err) - self.runner.writeUpdate( + self.stream.write( "\n" % test.id().rsplit(".")[-1] ) def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) - self.runner.writeUpdate( + self.stream.write( "\n" % test.id().rsplit(".")[-1] ) def addSkip(self, test, reason): unittest.TestResult.addSkip(self, test, reason) - self.runner.writeUpdate( + self.stream.write( "\n" % test.id().rsplit(".")[-1] ) -class LavaTestRunner: - def __init__(self, stream=sys.stderr, verbosity=0): - self.stream = stream - self.verbosity = verbosity - - def writeUpdate(self, message): - self.stream.write(message) - - def run(self, test): - result = LavaTestResult(self) - test(result) - result.testsRun - return result - - if __name__ == "__main__": unittest.main( - testRunner=LavaTestRunner(), + testRunner=unittest.TextTestRunner(resultclass=LavaTestResult), # these make sure that some options that are not applicable # remain hidden from the help menu. failfast=False, From patchwork Mon Mar 13 09:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172130 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B803123A7 for ; Mon, 13 Mar 2023 09:44:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67F4DC4339B; Mon, 13 Mar 2023 09:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700683; bh=lsj9O+XAxKbTWvzEW4OmUuQ0/1vEqxmXyH6TvL73pdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJJbpmcIYOLSgYtpt/E0Z3LeWmum1Be+49o5imE8Mbmz6ZEi+M387kgWgbuADKYw4 30F1fLCz2Xq4W0SzuQdLl8qGH71Ip+QwgOfrteuydLH/C5Or0gCh4BNubsY5oDTKYR DyiWTmuGX2FX+jzwDrBzQLmhOaWQPT1/uvuKO6x+eD/XdAeSbRDXKQytnpdiL3R4om fmysPHDKEor4IaixndYJwmkEpMEvgcMmaY9NiOwwgyd3zN1hHXTTiVi/E6AeDivxhf 6Bm0qwqWmJ8P+BY/7BhAu5GgNcMsCmlg1kdCIJIJcRpqL8mXIjKM6GkC7QCIj6bCxC vV1HCLQpxHcig== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 03/14] lava_runner: use TextTestResult Date: Mon, 13 Mar 2023 17:44:20 +0800 Message-Id: <20230313094431.507952-4-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To simplify, make LavaTestResult is-a TextTestResult. As a side-effect result, it prints errors and fails by the end of test running. See [1]. [1]: https://github.com/python/cpython/blob/main/Lib/unittest/runner.py#L139 Signed-off-by: Tzung-Bi Shih --- cros/runners/lava_runner.py | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py index 7524f65dcd39..70f8aa61132e 100755 --- a/cros/runners/lava_runner.py +++ b/cros/runners/lava_runner.py @@ -13,38 +13,34 @@ from cros.tests.cros_ec_power import * from cros.tests.cros_ec_extcon import * -class LavaTestResult(unittest.TestResult): - def __init__(self, stream, descriptions, verbosity): - unittest.TestResult.__init__(self) - self.stream = stream +class LavaTestResult(unittest.TextTestResult): + def writeLavaSignal(self, test, result): + test_case_id = test.id().rsplit(".")[-1] - def addSuccess(self, test): - unittest.TestResult.addSuccess(self, test) - self.stream.write( - "\n" - % test.id().rsplit(".")[-1] + # LAVA signal must be start-of-line. Print a newline if verbosity >= 1. + if self.showAll or self.dots: + self.stream.writeln() + + self.stream.writeln( + f"" ) + self.stream.flush() + + def addSuccess(self, test): + super().addSuccess(test) + self.writeLavaSignal(test, "pass") def addError(self, test, err): - unittest.TestResult.addError(self, test, err) - self.stream.write( - "\n" - % test.id().rsplit(".")[-1] - ) + super().addError(test, err) + self.writeLavaSignal(test, "unknown") def addFailure(self, test, err): - unittest.TestResult.addFailure(self, test, err) - self.stream.write( - "\n" - % test.id().rsplit(".")[-1] - ) + super().addFailure(test, err) + self.writeLavaSignal(test, "fail") def addSkip(self, test, reason): - unittest.TestResult.addSkip(self, test, reason) - self.stream.write( - "\n" - % test.id().rsplit(".")[-1] - ) + super().addSkip(test, reason) + self.writeLavaSignal(test, "skip") if __name__ == "__main__": From patchwork Mon Mar 13 09:44:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172131 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F14223A7 for ; Mon, 13 Mar 2023 09:44:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E30F2C433A0; Mon, 13 Mar 2023 09:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700685; bh=zOKVpcK7fJYF7L4PNzP8f0M2jUmarqfzj9FYGV1kP2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K3eyzPVTh90JLxt5FwMPBvokEVSNgP/BRIz2fkkBpah9GI8RnGh7mV2uCSxa05Lo3 MVLXtKspunQ1ff7rnSXMx2fb2pxQ27sAEb+8KWbWE0YpLAzUuLcUHzPwj18/pLEoM8 dl9mUI3cr0We2RY8yRl5Yg61PhTqEnwRs2g5n8Gi+o7had1mfrz+7SueFu3onmCdi2 nACpuwCDa2X5MgTiyDXAIjvffE2MSLP83YlQh5UsWgwxhAhYYca4up8jHI0XXitrO5 v2ycWViLpi3MQ77s4vLA28AKH+Ze03bNNg1LwdPqvf+nlTPRrH8MrTfUybTD0gmZpb jNVSEhAmzMbNg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 04/14] lava_runner: respect to verbosity flag from unittest framework Date: Mon, 13 Mar 2023 17:44:21 +0800 Message-Id: <20230313094431.507952-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 testRunner in unittest.main() shouldn't be an instance. Otherwise, any verbosity flag won't pass into the testRunner. For example: 1. m = unittest.main( testRunner=TextTestRunner(...), verbosity=0 ) The verbosity won't take effect in the TextTestRunner. Instead, it uses the default verbosity in TextTestRunner(), i.e., 1. 2. m = unittest.main( testRunner=TextTestRunner(...), ) When invoking `python3 -m ... -q`, it intends to set the verbosity to 0. However, the testRunner has been instantiated, the flag won't pass to the testRunner. Thus, LavaTestRunner is back. Signed-off-by: Tzung-Bi Shih --- cros/runners/lava_runner.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cros/runners/lava_runner.py b/cros/runners/lava_runner.py index 70f8aa61132e..427d41f2eadb 100755 --- a/cros/runners/lava_runner.py +++ b/cros/runners/lava_runner.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import functools import sys import unittest @@ -43,9 +44,15 @@ class LavaTestResult(unittest.TextTestResult): self.writeLavaSignal(test, "skip") +class LavaTestRunner(unittest.TextTestRunner): + __init__ = functools.partialmethod( + unittest.TextTestRunner.__init__, + resultclass=LavaTestResult) + + if __name__ == "__main__": unittest.main( - testRunner=unittest.TextTestRunner(resultclass=LavaTestResult), + testRunner=LavaTestRunner, # these make sure that some options that are not applicable # remain hidden from the help menu. failfast=False, From patchwork Mon Mar 13 09:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172132 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C1B23A7 for ; Mon, 13 Mar 2023 09:44:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69EF6C4339E; Mon, 13 Mar 2023 09:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700686; bh=WeptGaIkUuaHhJdA7twl4v56UfNwfXYyrUH0KK37HN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uMSTKMsBJRzHMad/hmy86KeQ54QbZ2KKHimeNGI2ldXHt4OxaOxrEDsy6VvDcOA/U QGX2XL2dL1l2lf8fZlcpMTMTNaCQHiCAJgUOHr7fdJQk+bUEZ6ZWLjE1uOyz4C+i3G jQTZxc/dfPK/Nqs5L/l/XCB5e1xHu5cZScdWKM6I8gff9k6fepg67eU+41vmRfsgX7 JlfxmxMdmEr5rYs26dNEEQNcmgqgQxv2guRqri2XfdF/OgRfs+zhKGRRtyb/6OAxzV eo5Vs/YbdCl1+aevWco4q0IVfCZ8OuZdhcU75u+8t3Cw1zNn6QygI+g83cGIJ8K4IU QviQgcV9CHnqw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 05/14] helpers/sysfs: fix NameError Date: Mon, 13 Mar 2023 17:44:22 +0800 Message-Id: <20230313094431.507952-6-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some errors have been revealed after the runner is-a TextTestRunner. Fix the following error: > NameError: name 'self' is not defined Signed-off-by: Tzung-Bi Shih --- cros/helpers/sysfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cros/helpers/sysfs.py b/cros/helpers/sysfs.py index f3abfabced24..1ccc0cd2ba24 100755 --- a/cros/helpers/sysfs.py +++ b/cros/helpers/sysfs.py @@ -33,6 +33,6 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype): for filename in files: s.assertEqual(os.path.exists(path + "/" + devname + "/" + filename), 1) except IOError as e: - self.skipTest("Exception occured: {0}, skipping".format(e.strerror)) + s.skipTest("Exception occured: {0}, skipping".format(e.strerror)) if match == 0: s.skipTest("No " + name + " found, skipping") From patchwork Mon Mar 13 09:44:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172133 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E50723A7 for ; Mon, 13 Mar 2023 09:44:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E486AC433EF; Mon, 13 Mar 2023 09:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700688; bh=FwSPRVesW2Gyt1ri6YvL40cclXRv6ZLqiQO8yAUou+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uau468kY8nhyxGeQobAgRWlF/QUkIOJF/SWg+5xhq+bJaiNOP/KTLbrq0uMp3tY4+ yJC6DS6QHfCmzZ9T2Ll4ReyPwNiCw/oeeRvPs8Fk4kq2t6/wI0khdWu42CgtOjmbCA ZwHlaSpIV2u+iO1xC9J8LOM0NPJjxtmW6ct6VigOKuTH7efKyeIWxfHOYx3EZamoow HETj43O4cLSmdqA5185dMCy293u78jbb7XxDIUVOREDkQcCiLr93/h3WndLXJz8pfH ZjqedzTWWeE2plBjNjjHlkfDY20acnn94FlUfwzQeivbN4vyKJQVYPUZnzihoGXL7A h9fWAl6ixHnhQ== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 06/14] helpers/mcu: fix ResourceWarning on /dev/cros_ec Date: Mon, 13 Mar 2023 17:44:23 +0800 Message-Id: <20230313094431.507952-7-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some errors have been revealed after the runner is-a TextTestRunner. Fix the following warning: > ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/cros_ec' Signed-off-by: Tzung-Bi Shih --- cros/helpers/mcu.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index e1f09f39af89..80e3328cdf08 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -112,8 +112,6 @@ def is_feature_supported(feature): global ECFEATURES if ECFEATURES == -1: - fd = open("/dev/cros_ec", "r") - param = ec_params_get_features() response = ec_response_get_features() @@ -124,11 +122,10 @@ def is_feature_supported(feature): cmd.outsize = sizeof(response) memmove(addressof(cmd.data), addressof(param), cmd.outsize) - fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd) + with open("/dev/cros_ec", "r") as fh: + fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.outsize) - fd.close() - if cmd.result == 0: ECFEATURES = response.out_data else: From patchwork Mon Mar 13 09:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172134 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B85FC23A7 for ; Mon, 13 Mar 2023 09:44:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BF29C4339B; Mon, 13 Mar 2023 09:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700689; bh=NAb/tW4KA4Gh0mNxYdjrSzKgSMNRY+nHzJcxmk5hgXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=exc9qgLLJtU+AzUUDa+/DStD139m7Jw5sP3/UdC2ARRY/J/Yxvg2gYVp49pDSXtb3 Q70Jzs1X6+fpEJPaimRnbNXK1qNOXps+0LJ5MdqQD3dNHAWYssLXCAErFP3aEL7Spm Xg97X1QoNRDmdFDy4ZCxyldj5//FaHfxp0ZqTBa1z+VPwAvz6O7kAIb7sypHYQDJ6O bXjj/ej7M9lK4pCNvlOVYs3fLqtohZkQ7MFoTQhgPoVQsLhP9pVAvYBjUuZOE+p4Cs ae0T4RZQFbvNs56w8DRhzlDlGoHvjUzC8cmD8i9SRzBDzfuW6+pzNjszJQGCHM1MGV cuKDrt3Dr2AkA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 07/14] cros_ec_pwm: fix ResourceWarning on /sys/kernel/debug/pwm Date: Mon, 13 Mar 2023 17:44:24 +0800 Message-Id: <20230313094431.507952-8-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some errors have been revealed after the runner is-a TextTestRunner. Fix the following warning: > ResourceWarning: unclosed file <_io.TextIOWrapper name='/sys/kernel/debug/pwm' Signed-off-by: Tzung-Bi Shih --- cros/tests/cros_ec_pwm.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/cros/tests/cros_ec_pwm.py b/cros/tests/cros_ec_pwm.py index bcc9fbcea1d5..ba429a327db1 100644 --- a/cros/tests/cros_ec_pwm.py +++ b/cros/tests/cros_ec_pwm.py @@ -37,16 +37,14 @@ class TestCrosECPWM(unittest.TestCase): fd = open("/sys/class/backlight/backlight/brightness", "w") fd.write(str(brightness)) fd.close() - fd = open("/sys/kernel/debug/pwm", "r") - line = fd.readline() - while line: - if "backlight" in line: - start = line.find("duty") + 6 - self.assertNotEqual(start, 5) - end = start + line[start:].find(" ") - self.assertNotEqual(start, end) - duty = int(line[start:end]) - self.assertNotEqual(duty, 0) - break - line = fd.readline() - fd.close() + + with open("/sys/kernel/debug/pwm", "r") as fh: + for line in fh: + if "backlight" in line: + start = line.find("duty") + 6 + self.assertNotEqual(start, 5) + end = start + line[start:].find(" ") + self.assertNotEqual(start, end) + duty = int(line[start:end]) + self.assertNotEqual(duty, 0) + break From patchwork Mon Mar 13 09:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172135 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4234223A7 for ; Mon, 13 Mar 2023 09:44:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7B2AC433EF; Mon, 13 Mar 2023 09:44:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700691; bh=POf40pYdouJgqRpyWymB+P+khOAYzJCuFVtawEhAyyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2sD3WYc4FMwHIXVlXJTIvWo/x/TnnUT61MiQdPJztiJghzx5BBDDSb4mI4qKmn9L q1igdDdk3gagueWzfyaR9lXHaWYRjkSLIyWIT3Lxxcx8eavifRa7XDWS7RblzTfliB fxGwUCV6Vt6wa6mKyNdHMRvXBL0msKv+pZrB5uwmrCcHKfS0CDIT/Z4BFbWWBjJfeM Ofh6a8T8dRDPMPuAL35xXDkBHroktajCPRl8466PE68OVNO7pXbLbVNhQKEstT/ucO RdyW9hB+mVEy0D5Rezmu1BPzKZ/LBGA3e4uR1k/rQAjwGG5KAYyptzShWBH4H/8fNU f7GuxxNhPOP+g== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 08/14] treewide: use context manager on file objects Date: Mon, 13 Mar 2023 17:44:25 +0800 Message-Id: <20230313094431.507952-9-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use context manager on file objects so that the resource is correctly released even if an exception happens before it calls close(). Signed-off-by: Tzung-Bi Shih --- cros/helpers/kernel.py | 5 ++--- cros/helpers/mcu.py | 17 ++++++----------- cros/helpers/sysfs.py | 10 ++++------ cros/tests/cros_ec_accel.py | 5 ++--- cros/tests/cros_ec_pwm.py | 10 ++++------ cros/tests/cros_ec_rtc.py | 5 ++--- 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/cros/helpers/kernel.py b/cros/helpers/kernel.py index db0c69f01683..9e4d769c0531 100644 --- a/cros/helpers/kernel.py +++ b/cros/helpers/kernel.py @@ -14,9 +14,8 @@ def current_kernel_version(): """ Returns the current kernel version as an integer you can compare. """ - fd = open("/proc/version", "r") - current = fd.read().split()[2].split("-")[0].split(".") - fd.close() + with open("/proc/version", "r") as fh: + current = fh.read().split()[2].split("-")[0].split(".") return version_to_int(int(current[0]), int(current[1]), int(current[2])) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index 80e3328cdf08..27ce9ad5cc58 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -150,7 +150,6 @@ def mcu_hello(s, name): """ Checks basic comunication with MCU. """ if not os.path.exists("/dev/" + name): s.skipTest("MCU " + name + " not present, skipping") - fd = open("/dev/" + name, "r") param = ec_params_hello() param.in_data = 0xA0B0C0D0 # magic number that the EC expects on HELLO @@ -163,19 +162,16 @@ def mcu_hello(s, name): cmd.outsize = sizeof(response) memmove(addressof(cmd.data), addressof(param), cmd.insize) - fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd) + with open("/dev/" + name, "r") as fh: + fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.outsize) - fd.close() - s.assertEqual(cmd.result, 0) # magic number that the EC answers on HELLO s.assertEqual(response.out_data, 0xA1B2C3D4) def mcu_get_version(name): if os.path.exists("/dev/" + name): - fd = open("/dev/" + name, "r") - response = ec_response_get_version() cmd = cros_ec_command() @@ -184,25 +180,24 @@ def mcu_get_version(name): cmd.insize = sizeof(response) cmd.outsize = 0 - fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd) + with open("/dev/" + name, "r") as fh: + fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.insize) - fd.close() if cmd.result == 0: return response def mcu_reboot(name): - fd = open("/dev/" + name, "r") cmd = cros_ec_command() cmd.version = 0 cmd.command = EC_CMD_REBOOT cmd.insize = 0 cmd.outsize = 0 try: - fcntl.ioctl(fd, EC_DEV_IOCXCMD, cmd) + with open("/dev/" + name, "r") as fh: + fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) except IOError: pass - fd.close() def check_mcu_reboot_rw(s, name): if not os.path.exists("/dev/" + name): diff --git a/cros/helpers/sysfs.py b/cros/helpers/sysfs.py index 1ccc0cd2ba24..80653fd13431 100755 --- a/cros/helpers/sysfs.py +++ b/cros/helpers/sysfs.py @@ -6,9 +6,8 @@ import os def read_file(name): """ Returns the content of the file named 'name'.""" - fd = open(name, "r") - contents = fd.read() - fd.close() + with open(name, "r") as fh: + contents = fh.read() return contents @@ -21,9 +20,8 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype): try: for devname in os.listdir(path): if check_devtype: - fd = open(path + "/" + devname + "/name", "r") - devtype = fd.read() - fd.close() + with open(path + "/" + devname + "/name", "r") as fh: + devtype = fh.read() if not devtype.startswith(name): continue else: diff --git a/cros/tests/cros_ec_accel.py b/cros/tests/cros_ec_accel.py index 8861eb0e1c2c..b76d2a6fbb4d 100755 --- a/cros/tests/cros_ec_accel.py +++ b/cros/tests/cros_ec_accel.py @@ -57,8 +57,8 @@ class TestCrosECAccel(unittest.TestCase): try: for devname in os.listdir("/sys/bus/iio/devices"): base_path = "/sys/bus/iio/devices/" + devname + "/" - fd = open(base_path + "name", "r") - devtype = fd.read() + with open(base_path + "name", "r") as fh: + devtype = fh.read() if devtype.startswith("cros-ec-accel"): location = read_file(base_path + "location") accel_scale = float(read_file(base_path + "scale")) @@ -73,7 +73,6 @@ class TestCrosECAccel(unittest.TestCase): mag = math.sqrt(mag) self.assertTrue(abs(mag - exp) <= err) match += 1 - fd.close() except IOError as e: self.skipTest("Exception occured: {0}, skipping".format(e.strerror)) if match == 0: diff --git a/cros/tests/cros_ec_pwm.py b/cros/tests/cros_ec_pwm.py index ba429a327db1..2b7b4a3418b1 100644 --- a/cros/tests/cros_ec_pwm.py +++ b/cros/tests/cros_ec_pwm.py @@ -31,12 +31,10 @@ class TestCrosECPWM(unittest.TestCase): fd.close() if not is_ec_pwm: self.skipTest("No EC backlight pwm found, skipping") - fd = open("/sys/class/backlight/backlight/max_brightness", "r") - brightness = int(int(fd.read()) / 2) - fd.close() - fd = open("/sys/class/backlight/backlight/brightness", "w") - fd.write(str(brightness)) - fd.close() + with open("/sys/class/backlight/backlight/max_brightness", "r") as fh: + brightness = int(int(fh.read()) / 2) + with open("/sys/class/backlight/backlight/brightness", "w") as fh: + fh.write(str(brightness)) with open("/sys/kernel/debug/pwm", "r") as fh: for line in fh: diff --git a/cros/tests/cros_ec_rtc.py b/cros/tests/cros_ec_rtc.py index 9f497d2fcb7e..7afed70f0429 100755 --- a/cros/tests/cros_ec_rtc.py +++ b/cros/tests/cros_ec_rtc.py @@ -14,9 +14,8 @@ class TestCrosECRTC(unittest.TestCase): match = 0 try: for devname in os.listdir("/sys/class/rtc"): - fd = open("/sys/class/rtc/" + devname + "/name", "r") - devtype = fd.read() - fd.close() + with open("/sys/class/rtc/" + devname + "/name", "r") as fh: + devtype = fh.read() if devtype.startswith("cros-ec-rtc"): files = [ "date", From patchwork Mon Mar 13 09:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172136 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC29023A7 for ; Mon, 13 Mar 2023 09:44:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EC15C4339B; Mon, 13 Mar 2023 09:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700692; bh=mAwuBGJlTbhSNDH+WXQKl+8rladqzugSOXw9+ToCWxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M11OOyUYQIEku60ZkRHwHD/RlekxCIFF8n+r8Pa0SAJ2iE1RD9JBOwQFiT7bYDBWi LlfRgT/hPqpqCPlIojrc25xir757xSkebYGp4RtV8YKPCbA8CbXFHWU7J6wDpfrtbl AmqbJMq0vrbZp05+WeI+TsEdmEaUuC6yRehwtsszc5fj0oRe45gOwIDRU8PNpOzJNQ YMnvXi2mugJ5lKjnpJ4QyA6bF43QPgTYsx+aR6ODZwgA49peBfefzdjrAUReDhDcV3 /IFOi5QFDP0gJ3xluG4aC7JvXfGibBsO9TbcK+3xzaWfBhSjtpvbp1RQ/8bnwyGiNW q4HqfWRAUBTIw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 09/14] cros_ec_pwm: use RE to search EC backlight PWM Date: Mon, 13 Mar 2023 17:44:26 +0800 Message-Id: <20230313094431.507952-10-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use RE to search pattern instead of reading the file line by line. Signed-off-by: Tzung-Bi Shih --- cros/tests/cros_ec_pwm.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cros/tests/cros_ec_pwm.py b/cros/tests/cros_ec_pwm.py index 2b7b4a3418b1..7158463b115f 100644 --- a/cros/tests/cros_ec_pwm.py +++ b/cros/tests/cros_ec_pwm.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from cros.helpers.sysfs import * +import re import unittest @@ -13,23 +14,12 @@ class TestCrosECPWM(unittest.TestCase): """ if not os.path.exists("/sys/class/backlight/backlight/max_brightness"): self.skipTest("No backlight pwm found, skipping") - is_ec_pwm = False - fd = open("/sys/kernel/debug/pwm", "r") - line = fd.readline() - while line and not is_ec_pwm: - if line[0] != " " and ":ec-pwm" in line: - line = fd.readline() - while line: - if line[0] == "\n": - is_ec_pwm = False - break - if "backlight" in line: - is_ec_pwm = True - break - line = fd.readline() - line = fd.readline() - fd.close() - if not is_ec_pwm: + with open("/sys/kernel/debug/pwm", "r") as fh: + pwm = fh.read() + for s in pwm.split('\n\n'): + if re.match(r'.*:ec-pwm.*backlight', s, re.DOTALL): + break + else: self.skipTest("No EC backlight pwm found, skipping") with open("/sys/class/backlight/backlight/max_brightness", "r") as fh: brightness = int(int(fh.read()) / 2) From patchwork Mon Mar 13 09:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172137 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4608C23A7 for ; Mon, 13 Mar 2023 09:44:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9EECC433A0; Mon, 13 Mar 2023 09:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700694; bh=rnjXBeAcXxDUUsM8/mE+PueXwxV4Ifw9ZDIEQ8qjclQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=topM+HHO5q4Y/f5vdk7/Hua1YcHPrErGQOcOvSQXJ9zVTvQFXGmbJPZ3RG31fQADA ruk31aJeM5M8H1XTKzKSD4uRrlFTrwwh5+jknN20AQlwxNng6jTW6Ok8E+UR4B6COE PGV/9f+nDDc0oQn8cVvEDihtH3DACN9vnA6L0AIFbokLG+Xapes2BThvI/vmowBD1P kfaRmuFQSirQ6lFGGe1p1HwjQQaIHkzPQFjzkGMRwRHO0HiDB5XLwrrSPqBlqt22Uw ggZbasGTazUGlb+IRZueASC1zv1pfmG13p9n+RQTb9TK7/gz4FNVPLY/l0PDj5ZRSI IqesBXYBPEkrA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 10/14] helpers/mcu: fix packet too long error Date: Mon, 13 Mar 2023 17:44:27 +0800 Message-Id: <20230313094431.507952-11-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 sizeof(c_ulong) is 4 in some platforms. However, EC_CMD_GET_FEATURES returns 2 uint32[1]. Fix the following error from test execution: > Traceback (most recent call last): > File "...cros/tests/cros_ec_rtc.py", line 12, in test_cros_ec_rtc_abi > if not is_feature_supported(EC_FEATURE_RTC): > File "...cros/helpers/mcu.py", line 126, in is_feature_supported > fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) > OSError: [Errno 90] Message too long And the following error message from dmesg: > cros-ec-spi spi2.0: packet too long (8 bytes, expected 4) Use c_uint64 to explicitly specify the data size. [1]: https://crrev.com/6bf531fc1c115b24e2148fc4e040081ef354cdf6/include/ec_commands.h#1594 Signed-off-by: Tzung-Bi Shih --- cros/helpers/mcu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index 27ce9ad5cc58..506730e71115 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -90,11 +90,11 @@ class ec_response_get_version(Structure): ] class ec_params_get_features(Structure): - _fields_ = [("in_data", c_ulong)] + _fields_ = [("in_data", c_uint64)] class ec_response_get_features(Structure): - _fields_ = [("out_data", c_ulong)] + _fields_ = [("out_data", c_uint64)] def EC_FEATURE_MASK_0(event_code): From patchwork Mon Mar 13 09:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172138 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1E3F23A7 for ; Mon, 13 Mar 2023 09:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70F40C4339B; Mon, 13 Mar 2023 09:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700695; bh=geSItmkZ1ry1wVMagK9KqOXpXpfhHLhi6xl8i0vQ/Ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UH+NMy1TXE0+KzqjYl1hLNhBKBhpjmKMXJlkiYsPhEnLHgrFrHucOe3jf2drS86XA pwTofHTaxN1ldX/5kNTngH4+Onx7n/xXCN49QY5oVGt6cr0ZcpPAxuZ2Yrwyv6zJ8x lS7Fes8eY2xVAEd30X8CRfZzT/dz51w2h6HX0g3mXIJDjcTf4Q61HpZ/fSRm6w2E1m 8wpDGWjCyRrpnbB10wOsu8VZclyCrUO1ZFQSoZfRCs6vf6orOb44SA6NTx98+VUaVv QqpXUGBX2tj/qeuaOOEQwInYgkFDkNzTfXrCbSyhBTDDaaUr0sB2ytbS1SrYlW+Wf3 6JUVGKUd3k/mw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 11/14] helpers/mcu: fix EC_CMD_GET_FEATURES usage Date: Mon, 13 Mar 2023 17:44:28 +0800 Message-Id: <20230313094431.507952-12-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 EC_CMD_GET_FEATURES has no parameter. Remove it. Also, the in and out was reversed. Fix it. Signed-off-by: Tzung-Bi Shih --- cros/helpers/mcu.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index 506730e71115..7d197e600f47 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -89,12 +89,8 @@ class ec_response_get_version(Structure): ("current_image", c_uint), ] -class ec_params_get_features(Structure): - _fields_ = [("in_data", c_uint64)] - - class ec_response_get_features(Structure): - _fields_ = [("out_data", c_uint64)] + _fields_ = [("in_data", c_uint64)] def EC_FEATURE_MASK_0(event_code): @@ -112,22 +108,20 @@ def is_feature_supported(feature): global ECFEATURES if ECFEATURES == -1: - param = ec_params_get_features() response = ec_response_get_features() cmd = cros_ec_command() cmd.version = 0 cmd.command = EC_CMD_GET_FEATURES - cmd.insize = sizeof(param) - cmd.outsize = sizeof(response) + cmd.insize = sizeof(response) + cmd.outsize = 0 - memmove(addressof(cmd.data), addressof(param), cmd.outsize) with open("/dev/cros_ec", "r") as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) - memmove(addressof(response), addressof(cmd.data), cmd.outsize) + memmove(addressof(response), addressof(cmd.data), cmd.insize) if cmd.result == 0: - ECFEATURES = response.out_data + ECFEATURES = response.in_data else: return False From patchwork Mon Mar 13 09:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172139 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C6C823A7 for ; Mon, 13 Mar 2023 09:44:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED29BC433D2; Mon, 13 Mar 2023 09:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700697; bh=12UCfVN80jBPcfaXziP438pBrv60ZCjR/WTBbUfdpWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWdbqxbOJjyoiRGB30+TFRtEdM3Ccn5NUlysr+63wdFbiPWHCyFIUFddvisWx1yx0 cWiFN06fgvgpgqExYtiJGEueP4KmXlLzELWdYp2quonav3W91uZsPqxh2wwJVihQ9S G2JrN/Wjcez8uoBErVFwBmHYM+rKyY6zx/D7MdzvbVlWAss+3wQHW7ASXlCgcDzUao 1HmpwHnbmCTcvrB7M5CIOuV+Uro6VKTFO+146UMBaFVjA2GjExyoqv1z3O1IpkZzpv evRBPrGaEsRrotQl3v/BFeWwEc3CRgm6UTKy0+pQxAQMN/Bt1TSSTBa5fhvRO1LfTm sSN3hLNcFbVVw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 12/14] treewide: remove "r" in open() if reading mode Date: Mon, 13 Mar 2023 17:44:29 +0800 Message-Id: <20230313094431.507952-13-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 open()'s default mode is "r". To simplify, remove them if reading mode. Signed-off-by: Tzung-Bi Shih --- cros/helpers/kernel.py | 2 +- cros/helpers/mcu.py | 8 ++++---- cros/helpers/sysfs.py | 4 ++-- cros/tests/cros_ec_accel.py | 2 +- cros/tests/cros_ec_pwm.py | 6 +++--- cros/tests/cros_ec_rtc.py | 2 +- setup.py | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cros/helpers/kernel.py b/cros/helpers/kernel.py index 9e4d769c0531..c319f99a3143 100644 --- a/cros/helpers/kernel.py +++ b/cros/helpers/kernel.py @@ -14,7 +14,7 @@ def current_kernel_version(): """ Returns the current kernel version as an integer you can compare. """ - with open("/proc/version", "r") as fh: + with open("/proc/version") as fh: current = fh.read().split()[2].split("-")[0].split(".") return version_to_int(int(current[0]), int(current[1]), int(current[2])) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index 7d197e600f47..6c12affd4073 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -116,7 +116,7 @@ def is_feature_supported(feature): cmd.insize = sizeof(response) cmd.outsize = 0 - with open("/dev/cros_ec", "r") as fh: + with open("/dev/cros_ec") as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.insize) @@ -156,7 +156,7 @@ def mcu_hello(s, name): cmd.outsize = sizeof(response) memmove(addressof(cmd.data), addressof(param), cmd.insize) - with open("/dev/" + name, "r") as fh: + with open("/dev/" + name) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.outsize) @@ -174,7 +174,7 @@ def mcu_get_version(name): cmd.insize = sizeof(response) cmd.outsize = 0 - with open("/dev/" + name, "r") as fh: + with open("/dev/" + name) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.insize) @@ -188,7 +188,7 @@ def mcu_reboot(name): cmd.insize = 0 cmd.outsize = 0 try: - with open("/dev/" + name, "r") as fh: + with open("/dev/" + name) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) except IOError: pass diff --git a/cros/helpers/sysfs.py b/cros/helpers/sysfs.py index 80653fd13431..4d3b6735ef45 100755 --- a/cros/helpers/sysfs.py +++ b/cros/helpers/sysfs.py @@ -6,7 +6,7 @@ import os def read_file(name): """ Returns the content of the file named 'name'.""" - with open(name, "r") as fh: + with open(name) as fh: contents = fh.read() return contents @@ -20,7 +20,7 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype): try: for devname in os.listdir(path): if check_devtype: - with open(path + "/" + devname + "/name", "r") as fh: + with open(path + "/" + devname + "/name") as fh: devtype = fh.read() if not devtype.startswith(name): continue diff --git a/cros/tests/cros_ec_accel.py b/cros/tests/cros_ec_accel.py index b76d2a6fbb4d..3d6a54acac16 100755 --- a/cros/tests/cros_ec_accel.py +++ b/cros/tests/cros_ec_accel.py @@ -57,7 +57,7 @@ class TestCrosECAccel(unittest.TestCase): try: for devname in os.listdir("/sys/bus/iio/devices"): base_path = "/sys/bus/iio/devices/" + devname + "/" - with open(base_path + "name", "r") as fh: + with open(base_path + "name") as fh: devtype = fh.read() if devtype.startswith("cros-ec-accel"): location = read_file(base_path + "location") diff --git a/cros/tests/cros_ec_pwm.py b/cros/tests/cros_ec_pwm.py index 7158463b115f..6be5c292ffa2 100644 --- a/cros/tests/cros_ec_pwm.py +++ b/cros/tests/cros_ec_pwm.py @@ -14,19 +14,19 @@ class TestCrosECPWM(unittest.TestCase): """ if not os.path.exists("/sys/class/backlight/backlight/max_brightness"): self.skipTest("No backlight pwm found, skipping") - with open("/sys/kernel/debug/pwm", "r") as fh: + with open("/sys/kernel/debug/pwm") as fh: pwm = fh.read() for s in pwm.split('\n\n'): if re.match(r'.*:ec-pwm.*backlight', s, re.DOTALL): break else: self.skipTest("No EC backlight pwm found, skipping") - with open("/sys/class/backlight/backlight/max_brightness", "r") as fh: + with open("/sys/class/backlight/backlight/max_brightness") as fh: brightness = int(int(fh.read()) / 2) with open("/sys/class/backlight/backlight/brightness", "w") as fh: fh.write(str(brightness)) - with open("/sys/kernel/debug/pwm", "r") as fh: + with open("/sys/kernel/debug/pwm") as fh: for line in fh: if "backlight" in line: start = line.find("duty") + 6 diff --git a/cros/tests/cros_ec_rtc.py b/cros/tests/cros_ec_rtc.py index 7afed70f0429..e59fa383659d 100755 --- a/cros/tests/cros_ec_rtc.py +++ b/cros/tests/cros_ec_rtc.py @@ -14,7 +14,7 @@ class TestCrosECRTC(unittest.TestCase): match = 0 try: for devname in os.listdir("/sys/class/rtc"): - with open("/sys/class/rtc/" + devname + "/name", "r") as fh: + with open("/sys/class/rtc/" + devname + "/name") as fh: devtype = fh.read() if devtype.startswith("cros-ec-rtc"): files = [ diff --git a/setup.py b/setup.py index 92e4ed794245..958aaa89e143 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import setuptools -with open("README.md", "r") as fh: +with open("README.md") as fh: long_description = fh.read() setuptools.setup( From patchwork Mon Mar 13 09:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172140 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C329D23A7 for ; Mon, 13 Mar 2023 09:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7450DC433EF; Mon, 13 Mar 2023 09:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700698; bh=SaNWtsEe4AGb2/cI0tzOdT8HUbmnOBPRLv6v1h4G9gM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c/2teot32nw7MXk2V7QzdRrkezNL2S2UWjAk8Ow8tJ/Mi01vb2YM85qUy+fkku2JL n+szFDlBCxXnvwYu2wjVUjR8o4RJSVusnC77gdloW8PyP6TnyEsNPwPcySGNyeWmdt BTHbXbiBjrReo+jGFaazCaF6aTFII87C8ZUDQ/k4Zqf9OrL+CKTlyWUYZbGpb3uKri MpvBhQyURbG4cb62qZa3smKB3uMqNzlfMVyUB4iFDy85b9DewU1r7d8Ni4AIq0eXSW Nq5GI4BOe1c1TFIfziYONwvLeVAmQ1JX9Vei+LSY2oFSpNu9y1VRMKSRKRCD1bfJ5W CyqGF37b3Vglg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 13/14] treewide: don't use "+" operator for constructing paths Date: Mon, 13 Mar 2023 17:44:30 +0800 Message-Id: <20230313094431.507952-14-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Don't use "+" operator for constructing paths. Use os.path.join() instead. Signed-off-by: Tzung-Bi Shih --- cros/helpers/mcu.py | 19 ++++++++++++------- cros/helpers/sysfs.py | 6 ++++-- cros/tests/cros_ec_accel.py | 10 +++++----- cros/tests/cros_ec_extcon.py | 11 ++++++----- cros/tests/cros_ec_rtc.py | 5 +++-- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index 6c12affd4073..e2d2db0ef1ed 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -132,7 +132,8 @@ def check_mcu_abi(s, name): """ Checks that the MCU character device exists in /dev and then verifies the standard MCU ABI in /sys/class/chromeos. """ - if not os.path.exists("/dev/" + name): + dev = os.path.join("/dev", name) + if not os.path.exists(dev): s.skipTest("MCU " + name + " not supported, skipping") files = ["flashinfo", "reboot", "version"] sysfs_check_attributes_exists( @@ -142,7 +143,8 @@ def check_mcu_abi(s, name): def mcu_hello(s, name): """ Checks basic comunication with MCU. """ - if not os.path.exists("/dev/" + name): + dev = os.path.join("/dev", name) + if not os.path.exists(dev): s.skipTest("MCU " + name + " not present, skipping") param = ec_params_hello() param.in_data = 0xA0B0C0D0 # magic number that the EC expects on HELLO @@ -156,7 +158,7 @@ def mcu_hello(s, name): cmd.outsize = sizeof(response) memmove(addressof(cmd.data), addressof(param), cmd.insize) - with open("/dev/" + name) as fh: + with open(dev) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.outsize) @@ -165,7 +167,8 @@ def mcu_hello(s, name): s.assertEqual(response.out_data, 0xA1B2C3D4) def mcu_get_version(name): - if os.path.exists("/dev/" + name): + dev = os.path.join("/dev", name) + if os.path.exists(dev): response = ec_response_get_version() cmd = cros_ec_command() @@ -174,7 +177,7 @@ def mcu_get_version(name): cmd.insize = sizeof(response) cmd.outsize = 0 - with open("/dev/" + name) as fh: + with open(dev) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) memmove(addressof(response), addressof(cmd.data), cmd.insize) @@ -188,13 +191,15 @@ def mcu_reboot(name): cmd.insize = 0 cmd.outsize = 0 try: - with open("/dev/" + name) as fh: + dev = os.path.join("/dev", name) + with open(dev) as fh: fcntl.ioctl(fh, EC_DEV_IOCXCMD, cmd) except IOError: pass def check_mcu_reboot_rw(s, name): - if not os.path.exists("/dev/" + name): + dev = os.path.join("/dev", name) + if not os.path.exists(dev): s.skipTest("cros_fp not present, skipping") mcu_reboot(name) response = mcu_get_version(name) diff --git a/cros/helpers/sysfs.py b/cros/helpers/sysfs.py index 4d3b6735ef45..882bc4d14243 100755 --- a/cros/helpers/sysfs.py +++ b/cros/helpers/sysfs.py @@ -20,7 +20,8 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype): try: for devname in os.listdir(path): if check_devtype: - with open(path + "/" + devname + "/name") as fh: + p = os.path.join(path, devname, "name") + with open(p) as fh: devtype = fh.read() if not devtype.startswith(name): continue @@ -29,7 +30,8 @@ def sysfs_check_attributes_exists(s, path, name, files, check_devtype): continue match += 1 for filename in files: - s.assertEqual(os.path.exists(path + "/" + devname + "/" + filename), 1) + p = os.path.join(path, devname, filename) + s.assertEqual(os.path.exists(p), 1) except IOError as e: s.skipTest("Exception occured: {0}, skipping".format(e.strerror)) if match == 0: diff --git a/cros/tests/cros_ec_accel.py b/cros/tests/cros_ec_accel.py index 3d6a54acac16..15a92b7dd35d 100755 --- a/cros/tests/cros_ec_accel.py +++ b/cros/tests/cros_ec_accel.py @@ -56,17 +56,17 @@ class TestCrosECAccel(unittest.TestCase): match = 0 try: for devname in os.listdir("/sys/bus/iio/devices"): - base_path = "/sys/bus/iio/devices/" + devname + "/" - with open(base_path + "name") as fh: + base_path = os.path.join("/sys/bus/iio/devices", devname) + with open(os.path.join(base_path, "name")) as fh: devtype = fh.read() if devtype.startswith("cros-ec-accel"): - location = read_file(base_path + "location") - accel_scale = float(read_file(base_path + "scale")) + location = read_file(os.path.join(base_path, "location")) + accel_scale = float(read_file(os.path.join(base_path, "scale"))) exp = ACCEL_1G_IN_MS2 err = exp * ACCEL_MAG_VALID_OFFSET mag = 0 for axis in ["x", "y", "z"]: - axis_path = base_path + "in_accel_" + axis + "_raw" + axis_path = os.path.join(base_path, "in_accel_" + axis + "_raw") value = int(read_file(axis_path)) value *= accel_scale mag += value * value diff --git a/cros/tests/cros_ec_extcon.py b/cros/tests/cros_ec_extcon.py index b2864b52f4c0..8c496b868bb3 100755 --- a/cros/tests/cros_ec_extcon.py +++ b/cros/tests/cros_ec_extcon.py @@ -11,22 +11,23 @@ class TestCrosECextcon(unittest.TestCase): match = 0 try: for devname in os.listdir("/sys/class/extcon"): - devtype = read_file("/sys/class/extcon/" + devname + "/name") + d = os.path.join("/sys/class/extcon", devname) + devtype = read_file(os.path.join(d, "name")) if ".spi:ec@0:extcon@" in devtype: self.assertEqual( - os.path.exists("/sys/class/extcon/" + devname + "/state"), 1 + os.path.exists(os.path.join(d, "state")), 1 ) - for cable in os.listdir("/sys/class/extcon/" + devname): + for cable in os.listdir(d): if cable.startswith("cable"): self.assertEqual( os.path.exists( - "/sys/class/extcon/" + devname + "/" + cable + "/name" + os.path.join(d, cable, "name") ), 1, ) self.assertEqual( os.path.exists( - "/sys/class/extcon/" + devname + "/" + cable + "/state" + os.path.join(d, cable, "state") ), 1, ) diff --git a/cros/tests/cros_ec_rtc.py b/cros/tests/cros_ec_rtc.py index e59fa383659d..2d1ef3d58d85 100755 --- a/cros/tests/cros_ec_rtc.py +++ b/cros/tests/cros_ec_rtc.py @@ -14,7 +14,8 @@ class TestCrosECRTC(unittest.TestCase): match = 0 try: for devname in os.listdir("/sys/class/rtc"): - with open("/sys/class/rtc/" + devname + "/name") as fh: + d = os.path.join("/sys/class/rtc", devname) + with open(os.path.join(d, "name")) as fh: devtype = fh.read() if devtype.startswith("cros-ec-rtc"): files = [ @@ -28,7 +29,7 @@ class TestCrosECRTC(unittest.TestCase): match += 1 for filename in files: self.assertEqual( - os.path.exists("/sys/class/rtc/" + devname + "/" + filename), 1 + os.path.exists(os.path.join(d, filename)), 1 ) except IOError as e: self.skipTest("Exception occured: {0}, skipping".format(e.strerror)) From patchwork Mon Mar 13 09:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 13172141 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 480B123A7 for ; Mon, 13 Mar 2023 09:45:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEDEAC4339C; Mon, 13 Mar 2023 09:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678700700; bh=rsnSL6GguEiZ0FKVcjrYvBFmFEAcSMqqw3PXRx1ugZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TRuYUBau+0vmGEGOfGjnj6ywyN1jg+j/IWQyrlPWx1FpbR+0Pq2Ph/L7clUSlPD5p hqQf+iMStYK2J4f1khRdRZCLCVLHQNbC/DmB0H7YPeU5jUtfc4LW+P9Pq1r1eL+4PC CbGPJLsyAeESuFLAV2bshKTM/DYo5u8iRJO1d/bxx6ZF1ZKPCHhV/ZoRf8NuK6072y 5Qd8dkZOpLqaYJbTTR+zMyoA5i35AVXvQ9SjwBY0po+VttJ1X7YeW1nDsS/0RBWAow eyn2Qhq4bfe/gW61fmeZdXm+vZag29Th2elg7oEld3/3/u0UxO0vwbc+hbFWi7baSB y5mgxEMVDeUZA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, guillaume.tucker@collabora.com, denys.f@collabora.com, ricardo.canuelo@collabora.com Subject: [PATCH 14/14] treewide: don't use "+" operator for concatenating strings Date: Mon, 13 Mar 2023 17:44:31 +0800 Message-Id: <20230313094431.507952-15-tzungbi@kernel.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230313094431.507952-1-tzungbi@kernel.org> References: <20230313094431.507952-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Don't use "+" operator for concatenating strings. Use f-string instead. Signed-off-by: Tzung-Bi Shih --- cros/helpers/mcu.py | 4 ++-- cros/tests/cros_ec_accel.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cros/helpers/mcu.py b/cros/helpers/mcu.py index e2d2db0ef1ed..d756f25a9c6e 100644 --- a/cros/helpers/mcu.py +++ b/cros/helpers/mcu.py @@ -134,7 +134,7 @@ def check_mcu_abi(s, name): """ dev = os.path.join("/dev", name) if not os.path.exists(dev): - s.skipTest("MCU " + name + " not supported, skipping") + s.skipTest(f"MCU {name} not supported, skipping") files = ["flashinfo", "reboot", "version"] sysfs_check_attributes_exists( s, "/sys/class/chromeos/", name, files, False @@ -145,7 +145,7 @@ def mcu_hello(s, name): """ Checks basic comunication with MCU. """ dev = os.path.join("/dev", name) if not os.path.exists(dev): - s.skipTest("MCU " + name + " not present, skipping") + s.skipTest(f"MCU {name} not present, skipping") param = ec_params_hello() param.in_data = 0xA0B0C0D0 # magic number that the EC expects on HELLO diff --git a/cros/tests/cros_ec_accel.py b/cros/tests/cros_ec_accel.py index 15a92b7dd35d..22d7affe3632 100755 --- a/cros/tests/cros_ec_accel.py +++ b/cros/tests/cros_ec_accel.py @@ -66,7 +66,7 @@ class TestCrosECAccel(unittest.TestCase): err = exp * ACCEL_MAG_VALID_OFFSET mag = 0 for axis in ["x", "y", "z"]: - axis_path = os.path.join(base_path, "in_accel_" + axis + "_raw") + axis_path = os.path.join(base_path, f"in_accel_{axis}_raw") value = int(read_file(axis_path)) value *= accel_scale mag += value * value