1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * NAME
22 * gettimeofday01.c
23 *
24 * DESCRIPTION
25 * Testcase to check that gettimeofday(2) sets errno to EFAULT.
26 *
27 * ALGORITHM
28 * Call gettimeofday() with an invalid buffer, and expect EFAULT to be
29 * set in errno.
30 *
31 * HISTORY
32 * 07/2001 Ported by Wayne Boyer
33 *
34 * RESTRICTIONS
35 * NONE
36 */
37
38 #include <sys/time.h>
39 #include <errno.h>
40 #include "test.h"
41 #include <sys/syscall.h>
42 #include <unistd.h>
43
44 #define gettimeofday(a,b) syscall(__NR_gettimeofday,a,b)
45
46 char *TCID = "gettimeofday01";
47 int TST_TOTAL = 1;
48
49 #if !defined UCLINUX
50
51 void cleanup(void);
52 void setup(void);
53
main(int ac,char ** av)54 int main(int ac, char **av)
55 {
56 int lc;
57 int ret;
58
59 tst_parse_opts(ac, av, NULL, NULL);
60
61 setup();
62
63 for (lc = 0; TEST_LOOPING(lc); lc++) {
64 tst_count = 0;
65
66 TEST(gettimeofday((void *)-1, (void *)-1));
67
68 /* gettimeofday returns an int, so we need to turn the long
69 * TEST_RETURN into an int to test with */
70 ret = TEST_RETURN;
71 if (ret != -1) {
72 tst_resm(TFAIL,
73 "call succeeded unexpectedly (got back %i, wanted -1)",
74 ret);
75 continue;
76 }
77
78 if (TEST_ERRNO == EFAULT)
79 tst_resm(TPASS,
80 "gettimeofday(2) set the errno EFAULT correctly");
81 else
82 tst_resm(TFAIL,
83 "gettimeofday(2) didn't set errno to EFAULT, errno=%i (%s)",
84 errno, strerror(errno));
85 }
86
87 cleanup();
88 tst_exit();
89 }
90
setup(void)91 void setup(void)
92 {
93
94 tst_sig(NOFORK, DEF_HANDLER, cleanup);
95
96 TEST_PAUSE;
97 }
98
cleanup(void)99 void cleanup(void)
100 {
101 }
102 #else
103
main(void)104 int main(void)
105 {
106 tst_brkm(TCONF, "gettimeofday EFAULT check disabled on uClinux");
107 }
108
109 #endif
110