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 <unistd.h>
42 #include "lapi/syscalls.h"
43
44 char *TCID = "gettimeofday01";
45 int TST_TOTAL = 1;
46
47 #if !defined UCLINUX
48
49 void cleanup(void);
50 void setup(void);
51
main(int ac,char ** av)52 int main(int ac, char **av)
53 {
54 int lc;
55 int ret;
56
57 tst_parse_opts(ac, av, NULL, NULL);
58
59 setup();
60
61 for (lc = 0; TEST_LOOPING(lc); lc++) {
62 tst_count = 0;
63
64 TEST(ltp_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));
65
66 /* gettimeofday returns an int, so we need to turn the long
67 * TEST_RETURN into an int to test with */
68 ret = TEST_RETURN;
69 if (ret != -1) {
70 tst_resm(TFAIL,
71 "call succeeded unexpectedly (got back %i, wanted -1)",
72 ret);
73 continue;
74 }
75
76 if (TEST_ERRNO == EFAULT)
77 tst_resm(TPASS,
78 "gettimeofday(2) set the errno EFAULT correctly");
79 else
80 tst_resm(TFAIL,
81 "gettimeofday(2) didn't set errno to EFAULT, errno=%i (%s)",
82 errno, strerror(errno));
83 }
84
85 cleanup();
86 tst_exit();
87 }
88
setup(void)89 void setup(void)
90 {
91
92 tst_sig(NOFORK, DEF_HANDLER, cleanup);
93
94 TEST_PAUSE;
95 }
96
cleanup(void)97 void cleanup(void)
98 {
99 }
100 #else
101
main(void)102 int main(void)
103 {
104 tst_brkm(TCONF, "gettimeofday EFAULT check disabled on uClinux");
105 }
106
107 #endif
108