xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2001-2023
5*49cdfc7eSAndroid Build Coastguard Worker  */
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  * Test for gettimeofday error.
11*49cdfc7eSAndroid Build Coastguard Worker  *
12*49cdfc7eSAndroid Build Coastguard Worker  * - EFAULT: tv pointed outside the accessible address space
13*49cdfc7eSAndroid Build Coastguard Worker  * - EFAULT: tz pointed outside the accessible address space
14*49cdfc7eSAndroid Build Coastguard Worker  * - EFAULT: both tv and tz pointed outside the accessible address space
15*49cdfc7eSAndroid Build Coastguard Worker  */
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker static struct timeval tv1;
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker static struct tcase {
23*49cdfc7eSAndroid Build Coastguard Worker 	void *tv;
24*49cdfc7eSAndroid Build Coastguard Worker 	void *tz;
25*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
26*49cdfc7eSAndroid Build Coastguard Worker 	/* timezone structure is obsolete, tz should be treated as null */
27*49cdfc7eSAndroid Build Coastguard Worker 	{(void *)-1, NULL},
28*49cdfc7eSAndroid Build Coastguard Worker 	{&tv1, (void *)-1},
29*49cdfc7eSAndroid Build Coastguard Worker 	{(void *)-1, (void *)-1},
30*49cdfc7eSAndroid Build Coastguard Worker };
31*49cdfc7eSAndroid Build Coastguard Worker 
verify_gettimeofday(unsigned int n)32*49cdfc7eSAndroid Build Coastguard Worker static void verify_gettimeofday(unsigned int n)
33*49cdfc7eSAndroid Build Coastguard Worker {
34*49cdfc7eSAndroid Build Coastguard Worker 	struct tcase *tc = &tcases[n];
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(tst_syscall(__NR_gettimeofday, tc->tv, tc->tz), EFAULT);
37*49cdfc7eSAndroid Build Coastguard Worker }
38*49cdfc7eSAndroid Build Coastguard Worker 
39*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
40*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
41*49cdfc7eSAndroid Build Coastguard Worker 	.test = verify_gettimeofday,
42*49cdfc7eSAndroid Build Coastguard Worker };
43