[tip: timers/core] selftests: timers: nanosleep: Move all single clock tests out of the loop in main()

tip-bot2 for Thomas Weißschuh (Schneider Electric) posted 1 patch 1 month, 2 weeks ago
tools/testing/selftests/timers/nanosleep.c | 51 +++++++++++----------
1 file changed, 28 insertions(+), 23 deletions(-)
[tip: timers/core] selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
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:     061341a568146000de8d41791bf7612b2f6813b5
Gitweb:        https://git.kernel.org/tip/061341a568146000de8d41791bf7612b2f6813b5
Author:        Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de>
AuthorDate:    Mon, 03 Aug 2026 12:04:42 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 11 Aug 2026 18:11:20 +02:00

selftests: timers: nanosleep: Move all single clock tests out of the loop in main()

Make the code easier to read by avoiding a goto.

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-11-910cbd485390@linutronix.de
---
 tools/testing/selftests/timers/nanosleep.c | 51 +++++++++++----------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 0a2ca17..5037481 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -132,10 +132,35 @@ static int nanosleep_test_remaining(int clockid)
 	return KSFT_PASS;
 }
 
+static void nanosleep_test_clock(clockid_t clockid)
+{
+	long long length = 10;
+	int ret;
+
+	while (length <= (NSEC_PER_SEC * 10)) {
+		ret = nanosleep_test(clockid, length);
+		if (ret == KSFT_SKIP) {
+			ksft_test_result_skip("%s\n", clock_name(clockid));
+			return;
+		}
+		if (ret == KSFT_FAIL) {
+			ksft_test_result_fail("%s\n", clock_name(clockid));
+			ksft_exit_fail();
+		}
+		length *= 100;
+	}
+
+	ret = nanosleep_test_remaining(clockid);
+	if (ret == KSFT_FAIL) {
+		ksft_test_result_fail("%s\n", clock_name(clockid));
+		ksft_exit_fail();
+	}
+	ksft_test_result_pass("%s\n", clock_name(clockid));
+}
+
 int main(int argc, char **argv)
 {
-	long long length;
-	int clockid, ret;
+	int clockid;
 
 	static const clockid_t tested_clocks[] = {
 		CLOCK_REALTIME,
@@ -154,27 +179,7 @@ int main(int argc, char **argv)
 
 		fflush(stdout);
 
-		length = 10;
-		while (length <= (NSEC_PER_SEC * 10)) {
-			ret = nanosleep_test(clockid, length);
-			if (ret == KSFT_SKIP) {
-				ksft_test_result_skip("%s\n", clock_name(clockid));
-				goto next;
-			}
-			if (ret == KSFT_FAIL) {
-				ksft_test_result_fail("%s\n", clock_name(clockid));
-				ksft_exit_fail();
-			}
-			length *= 100;
-		}
-		ret = nanosleep_test_remaining(clockid);
-		if (ret == KSFT_FAIL) {
-			ksft_test_result_fail("%s\n", clock_name(clockid));
-			ksft_exit_fail();
-		}
-		ksft_test_result_pass("%s\n", clock_name(clockid));
-next:
-		ret = 0;
+		nanosleep_test_clock(clockid);
 	}
 	ksft_exit_pass();
 }