1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is
13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement
14f08c3bdfSopenharmony_ci * or the like.  Any license provided herein, whether implied or
15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file.  Patent licenses, if
16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with
17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever.
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24f08c3bdfSopenharmony_ci * Mountain View, CA  94043, or:
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * http://www.sgi.com
27f08c3bdfSopenharmony_ci *
28f08c3bdfSopenharmony_ci * For further information regarding this notice, see:
29f08c3bdfSopenharmony_ci *
30f08c3bdfSopenharmony_ci * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31f08c3bdfSopenharmony_ci *
32f08c3bdfSopenharmony_ci */
33f08c3bdfSopenharmony_ci/* $Id: rename02.c,v 1.8 2009/11/02 13:57:18 subrata_modak Exp $ */
34f08c3bdfSopenharmony_ci/**********************************************************
35f08c3bdfSopenharmony_ci *
36f08c3bdfSopenharmony_ci *    OS Test - Silicon Graphics, Inc.
37f08c3bdfSopenharmony_ci *
38f08c3bdfSopenharmony_ci *    TEST IDENTIFIER	: rename02
39f08c3bdfSopenharmony_ci *
40f08c3bdfSopenharmony_ci *    EXECUTED BY	: anyone
41f08c3bdfSopenharmony_ci *
42f08c3bdfSopenharmony_ci *    TEST TITLE	: Basic test for rename(2)
43f08c3bdfSopenharmony_ci *
44f08c3bdfSopenharmony_ci *    PARENT DOCUMENT	: usctpl01
45f08c3bdfSopenharmony_ci *
46f08c3bdfSopenharmony_ci *    TEST CASE TOTAL	: 1
47f08c3bdfSopenharmony_ci *
48f08c3bdfSopenharmony_ci *    WALL CLOCK TIME	: 1
49f08c3bdfSopenharmony_ci *
50f08c3bdfSopenharmony_ci *    CPU TYPES		: ALL
51f08c3bdfSopenharmony_ci *
52f08c3bdfSopenharmony_ci *    AUTHOR		: William Roske
53f08c3bdfSopenharmony_ci *
54f08c3bdfSopenharmony_ci *    CO-PILOT		: Dave Fenner
55f08c3bdfSopenharmony_ci *
56f08c3bdfSopenharmony_ci *    DATE STARTED	: 03/30/92
57f08c3bdfSopenharmony_ci *
58f08c3bdfSopenharmony_ci *    INITIAL RELEASE	: UNICOS 7.0
59f08c3bdfSopenharmony_ci *
60f08c3bdfSopenharmony_ci *    TEST CASES
61f08c3bdfSopenharmony_ci *
62f08c3bdfSopenharmony_ci * 	1.) rename(2) returns...(See Description)
63f08c3bdfSopenharmony_ci *
64f08c3bdfSopenharmony_ci *    INPUT SPECIFICATIONS
65f08c3bdfSopenharmony_ci * 	The standard options for system call tests are accepted.
66f08c3bdfSopenharmony_ci *	(See the parse_opts(3) man page).
67f08c3bdfSopenharmony_ci *
68f08c3bdfSopenharmony_ci *    OUTPUT SPECIFICATIONS
69f08c3bdfSopenharmony_ci *$
70f08c3bdfSopenharmony_ci *    DURATION
71f08c3bdfSopenharmony_ci * 	Terminates - with frequency and infinite modes.
72f08c3bdfSopenharmony_ci *
73f08c3bdfSopenharmony_ci *    SIGNALS
74f08c3bdfSopenharmony_ci * 	Uses SIGUSR1 to pause before test if option set.
75f08c3bdfSopenharmony_ci * 	(See the parse_opts(3) man page).
76f08c3bdfSopenharmony_ci *
77f08c3bdfSopenharmony_ci *    RESOURCES
78f08c3bdfSopenharmony_ci * 	None
79f08c3bdfSopenharmony_ci *
80f08c3bdfSopenharmony_ci *    ENVIRONMENTAL NEEDS
81f08c3bdfSopenharmony_ci *      No run-time environmental needs.
82f08c3bdfSopenharmony_ci *
83f08c3bdfSopenharmony_ci *    SPECIAL PROCEDURAL REQUIREMENTS
84f08c3bdfSopenharmony_ci * 	None
85f08c3bdfSopenharmony_ci *
86f08c3bdfSopenharmony_ci *    INTERCASE DEPENDENCIES
87f08c3bdfSopenharmony_ci * 	None
88f08c3bdfSopenharmony_ci *
89f08c3bdfSopenharmony_ci *    DETAILED DESCRIPTION
90f08c3bdfSopenharmony_ci *	This is a Phase I test for the rename(2) system call.  It is intended
91f08c3bdfSopenharmony_ci *	to provide a limited exposure of the system call, for now.  It
92f08c3bdfSopenharmony_ci *	should/will be extended when full functional tests are written for
93f08c3bdfSopenharmony_ci *	rename(2).
94f08c3bdfSopenharmony_ci *
95f08c3bdfSopenharmony_ci * 	Setup:
96f08c3bdfSopenharmony_ci * 	  Setup signal handling.
97f08c3bdfSopenharmony_ci *	  Pause for SIGUSR1 if option specified.
98f08c3bdfSopenharmony_ci *
99f08c3bdfSopenharmony_ci * 	Test:
100f08c3bdfSopenharmony_ci *	 Loop if the proper options are given.
101f08c3bdfSopenharmony_ci * 	  Execute system call
102f08c3bdfSopenharmony_ci *	  Check return code, if system call failed (return=-1)
103f08c3bdfSopenharmony_ci *		Log the errno and Issue a FAIL message.
104f08c3bdfSopenharmony_ci *	  Otherwise, Issue a PASS message.
105f08c3bdfSopenharmony_ci *
106f08c3bdfSopenharmony_ci * 	Cleanup:
107f08c3bdfSopenharmony_ci * 	  Print errno log and/or timing stats if options given
108f08c3bdfSopenharmony_ci *
109f08c3bdfSopenharmony_ci *
110f08c3bdfSopenharmony_ci *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
111f08c3bdfSopenharmony_ci
112f08c3bdfSopenharmony_ci#include <sys/types.h>
113f08c3bdfSopenharmony_ci#include <fcntl.h>
114f08c3bdfSopenharmony_ci#include <errno.h>
115f08c3bdfSopenharmony_ci#include <string.h>
116f08c3bdfSopenharmony_ci#include <signal.h>
117f08c3bdfSopenharmony_ci#include "test.h"
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_civoid setup();
120f08c3bdfSopenharmony_civoid cleanup();
121f08c3bdfSopenharmony_ci
122f08c3bdfSopenharmony_cichar *TCID = "rename02";
123f08c3bdfSopenharmony_ciint TST_TOTAL = 1;
124f08c3bdfSopenharmony_ci
125f08c3bdfSopenharmony_ciint fd;
126f08c3bdfSopenharmony_cichar fname[255], mname[255];
127f08c3bdfSopenharmony_ci
128f08c3bdfSopenharmony_ciint main(int ac, char **av)
129f08c3bdfSopenharmony_ci{
130f08c3bdfSopenharmony_ci	int lc;
131f08c3bdfSopenharmony_ci
132f08c3bdfSopenharmony_ci	tst_parse_opts(ac, av, NULL, NULL);
133f08c3bdfSopenharmony_ci
134f08c3bdfSopenharmony_ci	setup();
135f08c3bdfSopenharmony_ci
136f08c3bdfSopenharmony_ci	for (lc = 0; TEST_LOOPING(lc); lc++) {
137f08c3bdfSopenharmony_ci
138f08c3bdfSopenharmony_ci		tst_count = 0;
139f08c3bdfSopenharmony_ci
140f08c3bdfSopenharmony_ci		/*
141f08c3bdfSopenharmony_ci		 * Call rename(2)
142f08c3bdfSopenharmony_ci		 */
143f08c3bdfSopenharmony_ci		TEST(rename(fname, mname));
144f08c3bdfSopenharmony_ci
145f08c3bdfSopenharmony_ci		/* check return code */
146f08c3bdfSopenharmony_ci		if (TEST_RETURN == -1) {
147f08c3bdfSopenharmony_ci			tst_resm(TFAIL, "rename(%s, %s) Failed, errno=%d : %s",
148f08c3bdfSopenharmony_ci				 fname, mname, TEST_ERRNO,
149f08c3bdfSopenharmony_ci				 strerror(TEST_ERRNO));
150f08c3bdfSopenharmony_ci		} else {
151f08c3bdfSopenharmony_ci			tst_resm(TPASS, "rename(%s, %s) returned %ld",
152f08c3bdfSopenharmony_ci				 fname, mname, TEST_RETURN);
153f08c3bdfSopenharmony_ci			if (unlink(mname) == -1) {
154f08c3bdfSopenharmony_ci				tst_resm(TWARN,
155f08c3bdfSopenharmony_ci					 "unlink(%s) Failed, errno=%d : %s",
156f08c3bdfSopenharmony_ci					 mname, errno, strerror(errno));
157f08c3bdfSopenharmony_ci			}
158f08c3bdfSopenharmony_ci			SAFE_TOUCH(cleanup, fname, 0700, NULL);
159f08c3bdfSopenharmony_ci		}
160f08c3bdfSopenharmony_ci	}
161f08c3bdfSopenharmony_ci
162f08c3bdfSopenharmony_ci	cleanup();
163f08c3bdfSopenharmony_ci	tst_exit();
164f08c3bdfSopenharmony_ci
165f08c3bdfSopenharmony_ci}
166f08c3bdfSopenharmony_ci
167f08c3bdfSopenharmony_ci/***************************************************************
168f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test.
169f08c3bdfSopenharmony_ci ***************************************************************/
170f08c3bdfSopenharmony_civoid setup(void)
171f08c3bdfSopenharmony_ci{
172f08c3bdfSopenharmony_ci
173f08c3bdfSopenharmony_ci	tst_sig(NOFORK, DEF_HANDLER, cleanup);
174f08c3bdfSopenharmony_ci
175f08c3bdfSopenharmony_ci	TEST_PAUSE;
176f08c3bdfSopenharmony_ci
177f08c3bdfSopenharmony_ci	tst_tmpdir();
178f08c3bdfSopenharmony_ci
179f08c3bdfSopenharmony_ci	sprintf(fname, "./tfile_%d", getpid());
180f08c3bdfSopenharmony_ci	sprintf(mname, "./rnfile_%d", getpid());
181f08c3bdfSopenharmony_ci	SAFE_TOUCH(cleanup, fname, 0700, NULL);
182f08c3bdfSopenharmony_ci}
183f08c3bdfSopenharmony_ci
184f08c3bdfSopenharmony_ci/***************************************************************
185f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test at
186f08c3bdfSopenharmony_ci *		completion or premature exit.
187f08c3bdfSopenharmony_ci ***************************************************************/
188f08c3bdfSopenharmony_civoid cleanup(void)
189f08c3bdfSopenharmony_ci{
190f08c3bdfSopenharmony_ci
191f08c3bdfSopenharmony_ci	tst_rmdir();
192f08c3bdfSopenharmony_ci}
193