robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 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 |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* 10/31/2002 Port to LTP robbiew@us.ibm.com */ |
| 21 | /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ |
| 22 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 23 | /* inode1.c */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 24 | /*====================================================================== |
| 25 | =================== TESTPLAN SEGMENT =================== |
| 26 | CALLS: mkdir, stat, open |
| 27 | |
| 28 | run using TERM mode |
| 29 | |
| 30 | >KEYS: < file system management I/O |
| 31 | >WHAT: < Do the system's file system management and I/O functions work |
| 32 | < correctly? |
| 33 | >HOW: < Construct a directory tree, create files in it, and verify |
| 34 | < that this was done as expected. |
| 35 | >BUGS: < |
| 36 | ======================================================================*/ |
| 37 | /* modified by dale 25-Jul-84 */ |
| 38 | |
| 39 | /************************************************/ |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 40 | #define PATH_STRING_LENGTH 100 |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 41 | #define NAME_LENGTH 8 |
| 42 | #define MAX_PATH_STRING_LENGTH (PATH_STRING_LENGTH - NAME_LENGTH) |
| 43 | #define MAX_DEPTH 3 |
| 44 | #define MAX_BREADTH 3 |
| 45 | #define FILE_LENGTH 100 |
| 46 | #define DIRECTORY_MODE 00777 |
| 47 | #define FILE_MODE 00777 |
| 48 | |
| 49 | /* #define PRINT define to get list while running */ |
| 50 | |
| 51 | #define TRUE 1 |
| 52 | #define FALSE 0 |
| 53 | #define READ 0 |
| 54 | #define WRITE 1 |
| 55 | |
| 56 | #include <stdio.h> |
robbiew | a70576c | 2003-03-04 18:33:41 +0000 | [diff] [blame] | 57 | #include <errno.h> |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 58 | #include <sys/types.h> |
| 59 | #include <sys/stat.h> |
| 60 | #include <fcntl.h> |
| 61 | #include <signal.h> |
| 62 | #include <errno.h> |
| 63 | |
| 64 | /** LTP Port **/ |
| 65 | #include "test.h" |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 66 | |
| 67 | void blexit(void); |
| 68 | void blenter(void); |
| 69 | void setup(void); |
| 70 | void fail_exit(void); |
| 71 | void anyfail(void); |
| 72 | void ok_exit(void); |
| 73 | |
| 74 | #define FAILED 0 |
| 75 | #define PASSED 1 |
| 76 | |
| 77 | int local_flag = PASSED; |
| 78 | int block_number; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 79 | FILE *temp; |
| 80 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | char *TCID = "inode01"; /* Test program identifier. */ |
| 82 | int TST_TOTAL = 2; /* Total number of test cases. */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 83 | /**************/ |
| 84 | |
| 85 | #ifdef LINUX |
| 86 | #include <string.h> |
| 87 | #endif |
| 88 | |
| 89 | char name[NAME_LENGTH + 1]; |
| 90 | char path_string[PATH_STRING_LENGTH + 1]; |
| 91 | char read_string[PATH_STRING_LENGTH + 1]; |
| 92 | char write_string[PATH_STRING_LENGTH + 1]; |
| 93 | char rm_string[200]; |
| 94 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | FILE *list_stream = NULL; |
| 96 | int file_id; |
| 97 | int list_id; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 98 | |
| 99 | int increment_name(), get_next_name(), mode(), escrivez(); |
| 100 | |
| 101 | int main() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 102 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | char root[16]; //as pids can get much longer |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 104 | int gen_ret_val, ch_ret_val, level; |
| 105 | int ret_val; |
| 106 | int generate(), check(); |
subrata_modak | 7523e3b | 2008-10-17 10:03:54 +0000 | [diff] [blame] | 107 | char path_list_string[PATH_STRING_LENGTH + 1]; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 108 | int status; |
| 109 | int len; |
| 110 | int term(); |
Jan Stancek | cb7c691 | 2013-03-20 10:44:33 +0100 | [diff] [blame] | 111 | int snp_ret; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 112 | |
| 113 | strcpy(path_string, "inode"); |
| 114 | sprintf(root, "A%d", getpid()); |
| 115 | strcat(path_string, root); |
| 116 | |
| 117 | strcpy(rm_string, "rm -rf "); |
| 118 | strcat(rm_string, path_string); |
| 119 | |
| 120 | setup(); |
| 121 | |
| 122 | if (signal(SIGTERM, (void (*)())term) == SIG_ERR) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 123 | fprintf(temp, "\tSIGTERM signal set failed!, errno=%d\n", |
| 124 | errno); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 125 | fail_exit(); |
| 126 | } |
| 127 | |
| 128 | blenter(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 129 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 130 | /********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 131 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 132 | /* make the root directory for */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 133 | /* the tree */ |
| 134 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 135 | /********************************/ |
| 136 | |
| 137 | ret_val = mkdir(path_string, DIRECTORY_MODE); |
| 138 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 139 | if (ret_val == -1) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 140 | perror("mkdir error"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 141 | fprintf(temp, "\tcreating directory '%s'\n", path_string); |
| 142 | fprintf(temp, "\t\n%s Impossible to create directory %s\n", |
| 143 | root, path_string); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 144 | fail_exit(); |
| 145 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 146 | #ifdef PRINT |
| 147 | printf("\n%s\n", path_string); |
| 148 | #endif |
| 149 | |
| 150 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | /* */ |
| 152 | /* create the "path_list" file, in */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 153 | /* which the list of generated paths */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | /* will be stored so that they later */ |
| 155 | /* may be checked */ |
| 156 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 157 | /****************************************/ |
| 158 | |
Jan Stancek | cb7c691 | 2013-03-20 10:44:33 +0100 | [diff] [blame] | 159 | snp_ret = snprintf(path_list_string, sizeof(path_list_string), |
| 160 | "%s/path_list", path_string); |
| 161 | if (snp_ret < 0 || snp_ret >= sizeof(path_list_string)) { |
| 162 | tst_resm(TBROK, "snprintf(path_list_string,..) returned %d", |
| 163 | snp_ret); |
| 164 | fail_exit(); |
| 165 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 166 | list_id = creat(path_list_string, FILE_MODE); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 167 | if (list_id == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 168 | fprintf(temp, |
| 169 | "\t\n%s The path_list file cannot be created, errno=%d \n", |
| 170 | root, errno); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 171 | fail_exit(); |
| 172 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 173 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 174 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | /* */ |
| 176 | /* and store its name in path_list */ |
| 177 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 178 | /****************************************/ |
| 179 | |
| 180 | strcpy(write_string, path_string); |
| 181 | len = strlen(write_string); |
| 182 | write_string[len++] = 'D'; |
| 183 | write_string[len] = '\0'; |
| 184 | escrivez(write_string); |
| 185 | |
| 186 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 187 | /* */ |
| 188 | /* generate the directory-file tree */ |
| 189 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 190 | /****************************************/ |
| 191 | |
| 192 | level = 0; |
| 193 | |
| 194 | #ifdef PRINT |
| 195 | printf("\n\t%s\n\n", "GENERATING:"); |
| 196 | #endif |
| 197 | |
| 198 | gen_ret_val = generate(path_string, level); |
| 199 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 200 | if (gen_ret_val) { |
| 201 | fprintf(temp, |
| 202 | "Failure occured in generate routine, return value %d\n", |
| 203 | gen_ret_val); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 204 | local_flag = FAILED; |
| 205 | } |
| 206 | |
| 207 | blexit(); |
| 208 | blenter(); |
| 209 | |
| 210 | close(list_id); |
| 211 | list_id = open(path_list_string, READ); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 212 | if (list_id == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 213 | fprintf(temp, |
| 214 | "\t\n%s The path_list file cannot be opened for reading, errno=%d\n", |
| 215 | root, errno); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 216 | fail_exit(); |
| 217 | } |
| 218 | list_stream = fdopen(list_id, "r"); |
| 219 | |
| 220 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 221 | /* */ |
| 222 | /* check the directory-file tree */ |
| 223 | /* for correctness */ |
| 224 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 225 | /****************************************/ |
| 226 | |
| 227 | #ifdef PRINT |
| 228 | printf("\n\t%s\n\n", "CHECKING:"); |
| 229 | #endif |
| 230 | |
| 231 | ch_ret_val = check(); |
| 232 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 233 | if (ch_ret_val) { |
| 234 | fprintf(temp, |
| 235 | "Failure occured in check routine, return value %d\n", |
| 236 | ch_ret_val); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 237 | local_flag = FAILED; |
| 238 | } |
| 239 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 240 | status = fclose(list_stream); |
| 241 | if (status != 0) { |
| 242 | fprintf(temp, |
| 243 | "Failed to close list_stream: ret=%d errno=%d (%s)\n", |
| 244 | status, errno, strerror(errno)); |
| 245 | local_flag = FAILED; |
| 246 | } |
robbiew | 5c367e4 | 2005-12-23 18:16:06 +0000 | [diff] [blame] | 247 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 248 | blexit(); |
| 249 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 250 | /* |
| 251 | * Now fork and exec a system call to remove the directory. |
| 252 | */ |
| 253 | |
| 254 | #ifdef DEBUG |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 255 | fprintf(temp, "\nClean up:\trm string = %s\n", rm_string); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 256 | #endif |
| 257 | fflush(stdout); |
| 258 | fflush(temp); |
| 259 | |
| 260 | status = system(rm_string); |
| 261 | |
| 262 | if (status) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 263 | fprintf(temp, "Caution-``%s'' may have failed\n", rm_string); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 264 | fprintf(temp, "rm command exit status = %d\n", status); |
| 265 | } |
| 266 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 267 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 268 | /* */ |
| 269 | /* .....and exit main */ |
| 270 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 271 | /****************************************/ |
| 272 | |
| 273 | anyfail(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 274 | /***** NOT REACHED ******/ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 275 | tst_exit(); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | int generate(string, level) |
| 279 | |
| 280 | /****************************************/ |
| 281 | /* */ |
| 282 | /* generate recursively a tree of */ |
| 283 | /* directories and files: within */ |
| 284 | /* created directory, an alternating */ |
| 285 | /* series of files and directories */ |
| 286 | /* are constructed---until tree */ |
| 287 | /* breadth and depth limits are */ |
| 288 | /* reached or an error occurs */ |
| 289 | /* */ |
| 290 | /****************************************/ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 291 | /***************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 292 | /* */ |
| 293 | char string[]; /* the directory path */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 294 | /* string below which a */ |
| 295 | /* tree is generated */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 296 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 297 | /***************************/ |
| 298 | |
| 299 | /***************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 300 | /* */ |
| 301 | int level; /* the tree depth variable */ |
| 302 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 303 | /***************************/ |
| 304 | { |
| 305 | int switch_flag; |
| 306 | int ret_val = 0; |
| 307 | int new_ret_val, len, ret_len; |
| 308 | char new_string[PATH_STRING_LENGTH + 1]; |
| 309 | int new_level; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 310 | int i, j; /* iteration counters */ |
Jan Stancek | cb7c691 | 2013-03-20 10:44:33 +0100 | [diff] [blame] | 311 | int snp_ret; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 312 | |
| 313 | switch_flag = level & TRUE; |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 314 | if (strlen(string) >= MAX_PATH_STRING_LENGTH) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 315 | |
| 316 | /********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 317 | /* */ |
| 318 | /* Maximum path name length */ |
| 319 | /* reached */ |
| 320 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 321 | /********************************/ |
| 322 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 323 | fprintf(temp, "\tMaximum path_name length reached.\n"); |
| 324 | return (-1); |
| 325 | } else if (level < MAX_DEPTH) { |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 326 | for (i = 0; i <= MAX_BREADTH; i++) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 327 | get_next_name(); |
Jan Stancek | cb7c691 | 2013-03-20 10:44:33 +0100 | [diff] [blame] | 328 | snp_ret = snprintf(new_string, sizeof(new_string), |
| 329 | "%s/%s", string, name); |
| 330 | if (snp_ret < 0 || snp_ret >= sizeof(new_string)) { |
| 331 | tst_resm(TBROK, "snprintf(new_string,..) " |
| 332 | "returned %d", snp_ret); |
| 333 | fail_exit(); |
| 334 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 335 | |
| 336 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 337 | /* */ |
| 338 | /* switch between creating files */ |
| 339 | /* and making directories */ |
| 340 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 341 | /****************************************/ |
| 342 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 343 | if (switch_flag) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 344 | switch_flag = FALSE; |
| 345 | |
| 346 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 347 | /* */ |
| 348 | /* create a new file */ |
| 349 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 350 | /****************************************/ |
| 351 | |
| 352 | file_id = creat(new_string, FILE_MODE); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 353 | if (file_id == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 354 | fprintf(temp, |
| 355 | "\tImpossible to create file %s, errno=%d\n", |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 356 | new_string, errno); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 357 | return (-2); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 358 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 359 | #ifdef PRINT |
| 360 | printf("%d %s F\n", level, new_string); |
| 361 | #endif |
| 362 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 363 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 364 | /* */ |
| 365 | /* write to it */ |
| 366 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 367 | /****************************************/ |
| 368 | |
| 369 | len = strlen(new_string); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 370 | for (j = 1; j <= FILE_LENGTH; j++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 371 | ret_len = |
| 372 | write(file_id, new_string, len); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 373 | if (ret_len != len) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 374 | fprintf(temp, |
| 375 | "\tUnsuccessful write to file %s, expected return of %d, got %d, errno=%d\n", |
| 376 | new_string, len, |
| 377 | ret_len, errno); |
| 378 | return (-3); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 379 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 380 | } |
| 381 | close(file_id); |
| 382 | |
| 383 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 384 | /* */ |
| 385 | /* and store its name in path_list */ |
| 386 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 387 | /****************************************/ |
| 388 | |
| 389 | strcpy(write_string, new_string); |
| 390 | len = strlen(write_string); |
| 391 | write_string[len++] = 'F'; |
| 392 | write_string[len] = '\0'; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 393 | escrivez(write_string); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 394 | } else { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 395 | switch_flag = TRUE; |
| 396 | |
| 397 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 398 | /* */ |
| 399 | /* or make a directory */ |
| 400 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 401 | /****************************************/ |
| 402 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 403 | ret_val = mkdir(new_string, DIRECTORY_MODE); |
| 404 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 405 | if (ret_val != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 406 | fprintf(temp, |
| 407 | "\tImpossible to create directory %s, errno=%d\n", |
| 408 | new_string, errno); |
| 409 | return (-5); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 410 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 411 | #ifdef PRINT |
| 412 | printf("%d %s D\n", level, new_string); |
| 413 | #endif |
| 414 | |
| 415 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 416 | /* */ |
| 417 | /* store its name in path_list */ |
| 418 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 419 | /****************************************/ |
| 420 | |
| 421 | strcpy(write_string, new_string); |
| 422 | len = strlen(write_string); |
| 423 | write_string[len++] = 'D'; |
| 424 | write_string[len] = '\0'; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 425 | escrivez(write_string); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 426 | |
| 427 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 428 | /* */ |
| 429 | /* and generate a new level */ |
| 430 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 431 | /****************************************/ |
| 432 | |
| 433 | new_level = level + 1; |
| 434 | new_ret_val = generate(new_string, new_level); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 435 | if (new_ret_val < ret_val) |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 436 | ret_val = new_ret_val; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | /********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 441 | /* */ |
| 442 | /* Maximum breadth reached */ |
| 443 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 444 | /********************************/ |
| 445 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 446 | return (ret_val); |
| 447 | } else |
| 448 | /********************************/ |
| 449 | /* */ |
| 450 | /* Maximum depth reached */ |
| 451 | /* */ |
| 452 | /********************************/ |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 453 | return 0; |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 454 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 455 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 456 | int check() |
| 457 | |
| 458 | /****************************************/ |
| 459 | /* */ |
| 460 | /* check for file and directory */ |
| 461 | /* correctness by reading records */ |
| 462 | /* from the path_list and attempting */ |
| 463 | /* to determine if the corresponding */ |
| 464 | /* files or directories are as */ |
| 465 | /* created */ |
| 466 | /* */ |
| 467 | /****************************************/ |
| 468 | { |
| 469 | int len, path_mode, val, ret_len, j; |
| 470 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 471 | for (;;) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 472 | |
| 473 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 474 | /* */ |
| 475 | /* read a path string from path_list */ |
| 476 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 477 | /****************************************/ |
| 478 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 479 | if (fscanf(list_stream, "%s", path_string) == EOF) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 480 | |
| 481 | #ifdef PRINT |
| 482 | printf("\nEnd of path_list file reached \n"); |
| 483 | #endif |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 484 | |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 485 | return 0; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 486 | } |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 487 | #ifdef PRINT |
| 488 | printf("%s\n", path_string); |
| 489 | #endif |
| 490 | |
| 491 | len = strlen(path_string); |
| 492 | len--; |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 493 | if (path_string[len] == 'F') { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 494 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 495 | /********************************/ |
| 496 | /* */ |
| 497 | /* this should be a file */ |
| 498 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 499 | /********************************/ |
| 500 | |
| 501 | path_string[len] = '\0'; |
| 502 | file_id = open(path_string, READ); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 503 | if (file_id <= 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 504 | fprintf(temp, |
| 505 | "\tImpossible to open file %s, errno=%d\n", |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 506 | path_string, errno); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 507 | return (-1); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 508 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 509 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 510 | else { |
| 511 | /********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 512 | /* */ |
| 513 | /* check its contents */ |
| 514 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 515 | /********************************/ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 516 | |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 517 | len = strlen(path_string); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 518 | for (j = 1; j <= FILE_LENGTH; j++) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 519 | ret_len = |
| 520 | read(file_id, read_string, len); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 521 | if (len != ret_len) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 522 | fprintf(temp, |
| 523 | "\tFile read error for file %s, expected return of %d, got %d, errno=%d\n", |
| 524 | path_string, len, |
| 525 | ret_len, errno); |
| 526 | return (-3); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 527 | } |
| 528 | read_string[len] = '\0'; |
| 529 | val = strcmp(read_string, path_string); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 530 | if (val != 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 531 | fprintf(temp, |
| 532 | "\tContents of file %s are different than expected: %s\n", |
| 533 | path_string, |
| 534 | read_string); |
| 535 | return (-4); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | close(file_id); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 539 | } /* else for */ |
| 540 | if (ret_len <= 0) { |
| 541 | fprintf(temp, "\tImpossible to read file %s\n", |
| 542 | path_string); |
| 543 | return (-2); |
| 544 | } |
| 545 | } else { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 546 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 547 | /********************************/ |
| 548 | /* */ |
| 549 | /* otherwise.......... */ |
| 550 | /* it should be a directory */ |
| 551 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 552 | /********************************/ |
| 553 | |
| 554 | path_string[len] = '\0'; |
| 555 | path_mode = mode(path_string); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 556 | if (path_mode == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 557 | fprintf(temp, |
| 558 | "\tPreviously created directory path %s was not open\n", |
| 559 | path_string); |
| 560 | return (-4); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 561 | } |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 562 | if ((040000 & path_mode) != 040000) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 563 | fprintf(temp, |
| 564 | "\tPath %s was not recognized to be a directory\n", |
| 565 | path_string); |
| 566 | fprintf(temp, "\tIts mode is %o\n", path_mode); |
| 567 | return (-5); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 570 | } /* while */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 573 | int get_next_name() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 574 | |
| 575 | /****************************************/ |
| 576 | /* */ |
| 577 | /* get the next---in a dictionary */ |
| 578 | /* sense---file or directory name */ |
| 579 | /* */ |
| 580 | /****************************************/ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 581 | { |
| 582 | static int k; |
| 583 | int i; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 584 | int last_position; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 585 | |
| 586 | last_position = NAME_LENGTH - 1; |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 587 | if (k == 0) { |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 588 | |
| 589 | /************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 590 | /* */ |
| 591 | /* initialize name */ |
| 592 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 593 | /************************/ |
| 594 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 595 | for (i = 0; i < NAME_LENGTH; i++) |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 596 | name[i] = 'a'; |
| 597 | name[NAME_LENGTH] = '\0'; |
| 598 | k++; |
| 599 | } |
| 600 | /********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 601 | /* */ |
| 602 | else |
| 603 | increment_name(last_position); /* i.e., beginning at the last */ |
| 604 | /* position */ |
| 605 | /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 606 | /********************************/ |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 607 | return 0; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | int increment_name(position) |
| 611 | |
| 612 | /****************************************/ |
| 613 | /* */ |
| 614 | /* recursively revise the letters in */ |
| 615 | /* a name to get the lexiographically */ |
| 616 | /* next name */ |
| 617 | /* */ |
| 618 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 619 | int position; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 620 | { |
| 621 | int next_position; |
| 622 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 623 | if (name[position] == 'z') |
| 624 | if (position == 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 625 | fprintf(temp, |
| 626 | "\tERROR: There are no more available names\n"); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 627 | fail_exit(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 628 | } else { |
| 629 | name[position] = 'a'; /**********************/ |
| 630 | next_position = --position; /* */ |
| 631 | increment_name(next_position); /* increment the */ |
| 632 | /* previous letter */ |
| 633 | /* */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 634 | /**********************/ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 635 | } |
| 636 | /*********************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 637 | /* */ |
| 638 | else |
| 639 | name[position]++; /* otherwise, increment this one */ |
| 640 | return 0; /* */ |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 641 | /*********************************/ |
| 642 | } |
| 643 | |
| 644 | int mode(path_string) |
| 645 | |
| 646 | /****************************************/ |
| 647 | /* */ |
| 648 | /* determine and return the mode of */ |
| 649 | /* the file named by path_string */ |
| 650 | /* */ |
| 651 | /****************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 652 | char path_string[]; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 653 | { |
| 654 | struct stat buf; |
| 655 | int ret_val, mod; |
| 656 | |
| 657 | ret_val = stat(path_string, &buf); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 658 | if (ret_val == -1) |
| 659 | return (-1); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 660 | else { |
| 661 | mod = buf.st_mode; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 662 | return (mod); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | int escrivez(string) |
| 667 | |
| 668 | char string[]; |
| 669 | { |
| 670 | char write_string[PATH_STRING_LENGTH + 1]; |
| 671 | int len, ret_len; |
| 672 | |
| 673 | strcpy(write_string, string); |
| 674 | len = strlen(write_string); |
| 675 | write_string[len] = '\n'; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 676 | len++; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 677 | ret_len = write(list_id, write_string, len); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 678 | if (len != ret_len) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 679 | fprintf(temp, |
| 680 | "\tA string of deviant length %d written to path_list, errno=%d\n", |
| 681 | ret_len, errno); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 682 | fail_exit(); |
| 683 | } |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 684 | return 0; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | int term() |
| 688 | { |
| 689 | int status; |
| 690 | |
| 691 | fprintf(temp, "\tterm - got SIGTERM, cleaning up.\n"); |
| 692 | |
| 693 | if (list_stream != NULL) |
| 694 | fclose(list_stream); |
| 695 | close(list_id); |
| 696 | close(file_id); |
| 697 | |
| 698 | status = system(rm_string); |
| 699 | if (status) { |
| 700 | fprintf(temp, "Caution - ``%s'' may have failed.\n", rm_string); |
| 701 | fprintf(temp, "rm command exit status = %d\n", status); |
| 702 | } |
| 703 | |
| 704 | ok_exit(); |
| 705 | /***NOT REACHED***/ |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 706 | return 0; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 707 | |
| 708 | } |
| 709 | |
| 710 | /** LTP Port **/ |
| 711 | /* |
| 712 | * setup |
| 713 | * |
| 714 | * Do set up - here its a dummy function |
| 715 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 716 | void setup() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 717 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 718 | tst_tmpdir(); |
| 719 | temp = stderr; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /* |
| 723 | * Function: blexit() |
| 724 | * |
| 725 | * Description: This function will exit a block, a block may be a lo |
| 726 | gical unit |
| 727 | * of a test. It will report the status if the test ie |
| 728 | fail or |
| 729 | * pass. |
| 730 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 731 | void blexit() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 732 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 733 | (local_flag == PASSED) ? tst_resm(TPASS, "Test block %d", block_number) |
| 734 | : tst_resm(TFAIL, "Test block %d", block_number); |
| 735 | block_number++; |
| 736 | return; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | /* |
| 740 | * Function: blenter() |
| 741 | * |
| 742 | * Description: Print message on entering a new block |
| 743 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 744 | void blenter() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 745 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 746 | local_flag = PASSED; |
| 747 | return; |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * fail_exit() |
| 752 | * |
| 753 | * Exit on failure |
| 754 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 755 | void fail_exit() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 756 | { |
Cyril Hrubis | 9fa8ad0 | 2014-12-16 13:20:49 +0100 | [diff] [blame] | 757 | tst_brkm(TFAIL, tst_rmdir, "Test failed"); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /* |
| 761 | * |
| 762 | * Function: anyfail() |
| 763 | * |
| 764 | * Description: Exit a test. |
| 765 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 766 | void anyfail() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 767 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 768 | (local_flag == FAILED) ? tst_resm(TFAIL, "Test failed") |
| 769 | : tst_resm(TPASS, "Test passed"); |
| 770 | tst_rmdir(); |
| 771 | tst_exit(); |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * ok_exit |
| 776 | * |
| 777 | * Calling block passed the test |
| 778 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 779 | void ok_exit() |
robbiew | f0888c0 | 2002-12-04 19:42:27 +0000 | [diff] [blame] | 780 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 781 | local_flag = PASSED; |
| 782 | return; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 783 | } |