Message ID | 20230920084903.1522728-1-mripard@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3981491vqi; Wed, 20 Sep 2023 01:56:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlEXI/uz+ZomEZcXeh0uBAYWHuW2puKpEWNw3AH447zKR71cw3V5Apf4Aw3hUPxHfzcGp/ X-Received: by 2002:a05:6a00:1895:b0:68e:2d2d:56c1 with SMTP id x21-20020a056a00189500b0068e2d2d56c1mr2202252pfh.9.1695200211022; Wed, 20 Sep 2023 01:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695200211; cv=none; d=google.com; s=arc-20160816; b=Ta5nErlcCqW8nz+7ogIM656NhmE+PsoBTIzA5OAEK+q2RYYaSq5GFjR/2NBkIxWb7x H+VwrvFotIQO7Gia6dEH58uvSdhMWZKS4PforUDFLgyZQAHZ7cHZDzzuuo8jsxNyv15x VyNE7igpgIAPZ+AJ6/yOODT2gXXY5ClCTO6m7sGIWHxybMX1Vc+IZ2AiWfqFYjJ0xnA5 9HTeBsivijUTnASzR/1u8nTNG18ZZHX54X9QDw8inCCA9tF0d5DCD+zJs5Pmnei3yFtp JbdpDmER538jo5S9vmnqcZqZEHGKIFhwyKJm1wgGo/4Pde5uTN9jHDlgLFlIea/cpGvs XmPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=6f2YjNt/+1rkpt/Lzv2XIvZ8Tczse3fWxIPQKRjUU6g=; fh=TLCuMDloLp2earPKFEtMHjAcQwhiAhbmgvUtXmK/gO0=; b=LGeJotjFvInFaHPTC0BAFxm05j0ZL3qrz3FDRIBg7ztRg8J03j//6yV2NO+4SkLkhv Tc1wlqxQDyTyihAaYvSFM8djHT5iOa8K9ujtFPs7JoBRcUSQXnDB316rbRgpVsARpjwP OV+RKAvUabdE+KkjEcL3T7seKP6ioGf1Ohviv6tIIMO8octQkJ5JVskcUjigxw7AhAVo B3ywYLXDmnjy1+QOqzuzwwtg3fRaCxGHZVyQqBZUBnzZAwVQp4CiaHSVV3PZ1vbR8RIg JFCTt28gwCgYAne3vvZ04nI8eE5xgF7lQdtDoDiTKFxeVE4FvWRIDkD087ZnbXMTShoJ rsRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fFAMTd+2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e20-20020a63d954000000b0056a9544e894si1674114pgj.397.2023.09.20.01.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 01:56:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fFAMTd+2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2431A819AD90; Wed, 20 Sep 2023 01:49:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233597AbjITItP (ORCPT <rfc822;toshivichauhan@gmail.com> + 26 others); Wed, 20 Sep 2023 04:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233125AbjITItO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 20 Sep 2023 04:49:14 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDAA93; Wed, 20 Sep 2023 01:49:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B8FCC433C7; Wed, 20 Sep 2023 08:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695199748; bh=qSsw71s1Fjqhd6GpejqtDVQ+WOuNOzjUTZO9Z7vF7/U=; h=From:To:Cc:Subject:Date:From; b=fFAMTd+2BBf2WY/P+COVYj/C+yt5CW2oUw5+/gHjtBVXIg8DfalWC6QQBjBe0+lzI HCRD/4HKgXi6HHRdTJBRaP3MAtQfvuk4CuqD3kn14luq9yfCUZ219qJyhzlljI5rZ0 8GOsRtOiS4bY3sHoIrlScmuKF1T6NIfYXb/i0b+ci1NyaVrMNe3xaEUKH13jcFMCtE gKwWWwElx1pddNUlBvkKnp7oOVbW9AUj9bTtiYF0FLTQuEVCaPLu/Si1b39j9VM/A9 rGnf/k9CCmLomNoq1h3YsW+zmKbfqgMn2wC3CnTBuBvXwxQ8sRFz1Wt+ImMkHcNRNN Zc5kHJiq44UWQ== From: Maxime Ripard <mripard@kernel.org> To: Brendan Higgins <brendan.higgins@linux.dev>, David Gow <davidgow@google.com> Cc: Maxime Ripard <mripard@kernel.org>, Jani Nikula <jani.nikula@linux.intel.com>, Rae Moar <rmoar@google.com>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] kunit: Warn if tests are slow Date: Wed, 20 Sep 2023 10:49:03 +0200 Message-ID: <20230920084903.1522728-1-mripard@kernel.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 01:49:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776783063226660472 X-GMAIL-MSGID: 1777546256625100721 |
Series |
[v2] kunit: Warn if tests are slow
|
|
Commit Message
Maxime Ripard
Sept. 20, 2023, 8:49 a.m. UTC
Kunit recently gained support to setup attributes, the first one being
the speed of a given test, then allowing to filter out slow tests.
A slow test is defined in the documentation as taking more than one
second. There's an another speed attribute called "super slow" but whose
definition is less clear.
Add support to the test runner to check the test execution time, and
report tests that should be marked as slow but aren't.
Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
To: Brendan Higgins <brendan.higgins@linux.dev>
To: David Gow <davidgow@google.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Rae Moar <rmoar@google.com>
Cc: linux-kselftest@vger.kernel.org
Cc: kunit-dev@googlegroups.com
Cc: linux-kernel@vger.kernel.org
Changes from v1:
- Split the patch out of the series
- Change to trigger the warning only if the runtime is twice the
threshold (Jani, Rae)
- Split the speed check into a separate function (Rae)
- Link: https://lore.kernel.org/all/20230911-kms-slow-tests-v1-0-d3800a69a1a1@kernel.org/
---
lib/kunit/test.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
Comments
On Wed, Sep 20, 2023 at 10:49:03AM +0200, Maxime Ripard wrote: > Kunit recently gained support to setup attributes, the first one being > the speed of a given test, then allowing to filter out slow tests. > > A slow test is defined in the documentation as taking more than one > second. There's an another speed attribute called "super slow" but whose > definition is less clear. > > Add support to the test runner to check the test execution time, and > report tests that should be marked as slow but aren't. > > Signed-off-by: Maxime Ripard <mripard@kernel.org> Ping? Thanks! Maxime
On Wed, Sep 20, 2023 at 4:49 AM Maxime Ripard <mripard@kernel.org> wrote: > > Kunit recently gained support to setup attributes, the first one being > the speed of a given test, then allowing to filter out slow tests. > > A slow test is defined in the documentation as taking more than one > second. There's an another speed attribute called "super slow" but whose > definition is less clear. > > Add support to the test runner to check the test execution time, and > report tests that should be marked as slow but aren't. > > Signed-off-by: Maxime Ripard <mripard@kernel.org> > Hello! Thanks for following up! Sorry for the delay in this response. This looks great to me. I do have one comment below regarding the KUNIT_SPEED_SLOW_THRESHOLD_S macro but other than that I would be happy with this patch. This patch does bring up the question of how to handle KUnit warnings as mentioned before. But I am happy to approach that in a future patch. And I do still have concerns with this being annoying for those on slower architectures but again that would depend on how we deal with KUnit warnings. Thanks! -Rae > --- > > To: Brendan Higgins <brendan.higgins@linux.dev> > To: David Gow <davidgow@google.com> > Cc: Jani Nikula <jani.nikula@linux.intel.com> > Cc: Rae Moar <rmoar@google.com> > Cc: linux-kselftest@vger.kernel.org > Cc: kunit-dev@googlegroups.com > Cc: linux-kernel@vger.kernel.org > > Changes from v1: > - Split the patch out of the series > - Change to trigger the warning only if the runtime is twice the > threshold (Jani, Rae) > - Split the speed check into a separate function (Rae) > - Link: https://lore.kernel.org/all/20230911-kms-slow-tests-v1-0-d3800a69a1a1@kernel.org/ > --- > lib/kunit/test.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 49698a168437..a1d5dd2bf87d 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -372,6 +372,25 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) > } > EXPORT_SYMBOL_GPL(kunit_init_test); > > +#define KUNIT_SPEED_SLOW_THRESHOLD_S 1 > + > +static void kunit_run_case_check_speed(struct kunit *test, > + struct kunit_case *test_case, > + struct timespec64 duration) > +{ > + enum kunit_speed speed = test_case->attr.speed; > + > + if (duration.tv_sec < (2 * KUNIT_SPEED_SLOW_THRESHOLD_S)) I think I would prefer that KUNIT_SPEED_SLOW_THRESHOLD_S is instead set to 2 rather than using 2 as the multiplier. I realize the actual threshold for the attributes is 1 sec but for the practical use of this warning it is 2 sec. Also I would still be open to this being 1 sec depending on others opinions. David, what are your thoughts on this? > + return; > + > + if (speed == KUNIT_SPEED_VERY_SLOW || speed == KUNIT_SPEED_SLOW) > + return; > + > + kunit_warn(test, > + "Test should be marked slow (runtime: %lld.%09lds)", > + duration.tv_sec, duration.tv_nsec); > +} > + > /* > * Initializes and runs test case. Does not clean up or do post validations. > */ > @@ -379,6 +398,8 @@ static void kunit_run_case_internal(struct kunit *test, > struct kunit_suite *suite, > struct kunit_case *test_case) > { > + struct timespec64 start, end; > + > if (suite->init) { > int ret; > > @@ -390,7 +411,13 @@ static void kunit_run_case_internal(struct kunit *test, > } > } > > + ktime_get_ts64(&start); > + > test_case->run_case(test); > + > + ktime_get_ts64(&end); > + > + kunit_run_case_check_speed(test, test_case, timespec64_sub(end, start)); > } > > static void kunit_case_internal_cleanup(struct kunit *test) > -- > 2.41.0 >
Hi Rae, On Tue, Oct 24, 2023 at 03:41:33PM -0400, Rae Moar wrote: > On Wed, Sep 20, 2023 at 4:49 AM Maxime Ripard <mripard@kernel.org> wrote: > > > > Kunit recently gained support to setup attributes, the first one being > > the speed of a given test, then allowing to filter out slow tests. > > > > A slow test is defined in the documentation as taking more than one > > second. There's an another speed attribute called "super slow" but whose > > definition is less clear. > > > > Add support to the test runner to check the test execution time, and > > report tests that should be marked as slow but aren't. > > > > Signed-off-by: Maxime Ripard <mripard@kernel.org> > > > > Hello! > > Thanks for following up! Sorry for the delay in this response. np, I kind of forgot about it too to be fair :) > This looks great to me. I do have one comment below regarding the > KUNIT_SPEED_SLOW_THRESHOLD_S macro but other than that I would be > happy with this patch. > > This patch does bring up the question of how to handle KUnit warnings > as mentioned before. But I am happy to approach that in a future > patch. > > And I do still have concerns with this being annoying for those on > slower architectures but again that would depend on how we deal with > KUnit warnings. Yeah, I agree there > > To: Brendan Higgins <brendan.higgins@linux.dev> > > To: David Gow <davidgow@google.com> > > Cc: Jani Nikula <jani.nikula@linux.intel.com> > > Cc: Rae Moar <rmoar@google.com> > > Cc: linux-kselftest@vger.kernel.org > > Cc: kunit-dev@googlegroups.com > > Cc: linux-kernel@vger.kernel.org > > > > Changes from v1: > > - Split the patch out of the series > > - Change to trigger the warning only if the runtime is twice the > > threshold (Jani, Rae) > > - Split the speed check into a separate function (Rae) > > - Link: https://lore.kernel.org/all/20230911-kms-slow-tests-v1-0-d3800a69a1a1@kernel.org/ > > --- > > lib/kunit/test.c | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > > index 49698a168437..a1d5dd2bf87d 100644 > > --- a/lib/kunit/test.c > > +++ b/lib/kunit/test.c > > @@ -372,6 +372,25 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) > > } > > EXPORT_SYMBOL_GPL(kunit_init_test); > > > > +#define KUNIT_SPEED_SLOW_THRESHOLD_S 1 > > + > > +static void kunit_run_case_check_speed(struct kunit *test, > > + struct kunit_case *test_case, > > + struct timespec64 duration) > > +{ > > + enum kunit_speed speed = test_case->attr.speed; > > + > > + if (duration.tv_sec < (2 * KUNIT_SPEED_SLOW_THRESHOLD_S)) > > I think I would prefer that KUNIT_SPEED_SLOW_THRESHOLD_S is instead > set to 2 rather than using 2 as the multiplier. I realize the actual > threshold for the attributes is 1 sec but for the practical use of > this warning it is 2 sec. Right. So I kind of disagree here. To me, the define should match the definition we have for a slow test. We chose to report it only if it exceeds it by a margin, but that's a separate thing from the actual threshold. I guess I could add a new version to make that distinction clearer. Would that work for you? Maxime
On Wed, 20 Sept 2023 at 16:49, Maxime Ripard <mripard@kernel.org> wrote: > > Kunit recently gained support to setup attributes, the first one being > the speed of a given test, then allowing to filter out slow tests. > > A slow test is defined in the documentation as taking more than one > second. There's an another speed attribute called "super slow" but whose > definition is less clear. > > Add support to the test runner to check the test execution time, and > report tests that should be marked as slow but aren't. > > Signed-off-by: Maxime Ripard <mripard@kernel.org> > > --- > > To: Brendan Higgins <brendan.higgins@linux.dev> > To: David Gow <davidgow@google.com> > Cc: Jani Nikula <jani.nikula@linux.intel.com> > Cc: Rae Moar <rmoar@google.com> > Cc: linux-kselftest@vger.kernel.org > Cc: kunit-dev@googlegroups.com > Cc: linux-kernel@vger.kernel.org > > Changes from v1: > - Split the patch out of the series > - Change to trigger the warning only if the runtime is twice the > threshold (Jani, Rae) > - Split the speed check into a separate function (Rae) > - Link: https://lore.kernel.org/all/20230911-kms-slow-tests-v1-0-d3800a69a1a1@kernel.org/ > --- I quite like this, though agree somewhat with Rae's comments below. I personally think the time thresholds are, by necessity, very 'fuzzy', due to the varying speeds of different hardware. Fortunately, the actual runtime of tests seems pretty well stratified, so the exact threshold doesn't really matter much. I ran some tests here, and all of the tests currently not marked slow take <1s on every machine I tried (including the ancient 66MHz 486), except for the drm_mm_* ones (which takes ~6s on my laptop, and times out after 15 minutes on the aforementioned 486). Both the 1s and 2s timeouts successfully distinguish those cases. Ideally, I think we'd have something like: #define KUNIT_SPEED_SLOW_THRESHOLD_S 1 /* 1 sec threshold for 'slow' tests */ #define KUNIT_SPEED_WARNING_MULTIPLIER 2 /* Warn when a test takes > twice the threshold. */ #define KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S (KUNIT_SPEED_WARNING_MULTIPLIER * KUNIT_SPEED_SLOW_THRESHOLD_S) Which is perhaps excessively verbose, but is very clear as to what we're doing. It also gives more scope to allow the ratio to be configured for people with very slow / fast machines in the future. Thoughts? Otherwise, this looks good to me. Reviewed-by: David Gow <davidgow@google.com> Cheers, -- David > lib/kunit/test.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 49698a168437..a1d5dd2bf87d 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -372,6 +372,25 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) > } > EXPORT_SYMBOL_GPL(kunit_init_test); > > +#define KUNIT_SPEED_SLOW_THRESHOLD_S 1 > + > +static void kunit_run_case_check_speed(struct kunit *test, > + struct kunit_case *test_case, > + struct timespec64 duration) > +{ > + enum kunit_speed speed = test_case->attr.speed; > + > + if (duration.tv_sec < (2 * KUNIT_SPEED_SLOW_THRESHOLD_S)) > + return; > + > + if (speed == KUNIT_SPEED_VERY_SLOW || speed == KUNIT_SPEED_SLOW) > + return; > + > + kunit_warn(test, > + "Test should be marked slow (runtime: %lld.%09lds)", > + duration.tv_sec, duration.tv_nsec); > +} > + > /* > * Initializes and runs test case. Does not clean up or do post validations. > */ > @@ -379,6 +398,8 @@ static void kunit_run_case_internal(struct kunit *test, > struct kunit_suite *suite, > struct kunit_case *test_case) > { > + struct timespec64 start, end; > + > if (suite->init) { > int ret; > > @@ -390,7 +411,13 @@ static void kunit_run_case_internal(struct kunit *test, > } > } > > + ktime_get_ts64(&start); > + > test_case->run_case(test); > + > + ktime_get_ts64(&end); > + > + kunit_run_case_check_speed(test, test_case, timespec64_sub(end, start)); > } > > static void kunit_case_internal_cleanup(struct kunit *test) > -- > 2.41.0 >
Hi, On Thu, Oct 26, 2023 at 03:06:39PM +0800, David Gow wrote: > On Wed, 20 Sept 2023 at 16:49, Maxime Ripard <mripard@kernel.org> wrote: > > > > Kunit recently gained support to setup attributes, the first one being > > the speed of a given test, then allowing to filter out slow tests. > > > > A slow test is defined in the documentation as taking more than one > > second. There's an another speed attribute called "super slow" but whose > > definition is less clear. > > > > Add support to the test runner to check the test execution time, and > > report tests that should be marked as slow but aren't. > > > > Signed-off-by: Maxime Ripard <mripard@kernel.org> > > > > --- > > > > To: Brendan Higgins <brendan.higgins@linux.dev> > > To: David Gow <davidgow@google.com> > > Cc: Jani Nikula <jani.nikula@linux.intel.com> > > Cc: Rae Moar <rmoar@google.com> > > Cc: linux-kselftest@vger.kernel.org > > Cc: kunit-dev@googlegroups.com > > Cc: linux-kernel@vger.kernel.org > > > > Changes from v1: > > - Split the patch out of the series > > - Change to trigger the warning only if the runtime is twice the > > threshold (Jani, Rae) > > - Split the speed check into a separate function (Rae) > > - Link: https://lore.kernel.org/all/20230911-kms-slow-tests-v1-0-d3800a69a1a1@kernel.org/ > > --- > > I quite like this, though agree somewhat with Rae's comments below. > > I personally think the time thresholds are, by necessity, very > 'fuzzy', due to the varying speeds of different hardware. Fortunately, > the actual runtime of tests seems pretty well stratified, so the exact > threshold doesn't really matter much. > > I ran some tests here, and all of the tests currently not marked slow > take <1s on every machine I tried (including the ancient 66MHz 486), > except for the drm_mm_* ones (which takes ~6s on my laptop, and times > out after 15 minutes on the aforementioned 486). Both the 1s and 2s > timeouts successfully distinguish those cases. I had a similar experience running the tests in qemu on a Pi4, which is probably the slowest machine we can reasonably expect. > Ideally, I think we'd have something like: > #define KUNIT_SPEED_SLOW_THRESHOLD_S 1 /* 1 sec threshold for 'slow' tests */ > #define KUNIT_SPEED_WARNING_MULTIPLIER 2 /* Warn when a test takes > > twice the threshold. */ > #define KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S > (KUNIT_SPEED_WARNING_MULTIPLIER * KUNIT_SPEED_SLOW_THRESHOLD_S) > > Which is perhaps excessively verbose, but is very clear as to what > we're doing. It also gives more scope to allow the ratio to be > configured for people with very slow / fast machines in the future. > > Thoughts? That looks like a good compromise to me, I'll send another version :) Thanks! Maxime
diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 49698a168437..a1d5dd2bf87d 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -372,6 +372,25 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) } EXPORT_SYMBOL_GPL(kunit_init_test); +#define KUNIT_SPEED_SLOW_THRESHOLD_S 1 + +static void kunit_run_case_check_speed(struct kunit *test, + struct kunit_case *test_case, + struct timespec64 duration) +{ + enum kunit_speed speed = test_case->attr.speed; + + if (duration.tv_sec < (2 * KUNIT_SPEED_SLOW_THRESHOLD_S)) + return; + + if (speed == KUNIT_SPEED_VERY_SLOW || speed == KUNIT_SPEED_SLOW) + return; + + kunit_warn(test, + "Test should be marked slow (runtime: %lld.%09lds)", + duration.tv_sec, duration.tv_nsec); +} + /* * Initializes and runs test case. Does not clean up or do post validations. */ @@ -379,6 +398,8 @@ static void kunit_run_case_internal(struct kunit *test, struct kunit_suite *suite, struct kunit_case *test_case) { + struct timespec64 start, end; + if (suite->init) { int ret; @@ -390,7 +411,13 @@ static void kunit_run_case_internal(struct kunit *test, } } + ktime_get_ts64(&start); + test_case->run_case(test); + + ktime_get_ts64(&end); + + kunit_run_case_check_speed(test, test_case, timespec64_sub(end, start)); } static void kunit_case_internal_cleanup(struct kunit *test)