xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2001
4  * Porting from Crackerjack to LTP is done by:
5  *              Manas Kumar Nayak <[email protected]>
6  *
7  * Copyright (c) Linux Test Project, 2009-2023
8  * Copyright (c) 2013 Cyril Hrubis <[email protected]>
9  * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
10  */
11 
12 /*\
13  * [Description]
14  *
15  * This test checks base timer_getoverrun() functionality.
16  */
17 
18 #include <signal.h>
19 #include <time.h>
20 #include "tst_safe_clocks.h"
21 #include "lapi/syscalls.h"
22 #include "lapi/common_timers.h"
23 
run(void)24 static void run(void)
25 {
26 	kernel_timer_t timer;
27 	struct sigevent ev;
28 
29 	ev.sigev_value = (union sigval) 0;
30 	ev.sigev_notify = SIGEV_SIGNAL;
31 	ev.sigev_signo = SIGALRM;
32 
33 	if (tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer))
34 		tst_brk(TBROK | TERRNO, "timer_create() failed");
35 
36 	TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
37 
38 	if (tst_syscall(__NR_timer_delete, timer))
39 		tst_brk(TBROK | TERRNO, "timer_delete() failed");
40 
41 	TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, timer), EINVAL);
42 }
43 
44 static struct tst_test test = {
45 	.test_all = run,
46 };
47