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