Skip to contentSkip to conversation

selftests: timers: Make sleep time in raw_skew configurable

PATCH Superseded Wake Liu 2 participants 6 messages Jul 10 – Jul 24

Subsystems (3)
lore
Share & tools
lore

Wake Liu

author
#0 lore raw

PATCH 1/1 selftests: timers: Make sleep time in raw_skew configurable

The raw_skew test currently sleeps for 120 seconds to estimate clock drift. This is a very long time for a single test, and can cause timeouts in automated test suites or CI systems.

Allow overriding the sleep time via a command line argument, so it can be adjusted if needed in different environments, while keeping the default at 120 seconds to preserve original behavior.

---
 tools/testing/selftests/timers/raw_skew.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +11 -2
index a7bae7d80916..03cdcecba8f4 100644
@@ -92,6 +92,15 @@ int main(int argc, char **argv)
 	struct timespec mon, raw, start, end;
 	long long delta1, delta2, interval, eppm, ppm;
 	struct timex tx1, tx2;
+	int sleep_sec = 120;
+
+	if (argc > 1) {
+		sleep_sec = atoi(argv[1]);
+		if (sleep_sec <= 0) {
+			printf("Invalid sleep time, using default 120s\n");
+			sleep_sec = 120;
+		}
+	}
 
 	setbuf(stdout, NULL);
 
@@ -109,9 +118,9 @@ int main(int argc, char **argv)
 	if (tx1.offset)
 		printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");
 
-	printf("Estimating clock drift: ");
+	printf("Estimating clock drift (%ds): ", sleep_sec);
 	fflush(stdout);
-	sleep(120);
+	sleep(sleep_sec);
 
 	get_monotonic_and_raw(&mon, &raw);
 	end = mon;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
maintainer
#1 lore raw
Quoted 5 lines · Wake Liu

The raw_skew test currently sleeps for 120 seconds to estimate clock drift. This is a very long time for a single test, and can cause timeouts in automated test suites or CI systems.

Sheesh, nobody has two minutes to spare? :)

Quoted 16 lines

Allow overriding the sleep time via a command line argument, so it can be adjusted if needed in different environments, while keeping the default at 120 seconds to preserve original behavior.

---
 tools/testing/selftests/timers/raw_skew.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +0 -0
index a7bae7d80916..03cdcecba8f4 100644
@@ -92,6 +92,15 @@ int main(int argc, char **argv)
        struct timespec mon, raw, start, end;
        long long delta1, delta2, interval, eppm, ppm;

tools/testing/selftests/timers/raw_skew.c int main(int argc, char **argv) · line 103

Quoted 10 lines
tools/testing/selftests/timers/raw_skew.c +9 -0
        struct timex tx1, tx2;
+       int sleep_sec = 120;
+
+       if (argc > 1) {
+               sleep_sec = atoi(argv[1]);
+               if (sleep_sec <= 0) {
+                       printf("Invalid sleep time, using default 120s\n");
+                       sleep_sec = 120;
+               }
+       }

This probably needs some usage documentation so folks can discover this? (Which may mean also supporting -h/--help)

Otherwise seems reasonable.

thanks!
-john

author
#2 lore raw

Thanks for the review :)
I've sent out v2 which addresses this by adding -h/--help support and usage documentation.

Quoted 44 lines · John Stultz
Quoted 5 lines · Wake Liu

The raw_skew test currently sleeps for 120 seconds to estimate clock drift. This is a very long time for a single test, and can cause timeouts in automated test suites or CI systems.

Sheesh, nobody has two minutes to spare? :)

Quoted 16 lines

Allow overriding the sleep time via a command line argument, so it can be adjusted if needed in different environments, while keeping the default at 120 seconds to preserve original behavior.

---
 tools/testing/selftests/timers/raw_skew.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +0 -0
