1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2012. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <pmacros.h> |
---|
34 | #include <unistd.h> |
---|
35 | #include <errno.h> |
---|
36 | #include <tmacros.h> |
---|
37 | |
---|
38 | #include <fcntl.h> /* For O_* constants */ |
---|
39 | #include <sys/stat.h> /* For mode constants */ |
---|
40 | #include <mqueue.h> |
---|
41 | |
---|
42 | #include "test_support.h" |
---|
43 | |
---|
44 | const char rtems_test_name[] = "PSXMSGQ 4"; |
---|
45 | |
---|
46 | /* forward declarations to avoid warnings */ |
---|
47 | void *POSIX_Init(void *argument); |
---|
48 | |
---|
49 | void *POSIX_Init( |
---|
50 | void *argument |
---|
51 | ) |
---|
52 | { |
---|
53 | struct mq_attr attr; |
---|
54 | mqd_t Queue, second_Queue; |
---|
55 | int sc; |
---|
56 | Heap_Information_block start; |
---|
57 | size_t to_alloc; |
---|
58 | void *alloced; |
---|
59 | bool sb; |
---|
60 | const char *name; |
---|
61 | |
---|
62 | TEST_BEGIN(); |
---|
63 | |
---|
64 | attr.mq_maxmsg = 1; |
---|
65 | attr.mq_msgsize = sizeof(int); |
---|
66 | |
---|
67 | puts( "Init - Open message queue instance 1" ); |
---|
68 | Queue = mq_open( "Queue", O_CREAT | O_RDWR, 0x777, &attr ); |
---|
69 | if ( Queue == (-1) ) |
---|
70 | perror( "mq_open failed" ); |
---|
71 | rtems_test_assert( Queue != (-1) ); |
---|
72 | |
---|
73 | puts( "Init - Open message queue instance 2 - FAIL - ENFILE " ); |
---|
74 | second_Queue = mq_open( "Queue2", O_CREAT | O_RDWR, 0x777, &attr ); |
---|
75 | if ( second_Queue != (-1) ) |
---|
76 | puts( "mq_open did not failed" ); |
---|
77 | rtems_test_assert( second_Queue == (-1) ); |
---|
78 | rtems_test_assert( errno == ENFILE ); |
---|
79 | |
---|
80 | puts( "Init - Unlink message queue instance 1" ); |
---|
81 | sc = mq_unlink( "Queue" ); |
---|
82 | if ( sc != 0 ) |
---|
83 | perror( "mq_unlink failed" ); |
---|
84 | rtems_test_assert( sc == 0 ); |
---|
85 | |
---|
86 | puts( "Init - Close message queue instance 1" ); |
---|
87 | sc = mq_close( Queue ); |
---|
88 | if ( sc != 0 ) |
---|
89 | perror( "mq_close failed" ); |
---|
90 | rtems_test_assert( sc == 0 ); |
---|
91 | |
---|
92 | sb = rtems_workspace_get_information( &start ); |
---|
93 | rtems_test_assert( start.Free.number == 1 ); |
---|
94 | to_alloc = start.Free.largest; |
---|
95 | |
---|
96 | /* find the largest we can actually allocate */ |
---|
97 | while ( 1 ) { |
---|
98 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
99 | if ( sb ) |
---|
100 | break; |
---|
101 | to_alloc -= 4; |
---|
102 | } |
---|
103 | |
---|
104 | rtems_workspace_free( alloced ); |
---|
105 | |
---|
106 | /* |
---|
107 | * Now do the test |
---|
108 | */ |
---|
109 | puts( "Init - Memory allocation error test" ); |
---|
110 | |
---|
111 | name = Get_Longest_Name(); |
---|
112 | do { |
---|
113 | sb = rtems_workspace_allocate( to_alloc, &alloced ); |
---|
114 | rtems_test_assert( sb ); |
---|
115 | |
---|
116 | second_Queue = mq_open(name,O_CREAT | O_RDWR, 0x777, &attr ); |
---|
117 | |
---|
118 | /* free the memory we snagged, then check the status */ |
---|
119 | rtems_workspace_free( alloced ); |
---|
120 | |
---|
121 | to_alloc -= 4; |
---|
122 | } while ( second_Queue == -1 ); |
---|
123 | |
---|
124 | puts( "Init - Message Queue created" ); |
---|
125 | |
---|
126 | puts( "Init - Unlink message queue" ); |
---|
127 | sc = mq_unlink( name ); |
---|
128 | if ( sc != 0 ) |
---|
129 | perror( "mq_unlink failed" ); |
---|
130 | rtems_test_assert( sc == 0 ); |
---|
131 | |
---|
132 | puts( "Init - Close message queue" ); |
---|
133 | sc = mq_close( second_Queue ); |
---|
134 | if ( sc != 0 ) |
---|
135 | perror( "mq_close failed" ); |
---|
136 | rtems_test_assert( sc == 0 ); |
---|
137 | |
---|
138 | TEST_END(); |
---|
139 | rtems_test_exit( 0 ); |
---|
140 | |
---|
141 | return NULL; /* just so the compiler thinks we returned something */ |
---|
142 | } |
---|
143 | |
---|
144 | /* configuration information */ |
---|
145 | |
---|
146 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
147 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
148 | |
---|
149 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
150 | |
---|
151 | /* account for message buffers and string names */ |
---|
152 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY \ |
---|
153 | (2 * CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, sizeof(int))) |
---|
154 | |
---|
155 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
156 | |
---|
157 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
158 | #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1 |
---|
159 | |
---|
160 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
161 | |
---|
162 | #define CONFIGURE_INIT |
---|
163 | #include <rtems/confdefs.h> |
---|