Skip to content

Commit 05d89fe

Browse files
Wake LiuKAGA-KOKO
authored andcommitted
selftests/timers: Clean up kernel version check in posix_timers
Several tests in the posix_timers selftest which test timer behavior related to SIG_IGN fail on kernels older than 6.13. This is due to a refactoring of signal handling in commit caf7743 ("signal: Handle ignored signals in do_sigaction(action != SIG_IGN)"). A previous attempt to fix this by adding a kernel version check to each of the nine affected tests was suboptimal, as it resulted in emitting the same skip message nine times. Following the suggestion from Thomas Gleixner, this is refactored to perform a single version check in main(). To satisfy the kselftest framework's requirement for the test count to match the declared plan, the plan is now conditionally set to 10 (for older kernels) or 19. While setting the plan conditionally may seem complex, it is the better approach to avoid the alternatives: either running tests on unsupported kernels that are known to fail, or emitting a noisy series of nine identical skip messages. A single informational message is now printed instead when the tests are skipped. Signed-off-by: Wake Liu <wakel@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250807085042.1690931-1-wakel@google.com/ Link: https://patch.msgid.link/20251103114502.584940-1-wakel@google.com
1 parent 4518767 commit 05d89fe

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

tools/testing/selftests/timers/posix_timers.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <time.h>
1919
#include <include/vdso/time64.h>
2020
#include <pthread.h>
21+
#include <stdbool.h>
2122

2223
#include "../kselftest.h"
2324

@@ -670,8 +671,14 @@ static void check_timer_create_exact(void)
670671

671672
int main(int argc, char **argv)
672673
{
674+
bool run_sig_ign_tests = ksft_min_kernel_version(6, 13);
675+
673676
ksft_print_header();
674-
ksft_set_plan(19);
677+
if (run_sig_ign_tests) {
678+
ksft_set_plan(19);
679+
} else {
680+
ksft_set_plan(10);
681+
}
675682

676683
ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n");
677684
ksft_print_msg("based timers if other threads run on the CPU...\n");
@@ -695,15 +702,20 @@ int main(int argc, char **argv)
695702
check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
696703
check_timer_distribution();
697704

698-
check_sig_ign(0);
699-
check_sig_ign(1);
700-
check_rearm();
701-
check_delete();
702-
check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
703-
check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
704-
check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
705-
check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
706-
check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
705+
if (run_sig_ign_tests) {
706+
check_sig_ign(0);
707+
check_sig_ign(1);
708+
check_rearm();
709+
check_delete();
710+
check_sigev_none(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
711+
check_sigev_none(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
712+
check_gettime(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
713+
check_gettime(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
714+
check_gettime(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
715+
} else {
716+
ksft_print_msg("Skipping SIG_IGN tests on kernel < 6.13\n");
717+
}
718+
707719
check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
708720
check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
709721
check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");

0 commit comments

Comments
 (0)