blob: 242e4874089b001106adea48dd47e43ca0b00519 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
nstrazfa31d552002-05-14 16:50:06 +000021 * Test Name : symlink05
plars865695b2001-08-27 22:15:12 +000022 *
23 * Test Description :
24 * Verify that, symlink will succeed to creat a symbolic link of an
25 * non-existing object name path.
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
plars865695b2001-08-27 22:15:12 +000027 * Expected Result:
subrata_modak4bb656a2009-02-26 12:02:09 +000028 * symlink() should return value 0 on success and symlink of an
plars865695b2001-08-27 22:15:12 +000029 * 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,
subrata_modakbdbaec52009-02-26 12:14:51 +000043 * Verify the Functionality of system call
plars865695b2001-08-27 22:15:12 +000044 * 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>
nstrazfa31d552002-05-14 16:50:06 +000053 * symlink05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
plars865695b2001-08-27 22:15:12 +000054 * 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"
plars865695b2001-08-27 22:15:12 +000080
81#define TESTFILE "testfile"
82#define SYMFILE "slink_file"
83
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020084char *TCID = "symlink05";
85int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000086
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020087void setup();
88void cleanup();
plars865695b2001-08-27 22:15:12 +000089
subrata_modak56207ce2009-03-23 13:35:39 +000090int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000091{
92 struct stat stat_buf; /* stat structure buffer */
Cyril Hrubis89af32a2012-10-24 16:39:11 +020093 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020094 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000095
Garrett Cooper45e285d2010-11-22 12:19:25 -080096 msg = parse_opts(ac, av, NULL, NULL);
97 if (msg != NULL) {
plars865695b2001-08-27 22:15:12 +000098 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper2c282152010-12-16 00:55:50 -080099
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 }
plars865695b2001-08-27 22:15:12 +0000101
plars865695b2001-08-27 22:15:12 +0000102 setup();
103
plars865695b2001-08-27 22:15:12 +0000104 for (lc = 0; TEST_LOOPING(lc); lc++) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800105
Caspar Zhangd59a6592013-03-07 14:59:12 +0800106 tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000107
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 /*
109 * Call symlink(2) to create a symlink of
plars865695b2001-08-27 22:15:12 +0000110 * an non-existing testfile.
111 */
112 TEST(symlink(TESTFILE, SYMFILE));
subrata_modakbdbaec52009-02-26 12:14:51 +0000113
plars865695b2001-08-27 22:15:12 +0000114 if (TEST_RETURN == -1) {
subrata_modak56207ce2009-03-23 13:35:39 +0000115 tst_resm(TFAIL,
plars865695b2001-08-27 22:15:12 +0000116 "symlink(%s, %s) Failed, errno=%d : %s",
117 TESTFILE, SYMFILE, TEST_ERRNO,
118 strerror(TEST_ERRNO));
119 } else {
120 /*
Cyril Hrubise38b9612014-06-02 17:20:57 +0200121 * Get the symlink file status information
122 * using lstat(2).
plars865695b2001-08-27 22:15:12 +0000123 */
Cyril Hrubise38b9612014-06-02 17:20:57 +0200124 if (lstat(SYMFILE, &stat_buf) < 0) {
125 tst_brkm(TFAIL, cleanup, "lstat(2) of "
126 "%s failed, error:%d",
127 SYMFILE, errno);
128 }
plars865695b2001-08-27 22:15:12 +0000129
Cyril Hrubise38b9612014-06-02 17:20:57 +0200130 /* Check if the st_mode contains a link */
131 if (!S_ISLNK(stat_buf.st_mode)) {
132 tst_resm(TFAIL,
133 "symlink of %s doesn't exist",
134 TESTFILE);
plars865695b2001-08-27 22:15:12 +0000135 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200136 tst_resm(TPASS, "symlink(%s, %s) "
137 "functionality successful",
138 TESTFILE, SYMFILE);
plars865695b2001-08-27 22:15:12 +0000139 }
140 }
141
142 /* Unlink the symlink file for next loop */
143 if (unlink(SYMFILE) == -1) {
144 tst_brkm(TBROK, cleanup,
145 "unlink(%s) Failed, errno=%d : %s",
146 SYMFILE, errno, strerror(errno));
147 }
Caspar Zhangd59a6592013-03-07 14:59:12 +0800148 tst_count++; /* incr TEST_LOOP counter */
Garrett Cooper2c282152010-12-16 00:55:50 -0800149 }
plars865695b2001-08-27 22:15:12 +0000150
plars865695b2001-08-27 22:15:12 +0000151 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800152 tst_exit();
plars865695b2001-08-27 22:15:12 +0000153
Garrett Cooper2c282152010-12-16 00:55:50 -0800154}
plars865695b2001-08-27 22:15:12 +0000155
156/*
157 * void
158 * setup() - performs all ONE TIME setup for this test.
159 * Create a temporary directory and change directory to it.
160 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400161void setup(void)
plars865695b2001-08-27 22:15:12 +0000162{
Garrett Cooper2c282152010-12-16 00:55:50 -0800163
plars865695b2001-08-27 22:15:12 +0000164 tst_sig(NOFORK, DEF_HANDLER, cleanup);
165
166 /* Pause if that option was specified
167 * TEST_PAUSE contains the code to fork the test with the -i option.
168 * You want to make sure you do this before you create your temporary
169 * directory.
170 */
171 TEST_PAUSE;
172
plars865695b2001-08-27 22:15:12 +0000173 tst_tmpdir();
174
Garrett Cooper2c282152010-12-16 00:55:50 -0800175}
plars865695b2001-08-27 22:15:12 +0000176
177/*
178 * void
179 * cleanup() - performs all ONE TIME cleanup for this test at
180 * completion or premature exit.
181 * Remove the temporary directory created in the setup.
182 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400183void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000184{
plars865695b2001-08-27 22:15:12 +0000185
plars865695b2001-08-27 22:15:12 +0000186 tst_rmdir();
187
Chris Dearmanec6edca2012-10-17 19:54:01 -0700188}