blob: 8a93d4c591515d1bd850c6c097bd4f3b1b016f28 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * gettimeofday01.c
vapiereb7c5db2007-03-19 07:08:46 +000023 *
plars865695b2001-08-27 22:15:12 +000024 * 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 *
plars865695b2001-08-27 22:15:12 +000031 * HISTORY
32 * 07/2001 Ported by Wayne Boyer
33 *
34 * RESTRICTIONS
35 * NONE
36 */
37
38#include <sys/time.h>
39#include <errno.h>
Garrett Coopere8530df2010-12-21 11:37:57 -080040#include "test.h"
mridge441599d2006-02-20 16:52:49 +000041#include <sys/syscall.h>
42#include <unistd.h>
43
44#define gettimeofday(a,b) syscall(__NR_gettimeofday,a,b)
plars865695b2001-08-27 22:15:12 +000045
46char *TCID = "gettimeofday01";
47int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000048
Cyril Hrubis9e4b1172014-09-23 13:10:52 +020049#if !defined UCLINUX
50
plars865695b2001-08-27 22:15:12 +000051void cleanup(void);
plars704b1f22003-03-18 17:34:44 +000052void setup(void);
plars865695b2001-08-27 22:15:12 +000053
robbiew96d23372003-03-26 20:40:04 +000054int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000055{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020056 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020057 const char *msg;
vapier72541472006-02-28 00:13:11 +000058 int ret;
plars865695b2001-08-27 22:15:12 +000059
Garrett Cooper45e285d2010-11-22 12:19:25 -080060 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080061 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000062 }
63
64 setup();
65
plars865695b2001-08-27 22:15:12 +000066 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080067 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000068
69 TEST(gettimeofday((void *)-1, (void *)-1));
70
vapier72541472006-02-28 00:13:11 +000071 /* gettimeofday returns an int, so we need to turn the long
72 * TEST_RETURN into an int to test with */
73 ret = TEST_RETURN;
74 if (ret != -1) {
subrata_modak56207ce2009-03-23 13:35:39 +000075 tst_resm(TFAIL,
76 "call succeeded unexpectedly (got back %i, wanted -1)",
77 ret);
plars865695b2001-08-27 22:15:12 +000078 continue;
79 }
80
vapiereb7c5db2007-03-19 07:08:46 +000081 if (TEST_ERRNO == EFAULT)
subrata_modak56207ce2009-03-23 13:35:39 +000082 tst_resm(TPASS,
83 "gettimeofday(2) set the errno EFAULT correctly");
vapiereb7c5db2007-03-19 07:08:46 +000084 else
subrata_modak56207ce2009-03-23 13:35:39 +000085 tst_resm(TFAIL,
86 "gettimeofday(2) didn't set errno to EFAULT, errno=%i (%s)",
87 errno, strerror(errno));
plars865695b2001-08-27 22:15:12 +000088 }
plars865695b2001-08-27 22:15:12 +000089
Cyril Hrubis9e4b1172014-09-23 13:10:52 +020090 cleanup();
Cyril Hrubis4dff8542014-09-23 12:11:59 +020091 tst_exit();
plars865695b2001-08-27 22:15:12 +000092}
vapiereb7c5db2007-03-19 07:08:46 +000093
vapiereb7c5db2007-03-19 07:08:46 +000094void setup(void)
plars865695b2001-08-27 22:15:12 +000095{
Garrett Cooper2c282152010-12-16 00:55:50 -080096
plars865695b2001-08-27 22:15:12 +000097 tst_sig(NOFORK, DEF_HANDLER, cleanup);
98
plars865695b2001-08-27 22:15:12 +000099 TEST_PAUSE;
100}
101
vapiereb7c5db2007-03-19 07:08:46 +0000102void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000103{
plars865695b2001-08-27 22:15:12 +0000104}
robbiewf75e2322003-03-11 16:21:12 +0000105#else
robbiewf75e2322003-03-11 16:21:12 +0000106
vapiereb7c5db2007-03-19 07:08:46 +0000107int main(void)
robbiewf75e2322003-03-11 16:21:12 +0000108{
Cyril Hrubis9e4b1172014-09-23 13:10:52 +0200109 tst_brkm(TCONF, "gettimeofday EFAULT check disabled on uClinux");
robbiewf75e2322003-03-11 16:21:12 +0000110}
111
Chris Dearmanec6edca2012-10-17 19:54:01 -0700112#endif