plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * gettimeofday01.c |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 23 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
Garrett Cooper | e8530df | 2010-12-21 11:37:57 -0800 | [diff] [blame] | 40 | #include "test.h" |
mridge | 441599d | 2006-02-20 16:52:49 +0000 | [diff] [blame] | 41 | #include <sys/syscall.h> |
| 42 | #include <unistd.h> |
| 43 | |
| 44 | #define gettimeofday(a,b) syscall(__NR_gettimeofday,a,b) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | |
| 46 | char *TCID = "gettimeofday01"; |
| 47 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
Cyril Hrubis | 9e4b117 | 2014-09-23 13:10:52 +0200 | [diff] [blame] | 49 | #if !defined UCLINUX |
| 50 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | void cleanup(void); |
plars | 704b1f2 | 2003-03-18 17:34:44 +0000 | [diff] [blame] | 52 | void setup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | |
robbiew | 96d2337 | 2003-03-26 20:40:04 +0000 | [diff] [blame] | 54 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 56 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 57 | const char *msg; |
vapier | 7254147 | 2006-02-28 00:13:11 +0000 | [diff] [blame] | 58 | int ret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 60 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 61 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | setup(); |
| 65 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 67 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | |
| 69 | TEST(gettimeofday((void *)-1, (void *)-1)); |
| 70 | |
vapier | 7254147 | 2006-02-28 00:13:11 +0000 | [diff] [blame] | 71 | /* 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 75 | tst_resm(TFAIL, |
| 76 | "call succeeded unexpectedly (got back %i, wanted -1)", |
| 77 | ret); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | continue; |
| 79 | } |
| 80 | |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 81 | if (TEST_ERRNO == EFAULT) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | tst_resm(TPASS, |
| 83 | "gettimeofday(2) set the errno EFAULT correctly"); |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 84 | else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | tst_resm(TFAIL, |
| 86 | "gettimeofday(2) didn't set errno to EFAULT, errno=%i (%s)", |
| 87 | errno, strerror(errno)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | |
Cyril Hrubis | 9e4b117 | 2014-09-23 13:10:52 +0200 | [diff] [blame] | 90 | cleanup(); |
Cyril Hrubis | 4dff854 | 2014-09-23 12:11:59 +0200 | [diff] [blame] | 91 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 93 | |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 94 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 96 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 98 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | TEST_PAUSE; |
| 100 | } |
| 101 | |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 102 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | } |
robbiew | f75e232 | 2003-03-11 16:21:12 +0000 | [diff] [blame] | 105 | #else |
robbiew | f75e232 | 2003-03-11 16:21:12 +0000 | [diff] [blame] | 106 | |
vapier | eb7c5db | 2007-03-19 07:08:46 +0000 | [diff] [blame] | 107 | int main(void) |
robbiew | f75e232 | 2003-03-11 16:21:12 +0000 | [diff] [blame] | 108 | { |
Cyril Hrubis | 9e4b117 | 2014-09-23 13:10:52 +0200 | [diff] [blame] | 109 | tst_brkm(TCONF, "gettimeofday EFAULT check disabled on uClinux"); |
robbiew | f75e232 | 2003-03-11 16:21:12 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 112 | #endif |