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; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
Cyril Hrubis | d6d11d0 | 2015-03-09 17:35:43 +0100 | [diff] [blame] | 57 | tst_parse_opts(ac, av, NULL, NULL); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 58 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 59 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 62 | int i; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 63 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 64 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 66 | for (i = 0; i < TST_TOTAL; i++) { |
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 | /* Call lseek(2) */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 69 | TEST(lseek(fd, (off_t) 1, whences[i])); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | if (TEST_RETURN == -1) { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 72 | if (TEST_ERRNO == EINVAL) { |
| 73 | tst_resm(TPASS, |
| 74 | "lseek(%s, 1, %d) Failed, errno=%d : %s", |
| 75 | fname, whences[i], |
| 76 | TEST_ERRNO, |
| 77 | strerror(TEST_ERRNO)); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 78 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 79 | tst_resm(TFAIL, |
| 80 | "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)", |
| 81 | fname, whences[i], |
| 82 | TEST_ERRNO, |
| 83 | strerror(TEST_ERRNO), |
| 84 | EINVAL); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 85 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 87 | tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld", |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 88 | fname, whences[i], TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 91 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 92 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 94 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 95 | tst_exit(); |
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 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 98 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
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 | TEST_PAUSE; |
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 | tst_tmpdir(); |
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 | sprintf(fname, "tfile_%d", getpid()); |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 107 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 108 | if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) { |
| 109 | tst_brkm(TBROK, cleanup, |
| 110 | "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s", |
| 111 | fname, errno, strerror(errno)); |
| 112 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 113 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | |
Cyril Hrubis | 1af2bad | 2011-10-26 17:03:08 +0200 | [diff] [blame] | 115 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 117 | if (close(fd) == -1) { |
| 118 | tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, |
| 119 | strerror(errno)); |
| 120 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 122 | tst_rmdir(); |
Wanlong Gao | 423e636 | 2011-10-25 09:58:04 +0800 | [diff] [blame] | 123 | } |