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 : symlink04 |
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 existing |
| 25 | * 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: |
| 28 | * symlink() should return value 0 on success and symbolic link of an |
| 29 | * 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 | * symlink04 [-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 | * None. |
| 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 | #include "test.h" |
| 79 | #include "usctest.h" |
| 80 | |
| 81 | #define TESTFILE "testfile" |
| 82 | #define SYMFILE "slink_file" |
| 83 | #define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH |
| 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | char *TCID = "symlink04"; /* Test program identifier. */ |
| 86 | int TST_TOTAL = 1; /* Total number of test cases. */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | int exp_enos[] = { 0 }; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | void setup(); /* Setup function for the test */ |
| 90 | void cleanup(); /* Cleanup function for the test */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | { |
| 94 | struct stat stat_buf; /* stat structure buffer */ |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 95 | int lc; |
| 96 | char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | |
| 98 | /* Parse standard options given to run the test. */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 99 | msg = parse_opts(ac, av, NULL, NULL); |
| 100 | if (msg != NULL) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 102 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | setup(); |
| 106 | |
| 107 | /* set the expected errnos... */ |
| 108 | TEST_EXP_ENOS(exp_enos); |
| 109 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 111 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame^] | 112 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 113 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Call symlink(2) to create a symlink of |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | * testfile. |
| 117 | */ |
| 118 | TEST(symlink(TESTFILE, SYMFILE)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 119 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | if (TEST_RETURN == -1) { |
| 121 | TEST_ERROR_LOG(TEST_ERRNO); |
| 122 | tst_resm(TFAIL, "symlink(%s, %s) Failed, errno=%d : %s", |
| 123 | TESTFILE, SYMFILE, TEST_ERRNO, |
| 124 | strerror(TEST_ERRNO)); |
| 125 | } else { |
| 126 | /* |
| 127 | * Perform functional verification if test |
| 128 | * executed without (-f) option. |
| 129 | */ |
| 130 | if (STD_FUNCTIONAL_TEST) { |
| 131 | /* |
| 132 | * Get the symlink file status information |
| 133 | * using lstat(2). |
| 134 | */ |
| 135 | if (lstat(SYMFILE, &stat_buf) < 0) { |
| 136 | tst_brkm(TFAIL, cleanup, "lstat(2) of " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 137 | "%s failed, error:%d", SYMFILE, |
| 138 | errno); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | |
| 141 | /* Check if the st_mode contains a link */ |
| 142 | if (!S_ISLNK(stat_buf.st_mode)) { |
| 143 | tst_resm(TFAIL, |
| 144 | "symlink of %s doesn't exist", |
| 145 | TESTFILE); |
| 146 | } else { |
| 147 | tst_resm(TPASS, "symlink(%s, %s) " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | "functionality successful", |
| 149 | TESTFILE, SYMFILE); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | } |
| 151 | } else { |
| 152 | tst_resm(TPASS, "Call succeeded"); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* Unlink the symlink file for next loop */ |
| 157 | if (unlink(SYMFILE) == -1) { |
| 158 | tst_brkm(TBROK, cleanup, |
| 159 | "unlink(%s) Failed, errno=%d : %s", |
| 160 | SYMFILE, errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 161 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame^] | 162 | tst_count++; /* incr TEST_LOOP counter */ |
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 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 165 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 166 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 168 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * void |
| 172 | * setup() - performs all ONE TIME setup for this test. |
| 173 | * Create a temporary directory and change directory to it. |
| 174 | * Create a test file under temporary directory and close it |
| 175 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 176 | void setup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 177 | { |
| 178 | int fd; /* file handle for testfile */ |
| 179 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 180 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 181 | |
| 182 | /* Pause if that option was specified |
| 183 | * TEST_PAUSE contains the code to fork the test with the -i option. |
| 184 | * You want to make sure you do this before you create your temporary |
| 185 | * directory. |
| 186 | */ |
| 187 | TEST_PAUSE; |
| 188 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 189 | tst_tmpdir(); |
| 190 | |
| 191 | /* creat/open a testfile */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 192 | if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 193 | tst_brkm(TBROK, cleanup, |
| 194 | "open(%s, O_RDWR|O_CREAT, %#o) Failed, errno=%d : %s", |
| 195 | TESTFILE, FILE_MODE, errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 197 | |
| 198 | /* Close the temporary file created above */ |
| 199 | if (close(fd) == -1) { |
| 200 | tst_resm(TBROK, "close(%s) Failed, errno=%d : %s", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 201 | TESTFILE, errno, strerror(errno)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 202 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 203 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * void |
| 207 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 208 | * completion or premature exit. |
| 209 | * Remove the test directory and testfile created in the setup. |
| 210 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 211 | void cleanup() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 212 | { |
| 213 | /* |
| 214 | * print timing stats if that option was specified. |
| 215 | * print errno log if that option was specified. |
| 216 | */ |
| 217 | TEST_CLEANUP; |
| 218 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 219 | tst_rmdir(); |
| 220 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 221 | } |