plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 33 | /* $Id: stat06.c,v 1.10 2009/11/02 13:57:19 subrata_modak Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 35 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | * OS Test - Silicon Graphics, Inc. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | * TEST IDENTIFIER : stat06 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 39 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | * TEST TITLE : stat(2) negative path testcases |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 43 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | * PARENT DOCUMENT : None |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 45 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | * TEST CASE TOTAL : 7 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | * WALL CLOCK TIME : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | * CPU TYPES : ALL |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | * AUTHOR : Richard Logan |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | * CO-PILOT : William Roske |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 55 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | * DATE STARTED : 03/30/94 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | * INITIAL RELEASE : UNICOS 7.0 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 59 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | * TEST CASES |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 61 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | * 1-7) See Testcases structure below. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 63 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | * INPUT SPECIFICATIONS |
| 65 | * The standard options for system call tests are accepted. |
| 66 | * (See the parse_opts(3) man page). |
| 67 | * -h : print help and exit |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 68 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | * OUTPUT SPECIFICATIONS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | *$ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | * DURATION |
| 72 | * Terminates - with frequency and infinite modes. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 73 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | * SIGNALS |
| 75 | * Uses SIGUSR1 to pause before test if option set. |
| 76 | * (See the parse_opts(3) man page). |
| 77 | * |
| 78 | * RESOURCES |
| 79 | * None |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 80 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | * ENVIRONMENTAL NEEDS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 82 | * The libcuts.a and libsys.a libraries must be included in |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | * the compilation of this test. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 84 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | * SPECIAL PROCEDURAL REQUIREMENTS |
| 86 | * None |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 87 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | * INTERCASE DEPENDENCIES |
| 89 | * None |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 90 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | * DETAILED DESCRIPTION |
| 92 | * This is a Phase I test for the stat(2) system call. It is intended |
| 93 | * to provide a limited exposure of the system call, for now. It |
| 94 | * should/will be extended when full functional tests are written for |
| 95 | * stat(2). |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 96 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | * Setup: |
| 98 | * Setup signal handling. |
| 99 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 100 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | * Test: |
| 102 | * Loop if the proper options are given. |
| 103 | * Execute system call |
| 104 | * Check return code, if system call failed (return=-1) |
| 105 | * Log the errno and Issue a FAIL message. |
| 106 | * Otherwise, Issue a PASS message. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 107 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | * Cleanup: |
| 109 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 110 | * |
| 111 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 113 | |
| 114 | #include <sys/types.h> |
| 115 | #include <sys/fcntl.h> |
| 116 | #include <sys/stat.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 117 | #include <sys/mman.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | #include <errno.h> |
| 119 | #include <string.h> |
| 120 | #include <signal.h> |
| 121 | #include <setjmp.h> |
| 122 | #include <unistd.h> |
| 123 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | |
| 125 | void setup(); |
| 126 | void cleanup(); |
| 127 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 128 | char *TCID = "stat06"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | char *bad_addr = 0; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 131 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 132 | #if !defined(UCLINUX) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | int high_address_setup(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 134 | char High_address[64]; |
| 135 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 136 | int longpath_setup(); |
| 137 | int no_setup(); |
| 138 | int filepath_setup(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | char Longpathname[PATH_MAX + 2]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 140 | struct stat statbuf; |
| 141 | jmp_buf sig11_recover; |
| 142 | void sig11_handler(int sig); |
| 143 | |
| 144 | struct test_case_t { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | char *pathname; |
| 146 | struct stat *stbuf; |
| 147 | char *desc; |
| 148 | int exp_errno; |
| 149 | int (*setupfunc) (); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 150 | } Test_cases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | { |
| 152 | "nonexistfile", &statbuf, "non-existent file", ENOENT, no_setup}, { |
| 153 | "", &statbuf, "path is empty string", ENOENT, no_setup}, { |
| 154 | "nefile/file", &statbuf, "path contains a non-existent file", |
| 155 | ENOENT, no_setup}, { |
| 156 | "file/file", &statbuf, "path contains a regular file", |
| 157 | ENOTDIR, filepath_setup}, { |
| 158 | Longpathname, &statbuf, "pathname too long", ENAMETOOLONG, |
| 159 | longpath_setup}, |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 160 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | { |
| 162 | High_address, &statbuf, "address beyond address space", EFAULT, |
| 163 | high_address_setup}, { |
| 164 | (char *)-1, &statbuf, "negative address", EFAULT, no_setup}, |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 165 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | { |
| 167 | NULL, NULL, NULL, 0, no_setup} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 168 | }; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 169 | |
Cyril Hrubis | b863a0b | 2014-09-24 13:15:29 +0200 | [diff] [blame] | 170 | int TST_TOTAL = ARRAY_SIZE(Test_cases); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 171 | |
| 172 | /*********************************************************************** |
| 173 | * Main |
| 174 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 176 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 177 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 178 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | char *fname; |
| 180 | char *desc; |
| 181 | int ind; |
| 182 | struct stat *stbuf; |
| 183 | struct sigaction sa, osa; |
| 184 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 185 | /*************************************************************** |
| 186 | * parse standard options |
| 187 | ***************************************************************/ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 188 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 189 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 191 | |
| 192 | /*************************************************************** |
| 193 | * perform global setup for test |
| 194 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 196 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 197 | /*************************************************************** |
| 198 | * check looping state if -c option given |
| 199 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 200 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 201 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 202 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 203 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 204 | for (ind = 0; Test_cases[ind].desc != NULL; ind++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 205 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 206 | fname = Test_cases[ind].pathname; |
| 207 | desc = Test_cases[ind].desc; |
| 208 | stbuf = Test_cases[ind].stbuf; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 209 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 210 | if (stbuf == (struct stat *)-1) { |
| 211 | /* special sig11 case */ |
| 212 | sa.sa_handler = &sig11_handler; |
| 213 | sigemptyset(&sa.sa_mask); |
| 214 | sa.sa_flags = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 216 | sigaction(SIGSEGV, NULL, &osa); |
| 217 | sigaction(SIGSEGV, &sa, NULL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 218 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | if (setjmp(sig11_recover)) { |
| 220 | TEST_RETURN = -1; |
| 221 | TEST_ERRNO = EFAULT; |
| 222 | } else { |
| 223 | TEST(stat(fname, stbuf)); |
| 224 | } |
| 225 | sigaction(SIGSEGV, &osa, NULL); |
| 226 | } else { |
| 227 | /* |
| 228 | * Call stat(2) |
| 229 | */ |
| 230 | |
| 231 | TEST(stat(fname, stbuf)); |
| 232 | } |
| 233 | |
| 234 | /* check return code */ |
| 235 | if (TEST_RETURN == -1) { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 236 | if (TEST_ERRNO == |
| 237 | Test_cases[ind].exp_errno) |
| 238 | tst_resm(TPASS, |
| 239 | "stat(<%s>, &stbuf) Failed, errno=%d", |
| 240 | desc, TEST_ERRNO); |
| 241 | else |
| 242 | tst_resm(TFAIL, |
| 243 | "stat(<%s>, &stbuf) Failed, errno=%d, expected errno:%d", |
| 244 | desc, TEST_ERRNO, |
| 245 | Test_cases |
| 246 | [ind].exp_errno); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 247 | } else { |
| 248 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 249 | "stat(<%s>, &stbuf) returned %ld, expected -1, errno:%d", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 250 | desc, TEST_RETURN, |
| 251 | Test_cases[ind].exp_errno); |
| 252 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 253 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 254 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 255 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 256 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 257 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 258 | tst_exit(); |
| 259 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 260 | |
| 261 | /*************************************************************** |
| 262 | * setup() - performs all ONE TIME setup for this test. |
| 263 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 264 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 265 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 266 | int ind; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 267 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 268 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 269 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 270 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 271 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 272 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 273 | |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 274 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 275 | bad_addr = mmap(0, 1, PROT_NONE, |
| 276 | MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); |
| 277 | if (bad_addr == MAP_FAILED) { |
| 278 | tst_brkm(TBROK, cleanup, "mmap failed"); |
| 279 | } |
| 280 | Test_cases[6].pathname = bad_addr; |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 281 | #endif |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 282 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 283 | for (ind = 0; Test_cases[ind].desc != NULL; ind++) { |
| 284 | Test_cases[ind].setupfunc(); |
| 285 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 286 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 287 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 288 | |
| 289 | /*************************************************************** |
| 290 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 291 | * completion or premature exit. |
| 292 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 293 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 294 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 295 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 296 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 297 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 298 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 299 | |
| 300 | /****************************************************************** |
| 301 | * no_setup() - does nothing |
| 302 | ******************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 303 | int no_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 304 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 305 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 306 | } |
| 307 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 308 | #if !defined(UCLINUX) |
| 309 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 310 | /****************************************************************** |
| 311 | * high_address_setup() - generates an address that should cause a segfault |
| 312 | ******************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 313 | int high_address_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 314 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 315 | int ind; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 316 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 317 | for (ind = 0; Test_cases[ind].desc != NULL; ind++) { |
| 318 | if (Test_cases[ind].pathname == High_address) { |
Garrett Cooper | 8fb1cdb | 2010-11-28 22:56:35 -0800 | [diff] [blame] | 319 | /*if (strcmp(Test_cases[ind].pathname, HIGH_ADDRESS) == 0) { ** */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 320 | Test_cases[ind].pathname = (char *)(sbrk(0) + 5); |
| 321 | break; |
| 322 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 323 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 324 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 325 | |
| 326 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 327 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 328 | |
| 329 | /****************************************************************** |
| 330 | * longpath_setup() - creates a filename that is too long |
| 331 | ******************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 332 | int longpath_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 333 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 334 | int ind; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 335 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 336 | for (ind = 0; ind <= PATH_MAX + 1; ind++) { |
| 337 | Longpathname[ind] = 'a'; |
| 338 | } |
| 339 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 340 | |
| 341 | } |
| 342 | |
| 343 | /****************************************************************** |
| 344 | * filepath_setup() creates a file the exists that we will treat as a directory |
| 345 | ******************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 346 | int filepath_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 347 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 348 | int fd; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 349 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 350 | if ((fd = creat("file", 0777)) == -1) { |
| 351 | tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s", |
| 352 | errno, strerror(errno)); |
| 353 | } |
| 354 | close(fd); |
| 355 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /****************************************************************** |
| 359 | * sig11_handler() - our segfault recover hack |
| 360 | ******************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 361 | void sig11_handler(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 362 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 363 | longjmp(sig11_recover, 1); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 364 | } |