* [PATCH 2/2] selftests: timers: Add a test for disarmed SIGEV_NONE timers
[not found] <20261023151411.28685-1-alex.lin.programmer@gmail.com>
@ 2026-10-23 15:14 ` Hung-Jui Lin
0 siblings, 0 replies; only message in thread
From: Hung-Jui Lin @ 2026-10-23 15:14 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Anna-Maria Behnsen, Frederic Weisbecker, linux-kernel,
Hung-Jui Lin, John Stultz, Stephen Boyd, Miroslav Lichvar,
Shuah Khan, linux-kselftest
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>
---
tools/testing/selftests/timers/posix_timers.c | 43 ++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index 52b7289e1..464609b8c 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -496,6 +496,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);
@@ -681,7 +720,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);
}
@@ -715,6 +754,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);
--
2.56.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 15:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261023151411.28685-1-alex.lin.programmer@gmail.com>
2026-10-23 15:14 ` [PATCH 2/2] selftests: timers: Add a test for disarmed SIGEV_NONE timers Hung-Jui Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox