source: rtems/testsuites/psxtmtests/psxtmmq01/init.c @ ef16a11

5
Last change on this file since ef16a11 was ef16a11, checked in by Sebastian Huber <sebastian.huber@…>, on 10/25/18 at 09:05:12

posix: Enable psxtmtests tests by default

Update #2514.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
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#include <fcntl.h>
14#include <timesys.h>
15#include <errno.h>
16#include <rtems/btimer.h>
17#include "test_support.h"
18#include <tmacros.h>
19#include <mqueue.h>
20#include <signal.h>   /* signal facilities */
21
22const char rtems_test_name[] = "PSXTMMQ 01";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26
27#define MQ_MAXMSG     1
28#define MQ_MSGSIZE    sizeof(int)
29
30mqd_t       queue;
31mqd_t       queue2;
32const char *q_name;
33
34static void benchmark_mq_open(int printable)
35{
36  benchmark_timer_t end_time;
37  struct mq_attr  attr;
38
39  attr.mq_maxmsg  = MQ_MAXMSG;
40  attr.mq_msgsize = MQ_MSGSIZE;
41  q_name= "queue";
42
43  benchmark_timer_initialize();
44    queue = mq_open( q_name, O_CREAT | O_RDWR , 0x777, &attr );
45  end_time = benchmark_timer_read();
46  rtems_test_assert( queue != (-1) );
47
48  if (printable == 1)
49    put_time(
50      "mq_open: first open",
51      end_time,
52      1,        /* Only executed once */
53      0,
54      0
55    );
56}
57
58static void benchmark_mq_open_second(int printable)
59{
60  benchmark_timer_t end_time;
61  struct mq_attr  attr;
62
63  attr.mq_maxmsg  = MQ_MAXMSG;
64  attr.mq_msgsize = MQ_MSGSIZE;
65
66  benchmark_timer_initialize();
67    queue2 =mq_open( q_name, O_RDONLY | O_CREAT , 0x777, &attr);
68  end_time = benchmark_timer_read();
69  rtems_test_assert( queue2 != (-1) );
70
71  if (printable == 1)
72    put_time(
73      "mq_open: second open",
74      end_time,
75      1,        /* Only executed once */
76      0,
77      0
78    );
79
80}
81
82static void benchmark_mq_close(int printable)
83{
84  benchmark_timer_t end_time;
85  int  status;
86
87  benchmark_timer_initialize();
88    status = mq_close(queue);
89  end_time = benchmark_timer_read();
90  rtems_test_assert( status == 0 );
91
92  if (printable == 1)
93    put_time(
94      "mq_close: close of first",
95      end_time,
96      1,        /* Only executed once */
97      0,
98      0
99    );
100}
101
102static void benchmark_mq_close_second(int printable)
103{
104  benchmark_timer_t end_time;
105  int  status;
106
107  benchmark_timer_initialize();
108    status = mq_close(queue2);
109  end_time = benchmark_timer_read();
110  rtems_test_assert( status == 0 );
111
112  if (printable == 1)
113    put_time(
114      "mq_close: close of second",
115      end_time,
116      1,        /* Only executed once */
117      0,
118      0
119    );
120}
121
122static void benchmark_mq_unlink(void)
123{
124  benchmark_timer_t end_time;
125  int  status;
126
127  benchmark_timer_initialize();
128    status = mq_unlink(q_name);
129  end_time = benchmark_timer_read();
130  rtems_test_assert( status == 0 );
131
132  put_time(
133    "mq_unlink: only case",
134    end_time,
135    1,        /* Only executed once */
136    0,
137    0
138  );
139}
140
141static void benchmark_mq_notify(void)
142{
143#if defined(RTEMS_POSIX_API)
144  benchmark_timer_t end_time;
145  int             status;
146  struct sigevent event;
147
148  event.sigev_notify = SIGEV_SIGNAL;
149  event.sigev_signo  = SIGUSR1;
150
151  benchmark_timer_initialize();
152    status = mq_notify( queue2, &event );
153  end_time = benchmark_timer_read();
154  rtems_test_assert( status == 0 );
155
156  put_time(
157    "mq_notify: only case",
158    end_time,
159    1,        /* Only executed once */
160    0,
161    0
162  );
163#endif
164}
165
166static void benchmark_mq_send(void)
167{
168  benchmark_timer_t end_time;
169  int  status;
170
171  status = 9;
172  benchmark_timer_initialize();
173    status = mq_send( queue, (const char *)&status, MQ_MSGSIZE, 1 );
174  end_time = benchmark_timer_read();
175  rtems_test_assert( status != (-1) );
176
177  put_time(
178    "mq_send: no threads waiting",
179    end_time,
180    1,        /* Only executed once */
181    0,
182    0
183  );
184}
185
186static void benchmark_mq_receive(void)
187{
188  benchmark_timer_t end_time;
189  int           status;
190  unsigned int  priority;
191  int           message[MQ_MAXMSG];
192  priority = 1;       /*priority low*/
193
194  benchmark_timer_initialize();
195    status = mq_receive( queue2, ( char *)message, MQ_MSGSIZE, &priority );
196  end_time = benchmark_timer_read();
197  rtems_test_assert( status != (-1) );
198
199  put_time(
200    "mq_receive: available",
201    end_time,
202    1,        /* Only executed once */
203    0,
204    0
205  );
206}
207
208static void benchmark_mq_timedsend(void)
209{
210  benchmark_timer_t end_time;
211  int              status;
212  struct timespec  timeout;
213
214  status = 5;
215  timeout.tv_sec  = 0;
216  timeout.tv_nsec = 1;
217  benchmark_timer_initialize();
218    status = mq_timedsend(
219             queue, (const char *)&status, MQ_MSGSIZE, 1, &timeout);
220  end_time = benchmark_timer_read();
221  rtems_test_assert( status != (-1) );
222
223  put_time(
224    "mq_timedsend: no threads waiting",
225    end_time,
226    1,        /* Only executed once */
227    0,
228    0
229  );
230}
231
232static void benchmark_mq_timedreceive(void)
233{
234  benchmark_timer_t end_time;
235  int              status;
236  unsigned int     priority;
237  struct timespec  timeout;
238  int              message[MQ_MAXMSG];
239
240  priority = 1;       /*priority low*/
241  timeout.tv_sec  = 0;
242  timeout.tv_nsec = 0;
243  benchmark_timer_initialize();
244    status = mq_timedreceive(
245                  queue2, ( char *)message, MQ_MSGSIZE, &priority, &timeout);
246  end_time = benchmark_timer_read();
247  rtems_test_assert( status != (-1) );
248
249  put_time(
250    "mq_timedreceive: available",
251    end_time,
252    1,        /* Only executed once */
253    0,
254    0
255  );
256}
257
258
259void *POSIX_Init(
260  void *argument
261)
262{
263  TEST_BEGIN();
264  /* create the first message queue READWRITE */
265  benchmark_mq_open(1);
266  /* send message using first queue */
267  benchmark_mq_send();
268  /* open a second message queue READ ONLY */
269  benchmark_mq_open_second(1);
270  /* receiving message using the seconde queue */
271  benchmark_mq_receive();
272  /* closing the second message queue */
273  benchmark_mq_close_second(0);
274  /* unlinking the first queue */
275  benchmark_mq_unlink();
276  /* closing the first queue */
277  benchmark_mq_close(0);
278  /* now repeat basically the same, but for the timed-send/recive */
279  /* open the first queue */
280  benchmark_mq_open(0);
281  /* send message using the first queue */
282  benchmark_mq_timedsend();
283  /* open a second message queue READ ONLY */
284  benchmark_mq_open_second(0);
285  /* receiving message using the seconde queue */
286  benchmark_mq_timedreceive();
287  /* calling notify */
288  benchmark_mq_notify();
289  /* closing the second message queue */
290  benchmark_mq_close_second(1);
291  /* closing the first queue */
292  benchmark_mq_close(1);
293
294 TEST_END();
295  rtems_test_exit(0);
296}
297
298/* configuration information */
299
300#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
301#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
302
303#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
304#define CONFIGURE_POSIX_INIT_THREAD_TABLE
305#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES  2
306
307#define CONFIGURE_INIT
308
309#include <rtems/confdefs.h>
310/* end of file */
Note: See TracBrowser for help on using the repository browser.