2022-07-13 21:33:20

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 0/9] selftests: timers: fixes and improvements

The timer selftests are quite useful for me when enabling timers on new
SoCs, e.g. like now with the CMT timer on a Renesas R-Car S4-8. During
development, I needed these fixes and additions to make full use of
the tests. I think they make all sense upstream, so here they are.

Patches are based on v5.19-rc1. Looking forward to comments.

Happy hacking,

Wolfram


Wolfram Sang (9):
selftests: timers: valid-adjtimex: build fix for newer toolchains
selftests: timers: fix declarations of main()
selftests: timers: nanosleep: adapt to kselftest framework
selftests: timers: inconsistency-check: adapt to kselftest framework
selftests: timers: clocksource-switch: fix passing errors from child
selftests: timers: clocksource-switch: sort includes
selftests: timers: clocksource-switch: add command line switch to skip
sanity check
selftests: timers: clocksource-switch: add 'runtime' command line
parameter
selftests: timers: clocksource-switch: adapt to kselftest framework

tools/testing/selftests/timers/adjtick.c | 2 +-
tools/testing/selftests/timers/change_skew.c | 2 +-
.../selftests/timers/clocksource-switch.c | 70 ++++++++++++-------
.../selftests/timers/inconsistency-check.c | 32 +++++----
tools/testing/selftests/timers/nanosleep.c | 18 +++--
tools/testing/selftests/timers/raw_skew.c | 2 +-
.../selftests/timers/skew_consistency.c | 2 +-
.../testing/selftests/timers/valid-adjtimex.c | 2 +-
8 files changed, 80 insertions(+), 50 deletions(-)

--
2.35.1


2022-07-13 21:34:27

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 9/9] selftests: timers: clocksource-switch: adapt to kselftest framework

So we have proper counters at the end of a test. We also print the
kselftest header at the end of the test, so we don't mix with the output
of the child process. There is only this one test anyhow.

Signed-off-by: Wolfram Sang <[email protected]>
---
tools/testing/selftests/timers/clocksource-switch.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
index a1d0d33738b6..e2c0e4485ea8 100644
--- a/tools/testing/selftests/timers/clocksource-switch.c
+++ b/tools/testing/selftests/timers/clocksource-switch.c
@@ -182,7 +182,9 @@ int main(int argc, char **argv)
out:
change_clocksource(orig_clk);

- if (status)
- return ksft_exit_fail();
- return ksft_exit_pass();
+ /* Print at the end to not mix output with child process */
+ ksft_print_header();
+ ksft_set_plan(1);
+ ksft_test_result(!status, "clocksource-switch\n");
+ ksft_exit(!status);
}
--
2.35.1

2022-07-13 21:34:38

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 8/9] selftests: timers: clocksource-switch: add 'runtime' command line parameter

So the user can decide how long the test should run.

Signed-off-by: Wolfram Sang <[email protected]>
---
tools/testing/selftests/timers/clocksource-switch.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
index 5256e6215980..a1d0d33738b6 100644
--- a/tools/testing/selftests/timers/clocksource-switch.c
+++ b/tools/testing/selftests/timers/clocksource-switch.c
@@ -124,14 +124,18 @@ int main(int argc, char **argv)
char orig_clk[512];
int count, i, status, opt;
int do_sanity_check = 1;
+ int runtime = 60;
pid_t pid;

/* Process arguments */
- while ((opt = getopt(argc, argv, "s")) != -1) {
+ while ((opt = getopt(argc, argv, "st:")) != -1) {
switch (opt) {
case 's':
do_sanity_check = 0;
break;
+ case 't':
+ runtime = atoi(optarg);
+ break;
default:
printf("Usage: %s [-s]\n", argv[0]);
printf(" -s: skip sanity checks\n");
@@ -167,7 +171,7 @@ int main(int argc, char **argv)
printf("Running Asynchronous Switching Tests...\n");
pid = fork();
if (!pid)
- return run_tests(60);
+ return run_tests(runtime);

while (pid != waitpid(pid, &status, WNOHANG))
for (i = 0; i < count; i++)
--
2.35.1

2022-07-13 21:35:34

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 5/9] selftests: timers: clocksource-switch: fix passing errors from child

The return value from system() is a waitpid-style integer. Do not return
it directly because with the implicit masking in exit() it will always
return 0. Access it with apropriate macros to really pass on errors.

Fixes: 7290ce1423c3 ("selftests/timers: Add clocksource-switch test from timetest suite")
Signed-off-by: Wolfram Sang <[email protected]>
---
tools/testing/selftests/timers/clocksource-switch.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
index ef8eb3604595..b57f0a9be490 100644
--- a/tools/testing/selftests/timers/clocksource-switch.c
+++ b/tools/testing/selftests/timers/clocksource-switch.c
@@ -110,10 +110,10 @@ int run_tests(int secs)

sprintf(buf, "./inconsistency-check -t %i", secs);
ret = system(buf);
- if (ret)
- return ret;
+ if (WIFEXITED(ret) && WEXITSTATUS(ret))
+ return WEXITSTATUS(ret);
ret = system("./nanosleep");
- return ret;
+ return WIFEXITED(ret) ? WEXITSTATUS(ret) : 0;
}


--
2.35.1

2022-07-13 21:37:43

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 4/9] selftests: timers: inconsistency-check: adapt to kselftest framework

