Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3774890rwa; Tue, 23 Aug 2022 09:55:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR5+LL5YSqKIVjV48ODozx/KXV2x/Lb0C8kVbUeMZlHFux2+3lWu34Yg4HotTimUG0fqlk8i X-Received: by 2002:a65:60d5:0:b0:41a:625e:4c44 with SMTP id r21-20020a6560d5000000b0041a625e4c44mr20879941pgv.364.1661273722332; Tue, 23 Aug 2022 09:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661273722; cv=none; d=google.com; s=arc-20160816; b=FXZhWx0EC2qLeeFk+t+NGCrrYcX66RWRFFN7wEFm2H++lEyJ1y/V/rULiJSF/dMMO1 7JNn6Kg0fyRm0mwMRQqGqd7gL5m/abhreUBNfbqCH7VfmdH+Cp125luVioz6kzTuu5wF GO4IjtPOC15Si8pc+N5DBs1Ud1y2OeV8B5JY5WVhzRxjxtMNjhIfIPie8HaWgJmTVhe/ +rLUQTCGtmMtjkdhBR/ChZ//ENmefBOHV6J5P/rTAbZ8dWm5L78wcLQRYeSr1aksgCsU BpYFtnTjYP76hqVIp/Xg05bwSbFjt8Epb8juiMB84/FlVviTAT6WoS9/GApj7I2jXy3y iQSA== 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:dkim-signature; bh=pCH+0+WgsyXCYOEIW3yqb1d5hzYj9lEXIljmIvf1UF4=; b=KmYDdHGleGV5RFWnoheERJHIMHFS63l8nAftJS6ZMXirrrZAC+hjeQN5tKgVhzcAim O2vQkLNymihXI61+uhgRVp1hI0JbeLHd8moyrXRt3vG11EuguK04qR9w4JlLNMbw+l5G ZRdpISXM/f+pY08m+fOnVHd8qmeyoI/BZiacvij0GfXRvQB3kZyeMUkn2anGtrSMGKSh wZBLm3bQM3NIvt/Z5MknyGq4+1jL0GdunD8M2+KlMVRI6XbFhKc6/nyKeOsFklIDvWrm uQlNPpYdp1kR6Tyld4GjbLerILAQA3wA/WjlUZ343uOX115uNbe/vN/4X7IIddEdniWU Lb4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GKnHlley; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63714c000000b003c64eaa98cbsi16386511pgn.58.2022.08.23.09.54.47; Tue, 23 Aug 2022 09:55:22 -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=GKnHlley; 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 S245524AbiHWQro (ORCPT + 99 others); Tue, 23 Aug 2022 12:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344135AbiHWQqu (ORCPT ); Tue, 23 Aug 2022 12:46:50 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47C68C6E9C for ; Tue, 23 Aug 2022 07:25:05 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id c21-20020a17090ae11500b001fab6a5be8aso6239630pjz.7 for ; Tue, 23 Aug 2022 07:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=pCH+0+WgsyXCYOEIW3yqb1d5hzYj9lEXIljmIvf1UF4=; b=GKnHlleymq6aVUseYQkCkYJTcj3+Hllew3xD3cBBcATPMgtQht5r0zd6CNdNPkGZ2E cIuhwPujGAJbEIybRkp5h8BCUG05Ni7Aqy5hlvyeV7ytytijPlGF0ML4yLsdbnxBlT7O v/Q4vYjT27cq8xCAfXaMxibDaCtMD0R+Wg8Xg6fxszjEq+5wNeGHhC8zjOk5uvyfOqWx ekWKec3iTLIBe1ko+sjdYz7CP8xzuVD0fcU/rY0CuNqyMJxQWRUIVOZfQDeldrSLAVCe KMOYtyEW1xBRTqndO+xaq0kjGZY0s5akiv1QJ/rF2MLw2HQZL7Ju5l7pMQIyVe7WlRjl 6/CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=pCH+0+WgsyXCYOEIW3yqb1d5hzYj9lEXIljmIvf1UF4=; b=QKrdtuK41RHW8ob+ZfptvgzD2pYuOYcl/yYoBF2O2nevNcl/HmEtBlRO+v5/s16S5x U1PcrBnQu08ITVtI7nmIhpLAeGyqVSA8JQwrQsSDCo/dxHTkbStkr8gLekHjYQHZldjZ Ah18o+s1BinTR7bhvXVA1dy4sS7l0+zDqe6/MBtKTznfMXQfa3m9E6eZLRj0LFu6gq8K acERWiXiXg/cnrWoz1jkXx4to1qFBtuhQPSnJblrz8DLTYvmg10JZ82d8BNHliD507+h PmBpRNLHRpnmu4HPZCrOShKHwOOX0ko7ncSXTFr89hcYTYkPptjGr524SOzx4+chHjLk +D1w== X-Gm-Message-State: ACgBeo2I8D4oPls08u1m9YzTfgwxj+aN+0kp0nr3id5fy0prBq3jo/F1 eV9l7m7RUW7jGrn3G5L6pmNk5GgWe901YzE= X-Received: from joefradley-custom-96.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:831]) (user=joefradley job=sendgmr) by 2002:aa7:8430:0:b0:536:5173:a2c6 with SMTP id q16-20020aa78430000000b005365173a2c6mr15526807pfn.4.1661264704758; Tue, 23 Aug 2022 07:25:04 -0700 (PDT) Date: Tue, 23 Aug 2022 07:24:54 -0700 In-Reply-To: <20220823142456.3977086-1-joefradley@google.com> Message-Id: <20220823142456.3977086-2-joefradley@google.com> Mime-Version: 1.0 References: <20220823142456.3977086-1-joefradley@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH v2 1/2] kunit: add kunit.enable to enable/disable KUnit test From: Joe Fradley To: Jonathan Corbet , Brendan Higgins , David Gow Cc: Joe Fradley , kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE,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 This patch adds the kunit.enable module parameter that will need to be set to true in addition to KUNIT being enabled for KUnit tests to run. The default value is true giving backwards compatibility. However, for the production+testing use case the new config option KUNIT_DEFAULT_ENABLED can be set to N requiring the tester to opt-in by passing kunit.enable=1 to the kernel. Signed-off-by: Joe Fradley --- Changes since v1: - Created a function to get kunit enable state - Check kunit enable state in kunit_run_all_tests() in executor.c - Load test module even if KUnit is disabled but still don't execute tests - Simplified kunit disable message and kunit.enable parameter description - Flipped around logic of new config to be KUNIT_DEFAULT_ENABLED - kunit_tool.py now passes kunit.enable=1 to kernel .../admin-guide/kernel-parameters.txt | 6 +++++ include/kunit/test.h | 2 ++ lib/kunit/Kconfig | 11 +++++++++ lib/kunit/executor.c | 4 ++++ lib/kunit/test.c | 24 +++++++++++++++++++ tools/testing/kunit/kunit_kernel.py | 1 + 6 files changed, 48 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index adfda56b2691..7aa3abd7f1c5 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2432,6 +2432,12 @@ 0: force disabled 1: force enabled + kunit.enable= [KUNIT] Enable executing KUnit tests. Requires + CONFIG_KUNIT to be set to be fully enabled. The + default value can be overridden via + KUNIT_DEFAULT_ENABLED. + Default is 1 (enabled) + kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs. Default is 0 (don't ignore, but inject #GP) diff --git a/include/kunit/test.h b/include/kunit/test.h index c958855681cc..ee6bf4ecbd89 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -228,6 +228,8 @@ static inline void kunit_set_failure(struct kunit *test) WRITE_ONCE(test->status, KUNIT_FAILURE); } +bool kunit_enabled(void); + void kunit_init_test(struct kunit *test, const char *name, char *log); int kunit_run_tests(struct kunit_suite *suite); diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 0b5dfb001bac..626719b95bad 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -59,4 +59,15 @@ config KUNIT_ALL_TESTS If unsure, say N. +config KUNIT_DEFAULT_ENABLED + bool "Default value of kunit.enable" + default y + help + Sets the default value of kunit.enable. If set to N then KUnit + tests will not execute unless kunit.enable=1 is passed to the + kernel command line. + + In most cases this should be left as Y. Only if additional opt-in + behavior is needed should this be set to N. + endif # KUNIT diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 5e223327196a..9bbc422c284b 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -190,6 +190,10 @@ int kunit_run_all_tests(void) { struct suite_set suite_set = {__kunit_suites_start, __kunit_suites_end}; int err = 0; + if (!kunit_enabled()) { + pr_info("kunit: disabled\n"); + goto out; + } if (filter_glob_param) { suite_set = kunit_filter_suites(&suite_set, filter_glob_param, &err); diff --git a/lib/kunit/test.c b/lib/kunit/test.c index b73d5bb5c473..1e54373309a4 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -54,6 +54,17 @@ void __kunit_fail_current_test(const char *file, int line, const char *fmt, ...) EXPORT_SYMBOL_GPL(__kunit_fail_current_test); #endif +/* + * Enable KUnit tests to run. + */ +#ifdef CONFIG_KUNIT_DEFAULT_ENABLED +static bool enable_param = true; +#else +static bool enable_param; +#endif +module_param_named(enable, enable_param, bool, 0); +MODULE_PARM_DESC(enable, "Enable KUnit tests"); + /* * KUnit statistic mode: * 0 - disabled @@ -586,10 +597,20 @@ static void kunit_init_suite(struct kunit_suite *suite) suite->suite_init_err = 0; } +bool kunit_enabled(void) +{ + return enable_param; +} + int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites) { unsigned int i; + if (!kunit_enabled() && num_suites > 0) { + pr_info("kunit: disabled\n"); + return 0; + } + for (i = 0; i < num_suites; i++) { kunit_init_suite(suites[i]); kunit_run_tests(suites[i]); @@ -607,6 +628,9 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites) { unsigned int i; + if (!kunit_enabled()) + return; + for (i = 0; i < num_suites; i++) kunit_exit_suite(suites[i]); diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index f5c26ea89714..ef794da420d7 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -359,6 +359,7 @@ class LinuxSourceTree: args = [] if filter_glob: args.append('kunit.filter_glob='+filter_glob) + args.append('kunit.enable=1') process = self._ops.start(args, build_dir) assert process.stdout is not None # tell mypy it's set -- 2.37.1.595.g718a3a8f04-goog