1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
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 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <pmacros.h> |
---|
17 | #include <unistd.h> |
---|
18 | #include <errno.h> |
---|
19 | #include <tmacros.h> |
---|
20 | |
---|
21 | #include <fcntl.h> /* For O_* constants */ |
---|
22 | #include <sys/stat.h> /* For mode constants */ |
---|
23 | #include <mqueue.h> |
---|
24 | |
---|
25 | #include "test_support.h" |
---|
26 | |
---|
27 | void *POSIX_Init( |
---|
28 | void *argument |
---|
29 | ) |
---|
30 | { |
---|
31 | struct mq_attr attr; |
---|
32 | mqd_t Queue, second_Queue; |
---|
33 | int sc; |
---|
34 | Heap_Information_block start; |
---|
35 | Heap_Information_block info; |
---|
36 | size_t to_alloc; |
---|
37 | void *alloced; |
---|
38 | bool sb; |
---|
39 | const char *name; |
---|
40 | |
---|
41 | puts( "\n\n*** POSIX MESSAGE QUEUE TEST 4 ***" ); |
---|
42 | |
---|
43 | attr.mq_maxmsg = 1; |
---|
44 | attr.mq_msgsize = sizeof(int); |
---|
45 | |
---|
46 | puts( "Init - Open message queue instance 1" ); |
---|
47 | Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr ); |
---|
48 | if ( Queue == (-1) ) |
---|
49 | perror( "mq_open failed" ); |
---|
50 | rtems_test_assert( Queue != (-1) ); |
---|
51 | |
---|
52 | puts( "Init - Open message queue instance 2 - FAIL - ENFILE " ); |
---|
53 | second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr ); |
---|
54 | if ( second_Queue != (-1) ) |
---|
55 | puts( "mq_open did not failed" ); |
---|
56 | rtems_test_assert( second_Queue == (-1) ); |
---|
57 | rtems_test_assert( errno == ENFILE ); |
---|
58 | |
---|
59 | puts( "Init - Unlink message queue instance 1" ); |
---|
60 | sc = mq_unlink( "Queue" ); |
---|
61 | if ( sc != 0 ) |
---|
62 | perror( "mq_unlink failed" ); |
---|
63 | rtems_test_assert( sc == 0 ); |
---|
64 | |
---|
65 | puts( "Init - Close message queue instance 1" ); |
---|
66 | sc = mq_close( Queue ); |
---|
67 | if ( sc != 0 ) |
---|
68 | perror( "mq_close failed" ); |
---|
69 | rtems_test_assert( sc == 0 ); |
---|
70 | |
---|
71 | sb = rtems_workspace_get_information( &start ); |
---|
72 | rtems_test_assert( start.Free.number == 1 ); |
---|
73 | to_alloc = start.Free.largest; |
---|
74 | |
---|
75 | /* find the largest we can actually allocate */ |
---|
76 | while ( 1 ) { |
---|
77 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
78 | if ( sb ) |
---|
79 | break; |
---|
80 | to_alloc -= 4; |
---|
81 | } |
---|
82 | |
---|
83 | rtems_workspace_free( alloced ); |
---|
84 | |
---|
85 | /* |
---|
86 | * Now do the test |
---|
87 | */ |
---|
88 | puts( "Init - Memory allocation error test" ); |
---|
89 | |
---|
90 | name = Get_Longest_Name(); |
---|
91 | do { |
---|
92 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
93 | rtems_test_assert( sb ); |
---|
94 | |
---|
95 | second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr ); |
---|
96 | |
---|
97 | /* free the memory we snagged, then check the status */ |
---|
98 | rtems_workspace_free( alloced ); |
---|
99 | |
---|
100 | to_alloc -= 4; |
---|
101 | } while ( second_Queue == -1 ); |
---|
102 | |
---|
103 | puts( "Init - Message Queue created" ); |
---|
104 | |
---|
105 | puts( "Init - Unlink message queue" ); |
---|
106 | sc = mq_unlink( name ); |
---|
107 | if ( sc != 0 ) |
---|
108 | perror( "mq_unlink failed" ); |
---|
109 | rtems_test_assert( sc == 0 ); |
---|
110 | |
---|
111 | puts( "Init - Close message queue" ); |
---|
112 | sc = mq_close( second_Queue ); |
---|
113 | if ( sc != 0 ) |
---|
114 | perror( "mq_close failed" ); |
---|
115 | rtems_test_assert( sc == 0 ); |
---|
116 | |
---|
117 | puts( "*** END OF POSIX MESSAGE QUEUE TEST 4 ***" ); |
---|
118 | rtems_test_exit( 0 ); |
---|
119 | |
---|
120 | return NULL; /* just so the compiler thinks we returned something */ |
---|
121 | } |
---|
122 | |
---|
123 | /* configuration information */ |
---|
124 | |
---|
125 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
126 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
127 | |
---|
128 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
129 | |
---|
130 | /* account for message buffers and string names */ |
---|
131 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY \ |
---|
132 | (2 * CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, sizeof(int))) |
---|
133 | |
---|
134 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
135 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1 |
---|
136 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS 2 |
---|
137 | |
---|
138 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
139 | |
---|
140 | #define CONFIGURE_INIT |
---|
141 | #include <rtems/confdefs.h> |
---|