plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 21 | * Test Name : symlink05 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Test Description : |
| 24 | * Verify that, symlink will succeed to creat a symbolic link of an |
| 25 | * non-existing object name path. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 27 | * Expected Result: |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * symlink() should return value 0 on success and symlink of an |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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, |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 43 | * Verify the Functionality of system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 53 | * symlink05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
| 81 | #define TESTFILE "testfile" |
| 82 | #define SYMFILE "slink_file" |
| 83 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 84 | char *TCID = "symlink05"; |
| 85 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 87 | void setup(); |
| 88 | void cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | { |
| 92 | struct stat stat_buf; /* stat structure buffer */ |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 93 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 94 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 95 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 96 | msg = parse_opts(ac, av, NULL, NULL); |
| 97 | if (msg != NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 98 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | setup(); |
| 103 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 105 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 106 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 107 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 108 | /* |
| 109 | * Call symlink(2) to create a symlink of |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | * an non-existing testfile. |
| 111 | */ |
| 112 | TEST(symlink(TESTFILE, SYMFILE)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 113 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | tst_resm(TFAIL, |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | "symlink(%s, %s) Failed, errno=%d : %s", |
| 117 | TESTFILE, SYMFILE, TEST_ERRNO, |
| 118 | strerror(TEST_ERRNO)); |
| 119 | } else { |
| 120 | /* |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 121 | * Get the symlink file status information |
| 122 | * using lstat(2). |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | */ |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 124 | if (lstat(SYMFILE, &stat_buf) < 0) { |
| 125 | tst_brkm(TFAIL, cleanup, "lstat(2) of " |
| 126 | "%s failed, error:%d", |
| 127 | SYMFILE, errno); |
| 128 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 130 | /* 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); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 136 | tst_resm(TPASS, "symlink(%s, %s) " |
| 137 | "functionality successful", |
| 138 | TESTFILE, SYMFILE); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | } |
| 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 Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 148 | tst_count++; /* incr TEST_LOOP counter */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 149 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 152 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 153 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 154 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 155 | |
| 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 Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 161 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 163 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 164 | 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 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 173 | tst_tmpdir(); |
| 174 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 175 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 176 | |
| 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 Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 183 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 184 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 185 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 186 | tst_rmdir(); |
| 187 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 188 | } |