plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 3 | * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | * Further, this software is distributed without any warranty that it is |
| 14 | * free of the rightful claim of any third person regarding infringement |
| 15 | * or the like. Any license provided herein, whether implied or |
| 16 | * otherwise, applies only to this software file. Patent licenses, if |
| 17 | * any, provided herein do not apply to combinations of this program with |
| 18 | * other software, or any other product whatsoever. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 21 | * with this program; if not, write the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | * |
| 24 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 25 | * Mountain View, CA 94043, or: |
| 26 | * |
| 27 | * http://www.sgi.com |
| 28 | * |
| 29 | * For further information regarding this notice, see: |
| 30 | * |
| 31 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 32 | * |
| 33 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | |
| 35 | #include <sys/types.h> |
| 36 | #include <fcntl.h> |
| 37 | #include <errno.h> |
| 38 | #include <string.h> |
| 39 | #include <signal.h> |
| 40 | #include <unistd.h> |
| 41 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 43 | static void setup(void); |
| 44 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 46 | static char fname[255]; |
| 47 | static int fd; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 48 | static int whences[] = { 5, -1, 7 }; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 50 | char *TCID = "lseek03"; |
Cyril Hrubis | b863a0b | 2014-09-24 13:15:29 +0200 | [diff] [blame] | 51 | int TST_TOTAL = ARRAY_SIZE(whences); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | { |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 55 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 56 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 58 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 59 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 60 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 63 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 64 | int i; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 66 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 68 | for (i = 0; i < TST_TOTAL; i++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 70 | /* Call lseek(2) */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | TEST(lseek(fd, (off_t) 1, whences[i])); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | if (TEST_RETURN == -1) { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 74 | if (TEST_ERRNO == EINVAL) { |
| 75 | tst_resm(TPASS, |
| 76 | "lseek(%s, 1, %d) Failed, errno=%d : %s", |
| 77 | fname, whences[i], |
| 78 | TEST_ERRNO, |
| 79 | strerror(TEST_ERRNO)); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 80 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 81 | tst_resm(TFAIL, |
| 82 | "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)", |
| 83 | fname, whences[i], |
| 84 | TEST_ERRNO, |
| 85 | strerror(TEST_ERRNO), |
| 86 | EINVAL); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 87 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 89 | tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld", |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 90 | fname, whences[i], TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 93 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 94 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 97 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 100 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 106 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 108 | sprintf(fname, "tfile_%d", getpid()); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 109 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { |
| 111 | tst_brkm(TBROK, cleanup, |
| 112 | "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", |
| 113 | fname, errno, strerror(errno)); |
| 114 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 115 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 117 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | if (close(fd) == -1) { |
| 120 | tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, |
| 121 | strerror(errno)); |
| 122 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 124 | tst_rmdir(); |
Wanlong Gao | 423e636 | 2011-10-25 09:58:04 +0800 | [diff] [blame] | 125 | } |