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 <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 #include "safe_macros.h"
81
82 #define TESTFILE "testfile"
83 #define SYMFILE "slink_file"
84
85 char *TCID = "symlink05";
86 int TST_TOTAL = 1;
87
88 void setup();
89 void cleanup();
90
main(int ac,char ** av)91 int main(int ac, char **av)
92 {
93 struct stat stat_buf; /* stat structure buffer */
94 int lc;
95
96 tst_parse_opts(ac, av, NULL, NULL);
97
98 setup();
99
100 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
102 tst_count = 0;
103
104 /*
105 * Call symlink(2) to create a symlink of
106 * an non-existing testfile.
107 */
108 TEST(symlink(TESTFILE, SYMFILE));
109
110 if (TEST_RETURN == -1) {
111 tst_resm(TFAIL,
112 "symlink(%s, %s) Failed, errno=%d : %s",
113 TESTFILE, SYMFILE, TEST_ERRNO,
114 strerror(TEST_ERRNO));
115 } else {
116 /*
117 * Get the symlink file status information
118 * using lstat(2).
119 */
120 if (lstat(SYMFILE, &stat_buf) < 0) {
121 tst_brkm(TFAIL, cleanup, "lstat(2) of "
122 "%s failed, error:%d",
123 SYMFILE, errno);
124 }
125
126 /* Check if the st_mode contains a link */
127 if (!S_ISLNK(stat_buf.st_mode)) {
128 tst_resm(TFAIL,
129 "symlink of %s doesn't exist",
130 TESTFILE);
131 } else {
132 tst_resm(TPASS, "symlink(%s, %s) "
133 "functionality successful",
134 TESTFILE, SYMFILE);
135 }
136 }
137
138 /* Unlink the symlink file for next loop */
139 SAFE_UNLINK(cleanup, SYMFILE);
140 tst_count++; /* incr TEST_LOOP counter */
141 }
142
143 cleanup();
144 tst_exit();
145
146 }
147
148 /*
149 * void
150 * setup() - performs all ONE TIME setup for this test.
151 * Create a temporary directory and change directory to it.
152 */
setup(void)153 void setup(void)
154 {
155
156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
157
158 /* Pause if that option was specified
159 * TEST_PAUSE contains the code to fork the test with the -i option.
160 * You want to make sure you do this before you create your temporary
161 * directory.
162 */
163 TEST_PAUSE;
164
165 tst_tmpdir();
166
167 }
168
169 /*
170 * void
171 * cleanup() - performs all ONE TIME cleanup for this test at
172 * completion or premature exit.
173 * Remove the temporary directory created in the setup.
174 */
cleanup(void)175 void cleanup(void)
176 {
177
178 tst_rmdir();
179
180 }
181