Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp692792pxb; Thu, 14 Jan 2021 16:43:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKQYQERzJm0E+5fe1w3u+wkvPH8un3XW02gHo4KqrwHOJNzCWJkbs4aeYwu+8T6osY4P93 X-Received: by 2002:a17:906:4705:: with SMTP id y5mr6938925ejq.112.1610671405483; Thu, 14 Jan 2021 16:43:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610671405; cv=none; d=google.com; s=arc-20160816; b=cEyKQlM7wjZdjTnd/JVlpV+zkX3KY4JmKwJaIWZoTe3sAiT3how41uftxVa9UptyLv aMFFwqXtl0Utewd+LHRWUFQ5f0tGPNrZQi5EEjRevkyQLzOeJmJ5zI0X7q8ModP/u/Bc hSnPswa7EPxjASvx0TH0+zptEzMGw/9PjZpnogowdhk7Z5+Yk3QQVx8t8gQklR67myHN NTyzTyGLlkmKwCq6fN/pTD3rnDsAAkrZ5NQFmbDE5wuL+Hm3wxDdRZWFfw3JGcC8lS8t Vh0My1drRK+GcYYtKPfX3FnuJ20U+EDiXXVSHXCjrM4YrgZVpUJOUPr4/V90M1Bnd5As rtSw== 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=Ei/JpQ2zh7azRbnOU06fASsUDF2UTmFQdjcoGaU2sMU=; b=SpVak8P4/mlm3RruG45pgOuF8xOdXhrl3XSEJQ4lmqI0rMFkyi/9wNO6/GhG40uPOT DaNO2iQDFuV/folTKJtheWGLLjb4K4MwO4d3+n3fCB4qUsVZFDJoT7VbN/Rf6Gx1wXud T2jamqlzLuSXXxKLIwjTKZFK5sEV9iSJqYEndaNcPn/Hu5l2ROSIDdokBLrBjuyh+MS6 LNGXCVB7xq/g50UyuIgQOMFQuNrNt36nIJRcIrR5DzVhxpY6I89Ta7kHb2BhrXjVfeLM LdAvMRHvIiVIzXD8FaTMQgQ4dCtChBO/X/Q0VRr0Jz96pCD0vawqYnvO6O1Kv2f2RLzB 7pwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eVJcbOig; 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 j9si2509422edf.438.2021.01.14.16.43.02; Thu, 14 Jan 2021 16:43:25 -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=eVJcbOig; 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 S1731394AbhAOAkq (ORCPT + 99 others); Thu, 14 Jan 2021 19:40:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbhAOAkq (ORCPT ); Thu, 14 Jan 2021 19:40:46 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50538C0613D6 for ; Thu, 14 Jan 2021 16:39:28 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id o6so4871222pgg.8 for ; Thu, 14 Jan 2021 16:39:28 -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=Ei/JpQ2zh7azRbnOU06fASsUDF2UTmFQdjcoGaU2sMU=; b=eVJcbOigJD+rGFjpOYc53RnYI+X0F7Sn49pZkSmU+vhDXgcXc1Lc4Wt0HEvS1IHkim VZAB1nQQnLfxcPW+vjvSfRw5QPvPJQ0gHD03KD7uGtuE+mbtKXw/BAxhgFT5ftcMTlSH 4jxmhVUYzEO5B3KrxIy+zuW3XCtoSfJsstukj0+w8CkAR4HUuGAIhiQAXON8PCd6gjio LM+HUm4qAyiIbHZ9bAjVrezaRWBf/YUzX38Tfj5C8LCz06/Sl/ynCbd1RpCVgGBQ1pQz 0Fenp07OHLQ7MbziJ4At4CZCMMpLi3JNAheosQkIOFXDmC564ZNCho8/71yHm4+pBZT6 /83g== 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=Ei/JpQ2zh7azRbnOU06fASsUDF2UTmFQdjcoGaU2sMU=; b=aE69qILTCjTI1yq3uxu8am/H70NTeGFc7fsYa/6auAZ+ye8N5lA0xwVVX0TPft7EqT lKKRnPEuoPHoN1Jja/jeI8lQ/erwyYRrSKwmErBpQkIYOQcb0WwhsiosY48yqAoXwaRr VAqlDCln+fLoPSd+DWG0We6cMnerseGPGcXSAPfqm5/j3rodNNMGrPPDg/awXFycgnC/ C8ak9s4oR9G3Z/SWF0cU1yPSFi8uPq2uHyMjk5w5YNFgr7PmpjJGpOOzhtVdRM8ElQBM qFl6wOCo29AAR0vVvlQpXT4X5Swl64amj17Pggk8nlWxpoY+U1jMwrFHBj7HOGaiR679 NXcg== X-Gm-Message-State: AOAM530dzNt8ROejJiX8SDODxVKbbi34yVwfmpuYBrfpeeZdZW+LxIc0 1SWkF/X0Dp4J5HtvdTMypn0U0E0CY7zhcw== 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:a17:902:242:b029:dc:3baf:2033 with SMTP id 60-20020a1709020242b02900dc3baf2033mr10009811plc.36.1610671167710; Thu, 14 Jan 2021 16:39:27 -0800 (PST) Date: Thu, 14 Jan 2021 16:39:13 -0800 In-Reply-To: <20210115003913.1406896-1-dlatypov@google.com> Message-Id: <20210115003913.1406896-3-dlatypov@google.com> Mime-Version: 1.0 References: <20210115003913.1406896-1-dlatypov@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH v4 3/3] kunit: tool: move kunitconfig parsing into __init__, make it optional From: Daniel Latypov To: brendanhiggins@google.com Cc: davidgow@google.com, 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 Reviewed-by: Brendan Higgins --- 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 e77ee06aa407..2076a5a2d060 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.30.0.296.g2bfb1c46d8-goog