blob: c0e7c710b7888fa7baa74cc4606966d73f5e8232 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000022 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
plars865695b2001-08-27 22:15:12 +000026 */
plars865695b2001-08-27 22:15:12 +000027
28#include <sys/types.h>
29#include <sys/fcntl.h>
30#include <errno.h>
31#include <string.h>
32#include <signal.h>
33#include "test.h"
plars865695b2001-08-27 22:15:12 +000034
Wanlong Gao777588e2013-02-04 17:11:18 +080035static void setup(void);
36static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000037
Wanlong Gao777588e2013-02-04 17:11:18 +080038char *TCID = "open03";
39int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000040
Wanlong Gao777588e2013-02-04 17:11:18 +080041static char fname[255];
42static int fd;
plars865695b2001-08-27 22:15:12 +000043
subrata_modak56207ce2009-03-23 13:35:39 +000044int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000045{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020046 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020047 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000048
Wanlong Gao777588e2013-02-04 17:11:18 +080049 msg = parse_opts(ac, av, NULL, NULL);
50 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080051 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000052
subrata_modak56207ce2009-03-23 13:35:39 +000053 setup();
plars865695b2001-08-27 22:15:12 +000054
subrata_modak56207ce2009-03-23 13:35:39 +000055 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080056 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000057
subrata_modak56207ce2009-03-23 13:35:39 +000058 TEST(open(fname, O_RDWR | O_CREAT, 0700));
subrata_modak56207ce2009-03-23 13:35:39 +000059 fd = TEST_RETURN;
plars865695b2001-08-27 22:15:12 +000060
subrata_modak56207ce2009-03-23 13:35:39 +000061 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080062 tst_resm(TFAIL | TTERRNO,
vapierf2ed15b2009-08-28 13:35:01 +000063 "open(%s,O_RDWR|O_CREAT,0700) failed", fname);
subrata_modak56207ce2009-03-23 13:35:39 +000064 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020065 tst_resm(TPASS,
66 "open(%s, O_RDWR|O_CREAT,0700) returned %ld",
67 fname, TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +000068
vapierf2ed15b2009-08-28 13:35:01 +000069 if (close(fd) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080070 tst_brkm(TBROK | TERRNO, cleanup,
vapierf2ed15b2009-08-28 13:35:01 +000071 "close(%s) failed", fname);
72 else if (unlink(fname) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +080073 tst_brkm(TBROK | TERRNO, cleanup,
vapierf2ed15b2009-08-28 13:35:01 +000074 "unlink(%s) failed", fname);
subrata_modak56207ce2009-03-23 13:35:39 +000075 }
Garrett Cooper2c282152010-12-16 00:55:50 -080076 }
plars865695b2001-08-27 22:15:12 +000077
subrata_modak56207ce2009-03-23 13:35:39 +000078 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080079 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080080}
plars865695b2001-08-27 22:15:12 +000081
Wanlong Gao777588e2013-02-04 17:11:18 +080082static void setup(void)
plars865695b2001-08-27 22:15:12 +000083{
subrata_modak56207ce2009-03-23 13:35:39 +000084 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +000085
subrata_modak56207ce2009-03-23 13:35:39 +000086 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +000087
subrata_modak56207ce2009-03-23 13:35:39 +000088 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +000089
subrata_modak56207ce2009-03-23 13:35:39 +000090 sprintf(fname, "tfile_%d", getpid());
Garrett Cooper2c282152010-12-16 00:55:50 -080091}
plars865695b2001-08-27 22:15:12 +000092
Wanlong Gao777588e2013-02-04 17:11:18 +080093static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000094{
subrata_modak56207ce2009-03-23 13:35:39 +000095 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -070096}