From patchwork Thu Nov 30 16:58:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 748860 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="F8OqNkGU" Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE79583 for ; Thu, 30 Nov 2023 08:58:40 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-7b37a2e6314so14069839f.1 for ; Thu, 30 Nov 2023 08:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1701363520; x=1701968320; darn=vger.kernel.org; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=kjfGUOrzOcR4VCFCR9ZAuqiy4DmfY+gNhzhv4Uomr1U=; b=F8OqNkGUafd5FWrSsioFV9IZrJ1u9pnpNnVr4UWnBECGKZ2jP41b9BIVe55bWrAwGn KMSV3xt9y738n3YnEcf2yp0edMKSD2EpxQXMc7+ftAj7H7H6X+zLSLPSG5ZH5VUrqhVm a/unZ30ed5vOGbSO0IXeGe0Gi0vznQZhMWgrw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701363520; x=1701968320; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kjfGUOrzOcR4VCFCR9ZAuqiy4DmfY+gNhzhv4Uomr1U=; b=CFv3/2oJBom6S77XaOHvT+gtpId4rwRrHYp9haaFsJCY5GE1A+D4fwaaexpm2YkHNY q6aVsfL4kTe9F/9Gfn562uLwF2tKjnKXMq9DkjLkHOndkBV4RUwkIJvGIIuWHRudKGty WJhk6/FKJ8hM+8fAeWhgfOQ1tqRFdfqdG4vj25Z+Z/jGVcU9TMF31KCQ5T99QRcKcibI RFSlfsJGGPHyQnj5DQ0la0ZeS9ZG5zNllNUUfFPrKa7G7VcBecDfYGMu9dkG4lcLTS8s DjG3EDk3Kw3upXcT6XCqCEH5KrWQVeUt63IiznhzZl2mniaQjYG3m6SJWWXrvcTqj+mB N+zA== X-Gm-Message-State: AOJu0YyGUumqLxHEkP7zrPVn8ryWsUj8nvX/gfANnvtUjbjTWdBi2kyh H++W934uh5u1wOakGT88hcJBPg== X-Google-Smtp-Source: AGHT+IFSVsGsXT2IkoG9CBP+31+G7sAfiES8qJIDWWX0VAYPQbMR17+QOR56yYT2iZGtf5zDVFwFAw== X-Received: by 2002:a05:6e02:b4a:b0:35c:baec:750c with SMTP id f10-20020a056e020b4a00b0035cbaec750cmr2483295ilu.1.1701363520298; Thu, 30 Nov 2023 08:58:40 -0800 (PST) Received: from [192.168.1.128] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id d15-20020a056e021c4f00b0035c8c6045cfsm213266ilg.72.2023.11.30.08.58.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Nov 2023 08:58:39 -0800 (PST) Message-ID: Date: Thu, 30 Nov 2023 09:58:39 -0700 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Linus Torvalds Cc: Shuah Khan , shuah , Brendan Higgins , David Gow , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org From: Shuah Khan Subject: [GIT PULL] KUnit fixes update for Linux 6.7-rc4 Hi Linus, Please pull the following KUnit fixes update for Linux 6.7-rc4. This KUnit fixes update for Linux 6.7-rc4 consists of three fixes to warnings and run-time test behavior. With these fixes, test suite counter will be reset correctly before running tests, kunit will warn if tests are too slow, and eliminate warning when kfree() as an action. diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit b85ea95d086471afb4ad062012a4d73cd328fa86: Linux 6.7-rc1 (2023-11-12 16:19:07 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux_kselftest-kunit-fixes-6.7-rc4 for you to fetch changes up to 1bddcf77ce6668692fc15e968fd0870d5524d112: kunit: test: Avoid cast warning when adding kfree() as an action (2023-11-14 13:01:57 -0700) ---------------------------------------------------------------- linux_kselftest-kunit-fixes-6.7-rc4 This KUnit fixes update for Linux 6.7-rc4 consists of three fixes to warnings and run-time test behavior. With these fixes, test suite counter will be reset correctly before running tests, kunit will warn if tests are too slow, and eliminate warning when kfree() as an action. ---------------------------------------------------------------- Maxime Ripard (1): kunit: Warn if tests are slow Michal Wajdeczko (1): kunit: Reset suite counter right before running tests Richard Fitzgerald (1): kunit: test: Avoid cast warning when adding kfree() as an action lib/kunit/kunit-test.c | 2 +- lib/kunit/test.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) ---------------------------------------------------------------- diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index 99d2a3a528e1..de2113a58fa0 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -562,7 +562,7 @@ static void kunit_log_test(struct kunit *test) KUNIT_EXPECT_TRUE(test, test->log->append_newlines); full_log = string_stream_get_string(test->log); - kunit_add_action(test, (kunit_action_t *)kfree, full_log); + kunit_add_action(test, kfree_wrapper, full_log); KUNIT_EXPECT_NOT_ERR_OR_NULL(test, strstr(full_log, "put this in log.")); KUNIT_EXPECT_NOT_ERR_OR_NULL(test, diff --git a/lib/kunit/test.c b/lib/kunit/test.c index f2eb71f1a66c..7aceb07a1af9 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -338,6 +338,36 @@ void kunit_init_test(struct kunit *test, const char *name, struct string_stream } EXPORT_SYMBOL_GPL(kunit_init_test); +/* Only warn when a test takes more than twice the threshold */ +#define KUNIT_SPEED_WARNING_MULTIPLIER 2 + +/* Slow tests are defined as taking more than 1s */ +#define KUNIT_SPEED_SLOW_THRESHOLD_S 1 + +#define KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S \ + (KUNIT_SPEED_WARNING_MULTIPLIER * KUNIT_SPEED_SLOW_THRESHOLD_S) + +#define s_to_timespec64(s) ns_to_timespec64((s) * NSEC_PER_SEC) + +static void kunit_run_case_check_speed(struct kunit *test, + struct kunit_case *test_case, + struct timespec64 duration) +{ + struct timespec64 slow_thr = + s_to_timespec64(KUNIT_SPEED_SLOW_WARNING_THRESHOLD_S); + enum kunit_speed speed = test_case->attr.speed; + + if (timespec64_compare(&duration, &slow_thr) < 0) + 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. */ @@ -345,6 +375,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; @@ -356,7 +388,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) @@ -670,6 +708,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_ return 0; } + kunit_suite_counter = 1; + static_branch_inc(&kunit_running); for (i = 0; i < num_suites; i++) { @@ -696,8 +736,6 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites) for (i = 0; i < num_suites; i++) kunit_exit_suite(suites[i]); - - kunit_suite_counter = 1; } EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);