selftests: timers: Add a test for disarmed SIGEV_NONE timers

timer_gettime() must report a zero it_value for a disarmed timer. For
SIGEV_NONE timers, common_timer_get() reported the remaining time of the
previous arming instead.

Add check_sigev_none_disarm(). It arms a SIGEV_NONE oneshot timer, checks
that a remaining time is reported, disarms the timer and checks that
it_value is zero. Run it for CLOCK_MONOTONIC and CLOCK_PROCESS_CPUTIME_ID,
as CPU timers use a separate implementation.

Without the preceding fix, the CLOCK_MONOTONIC case fails.

Signed-off-by: Hung-Jui Lin <alex.lin.programmer@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20261023151411.28685-2-alex.lin.programmer@gmail.com
This commit is contained in:
Hung-Jui Lin 2026-10-23 23:14:11 +08:00 committed by Thomas Gleixner
parent 141a27750e
commit 45aeb7b303

View File

@ -495,6 +495,45 @@ static void check_sigev_none(int which)
"check_sigev_none %s\n", name);
}
static void check_sigev_none_disarm(int which)
{
const char *name = clock_name(which);
struct itimerspec its;
struct sigevent sev;
timer_t timerid;
bool armed;
memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_NONE;
if (timer_create(which, &sev, &timerid))
fatal_error(name, "timer_create()");
/* Start a oneshot timer which does not expire during the test */
memset(&its, 0, sizeof(its));
its.it_value.tv_sec = 100;
if (timer_settime(timerid, 0, &its, NULL))
fatal_error(name, "timer_settime()");
if (timer_gettime(timerid, &its))
fatal_error(name, "timer_gettime()");
armed = its.it_value.tv_sec || its.it_value.tv_nsec;
/* Disarm it. The remaining time must be reported as 0 */
memset(&its, 0, sizeof(its));
if (timer_settime(timerid, 0, &its, NULL))
fatal_error(name, "timer_settime()");
if (timer_gettime(timerid, &its))
fatal_error(name, "timer_gettime()");
if (timer_delete(timerid))
fatal_error(name, "timer_delete()");
ksft_test_result(armed && !its.it_value.tv_sec && !its.it_value.tv_nsec,
"%s %s\n", __func__, name);
}
static void check_gettime(int which)
{
const char *name = clock_name(which);
@ -680,7 +719,7 @@ int main(int argc, char **argv)
ksft_print_header();
if (run_sig_ign_tests) {
ksft_set_plan(19);
ksft_set_plan(21);
} else {
ksft_set_plan(10);
}
@ -714,6 +753,8 @@ int main(int argc, char **argv)
check_delete();
check_sigev_none(CLOCK_MONOTONIC);
check_sigev_none(CLOCK_PROCESS_CPUTIME_ID);
check_sigev_none_disarm(CLOCK_MONOTONIC);
check_sigev_none_disarm(CLOCK_PROCESS_CPUTIME_ID);
check_gettime(CLOCK_MONOTONIC);
check_gettime(CLOCK_PROCESS_CPUTIME_ID);
check_gettime(CLOCK_THREAD_CPUTIME_ID);