From patchwork Thu Mar 16 22:06:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 70987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp25539wrt; Thu, 16 Mar 2023 15:22:59 -0700 (PDT) X-Google-Smtp-Source: AK7set+xF23ntP08zAXqXgLoQUNFYj6YRIfPK23cU8V38qsdIfGrWxzaLxRwOJrT0PNXvXMLtxHW X-Received: by 2002:a05:6a20:8ba1:b0:d5:21ab:6b with SMTP id m33-20020a056a208ba100b000d521ab006bmr5893154pzh.2.1679005379229; Thu, 16 Mar 2023 15:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679005379; cv=none; d=google.com; s=arc-20160816; b=gdOc6xXfYMLRGt6Rh8l+erbdLynx3CQ36wixomQpGpaEmr5NNrIxGJspZfQ6GM/Ad9 5Wuzowj3Nd5kRBkz9iDCmSVjJeQyl+pSuX4A31AU8+SC9zhtd3If64PJ/QIAc7kDNP2J OrHwchkJGeWPZR+mJEc1xrxjXkBI3aawTw4HWna7+j8kY6UYVLMRBTwDRogDM9tfxAgy qKSSkGjPgsYzT3lKIkk4BmNmpPFjbNPWtolV2TkafmiEyaVIWEeegBfKjnoBXSSb9XG2 +/S1h9glCO5AaPicBffiBMYTqZQHXPkYecs/NTXPPsULcYVbX6dNJ6I+DrbTqMgDD1B7 JEtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=5w/bUTaQvv0dE6Z9kgV2X6M6GsXpoWgjbDaqKfzvjzU=; b=HVMaKN4BAAB7QEBdmhIdSRpzZx5Q4v2HywEnkmT6I8eogE90yAGJf8pIIQKwa3ssP9 cQSrXrx6j9hGoLvOeT6XTEpvVO8D0aq8tqO25DeyylcQa8JWZVgpZahPDZHELgWyyN0M 1/I8jGFE/O7JwfnaJOhKGq34miHKFQu529vo18fX/Zryuf+BoIHLgAxvNbbd0cz+ZoVo 29S7h3HIN0FjOqGZqOa+KBs+f5uani9y8h5coDiAj3vYjXGtEctct4rnXYCE0ckWdcf5 xxOSu+BSGwCB6WM+aUwz6s7AghheBtDBCR1M3dTZ66EZ/j355d21ijmVr75TLQZPBc0l d1HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rIZGB5so; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a056a00164200b005a9d0456018si603603pfc.52.2023.03.16.15.22.44; Thu, 16 Mar 2023 15:22:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rIZGB5so; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjCPWHK (ORCPT + 99 others); Thu, 16 Mar 2023 18:07:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjCPWHH (ORCPT ); Thu, 16 Mar 2023 18:07:07 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8734488D85 for ; Thu, 16 Mar 2023 15:06:47 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id d22-20020a63d716000000b00502e3fb8ff3so794929pgg.10 for ; Thu, 16 Mar 2023 15:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679004407; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5w/bUTaQvv0dE6Z9kgV2X6M6GsXpoWgjbDaqKfzvjzU=; b=rIZGB5soI+YB2bwAFuUr9c+JWOpF0HrtgYe3XbqVePLIx5T7nAyu6sQkhvFb9ikBQo uFClwlCH26lx8vZzECJagMZ6U4LSE1qPlJW30AN2ao4CJ1fuFznQS06bR8Bm0RnSqNLs wYU7l/meIRfAoJGOe3R6K7zG9/xz+efX5pu0hxL4ei087YNIi/m8pAX03ul+Xt7Q+AjD 4DyGkhls6+O8D5kD7nRnFqprRdqELs0uJnLd6uV6/H5HUFtZ0tGmwFSeYhbzBPkqU9i/ mT/xyNImWDH4rmzcoZm942ZfNEU40kmejnt1+Xhh1wVM7wbpKI94Zm/l2SnrGI6R8LPj NsXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679004407; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5w/bUTaQvv0dE6Z9kgV2X6M6GsXpoWgjbDaqKfzvjzU=; b=fiKMFlnlq/KYHoI6eG0owExfIgv+B0Gag+eyjPWub5L/lVoOQNx2TlOhOhyMzZpFuM sVeHfo8um9u5UYIraq++xWpTkFRtwXgxHTRKQznhIPZZIYBpfzzf7Dl+4KumI0JJyWdC iB502rKjlkCXZJj9y0VtGbxrqToOnBdhbYwpBlp9pY6D3EOmrQFZwq95vkSBlk3pKwB0 vUTOX8CVzdVHeU5/DXFGkkYAQ8XbLXNxEyiXCKuLhu0SbxHR+eZG2QRGEUGKqsy5V1fk 6GguC9EphE3UPkkhd8xO+OSpzrVNU3gz8R9UMq8LLUTVLvvWuk5xtsXjNtR65EoHm+xh YLTw== X-Gm-Message-State: AO0yUKWGLH0yqlp40+w39BjTwisdNlDNvLh+AhevMH3ga7Xz1KHJOFfa rkckEt83tClP+ZtcuZbz2rCeJK3SgzGDPQ== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a17:902:d2c7:b0:1a0:4664:319c with SMTP id n7-20020a170902d2c700b001a04664319cmr2318672plc.6.1679004406964; Thu, 16 Mar 2023 15:06:46 -0700 (PDT) Date: Thu, 16 Mar 2023 15:06:36 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230316220638.983743-1-dlatypov@google.com> Subject: [PATCH v2 1/3] kunit: tool: add subscripts for type annotations where appropriate From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: rmoar@google.com, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, johannes@sipsolutions.net, Daniel Latypov , Johannes Berg X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760546903598388926?= X-GMAIL-MSGID: =?utf-8?q?1760564744437720940?= E.g. for subprocess.Popen, it can be opened in `text=True` mode where it returns strings, or `text=False` where it returns bytes. To differentiate, you can annotate types as `Popen[str]` or `Popen[bytes]`. This patch should add subscripts in all the places we were missing them. Reported-by: Johannes Berg Link: https://lore.kernel.org/linux-kselftest/20230315105055.9b2be0153625.I7a2cb99b95dff216c0feed4604255275e0b156a7@changeid/ Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- Note: this is unchanged, just added a 3rd patch to this series. --- tools/testing/kunit/kunit_kernel.py | 6 +++--- tools/testing/kunit/kunit_printer.py | 2 +- tools/testing/kunit/run_checks.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) base-commit: 2c6a96dad5797e57b4cf04101d6c8d5c7a571603 diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index 53e90c335834..e6fc8fcb071a 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -92,7 +92,7 @@ class LinuxSourceTreeOperations: if stderr: # likely only due to build warnings print(stderr.decode()) - def start(self, params: List[str], build_dir: str) -> subprocess.Popen: + def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: raise RuntimeError('not implemented!') @@ -112,7 +112,7 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations): kconfig.merge_in_entries(base_kunitconfig) return kconfig - def start(self, params: List[str], build_dir: str) -> subprocess.Popen: + def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: kernel_path = os.path.join(build_dir, self._kernel_path) qemu_command = ['qemu-system-' + self._qemu_arch, '-nodefaults', @@ -141,7 +141,7 @@ class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations): kconfig.merge_in_entries(base_kunitconfig) return kconfig - def start(self, params: List[str], build_dir: str) -> subprocess.Popen: + def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: """Runs the Linux UML binary. Must be named 'linux'.""" linux_bin = os.path.join(build_dir, 'linux') params.extend(['mem=1G', 'console=tty', 'kunit_shutdown=halt']) diff --git a/tools/testing/kunit/kunit_printer.py b/tools/testing/kunit/kunit_printer.py index 5f1cc55ecdf5..015adf87dc2c 100644 --- a/tools/testing/kunit/kunit_printer.py +++ b/tools/testing/kunit/kunit_printer.py @@ -15,7 +15,7 @@ _RESET = '\033[0;0m' class Printer: """Wraps a file object, providing utilities for coloring output, etc.""" - def __init__(self, output: typing.IO): + def __init__(self, output: typing.IO[str]): self._output = output self._use_color = output.isatty() diff --git a/tools/testing/kunit/run_checks.py b/tools/testing/kunit/run_checks.py index 066e6f938f6d..61cece1684df 100755 --- a/tools/testing/kunit/run_checks.py +++ b/tools/testing/kunit/run_checks.py @@ -37,7 +37,7 @@ def main(argv: Sequence[str]) -> None: if argv: raise RuntimeError('This script takes no arguments') - future_to_name: Dict[futures.Future, str] = {} + future_to_name: Dict[futures.Future[None], str] = {} executor = futures.ThreadPoolExecutor(max_workers=len(commands)) for name, argv in commands.items(): if name in necessary_deps and shutil.which(necessary_deps[name]) is None: From patchwork Thu Mar 16 22:06:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 70982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp20835wrt; Thu, 16 Mar 2023 15:09:50 -0700 (PDT) X-Google-Smtp-Source: AK7set/3NJubJ8R167493T8AdI+/RPKaxunj9H/v2SEwfGj1RxTlU8OvTH77bM0SV55ZA+EITDpt X-Received: by 2002:a17:90b:4c10:b0:23f:580d:b252 with SMTP id na16-20020a17090b4c1000b0023f580db252mr53377pjb.36.1679004590473; Thu, 16 Mar 2023 15:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679004590; cv=none; d=google.com; s=arc-20160816; b=DSxiHR7dEE8SjUeW18kUYByby89rNRXw8QPaf9EWzMFr+ZuRchrgOaoHupqCBmfPxj AZ+ZdNj13JVmZkdUy7RS99lmAu4ev8Ha6AfywSgYCEwgrB+YPJVFKjLzNP30SUdUU06p Bj5yEDlpAKY7mpcwckQ3BicT1G6KqFY9iHqWbTMl3vjTQXD1Fa5lIFpsPIn6AuzuYRLu IzsLJUNb5zaU625QZcduA8zQiqDvLKHEocJyXrh2hNtB6dSLZecGnUIAsO1B+KmBphqD H7gCkkuIq37yNKyoyeNl8/5+ID0dai3y7QX0jPtaanWYp/5E9glG5zbtXlYqb6dqupT/ KVOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=nyYEy94Hl6G702MitXTCkJDRHmSWmfCy0+kd4MGWn4Q=; b=TQPohB2rKt36EQwk0+gETd8cuYh31ddQFQrOvia9WM6IsoMLzR0XciKzD8t/sRtuYH CBJhH881jiGPIJUW2qdHDmvAJAzkzCLZ+Uofcv1utYAW2i6fcqkcnF8f/rvIiSsTmQF2 /4/smCGnpp0FI+i0VfCqvg4dFj18AHzqr0dKgA82/SGJJoithvZuXQ6QrtaNGOD35yDW IPd5cGKUuZqxmreMh2NdyhoI7Sdr0uNkNZQ20l2FFKoV7WgAUJmpKp9VIHaUysoRdjJt 8HdNAOVlD1m0F8CE3VF2myi/OFxOc8Kpy9BuiWdB8Yfj9K6rbjc86K+RrBzBiLwMGJe5 n35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EanqDwcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o1-20020a17090a4e8100b00229c28277c6si317150pjh.41.2023.03.16.15.09.05; Thu, 16 Mar 2023 15:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EanqDwcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbjCPWHN (ORCPT + 99 others); Thu, 16 Mar 2023 18:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjCPWHI (ORCPT ); Thu, 16 Mar 2023 18:07:08 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34730898E1 for ; Thu, 16 Mar 2023 15:06:49 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id q24-20020a17090a2e1800b00237c37964d4so3105981pjd.8 for ; Thu, 16 Mar 2023 15:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679004408; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nyYEy94Hl6G702MitXTCkJDRHmSWmfCy0+kd4MGWn4Q=; b=EanqDwcW1c4tC1c4bY046vhovdnIJfuNEJ3wfJIbUWk8ma6m2+lqMH5uF9wsp9B6Wx yg8sw5+/ddXkgh3Nt/ps/jbQt93TX9eXTU0jLxyEtKcSpVbGh+BzbuEEN7CqHJVL3UQh LWP4FyeLmZ6GWVegiqCsRIRSzggUZ6esVvpQyqFLjqpmdmZMM98FUTB1ERXOVP4+GQHK zCaD8Ry6u9/DC352Xq65Zic2iwgqnBaWx3z+76no5G6Pvey+yK6MvFFVcTdjO4lIKxi4 Snts9ss80NB7g4FY83XOcx4tVDjd8OBeTPrRsgZph26Q5RCc0zUzDbKsSRiW8UPM1QYM thzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679004408; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nyYEy94Hl6G702MitXTCkJDRHmSWmfCy0+kd4MGWn4Q=; b=DpTSnANvJ4x29SFq0wrx3uE6zOgJzV0jerP1r3BFtvev3mIwaLYzASeVvzMyzF6Xoc FQxDWOSZgSu6yHl7jrE+wJS0s/Bavwe3+Ix0PLWoyLusgM3tipTSOUi0jo1upjIxmAz2 0rPCsoMXmYwUlH4OgWSgGyYBO2/ZTXNW0xAYdvS2DQvxUzlIDHKzfROdQ9L+XzY6vSs5 D2CmgUgipraO1Iq43Tn6ZIfTGvoXFgMnv+x4m27vVJclAzgJBVUa7YeoL5yXejRmy6Tr bvCcoVJe9tKiwHGlKXEj9btY+kAo4dTvfg6J/gdk/XsAASWUx3wELE4bNdAW/LmQHgwi FzYw== X-Gm-Message-State: AO0yUKXO7a3hLAuCMtiqhIHAFZ0U0KKXY7YFUcuRsnsxk7l1iJIi8Vwk Wv+AB+F3kGgN3yl0VKPXIF9jFpZ9/DNngg== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a05:6a00:cca:b0:626:23a1:7b8a with SMTP id b10-20020a056a000cca00b0062623a17b8amr27092pfv.3.1679004408680; Thu, 16 Mar 2023 15:06:48 -0700 (PDT) Date: Thu, 16 Mar 2023 15:06:37 -0700 In-Reply-To: <20230316220638.983743-1-dlatypov@google.com> Mime-Version: 1.0 References: <20230316220638.983743-1-dlatypov@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230316220638.983743-2-dlatypov@google.com> Subject: [PATCH v2 2/3] kunit: tool: remove unused imports and variables From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: rmoar@google.com, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, johannes@sipsolutions.net, Daniel Latypov X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760563917326216222?= X-GMAIL-MSGID: =?utf-8?q?1760563917326216222?= We don't run a linter regularly over kunit.py code (the default settings on most don't like kernel style, e.g. tabs) so some of these imports didn't get removed when they stopped being used. Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- Note: this is unchanged, just added a 3rd patch to this series. --- tools/testing/kunit/kunit.py | 2 +- tools/testing/kunit/kunit_config.py | 2 +- tools/testing/kunit/kunit_kernel.py | 1 - tools/testing/kunit/kunit_parser.py | 1 - tools/testing/kunit/kunit_tool_test.py | 2 +- 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 741f15420467..52853634ba23 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -123,7 +123,7 @@ def _suites_from_test_list(tests: List[str]) -> List[str]: parts = t.split('.', maxsplit=2) if len(parts) != 2: raise ValueError(f'internal KUnit error, test name should be of the form ".", got "{t}"') - suite, case = parts + suite, _ = parts if not suites or suites[-1] != suite: suites.append(suite) return suites diff --git a/tools/testing/kunit/kunit_config.py b/tools/testing/kunit/kunit_config.py index 48b5f34b2e5d..9f76d7b89617 100644 --- a/tools/testing/kunit/kunit_config.py +++ b/tools/testing/kunit/kunit_config.py @@ -8,7 +8,7 @@ from dataclasses import dataclass import re -from typing import Dict, Iterable, List, Set, Tuple +from typing import Dict, Iterable, List, Tuple CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$' CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$' diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index e6fc8fcb071a..775842b912d8 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -18,7 +18,6 @@ import threading from typing import Iterator, List, Optional, Tuple import kunit_config -from kunit_printer import stdout import qemu_config KCONFIG_PATH = '.config' diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index a225799f6b1b..fbc094f0567e 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -12,7 +12,6 @@ from __future__ import annotations from dataclasses import dataclass import re -import sys import textwrap from enum import Enum, auto diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 0c2190514103..be35999bb84f 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -328,7 +328,7 @@ class KUnitParserTest(unittest.TestCase): def test_parse_subtest_header(self): ktap_log = test_data_path('test_parse_subtest_header.log') with open(ktap_log) as file: - result = kunit_parser.parse_run_tests(file.readlines()) + kunit_parser.parse_run_tests(file.readlines()) self.print_mock.assert_any_call(StrContains('suite (1 subtest)')) def test_show_test_output_on_failure(self): From patchwork Thu Mar 16 22:06:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 70986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp25244wrt; Thu, 16 Mar 2023 15:22:05 -0700 (PDT) X-Google-Smtp-Source: AK7set+GKQpjOqbHeVxciSJ4htq9lWzb1rxQp6HObQidZZmZZXTglFdS0xOoHxTJICsb8ACQgKQC X-Received: by 2002:aa7:9784:0:b0:5a9:c942:7294 with SMTP id o4-20020aa79784000000b005a9c9427294mr4161458pfp.34.1679005324749; Thu, 16 Mar 2023 15:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679005324; cv=none; d=google.com; s=arc-20160816; b=KcqpFnphN9oUyZwlvOYPsLHcjrCXWwD/3D+bvfuZKIELtBxlyjhwlE/q2Nboexl4vr B/7OApukqOdNf4c4EsTK2yOV7jcZPsvcmkVdcUzoNbFoAC0hn8yWGtdtecJ82JkMGo3n T6oU5I5hJF9xa0O73+k8k/+75bZdz8C1pgLNGZObzuL0C41Hr/ixh9WHzhCNVwh5VqS4 eC+ITHGF25V6Skaj8FicRN1JUxUVj6MDbtOZWHC0/GN5wC+AjDEHJcFEUAkJ4QKEcB0p Ve30Rkwa43Daa/wfBJZjt8qKwVioGpzEFUgltkvP/5D+tXBldX0kjy+crq6SNGN9i+oh OUZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=2h1nWW+Tx2qkQciskmHzf90FfoypHRB1YvIyPPSqDIg=; b=DBqgkDvlgU7PiwuFhzWCMxYZ9dNYx0wy19HJRjNAoN5hl0QXNQoEZyNeM8MJClVIWN t0d4F5GFGJXvKpWhriiIDAclTomiiWRZnWI9rnAx9QTy+/tebuS9FFT48vfXDcBf5YCH gwRZYstWcgA9bHoiRYoyHy/6A+1P66mcoyQd6d4/GzTN4VMEVldGkxdFjS03WpGGDDmh g450GkhMW8UddtArM08aP94i0q9pfjt1ECfpyGMYou8kFD4opshUVCdkAcS9xuURyMIg 75VZH4l7QXrQnh9pGajPh9JX78PV+9T22pJAg36eO4lyiXcPb27/tTBF1ZwymmLVZEHX q1Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F17vTJwK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a056a0008cc00b006256e67028dsi655054pfu.122.2023.03.16.15.21.49; Thu, 16 Mar 2023 15:22:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F17vTJwK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjCPWHQ (ORCPT + 99 others); Thu, 16 Mar 2023 18:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230087AbjCPWHJ (ORCPT ); Thu, 16 Mar 2023 18:07:09 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB8184801 for ; Thu, 16 Mar 2023 15:06:51 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54476ef9caeso28898457b3.6 for ; Thu, 16 Mar 2023 15:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679004410; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2h1nWW+Tx2qkQciskmHzf90FfoypHRB1YvIyPPSqDIg=; b=F17vTJwKW0LALuQ1LC/PSKl27Mv2IL7HV/6lO6Mdg4HwdTbjb/jX+HgWcnKAZXcwl3 A6Q6rtWbIgTXqAlgO0ASIynbjWyDoa25FT/LgOIUGQRnbwpuL8VcD1Mexz0XmDTWc/LJ kxQ3NCmuSwJLidyc1HkPwWIxVH3yYy815xFCNcOEV3+M64ZoQ0VywsgXuMsVdoncWo4w runTZCnEH/g+UVbq73zl6sYPsabp4U7Xrpw4ArgCvLv83qu5KO7kKhx9R/IJFPxMfHZL OwovGKq1VldQGDZZ3OvtAtyMcFgKiZ6z6fwMfBzxpW0UWmN+n8vSzbxR2ucRYpkatn3R PVrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679004410; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2h1nWW+Tx2qkQciskmHzf90FfoypHRB1YvIyPPSqDIg=; b=FswPSVRXEUr9X0qBe/h9AYTgwk5YSmhk1OxwViswcU3jaPI5OjjP+IYln3o3SPp7o0 +dZTCmSSn4YgsiK1bMlJ3Rsq6C7xRRPiU2k0chvWZ85b15cMTXyjMGoVAinUDZrr1t8V 0yNszIa7lLWBVh8gC+L/UvkFnYAFxr0XhluYnwwu9omR6E81HSagegD4r7BkKiVxI6dr r2kYsdZh1WuaYhF89ZevL1ZgfkMOYhlVEUQb6ImNdfMvADkeZ496Nz4QToFsQCf0LTDW S328iHKIrl16G/QMCXtSfpdVDGS5uwz+TMore4u8hpW7Ow003kqloKttw0ovoPRA3IUK YECg== X-Gm-Message-State: AO0yUKVJJqWihmJMM1h5P1UZnSusC/OtGvgZG0S1Zh+Yh1AfjoKly4+x K4HiUAN9I+V+mvEELiKA//n2XYWB/EHs5w== X-Received: from dlatypov-spec.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3f35]) (user=dlatypov job=sendgmr) by 2002:a05:6902:1101:b0:b26:d140:5f74 with SMTP id o1-20020a056902110100b00b26d1405f74mr1008741ybu.1.1679004410486; Thu, 16 Mar 2023 15:06:50 -0700 (PDT) Date: Thu, 16 Mar 2023 15:06:38 -0700 In-Reply-To: <20230316220638.983743-1-dlatypov@google.com> Mime-Version: 1.0 References: <20230316220638.983743-1-dlatypov@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230316220638.983743-3-dlatypov@google.com> Subject: [PATCH v2 3/3] kunit: tool: fix pre-existing `mypy --strict` errors and update run_checks.py From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: rmoar@google.com, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, johannes@sipsolutions.net, Daniel Latypov , Johannes Berg X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760564687291560832?= X-GMAIL-MSGID: =?utf-8?q?1760564687291560832?= Basically, get this command to be happy and make run_checks.py happy $ mypy --strict --exclude '_test.py$' --exclude qemu_configs/ ./tools/testing/kunit/ Primarily the changes are * add `-> None` return type annotations * add all the missing argument type annotations Previously, we had false positives from mypy in `main()`, see commit 09641f7c7d8f ("kunit: tool: surface and address more typing issues"). But after commit 2dc9d6ca52a4 ("kunit: kunit.py extract handlers") refactored things, the variable name reuse mypy hated is gone. Note: mypy complains we don't annotate the types the unused args in our signal handler. That's silly. But to make it happy, I've copy-pasted an appropriate annotation from https://github.com/python/typing/discussions/1042#discussioncomment-2013595. Reported-by: Johannes Berg Link: https://lore.kernel.org/linux-kselftest/9a172b50457f4074af41fe1dc8e55dcaf4795d7e.camel@sipsolutions.net/ Signed-off-by: Daniel Latypov Reviewed-by: David Gow --- tools/testing/kunit/kunit.py | 24 ++++++++++++------------ tools/testing/kunit/kunit_config.py | 4 ++-- tools/testing/kunit/kunit_kernel.py | 29 +++++++++++++++-------------- tools/testing/kunit/run_checks.py | 4 ++-- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 52853634ba23..3905c43369c3 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -269,7 +269,7 @@ def massage_argv(argv: Sequence[str]) -> Sequence[str]: def get_default_jobs() -> int: return len(os.sched_getaffinity(0)) -def add_common_opts(parser) -> None: +def add_common_opts(parser: argparse.ArgumentParser) -> None: parser.add_argument('--build_dir', help='As in the make command, it specifies the build ' 'directory.', @@ -320,13 +320,13 @@ def add_common_opts(parser) -> None: help='Additional QEMU arguments, e.g. "-smp 8"', action='append', metavar='') -def add_build_opts(parser) -> None: +def add_build_opts(parser: argparse.ArgumentParser) -> None: parser.add_argument('--jobs', help='As in the make command, "Specifies the number of ' 'jobs (commands) to run simultaneously."', type=int, default=get_default_jobs(), metavar='N') -def add_exec_opts(parser) -> None: +def add_exec_opts(parser: argparse.ArgumentParser) -> None: parser.add_argument('--timeout', help='maximum number of seconds to allow for all tests ' 'to run. This does not include time taken to build the ' @@ -351,7 +351,7 @@ def add_exec_opts(parser) -> None: type=str, choices=['suite', 'test']) -def add_parse_opts(parser) -> None: +def add_parse_opts(parser: argparse.ArgumentParser) -> None: parser.add_argument('--raw_output', help='If set don\'t parse output from kernel. ' 'By default, filters to just KUnit output. Use ' '--raw_output=all to show everything', @@ -386,7 +386,7 @@ def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree extra_qemu_args=qemu_args) -def run_handler(cli_args): +def run_handler(cli_args: argparse.Namespace) -> None: if not os.path.exists(cli_args.build_dir): os.mkdir(cli_args.build_dir) @@ -405,7 +405,7 @@ def run_handler(cli_args): sys.exit(1) -def config_handler(cli_args): +def config_handler(cli_args: argparse.Namespace) -> None: if cli_args.build_dir and ( not os.path.exists(cli_args.build_dir)): os.mkdir(cli_args.build_dir) @@ -421,7 +421,7 @@ def config_handler(cli_args): sys.exit(1) -def build_handler(cli_args): +def build_handler(cli_args: argparse.Namespace) -> None: linux = tree_from_args(cli_args) request = KunitBuildRequest(build_dir=cli_args.build_dir, make_options=cli_args.make_options, @@ -434,7 +434,7 @@ def build_handler(cli_args): sys.exit(1) -def exec_handler(cli_args): +def exec_handler(cli_args: argparse.Namespace) -> None: linux = tree_from_args(cli_args) exec_request = KunitExecRequest(raw_output=cli_args.raw_output, build_dir=cli_args.build_dir, @@ -450,10 +450,10 @@ def exec_handler(cli_args): sys.exit(1) -def parse_handler(cli_args): +def parse_handler(cli_args: argparse.Namespace) -> None: if cli_args.file is None: - sys.stdin.reconfigure(errors='backslashreplace') # pytype: disable=attribute-error - kunit_output = sys.stdin + sys.stdin.reconfigure(errors='backslashreplace') # type: ignore + kunit_output = sys.stdin # type: Iterable[str] else: with open(cli_args.file, 'r', errors='backslashreplace') as f: kunit_output = f.read().splitlines() @@ -475,7 +475,7 @@ subcommand_handlers_map = { } -def main(argv): +def main(argv: Sequence[str]) -> None: parser = argparse.ArgumentParser( description='Helps writing and running KUnit tests.') subparser = parser.add_subparsers(dest='subcommand') diff --git a/tools/testing/kunit/kunit_config.py b/tools/testing/kunit/kunit_config.py index 9f76d7b89617..eb5dd01210b1 100644 --- a/tools/testing/kunit/kunit_config.py +++ b/tools/testing/kunit/kunit_config.py @@ -8,7 +8,7 @@ from dataclasses import dataclass import re -from typing import Dict, Iterable, List, Tuple +from typing import Any, Dict, Iterable, List, Tuple CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$' CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$' @@ -34,7 +34,7 @@ class Kconfig: def __init__(self) -> None: self._entries = {} # type: Dict[str, str] - def __eq__(self, other) -> bool: + def __eq__(self, other: Any) -> bool: if not isinstance(other, self.__class__): return False return self._entries == other._entries diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index 775842b912d8..a3321a991f11 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -16,6 +16,7 @@ import shutil import signal import threading from typing import Iterator, List, Optional, Tuple +from types import FrameType import kunit_config import qemu_config @@ -56,7 +57,7 @@ class LinuxSourceTreeOperations: def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig: return base_kunitconfig - def make_olddefconfig(self, build_dir: str, make_options) -> None: + def make_olddefconfig(self, build_dir: str, make_options: Optional[List[str]]) -> None: command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig'] if self._cross_compile: command += ['CROSS_COMPILE=' + self._cross_compile] @@ -70,7 +71,7 @@ class LinuxSourceTreeOperations: except subprocess.CalledProcessError as e: raise ConfigError(e.output.decode()) - def make(self, jobs, build_dir: str, make_options) -> None: + def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None: command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)] if make_options: command.extend(make_options) @@ -132,7 +133,7 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations): class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations): """An abstraction over command line operations performed on a source tree.""" - def __init__(self, cross_compile=None): + def __init__(self, cross_compile: Optional[str]=None): super().__init__(linux_arch='um', cross_compile=cross_compile) def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig: @@ -215,7 +216,7 @@ def _get_qemu_ops(config_path: str, if not hasattr(config, 'QEMU_ARCH'): raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path) - params: qemu_config.QemuArchParams = config.QEMU_ARCH # type: ignore + params: qemu_config.QemuArchParams = config.QEMU_ARCH if extra_qemu_args: params.extra_qemu_params.extend(extra_qemu_args) return params.linux_arch, LinuxSourceTreeOperationsQemu( @@ -229,10 +230,10 @@ class LinuxSourceTree: build_dir: str, kunitconfig_paths: Optional[List[str]]=None, kconfig_add: Optional[List[str]]=None, - arch=None, - cross_compile=None, - qemu_config_path=None, - extra_qemu_args=None) -> None: + arch: Optional[str]=None, + cross_compile: Optional[str]=None, + qemu_config_path: Optional[str]=None, + extra_qemu_args: Optional[List[str]]=None) -> None: signal.signal(signal.SIGINT, self.signal_handler) if qemu_config_path: self._arch, self._ops = _get_qemu_ops(qemu_config_path, extra_qemu_args, cross_compile) @@ -275,7 +276,7 @@ class LinuxSourceTree: logging.error(message) return False - def build_config(self, build_dir: str, make_options) -> bool: + def build_config(self, build_dir: str, make_options: Optional[List[str]]) -> bool: kconfig_path = get_kconfig_path(build_dir) if build_dir and not os.path.exists(build_dir): os.mkdir(build_dir) @@ -303,7 +304,7 @@ class LinuxSourceTree: old_kconfig = kunit_config.parse_file(old_path) return old_kconfig != self._kconfig - def build_reconfig(self, build_dir: str, make_options) -> bool: + def build_reconfig(self, build_dir: str, make_options: Optional[List[str]]) -> bool: """Creates a new .config if it is not a subset of the .kunitconfig.""" kconfig_path = get_kconfig_path(build_dir) if not os.path.exists(kconfig_path): @@ -319,7 +320,7 @@ class LinuxSourceTree: os.remove(kconfig_path) return self.build_config(build_dir, make_options) - def build_kernel(self, jobs, build_dir: str, make_options) -> bool: + def build_kernel(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> bool: try: self._ops.make_olddefconfig(build_dir, make_options) self._ops.make(jobs, build_dir, make_options) @@ -328,7 +329,7 @@ class LinuxSourceTree: return False return self.validate_config(build_dir) - def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]: + def run_kernel(self, args: Optional[List[str]]=None, build_dir: str='', filter_glob: str='', timeout: Optional[int]=None) -> Iterator[str]: if not args: args = [] if filter_glob: @@ -339,7 +340,7 @@ class LinuxSourceTree: assert process.stdout is not None # tell mypy it's set # Enforce the timeout in a background thread. - def _wait_proc(): + def _wait_proc() -> None: try: process.wait(timeout=timeout) except Exception as e: @@ -365,6 +366,6 @@ class LinuxSourceTree: waiter.join() subprocess.call(['stty', 'sane']) - def signal_handler(self, unused_sig, unused_frame) -> None: + def signal_handler(self, unused_sig: int, unused_frame: Optional[FrameType]) -> None: logging.error('Build interruption occurred. Cleaning console.') subprocess.call(['stty', 'sane']) diff --git a/tools/testing/kunit/run_checks.py b/tools/testing/kunit/run_checks.py index 61cece1684df..8208c3b3135e 100755 --- a/tools/testing/kunit/run_checks.py +++ b/tools/testing/kunit/run_checks.py @@ -23,7 +23,7 @@ commands: Dict[str, Sequence[str]] = { 'kunit_tool_test.py': ['./kunit_tool_test.py'], 'kunit smoke test': ['./kunit.py', 'run', '--kunitconfig=lib/kunit', '--build_dir=kunit_run_checks'], 'pytype': ['/bin/sh', '-c', 'pytype *.py'], - 'mypy': ['/bin/sh', '-c', 'mypy *.py'], + 'mypy': ['mypy', '--strict', '--exclude', '_test.py$', '--exclude', 'qemu_configs/', '.'], } # The user might not have mypy or pytype installed, skip them if so. @@ -73,7 +73,7 @@ def main(argv: Sequence[str]) -> None: sys.exit(1) -def run_cmd(argv: Sequence[str]): +def run_cmd(argv: Sequence[str]) -> None: subprocess.check_output(argv, stderr=subprocess.STDOUT, cwd=ABS_TOOL_PATH, timeout=TIMEOUT)