All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] selftests: add option to print the time spent per test
@ 2026-11-20 11:25 Jori Koolstra (CIQ)
  2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jori Koolstra (CIQ) @ 2026-11-20 11:25 UTC (permalink / raw)
  To: Shuah Khan, David Ahern, David S. Miller, Hangbin Liu,
	Ricardo B. Marlière
  Cc: linux-kselftest, linux-kernel, Jori Koolstra (CIQ)

For CI/CD purposes it is useful to know how much time each selftest
took to complete, for instance, to know which suites to run for a
quick-fail diagnostic, or what percentage of tests you can expect to
complete on a paricular --override-timeout value.

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

The other patch of runner.sh fixes a bug when using --netns in
run_kselftest.sh.

Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
---
Changes in v2:
- Dropped convention change from the series (as Shuah requested)
- Link to v1: https://lore.kernel.org/r/20261118-kselftest-run-timer-v1-0-53a838b2d62b@xs4all.nl

---
Jori Koolstra (CIQ) (2):
      selftests: pass the timeout override to tests run in a netns
      selftests: add option to print the time spent per test

 tools/testing/selftests/kselftest/runner.sh | 21 +++++++++++++++++++++
 tools/testing/selftests/run_kselftest.sh    |  8 ++++++++
 2 files changed, 29 insertions(+)
---
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
change-id: 20261117-kselftest-run-timer-df3ac531652e

Best regards,
-- 
Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns
  2026-11-20 11:25 [PATCH v2 0/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
@ 2026-11-20 11:25 ` Jori Koolstra (CIQ)
  2026-11-23  6:25   ` Hangbin Liu
  2026-12-02  1:02   ` Hangbin Liu
  2026-11-20 11:25 ` [PATCH v2 2/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
  2026-12-01 22:31 ` [PATCH v2 0/2] " Ricardo B. Marlière
  2 siblings, 2 replies; 7+ messages in thread
From: Jori Koolstra (CIQ) @ 2026-11-20 11:25 UTC (permalink / raw)
  To: Shuah Khan, David Ahern, David S. Miller, Hangbin Liu,
	Ricardo B. Marlière
  Cc: linux-kselftest, linux-kernel, Jori Koolstra (CIQ)

When run_kselftest.sh is invoked with -n, each test is run by in_netns()
in a new bash process, which sources runner.sh again and then calls
run_one(). Sourcing runner.sh resets its global settings, which is why
in_netns() explicitly passes on logfile. kselftest_override_timeout is
not passed on, so -o/--override-timeout is silently ignored for tests
that are run in a network namespace and they use the timeout from their
settings file or the default instead.

Pass kselftest_override_timeout to the netns shell as well.

Fixes: 9d0b4ad82d61 ("kselftest/runner.sh: add netns support")
Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
---
 tools/testing/selftests/kselftest/runner.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 45fb8ec38493..bbb2e61f323c 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -169,6 +169,7 @@ in_netns()
 		BASE_DIR=$BASE_DIR
 		source $BASE_DIR/kselftest/runner.sh
 		logfile=$logfile
+		kselftest_override_timeout=$kselftest_override_timeout
 		run_one $DIR $TEST
 	EOF
 }

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] selftests: add option to print the time spent per test
  2026-11-20 11:25 [PATCH v2 0/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
  2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
@ 2026-11-20 11:25 ` Jori Koolstra (CIQ)
  2026-12-02  1:02   ` Hangbin Liu
  2026-12-01 22:31 ` [PATCH v2 0/2] " Ricardo B. Marlière
  2 siblings, 1 reply; 7+ messages in thread
From: Jori Koolstra (CIQ) @ 2026-11-20 11:25 UTC (permalink / raw)
  To: Shuah Khan, David Ahern, David S. Miller, Hangbin Liu,
	Ricardo B. Marlière
  Cc: linux-kselftest, linux-kernel, Jori Koolstra (CIQ)

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) <jkoolstra@xs4all.nl>
---
 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
 		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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns
  2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
@ 2026-11-23  6:25   ` Hangbin Liu
  2026-12-02  1:02   ` Hangbin Liu
  1 sibling, 0 replies; 7+ messages in thread
From: Hangbin Liu @ 2026-11-23  6:25 UTC (permalink / raw)
  To: Jori Koolstra (CIQ)
  Cc: Shuah Khan, David Ahern, David S. Miller,
	Ricardo B. Marlière, linux-kselftest, linux-kernel

On Fri, Nov 20, 2026 at 06:25:28AM -0500, Jori Koolstra (CIQ) wrote:
> When run_kselftest.sh is invoked with -n, each test is run by in_netns()
> in a new bash process, which sources runner.sh again and then calls
> run_one(). Sourcing runner.sh resets its global settings, which is why
> in_netns() explicitly passes on logfile. kselftest_override_timeout is
> not passed on, so -o/--override-timeout is silently ignored for tests
> that are run in a network namespace and they use the timeout from their
> settings file or the default instead.
> 
> Pass kselftest_override_timeout to the netns shell as well.
> 
> Fixes: 9d0b4ad82d61 ("kselftest/runner.sh: add netns support")
> Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
> ---
>  tools/testing/selftests/kselftest/runner.sh | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
> index 45fb8ec38493..bbb2e61f323c 100644
> --- a/tools/testing/selftests/kselftest/runner.sh
> +++ b/tools/testing/selftests/kselftest/runner.sh
> @@ -169,6 +169,7 @@ in_netns()
>  		BASE_DIR=$BASE_DIR
>  		source $BASE_DIR/kselftest/runner.sh
>  		logfile=$logfile
> +		kselftest_override_timeout=$kselftest_override_timeout
>  		run_one $DIR $TEST
>  	EOF
>  }