So we have proper counters at the end of a test, e.g.:
# Totals: pass:11 fail:0 xfail:0 xpass:0 skip:1 error:0

Signed-off-by: Wolfram Sang <[email protected]>
---
.../selftests/timers/inconsistency-check.c | 32 +++++++++++--------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c
index e6756d9c60a7..36a49fba6c9b 100644
--- a/tools/testing/selftests/timers/inconsistency-check.c
+++ b/tools/testing/selftests/timers/inconsistency-check.c
@@ -122,30 +122,28 @@ int consistency_test(int clock_type, unsigned long seconds)
if (inconsistent >= 0) {
unsigned long long delta;

- printf("\%s\n", start_str);
+ ksft_print_msg("\%s\n", start_str);
for (i = 0; i < CALLS_PER_LOOP; i++) {
if (i == inconsistent)
- printf("--------------------\n");
- printf("%lu:%lu\n", list[i].tv_sec,
+ ksft_print_msg("--------------------\n");
+ ksft_print_msg("%lu:%lu\n", list[i].tv_sec,
list[i].tv_nsec);
if (i == inconsistent + 1)
- printf("--------------------\n");
+ ksft_print_msg("--------------------\n");
}
delta = list[inconsistent].tv_sec * NSEC_PER_SEC;
delta += list[inconsistent].tv_nsec;
delta -= list[inconsistent+1].tv_sec * NSEC_PER_SEC;
delta -= list[inconsistent+1].tv_nsec;
- printf("Delta: %llu ns\n", delta);
+ ksft_print_msg("Delta: %llu ns\n", delta);
fflush(0);
/* timestamp inconsistency*/
t = time(0);
- printf("%s\n", ctime(&t));
- printf("[FAILED]\n");
+ ksft_print_msg("%s\n", ctime(&t));
return -1;
}
now = list[0].tv_sec;
}
- printf("[OK]\n");
return 0;
}

@@ -178,16 +176,22 @@ int main(int argc, char *argv[])

setbuf(stdout, NULL);

+ ksft_print_header();
+ ksft_set_plan(maxclocks - userclock);
+
for (clockid = userclock; clockid < maxclocks; clockid++) {

- if (clockid == CLOCK_HWSPECIFIC)
+ if (clockid == CLOCK_HWSPECIFIC || clock_gettime(clockid, &ts)) {
+ ksft_test_result_skip("%-31s\n", clockstring(clockid));
continue;
+ }

- if (!clock_gettime(clockid, &ts)) {
- printf("Consistent %-30s ", clockstring(clockid));
- if (consistency_test(clockid, runtime))
- return ksft_exit_fail();
+ if (consistency_test(clockid, runtime)) {
+ ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_exit_fail();
+ } else {
+ ksft_test_result_pass("%-31s\n", clockstring(clockid));
}
}
- return ksft_exit_pass();
+ ksft_exit_pass();
}
--
2.35.1

2022-07-13 21:43:29

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 3/9] selftests: timers: nanosleep: adapt to kselftest framework

So we have proper counters at the end of a test, e.g.:
# Totals: pass:4 fail:0 xfail:0 xpass:0 skip:8 error:0

Signed-off-by: Wolfram Sang <[email protected]>
---
tools/testing/selftests/timers/nanosleep.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
index 71b5441c2fd9..df1d03516e7b 100644
--- a/tools/testing/selftests/timers/nanosleep.c
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -133,33 +133,37 @@ int main(int argc, char **argv)
long long length;
int clockid, ret;

