[tip: timers/core] selftests: timers: nanosleep: Move all single clock tests out of the loop in main()
From: tip-bot2 for Thomas Weißschuh (Schneider Electric)
Date: Tue Aug 11 2026 - 12:39:37 EST
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@xxxxxxxxxxxxx>
AuthorDate: Mon, 03 Aug 2026 12:04:42 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
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@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Acked-by: John Stultz <jstultz@xxxxxxxxxx>
Link: https://patch.msgid.link/20260803-auxclock-nanosleep-prep-v2-11-910cbd485390@xxxxxxxxxxxxx
---
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();
}