From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.75 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796173344; b=2d0V37JeGuFLWGQrLyemsyK4jimwLE04ozwO174yyr9AVn8Djd8AxBaswnckLk/hZEQY FAs8ppNKbbWgRrLe39u2KrpqP/QPuENsDSgmTj/6TvIuVEqB1G4YTTRz+WOVCy/FJ4uqL xk+rEZiov0GjGD2y9idxCg7AlCFhUYEqFgdO2fvw7PzPBdX1+j0IjEuOsKYtuLITL5maY SlgRNVr1Nr3GWPpp9hnxFOOOc3Hpni6akznnm03WqL7yXnCk334ep9cr2W5n/A/fMxug8 ccSKHcRO0Brz368hSe+rCjGuVUkFtHALZ/hlEsWsA2qiizIB4dTamb1NODXzBUS0nOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796173344; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=mN0x+m0Tt8UieB+KOBVLna3CzMUmUvPq+IGrG+/W33E=; b=ltS3aX4UiFEa0JWAOnfbIqo6kTiyx3ikLrtHZmSd95a/QZNJkq99faROMMvCgsSM05vt Mj932mXlgQzVYh+7dGHFgm8kimsXM/iydrIrRSrWQoNIQruSbUwfxHl//+J7tUf4jPbLq VQ2y2t0BlVwr7giCspaIOnguL9e/y+V41Kb7NKkuNthL6agpGj4X3RZPRBaW4nZNp0bYi U2gcO2EGAvBzS0bE/0Tn6O5mU5o4i8B5IxbFJBlXHe2fLcK8ykmxWwcshDUC2MqqBEqwW oqEyWYuFT0nShzNqU7odDzknJAwCxNi/nqb6O+eDcx6bzANAuLhD9mj50fVempw5zOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=eAesewiH; arc=none smtp.remote-ip=95.215.58.75 Received: from mta1.migadu.com (out-75.mta1.migadu.com [95.215.58.75]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ED7C606A322 for ; Wed, 2 Dec 2026 01:02:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1ED7C606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=eAesewiH X-Envelope-To: linux-kselftest@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=oc07TCr0G/uzFaRm6tLlw/3wD+D3hBFhBzjL8fXh2qM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796173340; v=1; x=1796778140; b=eAesewiH8tcpEhkY2pM8tVwYV5Nir/D5eSLJewmtfhG7DALr3muDw2mF3LvIqi6JzGF1bU17 1ybfwhZxTdTUKS/0TxQJH8uclD6Lb14hworpi48a3RbJvgXREYdwLZ5erbxeL8da+PtZXbBOFE3 /0XdFsBZATfMvX9twvx0WSrM= X-Envelope-To: linux-kselftest@vger.kernel.org Received: by mta12.migadu.com with ESMTPS id d297886ff144a057; Wed, 02 Dec 2026 01:02:20 +0000 X-Mizu-Trace-ID: d297886ff144a057 X-Migadu-Flow: FLOW_OUT Date: Wed, 2 Dec 2026 09:02:00 +0800 From: Hangbin Liu To: "Jori Koolstra (CIQ)" Cc: Shuah Khan , David Ahern , "David S. Miller" , Ricardo =?iso-8859-1?Q?B=2E_Marli=E8re?= , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] selftests: add option to print the time spent per test Message-ID: References: <20261120-kselftest-run-timer-v2-0-9802690a370b@xs4all.nl> <20261120-kselftest-run-timer-v2-2-9802690a370b@xs4all.nl> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261120-kselftest-run-timer-v2-2-9802690a370b@xs4all.nl> On Fri, Nov 20, 2026 at 06:25:29AM -0500, Jori Koolstra (CIQ) wrote: > There is currently no way to see how long each test took when running > kselftests through run_kselftest.sh. This information is useful for > CI/CD systems. > > Add a -T/--timed option to run_kselftest.sh. When it is set, run_one() > prints a KTAP diagnostic line with the elapsed wall-clock time just > before the result line of each test that is actually run, e.g.: > > # selftests: timers: nanosleep > # time: 12.34s > ok 3 selftests: timers: nanosleep > > Signed-off-by: Jori Koolstra (CIQ) > --- > tools/testing/selftests/kselftest/runner.sh | 20 ++++++++++++++++++++ > tools/testing/selftests/run_kselftest.sh | 8 ++++++++ > 2 files changed, 28 insertions(+) > > diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh > index bbb2e61f323c..e4d05c7bfcd4 100644 > --- a/tools/testing/selftests/kselftest/runner.sh > +++ b/tools/testing/selftests/kselftest/runner.sh > @@ -16,6 +16,7 @@ export timeout_rc=124 > export logfile=/dev/stdout > export per_test_logging= > export per_test_log_dir=/tmp > +export per_test_timing= > export RUN_IN_NETNS= > > # Defaults for "settings" file fields: > @@ -56,6 +57,16 @@ tap_timeout() > fi > } > > +# Print the system uptime in hundredths of a second. > +uptime_cs() > +{ > + local up idle > + > + read up idle < /proc/uptime > + # Prefix the fraction with 1 so that a leading 0 isn't parsed as octal. > + echo $((${up%.*} * 100 + 1${up#*.} - 100)) > +} > + > run_one() > { > DIR="$1" > @@ -140,10 +151,18 @@ run_one() > fi > fi > cd `dirname $TEST` > /dev/null > + if [ -n "$per_test_timing" ]; then > + start=$(uptime_cs) > + fi > (((( tap_timeout "$cmd" 2>&1; echo $? >&3) | > tap_prefix >&4) 3>&1) | > (read xs; exit $xs)) 4>>"$logfile" > rc=$? > + if [ -n "$per_test_timing" ]; then > + elapsed=$(($(uptime_cs) - start)) > + ktap_print_msg "$(printf 'time: %d.%02ds' \ > + $((elapsed / 100)) $((elapsed % 100)))" > + fi Nit: maybe local start/elapsed? The other variables are also not local in this function. So I’ll leave this for Shuah to decide. > case "$rc" in > "$KSFT_PASS") > ktap_test_pass "$TEST_HDR_MSG";; > @@ -170,6 +189,7 @@ in_netns() > source $BASE_DIR/kselftest/runner.sh > logfile=$logfile > kselftest_override_timeout=$kselftest_override_timeout > + per_test_timing=$per_test_timing > run_one $DIR $TEST > EOF > } > diff --git a/tools/testing/selftests/run_kselftest.sh b/tools/testing/selftests/run_kselftest.sh > index e11b0e93ba41..0f2a8c619a9c 100755 > --- a/tools/testing/selftests/run_kselftest.sh > +++ b/tools/testing/selftests/run_kselftest.sh > @@ -32,6 +32,7 @@ Usage: $0 [OPTIONS] > -n | --netns Run each test in namespace > -h | --help Show this usage info > -o | --override-timeout Number of seconds after which we timeout > + -T | --timed Print the time spent on each test > EOF > exit $1 > } > @@ -101,6 +102,13 @@ while true; do > -o | --override-timeout) > kselftest_override_timeout="$2" > shift 2 ;; > + -T | --timed) > + if [ ! -r /proc/uptime ]; then > + echo "Timing tests requires /proc/uptime" >&2 > + exit 1 > + fi > + per_test_timing=1 > + shift ;; > -h | --help) > usage 0 ;; > "") > > -- > 2.56.1 > Others looks good to me. Tested-by: Hangbin Liu Reviewed-by: Hangbin Liu