+ ksft_print_header();
+ ksft_set_plan(NR_CLOCKIDS);
+
for (clockid = CLOCK_REALTIME; clockid < NR_CLOCKIDS; clockid++) {

/* Skip cputime clockids since nanosleep won't increment cputime */
if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
clockid == CLOCK_THREAD_CPUTIME_ID ||
- clockid == CLOCK_HWSPECIFIC)
+ clockid == CLOCK_HWSPECIFIC) {
+ ksft_test_result_skip("%-31s\n", clockstring(clockid));
continue;
+ }

- printf("Nanosleep %-31s ", clockstring(clockid));
fflush(stdout);

length = 10;
while (length <= (NSEC_PER_SEC * 10)) {
ret = nanosleep_test(clockid, length);
if (ret == UNSUPPORTED) {
- printf("[UNSUPPORTED]\n");
+ ksft_test_result_skip("%-31s\n", clockstring(clockid));
goto next;
}
if (ret < 0) {
- printf("[FAILED]\n");
- return ksft_exit_fail();
+ ksft_test_result_fail("%-31s\n", clockstring(clockid));
+ ksft_exit_fail();
}
length *= 100;
}
- printf("[OK]\n");
+ ksft_test_result_pass("%-31s\n", clockstring(clockid));
next:
ret = 0;
}
- return ksft_exit_pass();
+ ksft_exit_pass();
}
--
2.35.1

2022-07-13 21:47:41

by John Stultz

[permalink] [raw]
Subject: Re: [PATCH 8/9] selftests: timers: clocksource-switch: add 'runtime' command line parameter

On Wed, Jul 13, 2022 at 1:46 PM Wolfram Sang
<[email protected]> wrote:
>
> So the user can decide how long the test should run.
>
> Signed-off-by: Wolfram Sang <[email protected]>
> ---
> tools/testing/selftests/timers/clocksource-switch.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
> index 5256e6215980..a1d0d33738b6 100644
> --- a/tools/testing/selftests/timers/clocksource-switch.c
> +++ b/tools/testing/selftests/timers/clocksource-switch.c
> @@ -124,14 +124,18 @@ int main(int argc, char **argv)
> char orig_clk[512];
> int count, i, status, opt;
> int do_sanity_check = 1;
> + int runtime = 60;
> pid_t pid;
>
> /* Process arguments */
> - while ((opt = getopt(argc, argv, "s")) != -1) {
> + while ((opt = getopt(argc, argv, "st:")) != -1) {
> switch (opt) {
> case 's':
> do_sanity_check = 0;
> break;
> + case 't':
> + runtime = atoi(optarg);
> + break;
> default:
> printf("Usage: %s [-s]\n", argv[0]);
> printf(" -s: skip sanity checks\n");

Ah, one minor nit: Should the -t option get documented here in the
usage output?

thanks again!
-john

2022-07-14 09:10:01

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH 8/9] selftests: timers: clocksource-switch: add 'runtime' command line parameter

Hello!

On 7/13/22 11:46 PM, Wolfram Sang wrote:

> So the user can decide how long the test should run.
>
> Signed-off-by: Wolfram Sang <[email protected]>
> ---
> tools/testing/selftests/timers/clocksource-switch.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
> index 5256e6215980..a1d0d33738b6 100644
> --- a/tools/testing/selftests/timers/clocksource-switch.c
> +++ b/tools/testing/selftests/timers/clocksource-switch.c
[...]
> - while ((opt = getopt(argc, argv, "s")) != -1) {
> + while ((opt = getopt(argc, argv, "st:")) != -1) {
> switch (opt) {
> case 's':
> do_sanity_check = 0;
> break;
> + case 't':
> + runtime = atoi(optarg);
> + break;
> default:
> printf("Usage: %s [-s]\n", argv[0]);
> printf(" -s: skip sanity checks\n");

Hm, you probably forgot to update the usage msg?

[...]

MBR, Sergey

2022-07-14 11:43:56

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 8/9] selftests: timers: clocksource-switch: add 'runtime' command line parameter

> > default:
> > printf("Usage: %s [-s]\n", argv[0]);
> > printf(" -s: skip sanity checks\n");
>
> Hm, you probably forgot to update the usage msg?

Yup, thanks!


Attachments:
(No filename) (186.00 B)
signature.asc (849.00 B)
Download all attachments