source: rtems/testsuites/psxtmtests/psxtmmq01/init.c @ 50162e0

4.115
Last change on this file since 50162e0 was 50162e0, checked in by Joel Sherrill <joel.sherrill@…>, on 12/07/13 at 18:18:02

psxtmtests: Make output more uniform

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