index a7bae7d80916..03cdcecba8f4 100644
@@ -92,6 +92,15 @@ int main(int argc, char **argv)
        struct timespec mon, raw, start, end;
        long long delta1, delta2, interval, eppm, ppm;

tools/testing/selftests/timers/raw_skew.c int main(int argc, char **argv) · line 103

Quoted 10 lines
tools/testing/selftests/timers/raw_skew.c +9 -0
        struct timex tx1, tx2;
+       int sleep_sec = 120;
+
+       if (argc > 1) {
+               sleep_sec = atoi(argv[1]);
+               if (sleep_sec <= 0) {
+                       printf("Invalid sleep time, using default 120s\n");
+                       sleep_sec = 120;
+               }
+       }

This probably needs some usage documentation so folks can discover this? (Which may mean also supporting -h/--help)

Otherwise seems reasonable.

thanks!
-john

Signature · 2 lines
Best Regards,
Wake Liu
author
#3 lore raw

PATCH v2 1/1 selftests: timers: Make sleep time in raw_skew configurable

In reply to Wake Liu

The raw_skew test currently sleeps for 120 seconds to estimate clock drift. This is a very long time for a single test, and can cause timeouts in automated test suites or CI systems.

Allow overriding the sleep time via a command line argument, so it can be adjusted if needed in different environments, while keeping the default at 120 seconds to preserve original behavior.

Also add -h/--help support to document this option.

---
 tools/testing/selftests/timers/raw_skew.c | 24 +++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +22 -2
index a7bae7d80916..5fff3eaf1307 100644
@@ -27,6 +27,7 @@
 #include <time.h>
 #include <include/vdso/time64.h>
 #include "kselftest.h"
+#include <string.h>
 
 #define shift_right(x, s) ({		\
 	__typeof__(x) __x = (x);	\
@@ -87,11 +88,30 @@ void get_monotonic_and_raw(struct timespec *mon, struct timespec *raw)
 	}
 }
 
+static void usage(char *argv0)
+{
+	printf("Usage: %s [sleep_secs]\n", argv0);
+	printf("  sleep_secs: time to sleep in seconds to estimate clock drift (default: 120s)\n");
+}
+
 int main(int argc, char **argv)
 {
 	struct timespec mon, raw, start, end;
 	long long delta1, delta2, interval, eppm, ppm;
 	struct timex tx1, tx2;
+	int sleep_sec = 120;
+
+	if (argc > 1) {
+		if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
+			usage(argv[0]);
+			ksft_exit_pass();
+		}
+		sleep_sec = atoi(argv[1]);
+		if (sleep_sec <= 0) {
+			printf("Invalid sleep time, using default 120s\n");
+			sleep_sec = 120;
+		}
+	}
 
 	setbuf(stdout, NULL);
 
@@ -109,9 +129,9 @@ int main(int argc, char **argv)
 	if (tx1.offset)
 		printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");
 
-	printf("Estimating clock drift: ");
+	printf("Estimating clock drift (%ds): ", sleep_sec);
 	fflush(stdout);
-	sleep(120);
+	sleep(sleep_sec);
 
 	get_monotonic_and_raw(&mon, &raw);
 	end = mon;
Signature · 1 line
2.55.0.795.g602f6c329a-goog
author
#4 lore raw

Hi,

Friendly ping on this v2 patch.

It addresses the feedback from v1 by adding the usage documentation and -h/--help support.

Please let me know if you have any comments or if this looks good.

Thanks,
Wake

maintainer Acked-by on v2 1/1
#5 lore raw
In reply to Wake Liu
Quoted 5 lines · Wake Liu

The raw_skew test currently sleeps for 120 seconds to estimate clock drift. This is a very long time for a single test, and can cause timeouts in automated test suites or CI systems.

Quoted 7 lines

Allow overriding the sleep time via a command line argument, so it can be adjusted if needed in different environments, while keeping the default at 120 seconds to preserve original behavior.

Also add -h/--help support to document this option.