Thanks for the fix.

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] selftests: add option to print the time spent per test
  2026-11-20 11:25 [PATCH v2 0/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
  2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
  2026-11-20 11:25 ` [PATCH v2 2/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
@ 2026-12-01 22:31 ` Ricardo B. Marlière
  2 siblings, 0 replies; 7+ messages in thread
From: Ricardo B. Marlière @ 2026-12-01 22:31 UTC (permalink / raw)
  To: Jori Koolstra (CIQ), Shuah Khan, David Ahern, David S. Miller,
	Hangbin Liu, Ricardo B. Marlière
  Cc: linux-kselftest, linux-kernel

On Fri Nov 20, 2026 at 8:25 AM -03, Jori Koolstra (CIQ) wrote:
> For CI/CD purposes it is useful to know how much time each selftest
> took to complete, for instance, to know which suites to run for a
> quick-fail diagnostic, or what percentage of tests you can expect to
> complete on a paricular --override-timeout value.
>
> 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
>
> The other patch of runner.sh fixes a bug when using --netns in
> run_kselftest.sh.
>
> Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
> ---
> Changes in v2:
> - Dropped convention change from the series (as Shuah requested)
> - Link to v1: https://lore.kernel.org/r/20261118-kselftest-run-timer-v1-0-53a838b2d62b@xs4all.nl
>
> ---
> Jori Koolstra (CIQ) (2):
>       selftests: pass the timeout override to tests run in a netns
>       selftests: add option to print the time spent per test
>
>  tools/testing/selftests/kselftest/runner.sh | 21 +++++++++++++++++++++
>  tools/testing/selftests/run_kselftest.sh    |  8 ++++++++
>  2 files changed, 29 insertions(+)

For the series,

Reviewed-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>

Thanks!


> ---
> base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
> change-id: 20261117-kselftest-run-timer-df3ac531652e
>
> Best regards,



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] selftests: add option to print the time spent per test
  2026-11-20 11:25 ` [PATCH v2 2/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
@ 2026-12-02  1:02   ` Hangbin Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Hangbin Liu @ 2026-12-02  1:02 UTC (permalink / raw)
  To: Jori Koolstra (CIQ)
  Cc: Shuah Khan, David Ahern, David S. Miller,
	Ricardo B. Marlière, linux-kselftest, linux-kernel

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) <jkoolstra@xs4all.nl>
> ---
>  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 <liuhangbin@kylinos.cn>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns
  2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
  2026-11-23  6:25   ` Hangbin Liu
@ 2026-12-02  1:02   ` Hangbin Liu
  1 sibling, 0 replies; 7+ messages in thread
From: Hangbin Liu @ 2026-12-02  1:02 UTC (permalink / raw)
  To: Jori Koolstra (CIQ)
  Cc: Shuah Khan, David Ahern, David S. Miller,
	Ricardo B. Marlière, linux-kselftest, linux-kernel

On Fri, Nov 20, 2026 at 06:25:28AM -0500, Jori Koolstra (CIQ) wrote:
> When run_kselftest.sh is invoked with -n, each test is run by in_netns()
> in a new bash process, which sources runner.sh again and then calls
> run_one(). Sourcing runner.sh resets its global settings, which is why
> in_netns() explicitly passes on logfile. kselftest_override_timeout is
> not passed on, so -o/--override-timeout is silently ignored for tests
> that are run in a network namespace and they use the timeout from their
> settings file or the default instead.
> 
> Pass kselftest_override_timeout to the netns shell as well.
> 
> Fixes: 9d0b4ad82d61 ("kselftest/runner.sh: add netns support")
> Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
> ---
>  tools/testing/selftests/kselftest/runner.sh | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
> index 45fb8ec38493..bbb2e61f323c 100644
> --- a/tools/testing/selftests/kselftest/runner.sh
> +++ b/tools/testing/selftests/kselftest/runner.sh
> @@ -169,6 +169,7 @@ in_netns()
>  		BASE_DIR=$BASE_DIR
>  		source $BASE_DIR/kselftest/runner.sh
>  		logfile=$logfile
> +		kselftest_override_timeout=$kselftest_override_timeout
>  		run_one $DIR $TEST
>  	EOF
>  }
> 
> -- 
> 2.56.1
> 

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-02  1:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 11:25 [PATCH v2 0/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
2026-11-20 11:25 ` [PATCH v2 1/2] selftests: pass the timeout override to tests run in a netns Jori Koolstra (CIQ)
2026-11-23  6:25   ` Hangbin Liu
2026-12-02  1:02   ` Hangbin Liu
2026-11-20 11:25 ` [PATCH v2 2/2] selftests: add option to print the time spent per test Jori Koolstra (CIQ)
2026-12-02  1:02   ` Hangbin Liu
2026-12-01 22:31 ` [PATCH v2 0/2] " Ricardo B. Marlière

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.