Re: [PATCH] selftests/timers/posix_timers: reimplement check_timer_distribution()

From: Oleg Nesterov
Date: Tue Apr 09 2024 - 07:12:55 EST


On 04/09, Thomas Gleixner wrote:
>
> The discussion started about running new tests on older kernels. As this
> is a feature and not a bug fix that obviously fails on older kernels.

OK, I see... please see below.

> So something like the uncompiled below should work.

Hmm... this patch doesn't apply to Linus's tree...

It seems that this is because in your tree check_timer_distribution() does

if (timer_delete(id)) {
ksft_perror("Can't delete timer");
return 0;
}

while in Linus's tree it returns -1 if timer_delete() fails. Nevermind.

Thomas, I am almost shy to continue this discussion and waste your time ;)
But ...

> +static bool check_kernel_version(unsigned int min_major, unsigned int min_minor)
> +{
> + unsigned int major, minor;
> + struct utsname info;
> +
> + uname(&info);
> + if (sscanf(info.release, "%u.%u.", &major, &minor) != 2)
> + ksft_exit_fail();
> + return major > min_major || (major == min_major && minor >= min_minor);
> +}

this looks useful regardless. Perhaps it should be moved into
tools/testing/selftests/kselftest.h as ksft_ck_kernel_version() ?

> +static int check_timer_distribution(void)
> +{
> + const char *errmsg;
> +
> + if (!check_kernel_version(6, 3)) {
> + ksft_test_result_skip("check signal distribution (old kernel)\n");
> return 0;

..

> + ksft_test_result(!ctd_failed, "check signal distribution\n");

Perhaps

if (!ctd_failed)
ksft_test_result_pass("check signal distribution\n");
else if (check_kernel_version(6, 3))
ksft_test_result_fail("check signal distribution\n");
else
ksft_test_result_skip("check signal distribution (old kernel)\n");

makes more sense?

This way it can be used on the older kernels with bcb7ee79029d backported.

Oleg.