• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * Test Name : symlink05
22  *
23  * Test Description :
24  *  Verify that, symlink will succeed to creat a symbolic link of an
25  *  non-existing object name path.
26  *
27  * Expected Result:
28  *  symlink() should return value 0 on success and symlink of an
29  *  non-existing object should be created.
30  *
31  * Algorithm:
32  *  Setup:
33  *   Setup signal handling.
34  *   Create temporary directory.
35  *   Pause for SIGUSR1 if option specified.
36  *
37  *  Test:
38  *   Loop if the proper options are given.
39  *   Execute system call
40  *   Check return code, if system call failed (return=-1)
41  *   	Log the errno and Issue a FAIL message.
42  *   Otherwise,
43  *   	Verify the Functionality of system call
44  *      if successful,
45  *      	Issue Functionality-Pass message.
46  *      Otherwise,
47  *		Issue Functionality-Fail message.
48  *  Cleanup:
49  *   Print errno log and/or timing stats if options given
50  *   Delete the temporary directory created.
51  *
52  * Usage:  <for command-line>
53  *  symlink05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
54  *	where,  -c n : Run n copies concurrently.
55  *		-e   : Turn on errno logging.
56  *		-f   : Turn off functionality Testing.
57  *		-i n : Execute test n times.
58  *		-I x : Execute test for x seconds.
59  *		-P x : Pause for x seconds between iterations.
60  *		-t   : Turn on syscall timing.
61  *
62  * History
63  *	07/2001 John George
64  *		-Ported
65  *
66  * Restrictions:
67  *  This test should be run by 'non-super-user' only.
68  *
69  */
70 
71 #include <stdio.h>
72 #include <sys/types.h>
73 #include <sys/fcntl.h>
74 #include <errno.h>
75 #include <string.h>
76 #include <signal.h>
77 #include <sys/stat.h>
78 
79 #include "test.h"
80 
81 #define  TESTFILE	"testfile"
82 #define  SYMFILE	"slink_file"
83 
84 char *TCID = "symlink05";
85 int TST_TOTAL = 1;
86 
87 void setup();
88 void cleanup();
89 
main(int ac,char ** av)90 int main(int ac, char **av)
91 {
92 	struct stat stat_buf;	/* stat structure buffer */
93 	int lc;
94 
95 	tst_parse_opts(ac, av, NULL, NULL);
96 
97 	setup();
98 
99 	for (lc = 0; TEST_LOOPING(lc); lc++) {
100 
101 		tst_count = 0;
102 
103 		/*
104 		 * Call symlink(2) to create a symlink of
105 		 * an non-existing testfile.
106 		 */
107 		TEST(symlink(TESTFILE, SYMFILE));
108 
109 		if (TEST_RETURN == -1) {
110 			tst_resm(TFAIL,
111 				 "symlink(%s, %s) Failed, errno=%d : %s",
112 				 TESTFILE, SYMFILE, TEST_ERRNO,
113 				 strerror(TEST_ERRNO));
114 		} else {
115 			/*
116 			 * Get the symlink file status information
117 			 * using lstat(2).
118 			 */
119 			if (lstat(SYMFILE, &stat_buf) < 0) {
120 				tst_brkm(TFAIL, cleanup, "lstat(2) of "
121 					 "%s failed, error:%d",
122 					 SYMFILE, errno);
123 			}
124 
125 			/* Check if the st_mode contains a link  */
126 			if (!S_ISLNK(stat_buf.st_mode)) {
127 				tst_resm(TFAIL,
128 					 "symlink of %s doesn't exist",
129 					 TESTFILE);
130 			} else {
131 				tst_resm(TPASS, "symlink(%s, %s) "
132 					 "functionality successful",
133 					 TESTFILE, SYMFILE);
134 			}
135 		}
136 
137 		/* Unlink the symlink file for next loop */
138 		if (unlink(SYMFILE) == -1) {
139 			tst_brkm(TBROK, cleanup,
140 				 "unlink(%s) Failed, errno=%d : %s",
141 				 SYMFILE, errno, strerror(errno));
142 		}
143 		tst_count++;	/* incr TEST_LOOP counter */
144 	}
145 
146 	cleanup();
147 	tst_exit();
148 
149 }
150 
151 /*
152  * void
153  * setup() - performs all ONE TIME setup for this test.
154  *  Create a temporary directory and change directory to it.
155  */
setup(void)156 void setup(void)
157 {
158 
159 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
160 
161 	/* Pause if that option was specified
162 	 * TEST_PAUSE contains the code to fork the test with the -i option.
163 	 * You want to make sure you do this before you create your temporary
164 	 * directory.
165 	 */
166 	TEST_PAUSE;
167 
168 	tst_tmpdir();
169 
170 }
171 
172 /*
173  * void
174  * cleanup() - performs all ONE TIME cleanup for this test at
175  *             completion or premature exit.
176  *  Remove the temporary directory created in the setup.
177  */
cleanup(void)178 void cleanup(void)
179 {
180 
181 	tst_rmdir();
182 
183 }
184