1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2013 Red Hat, Inc., Frederic Weisbecker <fweisbec@redhat.com>
4 *
5 * Selftests for a few posix timers interface.
6 *
7 * Kernel loop code stolen from Steven Rostedt <srostedt@redhat.com>
8 */
9 #define _GNU_SOURCE
10 #include <sys/prctl.h>
11 #include <sys/time.h>
12 #include <sys/types.h>
13 #include <stdio.h>
14 #include <signal.h>
15 #include <stdint.h>
16 #include <string.h>
17 #include <unistd.h>
18 #include <time.h>
19 #include <include/vdso/time64.h>
20 #include <pthread.h>
21 #include <stdbool.h>
22
23 #include "kselftest.h"
24
25 #define DELAY 2
26
__fatal_error(const char * test,const char * name,const char * what)27 static void __fatal_error(const char *test, const char *name, const char *what)
28 {
29 char buf[64];
30 char *ret_str = NULL;
31
32 ret_str = strerror_r(errno, buf, sizeof(buf));
33
34 if (name && strlen(name) && ret_str)
35 ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, ret_str);
36 else if (ret_str)
37 ksft_exit_fail_msg("%s %s %s\n", test, what, ret_str);
38 else
39 ksft_exit_fail_msg("%s %s\n", test, what);
40
41 }
42
43 #define fatal_error(name, what) __fatal_error(__func__, name, what)
44
45 static volatile int done;
46
47 /* Busy loop in userspace to elapse ITIMER_VIRTUAL */
user_loop(void)48 static void user_loop(void)
49 {
50 while (!done);
51 }
52
53 /*
54 * Try to spend as much time as possible in kernelspace
55 * to elapse ITIMER_PROF.
56 */
kernel_loop(void)57 static void kernel_loop(void)
58 {
59 void *addr = sbrk(0);
60 int err = 0;
61
62 while (!done && !err) {
63 err = brk(addr + 4096);
64 err |= brk(addr);
65 }
66 }
67
68 /*
69 * Sleep until ITIMER_REAL expiration.
70 */
idle_loop(void)71 static void idle_loop(void)
72 {
73 pause();
74 }
75
sig_handler(int nr)76 static void sig_handler(int nr)
77 {
78 done = 1;
79 }
80
81 /*
82 * Check the expected timer expiration matches the GTOD elapsed delta since
83 * we armed the timer. Keep a 0.5 sec error margin due to various jitter.
84 */
check_diff(struct timeval start,struct timeval end)85 static int check_diff(struct timeval start, struct timeval end)
86 {
87 long long diff;
88
89 diff = end.tv_usec - start.tv_usec;
90 diff += (end.tv_sec - start.tv_sec) * USEC_PER_SEC;
91
92 if (llabs(diff - DELAY * USEC_PER_SEC) > USEC_PER_SEC / 2) {
93 printf("Diff too high: %lld..", diff);
94 return -1;
95 }
96
97 return 0;
98 }
99
check_itimer(int which,const char * name)100 static void check_itimer(int which, const char *name)
101 {
102 struct timeval start, end;
103 struct itimerval val = {
104 .it_value.tv_sec = DELAY,
105 };
106
107 done = 0;
108
109 if (which == ITIMER_VIRTUAL)
110 signal(SIGVTALRM, sig_handler);
111 else if (which == ITIMER_PROF)
112 signal(SIGPROF, sig_handler);
113 else if (which == ITIMER_REAL)
114 signal(SIGALRM, sig_handler);
115
116 if (gettimeofday(&start, NULL) < 0)
117 fatal_error(name, "gettimeofday()");
118
119 if (setitimer(which, &val, NULL) < 0)
120 fatal_error(name, "setitimer()");
121
122 if (which == ITIMER_VIRTUAL)
123 user_loop();
124 else if (which == ITIMER_PROF)
125 kernel_loop();
126 else if (which == ITIMER_REAL)
127 idle_loop();
128
129 if (gettimeofday(&end, NULL) < 0)
130 fatal_error(name, "gettimeofday()");
131
132 ksft_test_result(check_diff(start, end) == 0, "%s\n", name);
133 }
134
check_timer_create(int which,const char * name)135 static void check_timer_create(int which, const char *name)
136 {
137 struct timeval start, end;
138 struct itimerspec val = {
139 .it_value.tv_sec = DELAY,
140 };
141 timer_t id;
142
143 done = 0;
144
145 if (timer_create(which, NULL, &id) < 0)
146 fatal_error(name, "timer_create()");
147
148 if (signal(SIGALRM, sig_handler) == SIG_ERR)
149 fatal_error(name, "signal()");
150
151 if (gettimeofday(&start, NULL) < 0)
152 fatal_error(name, "gettimeofday()");
153
154 if (timer_settime(id, 0, &val, NULL) < 0)
155 fatal_error(name, "timer_settime()");
156
157 user_loop();
158
159 if (gettimeofday(&end, NULL) < 0)
160 fatal_error(name, "gettimeofday()");
161
162 ksft_test_result(check_diff(start, end) == 0,
163 "timer_create() per %s\n", name);
164 }
165
166 static pthread_t ctd_thread;
167 static volatile int ctd_count, ctd_failed;
168
ctd_sighandler(int sig)169 static void ctd_sighandler(int sig)
170 {
171 if (pthread_self() != ctd_thread)
172 ctd_failed = 1;
173 ctd_count--;
174 }
175
ctd_thread_func(void * arg)176 static void *ctd_thread_func(void *arg)
177 {
178 struct itimerspec val = {
179 .it_value.tv_sec = 0,
180 .it_value.tv_nsec = 1000 * 1000,
181 .it_interval.tv_sec = 0,
182 .it_interval.tv_nsec = 1000 * 1000,
183 };
184 timer_t id;
185
186 /* 1/10 seconds to ensure the leader sleeps */
187 usleep(10000);
188
189 ctd_count = 100;
190 if (timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id))
191 fatal_error(NULL, "timer_create()");
192 if (timer_settime(id, 0, &val, NULL))
193 fatal_error(NULL, "timer_settime()");
194 while (ctd_count > 0 && !ctd_failed)
195 ;
196
197 if (timer_delete(id))
198 fatal_error(NULL, "timer_delete()");
199
200 return NULL;
201 }
202
203 /*
204 * Test that only the running thread receives the timer signal.
205 */
check_timer_distribution(void)206 static void check_timer_distribution(void)
207 {
208 if (signal(SIGALRM, ctd_sighandler) == SIG_ERR)
209 fatal_error(NULL, "signal()");
210
211 if (pthread_create(&ctd_thread, NULL, ctd_thread_func, NULL))
212 fatal_error(NULL, "pthread_create()");
213
214 if (pthread_join(ctd_thread, NULL))
215 fatal_error(NULL, "pthread_join()");
216
217 if (!ctd_failed)
218 ksft_test_result_pass("check signal distribution\n");
219 else if (ksft_min_kernel_version(6, 3))
220 ksft_test_result_fail("check signal distribution\n");
221 else
222 ksft_test_result_skip("check signal distribution (old kernel)\n");
223 }
224
225 struct tmrsig {
226 int signals;
227 int overruns;
228 };
229
siginfo_handler(int sig,siginfo_t * si,void * uc)230 static void siginfo_handler(int sig, siginfo_t *si, void *uc)
231 {
232 struct tmrsig *tsig = si ? si->si_ptr : NULL;
233
234 if (tsig) {
235 tsig->signals++;
236 tsig->overruns += si->si_overrun;
237 }
238 }
239
ignore_thread(void * arg)240 static void *ignore_thread(void *arg)
241 {
242 unsigned int *tid = arg;
243 sigset_t set;
244
245 sigemptyset(&set);
246 sigaddset(&set, SIGUSR1);
247 if (sigprocmask(SIG_BLOCK, &set, NULL))
248 fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
249
250 *tid = gettid();
251 sleep(100);
252
253 if (sigprocmask(SIG_UNBLOCK, &set, NULL))
254 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)");
255 return NULL;
256 }
257
check_sig_ign(int thread)258 static void check_sig_ign(int thread)
259 {
260 struct tmrsig tsig = { };
261 struct itimerspec its;
262 unsigned int tid = 0;
263 struct sigaction sa;
264 struct sigevent sev;
265 pthread_t pthread;
266 timer_t timerid;
267 sigset_t set;
268
269 if (thread) {
270 if (pthread_create(&pthread, NULL, ignore_thread, &tid))
271 fatal_error(NULL, "pthread_create()");
272 sleep(1);
273 }
274
275 sa.sa_flags = SA_SIGINFO;
276 sa.sa_sigaction = siginfo_handler;
277 sigemptyset(&sa.sa_mask);
278 if (sigaction(SIGUSR1, &sa, NULL))
279 fatal_error(NULL, "sigaction()");
280
281 /* Block the signal */
282 sigemptyset(&set);
283 sigaddset(&set, SIGUSR1);
284 if (sigprocmask(SIG_BLOCK, &set, NULL))
285 fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
286
287 memset(&sev, 0, sizeof(sev));
288 sev.sigev_notify = SIGEV_SIGNAL;
289 sev.sigev_signo = SIGUSR1;
290 sev.sigev_value.sival_ptr = &tsig;
291 if (thread) {
292 sev.sigev_notify = SIGEV_THREAD_ID;
293 sev._sigev_un._tid = tid;
294 }
295
296 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid))
297 fatal_error(NULL, "timer_create()");
298
299 /* Start the timer to expire in 100ms and 100ms intervals */
300 its.it_value.tv_sec = 0;
301 its.it_value.tv_nsec = 100000000;
302 its.it_interval.tv_sec = 0;
303 its.it_interval.tv_nsec = 100000000;
304 timer_settime(timerid, 0, &its, NULL);
305
306 sleep(1);
307
308 /* Set the signal to be ignored */
309 if (signal(SIGUSR1, SIG_IGN) == SIG_ERR)
310 fatal_error(NULL, "signal(SIG_IGN)");
311
312 sleep(1);
313
314 if (thread) {
315 /* Stop the thread first. No signal should be delivered to it */
316 if (pthread_cancel(pthread))
317 fatal_error(NULL, "pthread_cancel()");
318 if (pthread_join(pthread, NULL))
319 fatal_error(NULL, "pthread_join()");
320 }
321
322 /* Restore the handler */
323 if (sigaction(SIGUSR1, &sa, NULL))
324 fatal_error(NULL, "sigaction()");
325
326 sleep(1);
327
328 /* Unblock it, which should deliver the signal in the !thread case*/
329 if (sigprocmask(SIG_UNBLOCK, &set, NULL))
330 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)");
331
332 if (timer_delete(timerid))
333 fatal_error(NULL, "timer_delete()");
334
335 if (!thread) {
336 ksft_test_result(tsig.signals == 1 && tsig.overruns == 29,
337 "check_sig_ign SIGEV_SIGNAL\n");
338 } else {
339 ksft_test_result(tsig.signals == 0 && tsig.overruns == 0,
340 "check_sig_ign SIGEV_THREAD_ID\n");
341 }
342 }
343
check_rearm(void)344 static void check_rearm(void)
345 {
346 struct tmrsig tsig = { };
347 struct itimerspec its;
348 struct sigaction sa;
349 struct sigevent sev;
350 timer_t timerid;
351 sigset_t set;
352
353 sa.sa_flags = SA_SIGINFO;
354 sa.sa_sigaction = siginfo_handler;
355 sigemptyset(&sa.sa_mask);
356 if (sigaction(SIGUSR1, &sa, NULL))
357 fatal_error(NULL, "sigaction()");
358
359 /* Block the signal */
360 sigemptyset(&set);
361 sigaddset(&set, SIGUSR1);
362 if (sigprocmask(SIG_BLOCK, &set, NULL))
363 fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
364
365 memset(&sev, 0, sizeof(sev));
366 sev.sigev_notify = SIGEV_SIGNAL;
367 sev.sigev_signo = SIGUSR1;
368 sev.sigev_value.sival_ptr = &tsig;
369 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid))
370 fatal_error(NULL, "timer_create()");
371
372 /* Start the timer to expire in 100ms and 100ms intervals */
373 its.it_value.tv_sec = 0;
374 its.it_value.tv_nsec = 100000000;
375 its.it_interval.tv_sec = 0;
376 its.it_interval.tv_nsec = 100000000;
377 if (timer_settime(timerid, 0, &its, NULL))
378 fatal_error(NULL, "timer_settime()");
379
380 sleep(1);
381
382 /* Reprogram the timer to single shot */
383 its.it_value.tv_sec = 10;
384 its.it_value.tv_nsec = 0;
385 its.it_interval.tv_sec = 0;
386 its.it_interval.tv_nsec = 0;
387 if (timer_settime(timerid, 0, &its, NULL))
388 fatal_error(NULL, "timer_settime()");
389
390 /* Unblock it, which should not deliver a signal */
391 if (sigprocmask(SIG_UNBLOCK, &set, NULL))
392 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)");
393
394 if (timer_delete(timerid))
395 fatal_error(NULL, "timer_delete()");
396
397 ksft_test_result(!tsig.signals, "check_rearm\n");
398 }
399
check_delete(void)400 static void check_delete(void)
401 {
402 struct tmrsig tsig = { };
403 struct itimerspec its;
404 struct sigaction sa;
405 struct sigevent sev;
406 timer_t timerid;
407 sigset_t set;
408
409 sa.sa_flags = SA_SIGINFO;
410 sa.sa_sigaction = siginfo_handler;
411 sigemptyset(&sa.sa_mask);
412 if (sigaction(SIGUSR1, &sa, NULL))
413 fatal_error(NULL, "sigaction()");
414
415 /* Block the signal */
416 sigemptyset(&set);
417 sigaddset(&set, SIGUSR1);
418 if (sigprocmask(SIG_BLOCK, &set, NULL))
419 fatal_error(NULL, "sigprocmask(SIG_BLOCK)");
420
421 memset(&sev, 0, sizeof(sev));
422 sev.sigev_notify = SIGEV_SIGNAL;
423 sev.sigev_signo = SIGUSR1;
424 sev.sigev_value.sival_ptr = &tsig;
425 if (timer_create(CLOCK_MONOTONIC, &sev, &timerid))
426 fatal_error(NULL, "timer_create()");
427
428 /* Start the timer to expire in 100ms and 100ms intervals */
429 its.it_value.tv_sec = 0;
430 its.it_value.tv_nsec = 100000000;
431 its.it_interval.tv_sec = 0;
432 its.it_interval.tv_nsec = 100000000;
433 if (timer_settime(timerid, 0, &its, NULL))
434 fatal_error(NULL, "timer_settime()");
435
436 sleep(1);
437
438 if (timer_delete(timerid))
439 fatal_error(NULL, "timer_delete()");
440
441 /* Unblock it, which should not deliver a signal */
442 if (sigprocmask(SIG_UNBLOCK, &set, NULL))
443 fatal_error(NULL, "sigprocmask(SIG_UNBLOCK)");
444
445 ksft_test_result(!tsig.signals, "check_delete\n");
446 }
447
calcdiff_ns(struct timespec t1,struct timespec t2)448 static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
449 {
450 int64_t diff;
451
452 diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
453 diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
454 return diff;
455 }
456
check_sigev_none(int which,const char * name)457 static void check_sigev_none(int which, const char *name)
458 {
459 struct timespec start, now;
460 struct itimerspec its;
461 struct sigevent sev;
462 timer_t timerid;
463
464 memset(&sev, 0, sizeof(sev));
465 sev.sigev_notify = SIGEV_NONE;
466
467 if (timer_create(which, &sev, &timerid))
468 fatal_error(name, "timer_create()");
469
470 /* Start the timer to expire in 100ms and 100ms intervals */
471 its.it_value.tv_sec = 0;
472 its.it_value.tv_nsec = 100000000;
473 its.it_interval.tv_sec = 0;
474 its.it_interval.tv_nsec = 100000000;
475 timer_settime(timerid, 0, &its, NULL);
476
477 if (clock_gettime(which, &start))
478 fatal_error(name, "clock_gettime()");
479
480 do {
481 if (clock_gettime(which, &now))
482 fatal_error(name, "clock_gettime()");
483 } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
484
485 if (timer_gettime(timerid, &its))
486 fatal_error(name, "timer_gettime()");
487
488 if (timer_delete(timerid))
489 fatal_error(name, "timer_delete()");
490
491 ksft_test_result(its.it_value.tv_sec || its.it_value.tv_nsec,
492 "check_sigev_none %s\n", name);
493 }
494
check_gettime(int which,const char * name)495 static void check_gettime(int which, const char *name)
496 {
497 struct itimerspec its, prev;
498 struct timespec start, now;
499 struct sigevent sev;
500 timer_t timerid;
501 int wraps = 0;
502 sigset_t set;
503
504 /* Block the signal */
505 sigemptyset(&set);
506 sigaddset(&set, SIGUSR1);
507 if (sigprocmask(SIG_BLOCK, &set, NULL))
508 fatal_error(name, "sigprocmask(SIG_BLOCK)");
509
510 memset(&sev, 0, sizeof(sev));
511 sev.sigev_notify = SIGEV_SIGNAL;
512 sev.sigev_signo = SIGUSR1;
513
514 if (timer_create(which, &sev, &timerid))
515 fatal_error(name, "timer_create()");
516
517 /* Start the timer to expire in 100ms and 100ms intervals */
518 its.it_value.tv_sec = 0;
519 its.it_value.tv_nsec = 100000000;
520 its.it_interval.tv_sec = 0;
521 its.it_interval.tv_nsec = 100000000;
522 if (timer_settime(timerid, 0, &its, NULL))
523 fatal_error(name, "timer_settime()");
524
525 if (timer_gettime(timerid, &prev))
526 fatal_error(name, "timer_gettime()");
527
528 if (clock_gettime(which, &start))
529 fatal_error(name, "clock_gettime()");
530
531 do {
532 if (clock_gettime(which, &now))
533 fatal_error(name, "clock_gettime()");
534 if (timer_gettime(timerid, &its))
535 fatal_error(name, "timer_gettime()");
536 if (its.it_value.tv_nsec > prev.it_value.tv_nsec)
537 wraps++;
538 prev = its;
539
540 } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
541
542 if (timer_delete(timerid))
543 fatal_error(name, "timer_delete()");
544
545 ksft_test_result(wraps > 1, "check_gettime %s\n", name);
546 }
547
check_overrun(int which,const char * name)548 static void check_overrun(int which, const char *name)
549 {
550 struct timespec start, now;
551 struct tmrsig tsig = { };
552 struct itimerspec its;
553 struct sigaction sa;
554 struct sigevent sev;
555 timer_t timerid;
556 sigset_t set;
557
558 sa.sa_flags = SA_SIGINFO;
559 sa.sa_sigaction = siginfo_handler;
560 sigemptyset(&sa.sa_mask);
561 if (sigaction(SIGUSR1, &sa, NULL))
562 fatal_error(name, "sigaction()");
563
564 /* Block the signal */
565 sigemptyset(&set);
566 sigaddset(&set, SIGUSR1);
567 if (sigprocmask(SIG_BLOCK, &set, NULL))
568 fatal_error(name, "sigprocmask(SIG_BLOCK)");
569
570 memset(&sev, 0, sizeof(sev));
571 sev.sigev_notify = SIGEV_SIGNAL;
572 sev.sigev_signo = SIGUSR1;
573 sev.sigev_value.sival_ptr = &tsig;
574 if (timer_create(which, &sev, &timerid))
575 fatal_error(name, "timer_create()");
576
577 /* Start the timer to expire in 100ms and 100ms intervals */
578 its.it_value.tv_sec = 0;
579 its.it_value.tv_nsec = 100000000;
580 its.it_interval.tv_sec = 0;
581 its.it_interval.tv_nsec = 100000000;
582 if (timer_settime(timerid, 0, &its, NULL))
583 fatal_error(name, "timer_settime()");
584
585 if (clock_gettime(which, &start))
586 fatal_error(name, "clock_gettime()");
587
588 do {
589 if (clock_gettime(which, &now))
590 fatal_error(name, "clock_gettime()");
591 } while (calcdiff_ns(now, start) < NSEC_PER_SEC);
592
593 /* Unblock it, which should deliver a signal */
594 if (sigprocmask(SIG_UNBLOCK, &set, NULL))
595 fatal_error(name, "sigprocmask(SIG_UNBLOCK)");
596
597 if (timer_delete(timerid))
598 fatal_error(name, "timer_delete()");
599
600 ksft_test_result(tsig.signals == 1 && tsig.overruns == 9,
601 "check_overrun %s\n", name);
602 }
603
604 #include <sys/syscall.h>
605
do_timer_create(int * id)606 static int do_timer_create(int *id)
607 {
608 return syscall(__NR_timer_create, CLOCK_MONOTONIC, NULL, id);
609 }
610
do_timer_delete(int id)611 static int do_timer_delete(int id)
612 {
613 return syscall(__NR_timer_delete, id);
614 }
615
616 #ifndef PR_TIMER_CREATE_RESTORE_IDS
617 # define PR_TIMER_CREATE_RESTORE_IDS 77
618 # define PR_TIMER_CREATE_RESTORE_IDS_OFF 0
619 # define PR_TIMER_CREATE_RESTORE_IDS_ON 1
620 # define PR_TIMER_CREATE_RESTORE_IDS_GET 2
621 #endif
622
check_timer_create_exact(void)623 static void check_timer_create_exact(void)
624 {
625 int id;
626
627 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_ON, 0, 0, 0)) {
628 switch (errno) {
629 case EINVAL:
630 ksft_test_result_skip("check timer create exact, not supported\n");
631 return;
632 default:
633 ksft_test_result_skip("check timer create exact, errno = %d\n", errno);
634 return;
635 }
636 }
637
638 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_GET, 0, 0, 0) != 1)
639 fatal_error(NULL, "prctl(GET) failed\n");
640
641 id = 8;
642 if (do_timer_create(&id) < 0)
643 fatal_error(NULL, "timer_create()");
644
645 if (do_timer_delete(id))
646 fatal_error(NULL, "timer_delete()");
647
648 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_OFF, 0, 0, 0))
649 fatal_error(NULL, "prctl(OFF)");
650
651 if (prctl(PR_TIMER_CREATE_RESTORE_IDS, PR_TIMER_CREATE_RESTORE_IDS_GET, 0, 0, 0) != 0)
652 fatal_error(NULL, "prctl(GET) failed\n");
653
654 if (id != 8) {
655 ksft_test_result_fail("check timer create exact %d != 8\n", id);
656 return;
657 }
658
659 /* Validate that it went back to normal mode and allocates ID 9 */
660 if (do_timer_create(&id) < 0)
661 fatal_error(NULL, "timer_create()");
662
663 if (do_timer_delete(id))
664 fatal_error(NULL, "timer_delete()");
665
666 if (id == 9)
667 ksft_test_result_pass("check timer create exact\n");
668 else
669 ksft_test_result_fail("check timer create exact. Disabling failed.\n");
670 }
671
main(int argc,char ** argv)672 int main(int argc, char **argv)
673 {
674 bool run_sig_ign_tests = ksft_min_kernel_version(6, 13);
675
676 ksft_print_header();
677 if (run_sig_ign_tests) {
678 ksft_set_plan(19);
679 } else {
680 ksft_set_plan(10);
681 }
682
683 ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n");
684 ksft_print_msg("based timers if other threads run on the CPU...\n");
685
686 check_timer_create_exact();
687
688 check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL");
689 check_itimer(ITIMER_PROF, "ITIMER_PROF");
690 check_itimer(ITIMER_REAL, "ITIMER_REAL");
691 check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
692
693 /*
694 * It's unfortunately hard to reliably test a timer expiration
695 * on parallel multithread cputime. We could arm it to expire
696 * on DELAY * nr_threads, with nr_threads busy looping, then wait
697 * the normal DELAY since the time is elapsing nr_threads faster.
698 * But for that we need to ensure we have real physical free CPUs
699 * to ensure true parallelism. So test only one thread until we
700 * find a better solution.
701 */
702 check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
703 check_timer_distribution();
704
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
719 check_overrun(CLOCK_MONOTONIC, "CLOCK_MONOTONIC");
720 check_overrun(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
721 check_overrun(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
722
723 ksft_finished();
724 }
725