Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp685407pxu; Thu, 7 Jan 2021 15:51:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSgmkf53dsnwJnlvmC+Xl8tOa6zrtCKg/CjjwKJD6iTbqPpf4TSYIFfhfhSifD4fOxmYjU X-Received: by 2002:a05:6402:1714:: with SMTP id y20mr3342387edu.2.1610063514534; Thu, 07 Jan 2021 15:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610063514; cv=none; d=google.com; s=arc-20160816; b=yAKIxPu/rnWNXBbwfXkpBY5WE1FhX+k1R23GZUJ7kEAiPzwgEcjbYxy7ItcyFT7OYG 4uYa/nJYYBn53enL3BOnliLTvnH8p26BLrDfRHnqpHxoJkRHposjeqvC/vIe1rzBmw/i ebGS1s6iTAG53a6hlxkbD5nKDBR8bG9lx2EHV4IaANMZQj3gLvs8zSqo/C41aWAILdRr jRpMXMAbUlOeWXTq1Wul8e5MBMvzUy0qjPGStSztQpaKBczotOQ/Yi+QdDJxIglhf3l/ yAFoaCPvi+JLVRDrLta4EAVIEuhZMuWL7Af/PJbeVMkYe53jOC+NTbHinLtIxf3kn/1V 3qlw== 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:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=C2n9JJbC3ufm/Maczydpg97ffZDIcqZmHWyAwbR/1R0=; b=ZU6YwZinMbzZQrxJSRiIme7HjhWUJWUM1ejGHkn3FTGO5Q7MOgw8KYdQwPtU2JFxQC tqld0M50lVfEJhOh5htFvcIBYNkuG/lHTPWP76tWy/lbzIK6PJ3AtM5yh1cUPHE5I8Jz a1iQXLUt9e3wDaB+R2MTydcTMGAMjGxTw4p52bqDmH98jC2f9BYy9lkAmJ3LTSI7YCsd DUrbdIGISCPa4C2TLOUURybGKMV890ZicnkHjgr4Cxrp2MSVpG/2o7hMSCNOY6DbcKeC SnrZ7LnyiDmdgtcCoWL79L1YoCaHhomHElghXuNVxBNeXm9FshX6nWzjzpcxv4C4vSyo WIcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RZeR3Ifg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp1si2820418ejc.21.2021.01.07.15.51.29; Thu, 07 Jan 2021 15:51:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RZeR3Ifg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729287AbhAGXtN (ORCPT + 99 others); Thu, 7 Jan 2021 18:49:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727858AbhAGXtM (ORCPT ); Thu, 7 Jan 2021 18:49:12 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0185BC0612F9 for ; Thu, 7 Jan 2021 15:48:32 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id o9so13137294yba.4 for ; Thu, 07 Jan 2021 15:48:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=C2n9JJbC3ufm/Maczydpg97ffZDIcqZmHWyAwbR/1R0=; b=RZeR3IfgJjKaONVYgI0IjUEmCZBHCDg3yn2grnOvoSINeJwCSZ1V4YI086yiuhVCwm cEE3eeXyVDvy+ndldMdYRlnyeg9QrRLI0YEXpDHBC4Pik0hE62Z8tPVB7VPrz0AQjzQh sLc1zfW4oetGssNI2PloZytlnTh7q9JFBcg2BCAjh5c8NxlJq7M4pJm/z8rzYK5JXP4L h0GUUJ1VSSfSR/iiaDUsTsPa8u4K9dl5coHavWvUlBjyEV4TqVGGx8w2hG8Sy1Z3BPcM U9V1oQ3VP3vADaPrjEgX1YzUCe6K+VyrwPrY/bCXQsrIUYe1wNqnFg7O+VS3kmYg94OI ii7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=C2n9JJbC3ufm/Maczydpg97ffZDIcqZmHWyAwbR/1R0=; b=rFVhIoyJtYjvFgUlSj+/KS9mSGXxr+pI8jxpnOs7+Mo4qBAZ7KwwDyMby3TuAvca4H 5U2x0GnStTkKRA+jepj32574a+7Eb1EvdJr+rUHLOwadoEqYr3xqqCMSme33ZTulX/KJ /awJn4fqxFIe6QF+0popLfck8Ee3tOBaEKvK3XTVhoL/qBU7a7cHR0kq1zOSE+P0j/yX NOmH29l4WIE2/Jb6mnxsOFxoi9G95lirAvAfXH0AhtuNBTTpoOt5pGFkQL3ugq9KLJH3 X4uJX2O+12YyhiWZGIqznUsMka9RVNM9ekvPYdVgdB5TTyH4PFIH5iX9h7ZFEAfAFH1t HWog== X-Gm-Message-State: AOAM5321RaIMVUSWF7mBy1dlKeuQkQ7ilne9dtMeQ3e6OOzTU9kddApk oBhMILeB2za2yMhxAKOqx9ZEtV/2+HtxCw== Sender: "dlatypov via sendgmr" X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:a28c:fdff:fee3:28c6]) (user=dlatypov job=sendgmr) by 2002:a5b:990:: with SMTP id c16mr1756491ybq.381.1610063311223; Thu, 07 Jan 2021 15:48:31 -0800 (PST) Date: Thu, 7 Jan 2021 15:48:03 -0800 In-Reply-To: <20210107234803.1096592-1-dlatypov@google.com> Message-Id: <20210107234803.1096592-3-dlatypov@google.com> Mime-Version: 1.0 References: <20210107234803.1096592-1-dlatypov@google.com> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH v3 3/3] kunit: tool: move kunitconfig parsing into __init__, make it optional From: Daniel Latypov To: davidgow@google.com, brendanhiggins@google.com Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LinuxSourceTree will unceremoniously crash if the user doesn't call read_kunitconfig() first in a number of functions. And currently every place we create an instance, the caller also calls create_kunitconfig() and read_kunitconfig(). Move these instead into __init__() so they can't be forgotten and to reduce copy-paste. The https://github.com/google/pytype type-checker complained that _config wasn't initialized. With this, kunit_tool now type checks under both pytype and mypy. Add an optional boolean that can be used to disable this for use cases in the future where we might not need/want to load the config. Signed-off-by: Daniel Latypov --- tools/testing/kunit/kunit.py | 20 ++++---------------- tools/testing/kunit/kunit_kernel.py | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 5521e0a8201e..e808a47c839b 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -256,10 +256,7 @@ def main(argv, linux=None): os.mkdir(cli_args.build_dir) if not linux: - linux = kunit_kernel.LinuxSourceTree() - - linux.create_kunitconfig(cli_args.build_dir) - linux.read_kunitconfig(cli_args.build_dir) + linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir) request = KunitRequest(cli_args.raw_output, cli_args.timeout, @@ -277,10 +274,7 @@ def main(argv, linux=None): os.mkdir(cli_args.build_dir) if not linux: - linux = kunit_kernel.LinuxSourceTree() - - linux.create_kunitconfig(cli_args.build_dir) - linux.read_kunitconfig(cli_args.build_dir) + linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir) request = KunitConfigRequest(cli_args.build_dir, cli_args.make_options) @@ -292,10 +286,7 @@ def main(argv, linux=None): sys.exit(1) elif cli_args.subcommand == 'build': if not linux: - linux = kunit_kernel.LinuxSourceTree() - - linux.create_kunitconfig(cli_args.build_dir) - linux.read_kunitconfig(cli_args.build_dir) + linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir) request = KunitBuildRequest(cli_args.jobs, cli_args.build_dir, @@ -309,10 +300,7 @@ def main(argv, linux=None): sys.exit(1) elif cli_args.subcommand == 'exec': if not linux: - linux = kunit_kernel.LinuxSourceTree() - - linux.create_kunitconfig(cli_args.build_dir) - linux.read_kunitconfig(cli_args.build_dir) + linux = kunit_kernel.LinuxSourceTree(cli_args.build_dir) exec_request = KunitExecRequest(cli_args.timeout, cli_args.build_dir, diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index db7ed84ea410..bf7a784ac6eb 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -123,28 +123,29 @@ def get_outfile_path(build_dir) -> str: class LinuxSourceTree(object): """Represents a Linux kernel source tree with KUnit tests.""" - def __init__(self) -> None: - self._ops = LinuxSourceTreeOperations() + def __init__(self, build_dir: str, load_config=True, defconfig=DEFAULT_KUNITCONFIG_PATH) -> None: signal.signal(signal.SIGINT, self.signal_handler) - def clean(self) -> bool: - try: - self._ops.make_mrproper() - except ConfigError as e: - logging.error(e) - return False - return True + self._ops = LinuxSourceTreeOperations() + + if not load_config: + return - def create_kunitconfig(self, build_dir, defconfig=DEFAULT_KUNITCONFIG_PATH) -> None: kunitconfig_path = get_kunitconfig_path(build_dir) if not os.path.exists(kunitconfig_path): shutil.copyfile(defconfig, kunitconfig_path) - def read_kunitconfig(self, build_dir) -> None: - kunitconfig_path = get_kunitconfig_path(build_dir) self._kconfig = kunit_config.Kconfig() self._kconfig.read_from_file(kunitconfig_path) + def clean(self) -> bool: + try: + self._ops.make_mrproper() + except ConfigError as e: + logging.error(e) + return False + return True + def validate_config(self, build_dir) -> bool: kconfig_path = get_kconfig_path(build_dir) validated_kconfig = kunit_config.Kconfig() -- 2.29.2.729.g45daf8777d-goog