[f94344f] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1989-2010. |
---|
[cfde6479] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | * |
---|
| 9 | * $Id$ |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | /* Includes */ |
---|
[f94344f] | 13 | #include <bsp.h> |
---|
| 14 | #include <tmacros.h> |
---|
[cfde6479] | 15 | #include <stdio.h> |
---|
| 16 | #include <sys/types.h> |
---|
| 17 | #include <sys/stat.h> |
---|
| 18 | #include <fcntl.h> |
---|
| 19 | #include <unistd.h> |
---|
| 20 | #include <errno.h> |
---|
| 21 | |
---|
| 22 | #include <rtems.h> |
---|
| 23 | #include <rtems/libio.h> |
---|
| 24 | |
---|
| 25 | #define NUM_OPEN_REQ 26 |
---|
| 26 | |
---|
| 27 | void test_main(void) |
---|
| 28 | { |
---|
| 29 | |
---|
| 30 | int status = -1; |
---|
| 31 | int fd = 0; |
---|
| 32 | int index = 0; |
---|
| 33 | int num_opens = 0; |
---|
| 34 | |
---|
| 35 | puts("\n\n*** FIFO / PIPE OPEN TEST - 4 ***"); |
---|
| 36 | puts( |
---|
| 37 | "\n\nConfiguration: Pipes configured, \ |
---|
| 38 | but number of barriers configured = 2\n" |
---|
| 39 | ); |
---|
| 40 | |
---|
| 41 | puts("\n\nCreating directory /tmp"); |
---|
| 42 | status = mkdir("/tmp", 0777); |
---|
| 43 | rtems_test_assert(status == 0); |
---|
| 44 | |
---|
| 45 | puts("\n\nCreating fifo /tmp/fifo"); |
---|
| 46 | status = mkfifo("/tmp/fifo01", 0777); |
---|
| 47 | rtems_test_assert(status == 0); |
---|
| 48 | |
---|
| 49 | puts("\n\nAttempt to open the fifo file in RDWR mode\n"); |
---|
| 50 | puts("Should be successful and non-negative\ |
---|
| 51 | file descriptor expected"); |
---|
| 52 | |
---|
| 53 | fd = open("/tmp/fifo01", O_RDWR); |
---|
| 54 | rtems_test_assert(fd > 0); |
---|
| 55 | ++num_opens; |
---|
| 56 | |
---|
| 57 | puts("\n\nClosing the fifo file"); |
---|
| 58 | status = close(fd); |
---|
| 59 | rtems_test_assert(status == 0); |
---|
| 60 | |
---|
| 61 | puts("\n\nAttempt to open the fifo file in \ |
---|
| 62 | RDONLY and NONBLOCK mode\n"); |
---|
| 63 | puts("Should be successful and non-negative\ |
---|
| 64 | file descriptor expected"); |
---|
| 65 | |
---|
| 66 | fd = open("/tmp/fifo01", O_RDONLY | O_NONBLOCK); |
---|
| 67 | rtems_test_assert(fd > 0); |
---|
| 68 | ++num_opens; |
---|
| 69 | |
---|
| 70 | puts("\n\nClosing the fifo file"); |
---|
| 71 | status = close(fd); |
---|
| 72 | rtems_test_assert(status == 0); |
---|
| 73 | |
---|
| 74 | puts("\n\nAttempt to open the fifo file in \ |
---|
| 75 | WRONLY and NONBLOCK mode\n"); |
---|
| 76 | puts("Should return with an error ENXIO"); |
---|
| 77 | |
---|
| 78 | fd = open("/tmp/fifo01", O_WRONLY | O_NONBLOCK); |
---|
| 79 | rtems_test_assert(fd == -1); |
---|
| 80 | rtems_test_assert(errno == ENXIO); |
---|
| 81 | ++num_opens; |
---|
| 82 | |
---|
| 83 | // Number of attempts to open fifo till now = 3 |
---|
| 84 | // Number of attempts to move the static char |
---|
| 85 | // from 'a' -> 'z' = 26 |
---|
| 86 | // => Number of opens required = 23 |
---|
| 87 | puts("\n\nMultiple opens\n"); |
---|
| 88 | for(index = 0; index < NUM_OPEN_REQ - num_opens; ++index) { |
---|
| 89 | |
---|
| 90 | fd = open("/tmp/fifo01", O_RDONLY | O_NONBLOCK); |
---|
| 91 | rtems_test_assert(fd > 0); |
---|
| 92 | |
---|
| 93 | status = close(fd); |
---|
| 94 | rtems_test_assert(status == 0); |
---|
| 95 | |
---|
| 96 | printf("%d... ", index+1); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | puts("\n\nRemove the entry /tmp/fifo01"); |
---|
| 100 | status = unlink("/tmp/fifo01"); |
---|
| 101 | rtems_test_assert(status == 0); |
---|
| 102 | |
---|
| 103 | puts("\n\nRemove directory /tmp"); |
---|
| 104 | status = rmdir("/tmp"); |
---|
| 105 | rtems_test_assert(status == 0); |
---|
| 106 | |
---|
| 107 | puts("\n\n*** END OF FIFO / PIPE OPEN TEST - 4 ***"); |
---|
| 108 | } |
---|
| 109 | |
---|
[f94344f] | 110 | rtems_task Init( |
---|
| 111 | rtems_task_argument not_used |
---|
| 112 | ) |
---|
| 113 | { |
---|
| 114 | test_main(); |
---|
| 115 | rtems_test_exit(0); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 119 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 120 | |
---|
| 121 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
| 122 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6 |
---|
| 123 | |
---|
| 124 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 125 | |
---|
| 126 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 127 | #define CONFIGURE_PIPES_ENABLED |
---|
| 128 | #define CONFIGURE_INIT |
---|
| 129 | #define CONFIGURE_MAXIMUM_BARRIERS 2 |
---|
| 130 | |
---|
| 131 | #include <rtems/confdefs.h> |
---|
| 132 | |
---|
| 133 | /* end of file */ |
---|