blob: d9e41ca55b7b12ec638a29ca92cfd664dd3ba028 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
Cyril Hrubis1af2bad2011-10-26 17:03:08 +02003 * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
plars865695b2001-08-27 22:15:12 +00004 *
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 Gaofed96412012-10-24 10:10:29 +080021 * with this program; if not, write the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000023 *
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 */
plars865695b2001-08-27 22:15:12 +000034
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"
plars865695b2001-08-27 22:15:12 +000042
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020043static void setup(void);
44static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000045
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020046static char fname[255];
47static int fd;
Wanlong Gao354ebb42012-12-07 10:10:04 +080048static int whences[] = { 5, -1, 7 };
plars865695b2001-08-27 22:15:12 +000049
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020050char *TCID = "lseek03";
Cyril Hrubisb863a0b2014-09-24 13:15:29 +020051int TST_TOTAL = ARRAY_SIZE(whences);
plars865695b2001-08-27 22:15:12 +000052
subrata_modak56207ce2009-03-23 13:35:39 +000053int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000054{
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020055 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020056 const char *msg;
plars865695b2001-08-27 22:15:12 +000057
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020058 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000059 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080060
subrata_modak56207ce2009-03-23 13:35:39 +000061 setup();
plars865695b2001-08-27 22:15:12 +000062
subrata_modak56207ce2009-03-23 13:35:39 +000063 for (lc = 0; TEST_LOOPING(lc); lc++) {
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020064 int i;
plars865695b2001-08-27 22:15:12 +000065
Caspar Zhangd59a6592013-03-07 14:59:12 +080066 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000067
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020068 for (i = 0; i < TST_TOTAL; i++) {
plars865695b2001-08-27 22:15:12 +000069
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020070 /* Call lseek(2) */
Wanlong Gao354ebb42012-12-07 10:10:04 +080071 TEST(lseek(fd, (off_t) 1, whences[i]));
plars865695b2001-08-27 22:15:12 +000072
subrata_modak56207ce2009-03-23 13:35:39 +000073 if (TEST_RETURN == -1) {
Cyril Hrubise38b9612014-06-02 17:20:57 +020074 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 Hrubis1af2bad2011-10-26 17:03:08 +020080 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020081 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 Hrubis1af2bad2011-10-26 17:03:08 +020087 }
subrata_modak56207ce2009-03-23 13:35:39 +000088 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +000089 tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld",
Cyril Hrubis1af2bad2011-10-26 17:03:08 +020090 fname, whences[i], TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000091 }
plars865695b2001-08-27 22:15:12 +000092 }
subrata_modakbdbaec52009-02-26 12:14:51 +000093
Garrett Cooper2c282152010-12-16 00:55:50 -080094 }
plars865695b2001-08-27 22:15:12 +000095
subrata_modak56207ce2009-03-23 13:35:39 +000096 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080097 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080098}
plars865695b2001-08-27 22:15:12 +000099
Cyril Hrubis1af2bad2011-10-26 17:03:08 +0200100void setup(void)
plars865695b2001-08-27 22:15:12 +0000101{
subrata_modak56207ce2009-03-23 13:35:39 +0000102 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000103
subrata_modak56207ce2009-03-23 13:35:39 +0000104 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000105
subrata_modak56207ce2009-03-23 13:35:39 +0000106 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000107
subrata_modak56207ce2009-03-23 13:35:39 +0000108 sprintf(fname, "tfile_%d", getpid());
Cyril Hrubis1af2bad2011-10-26 17:03:08 +0200109
subrata_modak56207ce2009-03-23 13:35:39 +0000110 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 Cooper2c282152010-12-16 00:55:50 -0800115}
plars865695b2001-08-27 22:15:12 +0000116
Cyril Hrubis1af2bad2011-10-26 17:03:08 +0200117void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000118{
subrata_modak56207ce2009-03-23 13:35:39 +0000119 if (close(fd) == -1) {
120 tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno,
121 strerror(errno));
122 }
plars865695b2001-08-27 22:15:12 +0000123
subrata_modak56207ce2009-03-23 13:35:39 +0000124 tst_rmdir();
Wanlong Gao423e6362011-10-25 09:58:04 +0800125}