1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2014. |
---|
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.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <tmacros.h> |
---|
15 | #include "test_support.h" |
---|
16 | |
---|
17 | #include <sys/types.h> |
---|
18 | #include <sys/stat.h> |
---|
19 | #include <fcntl.h> |
---|
20 | #include <unistd.h> |
---|
21 | #include <errno.h> |
---|
22 | #include <rtems/malloc.h> |
---|
23 | |
---|
24 | const char rtems_test_name[] = "SPFIFO 2"; |
---|
25 | |
---|
26 | #define NUM_OPEN_REQ 26 |
---|
27 | |
---|
28 | static void create_fifo(void) |
---|
29 | { |
---|
30 | int status; |
---|
31 | |
---|
32 | status = mkfifo("/fifo01", 0777); |
---|
33 | rtems_test_assert(status == 0); |
---|
34 | } |
---|
35 | |
---|
36 | static void open_fifo(int expected, int flags) |
---|
37 | { |
---|
38 | int fd; |
---|
39 | |
---|
40 | fd = open("/fifo01", flags); |
---|
41 | printf( "expect status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) ); |
---|
42 | if ( expected ) { |
---|
43 | rtems_test_assert(fd == -1); |
---|
44 | rtems_test_assert(errno == expected); |
---|
45 | } else { |
---|
46 | rtems_test_assert(fd != -1); |
---|
47 | close( fd ); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | static rtems_task Init( |
---|
52 | rtems_task_argument argument |
---|
53 | ) |
---|
54 | { |
---|
55 | void *p; |
---|
56 | int num_opens = 0; |
---|
57 | int index = 0; |
---|
58 | |
---|
59 | TEST_BEGIN(); |
---|
60 | |
---|
61 | puts( "Creating FIFO" ); |
---|
62 | create_fifo(); |
---|
63 | |
---|
64 | p = rtems_heap_greedy_allocate(NULL, 0); |
---|
65 | puts("Opening FIFO.. expect ENOMEM since no memory is available"); |
---|
66 | open_fifo(ENOMEM, O_RDWR); |
---|
67 | rtems_heap_greedy_free(p); |
---|
68 | |
---|
69 | puts( "Opening FIFO in RDWR mode. Expect OK" ); |
---|
70 | open_fifo(0, O_RDWR); |
---|
71 | ++num_opens; |
---|
72 | |
---|
73 | puts( "Opening FIFO in non blocking RDONLY mode. Expect OK"); |
---|
74 | open_fifo(0, O_RDONLY | O_NONBLOCK); |
---|
75 | ++num_opens; |
---|
76 | |
---|
77 | puts( "Opening FIFO in non blocking WRONLY mode. Expect ENXIO"); |
---|
78 | open_fifo(ENXIO, O_WRONLY | O_NONBLOCK); |
---|
79 | ++num_opens; |
---|
80 | |
---|
81 | puts("\nMultiple opens\n"); |
---|
82 | index = 0; |
---|
83 | do { |
---|
84 | |
---|
85 | printf("%d... ", index+1); |
---|
86 | open_fifo(0, O_RDONLY | O_NONBLOCK); |
---|
87 | ++index; |
---|
88 | } while ( index < NUM_OPEN_REQ - num_opens ); |
---|
89 | |
---|
90 | TEST_END(); |
---|
91 | |
---|
92 | rtems_test_exit(0); |
---|
93 | } |
---|
94 | |
---|
95 | /* configuration information */ |
---|
96 | |
---|
97 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
98 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
99 | |
---|
100 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
101 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
102 | |
---|
103 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
104 | |
---|
105 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 |
---|
106 | #define CONFIGURE_MAXIMUM_FIFOS 1 |
---|
107 | |
---|
108 | #define CONFIGURE_INIT |
---|
109 | |
---|
110 | #include <rtems/confdefs.h> |
---|
111 | /* end of file */ |
---|