1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2010. |
---|
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 | #include <tmacros.h> |
---|
13 | #include "test_support.h" |
---|
14 | |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/stat.h> |
---|
17 | #include <fcntl.h> |
---|
18 | #include <errno.h> |
---|
19 | |
---|
20 | #define MAXIMUM 10 |
---|
21 | rtems_id Barriers[MAXIMUM]; |
---|
22 | int BarrierCount; |
---|
23 | |
---|
24 | rtems_id Semaphores[MAXIMUM]; |
---|
25 | int SemaphoreCount; |
---|
26 | |
---|
27 | void create_all_barriers(void) |
---|
28 | { |
---|
29 | rtems_status_code status; |
---|
30 | int i; |
---|
31 | |
---|
32 | BarrierCount = 0; |
---|
33 | |
---|
34 | for ( i=0 ; i<MAXIMUM ; i++ ) { |
---|
35 | status = rtems_barrier_create( |
---|
36 | rtems_build_name( 'B', 'A', 'R', 0x30+i ), |
---|
37 | RTEMS_BARRIER_MANUAL_RELEASE, |
---|
38 | 0, |
---|
39 | &Barriers[i] |
---|
40 | ); |
---|
41 | if ( status == RTEMS_TOO_MANY ) { |
---|
42 | printf( "%d Barriers created\n", BarrierCount ); |
---|
43 | return; |
---|
44 | } |
---|
45 | |
---|
46 | directive_failed( status, "barrier create" ); |
---|
47 | BarrierCount++; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | void create_all_semaphores(void) |
---|
52 | { |
---|
53 | rtems_status_code status; |
---|
54 | int i; |
---|
55 | |
---|
56 | SemaphoreCount = 0; |
---|
57 | |
---|
58 | for ( i=0 ; i<MAXIMUM ; i++ ) { |
---|
59 | status = rtems_semaphore_create( |
---|
60 | rtems_build_name( 'S', 'E', 'M', 0x30+i ), |
---|
61 | 0, |
---|
62 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
63 | 0, |
---|
64 | &Semaphores[i] |
---|
65 | ); |
---|
66 | if ( status == RTEMS_TOO_MANY ) { |
---|
67 | printf( "%d Semaphores created\n", SemaphoreCount ); |
---|
68 | return; |
---|
69 | } |
---|
70 | |
---|
71 | directive_failed( status, "semaphore create" ); |
---|
72 | SemaphoreCount++; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | void delete_barrier(void) |
---|
77 | { |
---|
78 | rtems_status_code status; |
---|
79 | |
---|
80 | puts( "Deleting a barrier" ); |
---|
81 | status = rtems_barrier_delete( Barriers[BarrierCount] ); |
---|
82 | directive_failed( status, "barrier delete" ); |
---|
83 | } |
---|
84 | |
---|
85 | void delete_semaphore(void) |
---|
86 | { |
---|
87 | rtems_status_code status; |
---|
88 | |
---|
89 | puts( "Deleting a semaphore" ); |
---|
90 | status = rtems_semaphore_delete( Semaphores[SemaphoreCount] ); |
---|
91 | directive_failed( status, "semaphore delete" ); |
---|
92 | } |
---|
93 | |
---|
94 | void create_fifo(void) |
---|
95 | { |
---|
96 | int status; |
---|
97 | |
---|
98 | status = mkfifo("/fifo01", 0777); |
---|
99 | rtems_test_assert(status == 0); |
---|
100 | } |
---|
101 | |
---|
102 | void open_fifo(int expected) |
---|
103 | { |
---|
104 | int fd; |
---|
105 | |
---|
106 | fd = open("/fifo01", O_RDONLY); |
---|
107 | printf( "status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) ); |
---|
108 | if ( expected ) { |
---|
109 | rtems_test_assert(fd == -1); |
---|
110 | rtems_test_assert(errno == expected); |
---|
111 | } else { |
---|
112 | rtems_test_assert(fd != -1); |
---|
113 | close( fd ); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | rtems_task Init( |
---|
118 | rtems_task_argument argument |
---|
119 | ) |
---|
120 | { |
---|
121 | puts( "\n\n*** TEST FIFO 08 ***" ); |
---|
122 | |
---|
123 | puts( "Creating all barriers" ); |
---|
124 | create_all_barriers(); |
---|
125 | |
---|
126 | puts( "Creating all semaphores" ); |
---|
127 | create_all_semaphores(); |
---|
128 | |
---|
129 | puts( "Creating FIFO" ); |
---|
130 | create_fifo(); |
---|
131 | |
---|
132 | puts( "Opening FIFO.. expect ENOMEM (barrier - case 1)" ); |
---|
133 | open_fifo(ENOMEM); |
---|
134 | |
---|
135 | delete_barrier(); |
---|
136 | puts( "Opening FIFO.. expect ENOMEM (barrier - case 2)" ); |
---|
137 | open_fifo(ENOMEM); |
---|
138 | |
---|
139 | delete_barrier(); |
---|
140 | puts( "Opening FIFO.. expect ENOMEM (semaphore - case 1)" ); |
---|
141 | |
---|
142 | open_fifo(0); |
---|
143 | |
---|
144 | puts( "*** END OF TEST FIFO 08 ***" ); |
---|
145 | |
---|
146 | rtems_test_exit(0); |
---|
147 | } |
---|
148 | |
---|
149 | /* configuration information */ |
---|
150 | |
---|
151 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
152 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
153 | |
---|
154 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
155 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
156 | |
---|
157 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
158 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 |
---|
159 | #define CONFIGURE_FIFOS_ENABLED |
---|
160 | #define CONFIGURE_MAXIMUM_FIFOS 1 |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | |
---|
164 | #include <rtems/confdefs.h> |
---|
165 | /* end of file */ |
---|