[tip: timers/core] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()

tip-bot2 for Thomas Weißschuh (Schneider Electric) posted 1 patch 1 month, 2 weeks ago
tools/testing/selftests/timers/nsleep-lat.c | 23 +++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
[tip: timers/core] selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()
Posted by tip-bot2 for Thomas Weißschuh (Schneider Electric) 1 month, 2 weeks ago
The following commit has been merged into the timers/core branch of tip:

Commit-ID:     4fa377c19e111c539a530a8200996b911ceff9ff
Gitweb:        https://git.kernel.org/tip/4fa377c19e111c539a530a8200996b911ceff9ff
Author:        Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate:    Mon, 03 Aug 2026 12:04:48 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:21 +02:00

selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime()

Both these functions can fail.

The first calls to those functions are already checked and result in
KSFT_SKIP.

If they start failing afterwards unexpectedly, report a hard error.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-17-910cbd485390@linutronix.de
---
 tools/testing/selftests/timers/nsleep-lat.c | 23 +++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
index 266ca0c..5de0051 100644
--- a/tools/testing/selftests/timers/nsleep-lat.c
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -65,10 +65,16 @@ int nanosleep_lat_test(int clockid, long long ns)
 	count = 10;
 
 	/* First check relative latency */
-	clock_gettime(clockid, &start);
-	for (i = 0; i < count; i++)
-		clock_nanosleep(clockid, 0, &target, NULL);
-	clock_gettime(clockid, &end);
+	if (clock_gettime(clockid, &start))
+		return KSFT_FAIL;
+
+	for (i = 0; i < count; i++) {
+		if (clock_nanosleep(clockid, 0, &target, NULL))
+			return KSFT_FAIL;
+	}
+
+	if (clock_gettime(clockid, &end))
+		return KSFT_FAIL;
 
 	if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
 		ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
@@ -77,10 +83,13 @@ int nanosleep_lat_test(int clockid, long long ns)
 
 	/* Next check absolute latency */
 	for (i = 0; i < count; i++) {
-		clock_gettime(clockid, &start);
+		if (clock_gettime(clockid, &start))
+			return KSFT_FAIL;
 		target = timespec_add(start, ns);
-		clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL);
-		clock_gettime(clockid, &end);
+		if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
+			return KSFT_FAIL;
+		if (clock_gettime(clockid, &end))
+			return KSFT_FAIL;
 		latency += timespec_sub(target, end);
 	}