[1b4f2b30] | 1 | /* |
---|
[0895bdb] | 2 | * Psx13 |
---|
| 3 | * Chris Bond (working under Jennifer's account) |
---|
| 4 | * |
---|
| 5 | * This test exercises the following routines: |
---|
| 6 | * |
---|
| 7 | * device_lseek - test implemented |
---|
| 8 | * dup - test implemented |
---|
| 9 | * dup2 - test implemented |
---|
| 10 | * fdatasync - test implemented |
---|
| 11 | * fsync - test implemented |
---|
| 12 | * pathconf - test implemented |
---|
| 13 | * fpathconf - test implemented |
---|
| 14 | * umask - test implemented |
---|
| 15 | * utime - test implemented |
---|
[c40d3c4b] | 16 | * utimes - test implemented |
---|
[0895bdb] | 17 | * |
---|
[2e7e636f] | 18 | * COPYRIGHT (c) 1989-2009. |
---|
[0895bdb] | 19 | * On-Line Applications Research Corporation (OAR). |
---|
| 20 | * |
---|
| 21 | * The license and distribution terms for this file may be |
---|
| 22 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 23 | * http://www.rtems.org/license/LICENSE. |
---|
[0895bdb] | 24 | */ |
---|
| 25 | |
---|
[cafefbf] | 26 | #ifdef HAVE_CONFIG_H |
---|
| 27 | #include "config.h" |
---|
| 28 | #endif |
---|
| 29 | |
---|
[0895bdb] | 30 | #include <rtems.h> |
---|
| 31 | #include <rtems/libio.h> |
---|
| 32 | #include <fcntl.h> |
---|
| 33 | #include <unistd.h> |
---|
| 34 | #include <errno.h> |
---|
| 35 | #include <utime.h> |
---|
| 36 | |
---|
| 37 | #include <stdio.h> |
---|
[7b64b25b] | 38 | #include <unistd.h> |
---|
[0895bdb] | 39 | |
---|
[d802489] | 40 | #include <pmacros.h> |
---|
| 41 | |
---|
[698c2e50] | 42 | const char rtems_test_name[] = "PSX 13"; |
---|
| 43 | |
---|
[2e7e636f] | 44 | int InitFiles(void); |
---|
| 45 | int DeviceLSeekTest(void); |
---|
| 46 | int DupTest(void); |
---|
| 47 | int Dup2Test(void); |
---|
| 48 | int FDataSyncTest(void); |
---|
| 49 | int UMaskTest(void); |
---|
| 50 | int UTimeTest(void); |
---|
[c40d3c4b] | 51 | int UTimesTest(void); |
---|
[2e7e636f] | 52 | int PathConfTest(void); |
---|
| 53 | int FPathConfTest(void); |
---|
| 54 | int FSyncTest(void); |
---|
| 55 | |
---|
[0895bdb] | 56 | /*------------------------------------------------------------------- |
---|
| 57 | * InitFiles function |
---|
| 58 | * |
---|
[1b4f2b30] | 59 | * Initializes the three files to be used in the test. |
---|
| 60 | * |
---|
[0895bdb] | 61 | * arguments: none |
---|
| 62 | * assumptions: fopen, fprintf, fwrite, FILE are available |
---|
| 63 | * actions: creates testfile1, a text file with 'a'..'z' listed 4 times. |
---|
| 64 | * creates testfile2, a text file with 'a'..'z' listed 4 times. |
---|
| 65 | * creates testfile3, a binary file with 0..9 listed 4 times. |
---|
| 66 | * returns: TRUE if files opened successfully. |
---|
| 67 | * FALSE if fail on file open for write. |
---|
[1b4f2b30] | 68 | * |
---|
[0895bdb] | 69 | * ------------------------------------------------------------------ |
---|
| 70 | */ |
---|
| 71 | |
---|
[2e7e636f] | 72 | int InitFiles (void) |
---|
| 73 | { |
---|
[0895bdb] | 74 | int count; |
---|
| 75 | FILE *fp1, *fp2, *fp3; |
---|
| 76 | char letter; |
---|
| 77 | int number; |
---|
| 78 | int retval; |
---|
| 79 | |
---|
| 80 | fp1 = fopen("testfile1.tst", "wt"); |
---|
| 81 | fp2 = fopen("testfile2.tst", "wt"); |
---|
| 82 | fp3 = fopen("testfile4.tst", "wb"); |
---|
| 83 | |
---|
| 84 | if ((fp1 != NULL) && (fp2 != NULL) && (fp3 !=NULL)) { |
---|
| 85 | |
---|
| 86 | letter = 'a'; |
---|
| 87 | |
---|
| 88 | for (count=0 ; count<(26*4); ++count) { |
---|
| 89 | fprintf (fp1, "%c", letter); |
---|
| 90 | fprintf (fp2, "%c", letter); |
---|
| 91 | |
---|
| 92 | ++letter; |
---|
| 93 | if (letter > 'z') |
---|
| 94 | letter = 'a'; |
---|
| 95 | } |
---|
[1b4f2b30] | 96 | |
---|
[0895bdb] | 97 | number = 0; |
---|
| 98 | |
---|
| 99 | for (count = 0; count <40; ++count) { |
---|
| 100 | |
---|
| 101 | fwrite (&number, 1, sizeof(int), fp3); |
---|
| 102 | |
---|
| 103 | ++number; |
---|
| 104 | if (number > 9) |
---|
| 105 | number = 0; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | fclose(fp1); |
---|
| 109 | fclose(fp2); |
---|
| 110 | fclose(fp3); |
---|
| 111 | |
---|
| 112 | retval = TRUE; |
---|
| 113 | } |
---|
| 114 | |
---|
[1b4f2b30] | 115 | else |
---|
[0895bdb] | 116 | retval = FALSE; |
---|
| 117 | |
---|
| 118 | /* assert (retval == TRUE);*/ |
---|
| 119 | |
---|
| 120 | return (retval); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /* --------------------------------------------------------------- |
---|
| 124 | * DeviceLSeekTest function |
---|
| 125 | * |
---|
| 126 | * Hits the device_lseek code by lseeking on the console. |
---|
| 127 | * |
---|
| 128 | * arguments: none |
---|
| 129 | * assumptions: lseek available |
---|
[1b4f2b30] | 130 | * actions: hits lseek with some dummy arguments. |
---|
[0895bdb] | 131 | * returns: value of return from lseek. |
---|
| 132 | * |
---|
| 133 | * --------------------------------------------------------------- |
---|
| 134 | */ |
---|
| 135 | |
---|
[2e7e636f] | 136 | int DeviceLSeekTest (void) |
---|
| 137 | { |
---|
[0895bdb] | 138 | int error = -1, retval = FALSE; |
---|
| 139 | |
---|
| 140 | int fd = open ("/dev/console", O_RDONLY); |
---|
| 141 | |
---|
| 142 | error = lseek(fd, 5, SEEK_SET); |
---|
| 143 | |
---|
| 144 | if (error == 0) |
---|
| 145 | retval = TRUE; |
---|
| 146 | else |
---|
| 147 | retval = FALSE; |
---|
| 148 | |
---|
[99e6fb52] | 149 | close( fd ); /* assert (retval == TRUE);*/ |
---|
[0895bdb] | 150 | |
---|
| 151 | return (retval); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /* --------------------------------------------------------------- |
---|
| 155 | * DupTest function |
---|
| 156 | * |
---|
| 157 | * Hits the dup code. |
---|
| 158 | * |
---|
| 159 | * arguments: none |
---|
| 160 | * assumptions: dup, open, close, fcntl available. |
---|
| 161 | * actions: Gets a file descriptor(fd1) for test file1. |
---|
| 162 | * dups fd1 to fd2. |
---|
| 163 | * sets fd1 to append mode |
---|
[1b4f2b30] | 164 | * checks fd2 to ensure it's in append mode, also. |
---|
[0895bdb] | 165 | * returns: success if fd2 is indeed a copy of fd1. |
---|
| 166 | * |
---|
| 167 | * --------------------------------------------------------------- |
---|
| 168 | */ |
---|
| 169 | |
---|
[2e7e636f] | 170 | int DupTest(void) |
---|
| 171 | { |
---|
[0895bdb] | 172 | int fd1, fd2; |
---|
| 173 | |
---|
| 174 | int flags = 0, retval = FALSE; |
---|
| 175 | |
---|
| 176 | fd1 = open ("testfile1.tst", O_RDONLY); |
---|
| 177 | fd2 = dup(fd1); |
---|
| 178 | |
---|
| 179 | if (fd2 != -1) { |
---|
| 180 | |
---|
[c2f9b97] | 181 | fcntl(fd1, F_SETFL, O_APPEND); |
---|
| 182 | flags = fcntl(fd2, F_GETFL); |
---|
[0895bdb] | 183 | |
---|
| 184 | close (fd1); |
---|
| 185 | |
---|
| 186 | flags = (flags & O_APPEND); |
---|
[1b4f2b30] | 187 | |
---|
[0895bdb] | 188 | retval = (flags == O_APPEND); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | else |
---|
| 192 | retval = FALSE; |
---|
| 193 | |
---|
[99e6fb52] | 194 | close( fd1 ); |
---|
| 195 | close( fd2 ); |
---|
[0895bdb] | 196 | /* assert (retval == TRUE);*/ |
---|
| 197 | |
---|
| 198 | return (retval); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | /* --------------------------------------------------------------- |
---|
| 202 | * Dup2Test function |
---|
| 203 | * |
---|
| 204 | * Hits the dup2 code. |
---|
| 205 | * |
---|
| 206 | * arguments: none |
---|
| 207 | * assumptions: dup, dup2, open, close, fcntl available. |
---|
| 208 | * actions: Gets a file descriptor(fd1) for test file1. |
---|
| 209 | * dups fd1 to fd2. |
---|
| 210 | * sets fd1 to append mode |
---|
[1b4f2b30] | 211 | * checks fd2 to ensure it's in append mode, also. |
---|
[0895bdb] | 212 | * sets fd1 to invalid value, fd2 to valid, tries to dup2. |
---|
| 213 | * sets fd2 to invalid value, fd1 to valid tries to dup2. |
---|
| 214 | * returns: success if fd2 is a copy of fd1, and invalid fd1 or fd2 produce errors. |
---|
| 215 | * |
---|
| 216 | * --------------------------------------------------------------- |
---|
| 217 | */ |
---|
| 218 | |
---|
[2e7e636f] | 219 | int Dup2Test(void) |
---|
| 220 | { |
---|
[0895bdb] | 221 | int fd1, fd2; |
---|
| 222 | |
---|
| 223 | int flags = 0, retval = FALSE; |
---|
| 224 | |
---|
| 225 | int error = 0; |
---|
| 226 | |
---|
| 227 | fd1 = open ("testfile1.tst", O_RDONLY); |
---|
| 228 | fd2 = open ("testfile2.tst", O_RDONLY); |
---|
| 229 | error = dup2(fd1, fd2); |
---|
| 230 | |
---|
| 231 | /* make sure dup2 works if both fd1 and fd2 are valid file descriptors. */ |
---|
| 232 | |
---|
| 233 | if (error != -1) { |
---|
| 234 | |
---|
[c2f9b97] | 235 | fcntl(fd1, F_SETFL, O_APPEND); |
---|
| 236 | flags = fcntl(fd1, F_GETFL); |
---|
[0895bdb] | 237 | |
---|
| 238 | flags = (flags & O_APPEND); |
---|
| 239 | retval = (flags == O_APPEND); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | else { |
---|
| 243 | retval = FALSE; |
---|
| 244 | close(fd2); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | if (retval == TRUE) { |
---|
| 248 | |
---|
| 249 | /* make sure dup2 fails correctly if one or the other arguments are invalid. */ |
---|
| 250 | /* this assumes -1 is an invalid value for a file descriptor!!! (POSIX book, p.135) */ |
---|
| 251 | |
---|
| 252 | fd1 = -1; |
---|
| 253 | |
---|
| 254 | if (dup2 (fd1, fd2) != -1) |
---|
| 255 | retval = FALSE; |
---|
| 256 | else { |
---|
| 257 | fd1 = dup(fd2); |
---|
| 258 | fd2 = -1; |
---|
[1b4f2b30] | 259 | |
---|
[0895bdb] | 260 | if (dup2(fd1, fd2) != -1) |
---|
| 261 | retval = FALSE; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | close (fd1); |
---|
[99e6fb52] | 266 | close (fd2); |
---|
[0895bdb] | 267 | /* assert (retval == TRUE);*/ |
---|
| 268 | |
---|
| 269 | return (retval); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | /* --------------------------------------------------------------- |
---|
| 273 | * FDataSyncTest function |
---|
| 274 | * |
---|
| 275 | * Hits the fdatasync code. Does NOT test the functionality of the |
---|
| 276 | * underlying fdatasync entry in the IMFS op table. |
---|
| 277 | * |
---|
| 278 | * arguments: none |
---|
| 279 | * assumptions: open, close, fdatasync functions available. |
---|
| 280 | * actions: attempts to fdatasync a file descriptor flagged as read-only. |
---|
| 281 | * attempts to fdatasync an invalid file descriptor (-1). |
---|
| 282 | * attempts to fdatasync a perfectly valid fd opened as RDWR |
---|
| 283 | * |
---|
[2e7e636f] | 284 | * returns: TRUE if attempt to fdatasync invalid and read-only filed |
---|
| 285 | * descriptor fail, and fdatasync succeeds on valid fd. |
---|
[0895bdb] | 286 | * FALSE otherwise. |
---|
| 287 | * |
---|
| 288 | * --------------------------------------------------------------- |
---|
| 289 | */ |
---|
| 290 | |
---|
[2e7e636f] | 291 | int FDataSyncTest(void) |
---|
| 292 | { |
---|
[0895bdb] | 293 | int fd = -1; |
---|
| 294 | int error = 0, retval = TRUE; |
---|
[1b4f2b30] | 295 | |
---|
[0895bdb] | 296 | /* Try it with a RD_ONLY file. */ |
---|
[1b4f2b30] | 297 | |
---|
[0895bdb] | 298 | fd = open ("testfile1.tst", O_RDONLY); |
---|
| 299 | |
---|
| 300 | error = fdatasync(fd); |
---|
| 301 | if ((error == -1) && (errno == EINVAL)) |
---|
| 302 | retval = TRUE; |
---|
| 303 | else |
---|
| 304 | retval = FALSE; |
---|
[1b4f2b30] | 305 | |
---|
[0895bdb] | 306 | close (fd); |
---|
| 307 | |
---|
| 308 | if (retval == TRUE) { |
---|
| 309 | |
---|
| 310 | /* Try it with a bad file descriptor */ |
---|
| 311 | |
---|
| 312 | fd = -1; |
---|
| 313 | |
---|
| 314 | error = fdatasync(fd); |
---|
| 315 | if ((errno == EBADF) && (error == -1)) |
---|
| 316 | retval = TRUE; |
---|
| 317 | else |
---|
| 318 | retval = FALSE; |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | /* Okay - now the success case... */ |
---|
| 322 | |
---|
| 323 | if (retval == TRUE) { |
---|
| 324 | fd = open ("testfile1.tst", O_RDWR); |
---|
| 325 | error = fdatasync(fd); |
---|
| 326 | |
---|
| 327 | if (error == 0) |
---|
| 328 | retval = TRUE; |
---|
| 329 | else |
---|
| 330 | retval = FALSE; |
---|
| 331 | |
---|
| 332 | close (fd); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | /* assert (retval == TRUE);*/ |
---|
| 336 | |
---|
| 337 | return (retval); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | /* --------------------------------------------------------------- |
---|
| 341 | * UMaskTest function |
---|
| 342 | * |
---|
| 343 | * Hits the umask code. |
---|
| 344 | * |
---|
| 345 | * arguments: none |
---|
| 346 | * assumptions: umask function available. |
---|
| 347 | * actions: set umask to 0ctal 23. |
---|
| 348 | * set umask to Octal 22, retrieve the old value. |
---|
| 349 | * |
---|
| 350 | * returns: TRUE if old value is 23, |
---|
| 351 | * FALSE otherwise. |
---|
| 352 | * |
---|
| 353 | * --------------------------------------------------------------- |
---|
| 354 | */ |
---|
| 355 | |
---|
[2e7e636f] | 356 | int UMaskTest (void) |
---|
| 357 | { |
---|
| 358 | mode_t error = 0; |
---|
| 359 | int retval = FALSE; |
---|
[0895bdb] | 360 | |
---|
[2e7e636f] | 361 | umask(023); |
---|
[0895bdb] | 362 | error = umask(022); |
---|
| 363 | |
---|
| 364 | if (error == 023) |
---|
| 365 | retval = TRUE; |
---|
| 366 | else |
---|
| 367 | retval = FALSE; |
---|
| 368 | |
---|
| 369 | /* assert (retval == TRUE);*/ |
---|
| 370 | |
---|
| 371 | return(retval); |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | /* --------------------------------------------------------------- |
---|
| 375 | * UTimeTest function |
---|
| 376 | * |
---|
[1b4f2b30] | 377 | * Hits the utime code. Does NOT test the functionality of the underlying utime |
---|
[0895bdb] | 378 | * entry in the IMFS op table. |
---|
| 379 | * |
---|
| 380 | * arguments: none |
---|
| 381 | * assumptions: utime function available. |
---|
| 382 | * actions: set utime for an invalid filename. |
---|
| 383 | * set utime for a valid filename. |
---|
| 384 | * |
---|
[2e7e636f] | 385 | * returns: TRUE if time on valid file is set correctly and utime failed on |
---|
| 386 | * an invalid filename. |
---|
[0895bdb] | 387 | * FALSE otherwise. |
---|
| 388 | * |
---|
| 389 | * --------------------------------------------------------------- |
---|
| 390 | */ |
---|
| 391 | |
---|
[2e7e636f] | 392 | int UTimeTest (void) |
---|
| 393 | { |
---|
[0895bdb] | 394 | int error = 0, retval = FALSE; |
---|
| 395 | struct utimbuf time; |
---|
| 396 | struct stat fstat; |
---|
| 397 | |
---|
| 398 | /* First, an invalid filename. */ |
---|
| 399 | error = utime("!This is an =invalid p@thname!!! :)", NULL); |
---|
| 400 | |
---|
| 401 | if (error == -1) |
---|
| 402 | retval = TRUE; |
---|
| 403 | else |
---|
| 404 | retval = FALSE; |
---|
| 405 | |
---|
| 406 | /* Now, the success test. */ |
---|
| 407 | if (retval == TRUE) { |
---|
| 408 | |
---|
| 409 | time.actime = 12345; |
---|
| 410 | time.modtime = 54321; |
---|
| 411 | |
---|
| 412 | error = utime("testfile1.tst", &time); |
---|
| 413 | |
---|
| 414 | if (error == 0) { |
---|
| 415 | |
---|
| 416 | /* But, did it set the time? */ |
---|
| 417 | stat ("testfile1.tst", &fstat); |
---|
| 418 | |
---|
| 419 | if ((fstat.st_atime == 12345) && (fstat.st_mtime == 54321 )) |
---|
| 420 | retval = TRUE; |
---|
[1b4f2b30] | 421 | else |
---|
[0895bdb] | 422 | retval = FALSE; |
---|
| 423 | } |
---|
| 424 | else |
---|
| 425 | retval = FALSE; |
---|
[efdc6987] | 426 | |
---|
| 427 | error = utime("testfile1.tst", NULL ); |
---|
| 428 | retval &= (error == 0) ? TRUE : FALSE; |
---|
[0895bdb] | 429 | } |
---|
| 430 | |
---|
| 431 | /* assert (retval == TRUE);*/ |
---|
| 432 | |
---|
| 433 | return (retval); |
---|
| 434 | } |
---|
| 435 | |
---|
[c40d3c4b] | 436 | /* --------------------------------------------------------------- |
---|
| 437 | * UTimesTest function |
---|
| 438 | * |
---|
| 439 | * Hits the utimes code. Does NOT test the functionality of the underlying utime |
---|
| 440 | * entry in the IMFS op table. |
---|
| 441 | * |
---|
| 442 | * arguments: none |
---|
| 443 | * assumptions: utimes function available. |
---|
| 444 | * actions: set utimes for an invalid filename. |
---|
| 445 | * set utimes for a valid filename. |
---|
| 446 | * |
---|
| 447 | * returns: TRUE if time on valid file is set correctly and utimes failed on |
---|
| 448 | * an invalid filename. |
---|
| 449 | * FALSE otherwise. |
---|
| 450 | * |
---|
| 451 | * --------------------------------------------------------------- |
---|
| 452 | */ |
---|
| 453 | |
---|
| 454 | int UTimesTest (void) |
---|
| 455 | { |
---|
| 456 | int error = 0, retval = FALSE; |
---|
| 457 | struct timeval time[2]; |
---|
| 458 | struct stat fstat; |
---|
| 459 | |
---|
| 460 | /* First, an invalid filename. */ |
---|
| 461 | error = utimes("!This is an =invalid p@thname!!! :)", NULL); |
---|
| 462 | |
---|
| 463 | if (error == -1) |
---|
| 464 | retval = TRUE; |
---|
| 465 | else |
---|
| 466 | retval = FALSE; |
---|
| 467 | |
---|
| 468 | /* Now, the success test. */ |
---|
| 469 | if (retval == TRUE) { |
---|
| 470 | |
---|
| 471 | time[0].tv_sec = 12345; |
---|
| 472 | time[1].tv_sec = 54321; |
---|
| 473 | |
---|
[2da9a31a] | 474 | error = utimes("testfile1.tst", (struct timeval *)&time); |
---|
[c40d3c4b] | 475 | |
---|
| 476 | if (error == 0) { |
---|
| 477 | |
---|
| 478 | /* But, did it set the time? */ |
---|
| 479 | stat ("testfile1.tst", &fstat); |
---|
| 480 | |
---|
| 481 | if ((fstat.st_atime == 12345) && (fstat.st_mtime == 54321 )) |
---|
| 482 | retval = TRUE; |
---|
| 483 | else |
---|
| 484 | retval = FALSE; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | else |
---|
| 488 | retval = FALSE; |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | /* assert (retval == TRUE);*/ |
---|
| 492 | |
---|
| 493 | return (retval); |
---|
| 494 | } |
---|
| 495 | |
---|
[0895bdb] | 496 | /* --------------------------------------------------------------- |
---|
| 497 | * PathConfTest function |
---|
| 498 | * |
---|
| 499 | * Hits the pathconf code. |
---|
| 500 | * |
---|
| 501 | * arguments: none |
---|
| 502 | * assumptions: pathconf function available. |
---|
| 503 | * actions: Try to pathconf a bad filename. |
---|
| 504 | * Try to pathconf a good filename. |
---|
| 505 | * |
---|
| 506 | * returns: TRUE if pathconf fails on bad file, succeeds on good file. |
---|
| 507 | * FALSE otherwise. |
---|
| 508 | * |
---|
| 509 | * --------------------------------------------------------------- |
---|
| 510 | */ |
---|
| 511 | |
---|
[2e7e636f] | 512 | int PathConfTest (void) |
---|
| 513 | { |
---|
[0895bdb] | 514 | int error = 0, retval = FALSE; |
---|
| 515 | |
---|
| 516 | error = pathconf("thisfiledoesnotexist", _PC_LINK_MAX); |
---|
| 517 | |
---|
| 518 | if (error == -1) { |
---|
| 519 | error = pathconf("testfile1.tst", _PC_LINK_MAX); |
---|
| 520 | |
---|
| 521 | if (error != -1) |
---|
| 522 | retval = TRUE; |
---|
| 523 | else |
---|
| 524 | retval = FALSE; |
---|
| 525 | } |
---|
[1b4f2b30] | 526 | |
---|
| 527 | else |
---|
[0895bdb] | 528 | retval = FALSE; |
---|
| 529 | |
---|
| 530 | /* assert (retval == TRUE);*/ |
---|
| 531 | |
---|
| 532 | return(retval); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | /* --------------------------------------------------------------- |
---|
| 536 | * FPathConfTest function |
---|
| 537 | * |
---|
| 538 | * Hits the fpathconf code. |
---|
| 539 | * |
---|
| 540 | * arguments: none |
---|
| 541 | * assumptions: fpathconf function available. |
---|
| 542 | * actions: Call fpathconf with all arguments, plus an invalid. |
---|
| 543 | * |
---|
[1b4f2b30] | 544 | * returns: TRUE always. |
---|
[0895bdb] | 545 | * |
---|
| 546 | * --------------------------------------------------------------- |
---|
| 547 | */ |
---|
| 548 | |
---|
[2e7e636f] | 549 | int FPathConfTest (void) |
---|
| 550 | { |
---|
[0895bdb] | 551 | int error = 0, retval = TRUE; |
---|
| 552 | |
---|
| 553 | int fd = -1; |
---|
| 554 | |
---|
| 555 | error = fpathconf(fd, _PC_LINK_MAX); |
---|
| 556 | |
---|
| 557 | if (error == -1) { |
---|
| 558 | fd = open("testfile1.tst", O_RDWR); |
---|
[1b4f2b30] | 559 | |
---|
[0895bdb] | 560 | error = fpathconf(fd, _PC_LINK_MAX); |
---|
| 561 | error = fpathconf(fd, _PC_MAX_CANON); |
---|
| 562 | error = fpathconf(fd, _PC_MAX_INPUT); |
---|
| 563 | error = fpathconf(fd, _PC_NAME_MAX); |
---|
| 564 | error = fpathconf(fd, _PC_PATH_MAX); |
---|
| 565 | error = fpathconf(fd, _PC_PIPE_BUF); |
---|
| 566 | error = fpathconf(fd, _PC_CHOWN_RESTRICTED); |
---|
[1b4f2b30] | 567 | error = fpathconf(fd, _PC_NO_TRUNC); |
---|
[0895bdb] | 568 | error = fpathconf(fd, _PC_VDISABLE); |
---|
| 569 | error = fpathconf(fd, _PC_ASYNC_IO); |
---|
| 570 | error = fpathconf(fd, _PC_PRIO_IO); |
---|
| 571 | error = fpathconf(fd, _PC_SYNC_IO); |
---|
| 572 | error = fpathconf(fd, 255); |
---|
[1b4f2b30] | 573 | |
---|
[efdc6987] | 574 | close(fd); |
---|
| 575 | |
---|
| 576 | fd = open("testfile1.tst", O_WRONLY); |
---|
[6e6fd513] | 577 | |
---|
[efdc6987] | 578 | error = fpathconf(fd, _PC_LINK_MAX); |
---|
| 579 | |
---|
[0895bdb] | 580 | retval = TRUE; |
---|
| 581 | } |
---|
[1b4f2b30] | 582 | |
---|
| 583 | else |
---|
[0895bdb] | 584 | retval = FALSE; |
---|
| 585 | |
---|
| 586 | /* assert (retval == TRUE);*/ |
---|
| 587 | |
---|
| 588 | return(retval); |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | /* --------------------------------------------------------------- |
---|
| 592 | * FSyncTest function |
---|
| 593 | * |
---|
| 594 | * Hits the fsync code. |
---|
| 595 | * |
---|
| 596 | * arguments: none |
---|
| 597 | * assumptions: open, fsync functions available. |
---|
| 598 | * actions: open test file, |
---|
| 599 | * try to fsync it. |
---|
| 600 | * |
---|
| 601 | * returns: TRUE if fsync doesn't return -1, |
---|
| 602 | * FALSE otherwise. |
---|
| 603 | * |
---|
| 604 | * --------------------------------------------------------------- |
---|
| 605 | */ |
---|
| 606 | |
---|
[2e7e636f] | 607 | int FSyncTest (void) |
---|
| 608 | { |
---|
[0895bdb] | 609 | int error = 0, retval = FALSE; |
---|
| 610 | int fd = -1; |
---|
[1b4f2b30] | 611 | |
---|
[0895bdb] | 612 | fd = open("testfile1.tst", O_RDWR); |
---|
| 613 | |
---|
| 614 | if (fd != -1) { |
---|
| 615 | |
---|
| 616 | error = fsync(fd); |
---|
| 617 | |
---|
| 618 | if (error != -1) |
---|
| 619 | retval = TRUE; |
---|
| 620 | else |
---|
| 621 | retval = FALSE; |
---|
| 622 | |
---|
| 623 | close(fd); |
---|
| 624 | } |
---|
| 625 | |
---|
[1b4f2b30] | 626 | else |
---|
[0895bdb] | 627 | retval = FALSE; |
---|
| 628 | |
---|
| 629 | /* assert (retval == TRUE);*/ |
---|
| 630 | |
---|
| 631 | return(retval); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /* --------------------------------------------------------------- |
---|
| 635 | * Main function |
---|
| 636 | * |
---|
| 637 | * main entry point to the test |
---|
| 638 | * |
---|
[1b4f2b30] | 639 | * --------------------------------------------------------------- |
---|
[0895bdb] | 640 | */ |
---|
| 641 | |
---|
| 642 | #if defined(__rtems__) |
---|
[2e7e636f] | 643 | int test_main(void); |
---|
[0895bdb] | 644 | int test_main(void) |
---|
| 645 | #else |
---|
| 646 | int main( |
---|
| 647 | int argc, |
---|
| 648 | char **argv |
---|
| 649 | ) |
---|
| 650 | #endif |
---|
| 651 | { |
---|
[698c2e50] | 652 | TEST_BEGIN(); |
---|
[54a5ee7] | 653 | |
---|
[0895bdb] | 654 | if (InitFiles() == TRUE) { |
---|
[c2f9b97] | 655 | printf ("\nFiles initialized successfully.\n"); |
---|
[0895bdb] | 656 | |
---|
[c2f9b97] | 657 | printf ("Testing device_lseek()... "); |
---|
[0895bdb] | 658 | if (DeviceLSeekTest() == TRUE) |
---|
[c2f9b97] | 659 | printf ("Success.\n"); |
---|
[0895bdb] | 660 | else |
---|
[c2f9b97] | 661 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 662 | |
---|
[c2f9b97] | 663 | printf ("Testing dup()............ "); |
---|
[0895bdb] | 664 | if (DupTest() == TRUE) |
---|
[c2f9b97] | 665 | printf ("Success.\n"); |
---|
[0895bdb] | 666 | else |
---|
[c2f9b97] | 667 | printf ("Failed!!!\n"); |
---|
[1b4f2b30] | 668 | |
---|
[c2f9b97] | 669 | printf ("Testing dup2()........... "); |
---|
[0895bdb] | 670 | if (Dup2Test() == TRUE) |
---|
[c2f9b97] | 671 | printf ("Success.\n"); |
---|
[0895bdb] | 672 | else |
---|
[c2f9b97] | 673 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 674 | |
---|
[c2f9b97] | 675 | printf ("Testing fdatasync()...... "); |
---|
[0895bdb] | 676 | if (FDataSyncTest() == TRUE) |
---|
[c2f9b97] | 677 | printf ("Success.\n"); |
---|
[0895bdb] | 678 | else |
---|
[c2f9b97] | 679 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 680 | |
---|
[c2f9b97] | 681 | printf ("Testing umask().......... "); |
---|
[0895bdb] | 682 | if (UMaskTest() == TRUE) |
---|
[c2f9b97] | 683 | printf ("Success.\n"); |
---|
[0895bdb] | 684 | else |
---|
[c2f9b97] | 685 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 686 | |
---|
[c2f9b97] | 687 | printf ("Testing utime().......... "); |
---|
[0895bdb] | 688 | if (UTimeTest() == TRUE) |
---|
[c2f9b97] | 689 | printf ("Success.\n"); |
---|
[0895bdb] | 690 | else |
---|
[c2f9b97] | 691 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 692 | |
---|
[c40d3c4b] | 693 | printf ("Testing utimes().......... "); |
---|
| 694 | if (UTimesTest() == TRUE) |
---|
| 695 | printf ("Success.\n"); |
---|
| 696 | else |
---|
| 697 | printf ("Failed!!!\n"); |
---|
| 698 | |
---|
[c2f9b97] | 699 | printf ("Testing fsync().......... "); |
---|
[0895bdb] | 700 | if (FSyncTest() == TRUE) |
---|
[c2f9b97] | 701 | printf ("Success.\n"); |
---|
[0895bdb] | 702 | else |
---|
[c2f9b97] | 703 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 704 | |
---|
[c2f9b97] | 705 | printf ("Testing pathconf()....... "); |
---|
[0895bdb] | 706 | if (PathConfTest() == TRUE) |
---|
[c2f9b97] | 707 | printf ("Success.\n"); |
---|
[0895bdb] | 708 | else |
---|
[c2f9b97] | 709 | printf ("Failed!!!\n"); |
---|
[1b4f2b30] | 710 | |
---|
[c2f9b97] | 711 | printf ("Testing fpathconf()...... "); |
---|
[0895bdb] | 712 | if (FPathConfTest() == TRUE) |
---|
[c2f9b97] | 713 | printf ("Success.\n"); |
---|
[0895bdb] | 714 | else |
---|
[c2f9b97] | 715 | printf ("Failed!!!\n"); |
---|
[0895bdb] | 716 | |
---|
[d216fca7] | 717 | printf ("Testing sync()...... "); |
---|
| 718 | sync(); |
---|
[8c26e798] | 719 | printf ("Done.\n"); |
---|
| 720 | |
---|
| 721 | TEST_END(); |
---|
[d216fca7] | 722 | } |
---|
[0895bdb] | 723 | |
---|
[d802489] | 724 | rtems_test_exit(0); |
---|
[0895bdb] | 725 | } |
---|