xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/setitimer/setitimer02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2001
4  * 03/2001 - Written by Wayne Boyer
5  *
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Check that setitimer() call fails:
12  *
13  * 1. EFAULT with invalid itimerval pointer
14  * 2. EINVAL when called with an invalid first argument
15  */
16 
17 #include <errno.h>
18 #include <sys/time.h>
19 #include <stdlib.h>
20 #include "tst_test.h"
21 #include "lapi/syscalls.h"
22 #include "tst_timer.h"
23 
24 static struct __kernel_old_itimerval *value, *ovalue;
25 
verify_setitimer(unsigned int i)26 static void verify_setitimer(unsigned int i)
27 {
28 	switch (i) {
29 	case 0:
30 		TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT);
31 		break;
32 	case 1:
33 		TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT);
34 		break;
35 	case 2:
36 		TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL);
37 		break;
38 	}
39 }
40 
setup(void)41 static void setup(void)
42 {
43 	value->it_value.tv_sec = 30;
44 	value->it_value.tv_usec = 0;
45 	value->it_interval.tv_sec = 0;
46 	value->it_interval.tv_usec = 0;
47 }
48 
49 static struct tst_test test = {
50 	.tcnt = 3,
51 	.test = verify_setitimer,
52 	.setup = setup,
53 	.bufs = (struct tst_buffers[]) {
54 		{&value,  .size = sizeof(struct __kernel_old_itimerval)},
55 		{&ovalue, .size = sizeof(struct __kernel_old_itimerval)},
56 		{}
57 	}
58 };
59