Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2968633rdb; Mon, 4 Dec 2023 12:33:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnolaIEwMi06yT77UlpbMsKEzXhBW4r7R/L1DiM7LNZyo0M0zFjegQ3OhIU12rgQbcdyJo X-Received: by 2002:a17:903:98c:b0:1d0:7535:8b94 with SMTP id mb12-20020a170903098c00b001d075358b94mr5382483plb.97.1701722027968; Mon, 04 Dec 2023 12:33:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701722027; cv=none; d=google.com; s=arc-20160816; b=BE3SiEjcJXeKIudrCcNWvbZcztMWvKOfKSOrIdoZXU5cCMzKuBQO3CW62t2wc/ae3h g9R1A5NgPny2dlKet1Xt10KTbxOg9fC/LAEdUN1Y3a/LJ/rOpN0mEbVrUcOlw7tjFGOm +zXLxAlMc35N/Jckl/k/eznA7Wn00KB8I61dQgwiADc3cJn43RkHEwSfn1bHANFgiY3P 84d9+c2r4lwxfSF/+T01H8yco7q83ohJ7nKYJMPzMOgkbp2yUVeJ4mX/CXgKJYoFCtIx DH1ptm4gTg2AhCawi35PpAdEUhinTVP8soCqUf+VVTdSwBOAq9AkIeq07IRWDuz0Ag/W EmKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ptw1P7YVRFB2MeX8Ih9itJrcqjaWBrwIrJCmB5GcRoU=; fh=mvRgDJyFfaRPjpBRefox6c3NpXEJuv2+zU5v/xApE0Y=; b=fqFch1Z2GG2hL6aY63Ti/OulpVkLWwe/XaRvbTI8XQiEdnd4RVGOjavoi5HQYqaWvu inTqdDMfyBX0Y/WiuMrX20FyrsipGiM91lV5ZxO3E5JNwLA8LMAg+tqSgOZ6Tbl13Idn l7INKYx9yOlY/j7dwBZLWZvHkkqSKgC116lKCAhXzjPago59Oc/zM3FG2eSzabSWJLbu dJBPxdSIr7ecG0HCmA87Q2tfEHE0XiLF9eCp6Knc5wUpnVWHoouSp4iR7b4C2+U6Yenk x1wP614UL5SJuhTM+AxczMzH4rpfRqXeI2eOZ/3kBOmorPSrwZqM+flTHSRYVrR5Nmky aKZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bRdo68l9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d9-20020a170902728900b001d0be32b0d0si600902pll.352.2023.12.04.12.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:33:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bRdo68l9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 5D3A6805742B; Mon, 4 Dec 2023 12:33:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345626AbjLDUdT (ORCPT + 99 others); Mon, 4 Dec 2023 15:33:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345544AbjLDUdR (ORCPT ); Mon, 4 Dec 2023 15:33:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FD5BD7 for ; Mon, 4 Dec 2023 12:33:24 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2E99C433C8; Mon, 4 Dec 2023 20:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701722003; bh=DmLcVDVMT5DQb4/cnrHAIskw0sq/6uoZsdZgUyZ0CGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRdo68l9MepVTosbqD8pe8I/w3MwY0W5Jn5Rk1xGbcRgwa9KCkfvS7AIvdZa/IWHG MOtMdFnm1qPIOGLx5NaAHbqBlqFxYSz8eA1gLkxuGLEuvN3RwxuxPWpS0l6AXUoV0z cik3+SVtZvniuhVQFsjEkVMiMauNfqdeh5hHwq3weOE56VGcgHVSoiT0VIO7TAP3q0 dttMJMxi3KR70DMw5rypot5esMyYo61l9rpaNYc3IFSgiX5k15iihj1xEkQjyV3ylh BdEyazHEdO23dIZVL2yuJXhQYaxgN4eEm2hxqYxJlPqAP5ulOT62XXuSIaCHyyIYa8 phxIdlyrROMpw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maxime Ripard , David Gow , Shuah Khan , Sasha Levin , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Subject: [PATCH AUTOSEL 6.6 02/32] kunit: Warn if tests are slow Date: Mon, 4 Dec 2023 15:32:22 -0500 Message-ID: <20231204203317.2092321-2-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231204203317.2092321-1-sashal@kernel.org> References: <20231204203317.2092321-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.4 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,T_SCC_BODY_TEXT_LINE 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: 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]); Mon, 04 Dec 2023 12:33:45 -0800 (PST) From: Maxime Ripard [ Upstream commit f8f2847f739dc899d0e563eac01299dadefa64ff ] 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 Reviewed-by: David Gow Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- lib/kunit/test.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 421f139814123..e451cfe6143ec 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -372,6 +372,36 @@ void kunit_init_test(struct kunit *test, const char *name, char *log) } 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. */ @@ -379,6 +409,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 +422,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.42.0