File indexing completed on 2025-05-11 08:24:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 #include <fcntl.h>
0033 #include <timesys.h>
0034 #include <errno.h>
0035 #include <rtems/btimer.h>
0036 #include "test_support.h"
0037 #include <tmacros.h>
0038 #include <mqueue.h>
0039 #include <signal.h> /* signal facilities */
0040
0041 const char rtems_test_name[] = "PSXTMMQ 01";
0042
0043
0044 void *POSIX_Init(void *argument);
0045
0046 #define MQ_MAXMSG 1
0047 #define MQ_MSGSIZE sizeof(int)
0048
0049 mqd_t queue;
0050 mqd_t queue2;
0051 const char *q_name;
0052
0053 static void benchmark_mq_open(int printable)
0054 {
0055 benchmark_timer_t end_time;
0056 struct mq_attr attr;
0057
0058 attr.mq_maxmsg = MQ_MAXMSG;
0059 attr.mq_msgsize = MQ_MSGSIZE;
0060 q_name= "queue";
0061
0062 benchmark_timer_initialize();
0063 queue = mq_open( q_name, O_CREAT | O_RDWR , 0x777, &attr );
0064 end_time = benchmark_timer_read();
0065 rtems_test_assert( queue != (-1) );
0066
0067 if (printable == 1)
0068 put_time(
0069 "mq_open: first open",
0070 end_time,
0071 1,
0072 0,
0073 0
0074 );
0075 }
0076
0077 static void benchmark_mq_open_second(int printable)
0078 {
0079 benchmark_timer_t end_time;
0080 struct mq_attr attr;
0081
0082 attr.mq_maxmsg = MQ_MAXMSG;
0083 attr.mq_msgsize = MQ_MSGSIZE;
0084
0085 benchmark_timer_initialize();
0086 queue2 =mq_open( q_name, O_RDONLY | O_CREAT , 0x777, &attr);
0087 end_time = benchmark_timer_read();
0088 rtems_test_assert( queue2 != (-1) );
0089
0090 if (printable == 1)
0091 put_time(
0092 "mq_open: second open",
0093 end_time,
0094 1,
0095 0,
0096 0
0097 );
0098
0099 }
0100
0101 static void benchmark_mq_close(int printable)
0102 {
0103 benchmark_timer_t end_time;
0104 int status;
0105
0106 benchmark_timer_initialize();
0107 status = mq_close(queue);
0108 end_time = benchmark_timer_read();
0109 rtems_test_assert( status == 0 );
0110
0111 if (printable == 1)
0112 put_time(
0113 "mq_close: close of first",
0114 end_time,
0115 1,
0116 0,
0117 0
0118 );
0119 }
0120
0121 static void benchmark_mq_close_second(int printable)
0122 {
0123 benchmark_timer_t end_time;
0124 int status;
0125
0126 benchmark_timer_initialize();
0127 status = mq_close(queue2);
0128 end_time = benchmark_timer_read();
0129 rtems_test_assert( status == 0 );
0130
0131 if (printable == 1)
0132 put_time(
0133 "mq_close: close of second",
0134 end_time,
0135 1,
0136 0,
0137 0
0138 );
0139 }
0140
0141 static void benchmark_mq_unlink(void)
0142 {
0143 benchmark_timer_t end_time;
0144 int status;
0145
0146 benchmark_timer_initialize();
0147 status = mq_unlink(q_name);
0148 end_time = benchmark_timer_read();
0149 rtems_test_assert( status == 0 );
0150
0151 put_time(
0152 "mq_unlink: only case",
0153 end_time,
0154 1,
0155 0,
0156 0
0157 );
0158 }
0159
0160 static void benchmark_mq_notify(void)
0161 {
0162 #if defined(RTEMS_POSIX_API)
0163 benchmark_timer_t end_time;
0164 int status;
0165 struct sigevent event;
0166
0167 event.sigev_notify = SIGEV_SIGNAL;
0168 event.sigev_signo = SIGUSR1;
0169
0170 benchmark_timer_initialize();
0171 status = mq_notify( queue2, &event );
0172 end_time = benchmark_timer_read();
0173 rtems_test_assert( status == 0 );
0174
0175 put_time(
0176 "mq_notify: only case",
0177 end_time,
0178 1,
0179 0,
0180 0
0181 );
0182 #endif
0183 }
0184
0185 static void benchmark_mq_send(void)
0186 {
0187 benchmark_timer_t end_time;
0188 int status;
0189
0190 status = 9;
0191 benchmark_timer_initialize();
0192 status = mq_send( queue, (const char *)&status, MQ_MSGSIZE, 1 );
0193 end_time = benchmark_timer_read();
0194 rtems_test_assert( status != (-1) );
0195
0196 put_time(
0197 "mq_send: no threads waiting",
0198 end_time,
0199 1,
0200 0,
0201 0
0202 );
0203 }
0204
0205 static void benchmark_mq_receive(void)
0206 {
0207 benchmark_timer_t end_time;
0208 int status;
0209 unsigned int priority;
0210 int message[MQ_MAXMSG];
0211 priority = 1;
0212
0213 benchmark_timer_initialize();
0214 status = mq_receive( queue2, ( char *)message, MQ_MSGSIZE, &priority );
0215 end_time = benchmark_timer_read();
0216 rtems_test_assert( status != (-1) );
0217
0218 put_time(
0219 "mq_receive: available",
0220 end_time,
0221 1,
0222 0,
0223 0
0224 );
0225 }
0226
0227 static void benchmark_mq_timedsend(void)
0228 {
0229 benchmark_timer_t end_time;
0230 int status;
0231 struct timespec timeout;
0232
0233 status = 5;
0234 timeout.tv_sec = 0;
0235 timeout.tv_nsec = 1;
0236 benchmark_timer_initialize();
0237 status = mq_timedsend(
0238 queue, (const char *)&status, MQ_MSGSIZE, 1, &timeout);
0239 end_time = benchmark_timer_read();
0240 rtems_test_assert( status != (-1) );
0241
0242 put_time(
0243 "mq_timedsend: no threads waiting",
0244 end_time,
0245 1,
0246 0,
0247 0
0248 );
0249 }
0250
0251 static void benchmark_mq_timedreceive(void)
0252 {
0253 benchmark_timer_t end_time;
0254 int status;
0255 unsigned int priority;
0256 struct timespec timeout;
0257 int message[MQ_MAXMSG];
0258
0259 priority = 1;
0260 timeout.tv_sec = 0;
0261 timeout.tv_nsec = 0;
0262 benchmark_timer_initialize();
0263 status = mq_timedreceive(
0264 queue2, ( char *)message, MQ_MSGSIZE, &priority, &timeout);
0265 end_time = benchmark_timer_read();
0266 rtems_test_assert( status != (-1) );
0267
0268 put_time(
0269 "mq_timedreceive: available",
0270 end_time,
0271 1,
0272 0,
0273 0
0274 );
0275 }
0276
0277
0278 void *POSIX_Init(
0279 void *argument
0280 )
0281 {
0282 TEST_BEGIN();
0283
0284 benchmark_mq_open(1);
0285
0286 benchmark_mq_send();
0287
0288 benchmark_mq_open_second(1);
0289
0290 benchmark_mq_receive();
0291
0292 benchmark_mq_close_second(0);
0293
0294 benchmark_mq_unlink();
0295
0296 benchmark_mq_close(0);
0297
0298
0299 benchmark_mq_open(0);
0300
0301 benchmark_mq_timedsend();
0302
0303 benchmark_mq_open_second(0);
0304
0305 benchmark_mq_timedreceive();
0306
0307 benchmark_mq_notify();
0308
0309 benchmark_mq_close_second(1);
0310
0311 benchmark_mq_close(1);
0312
0313 TEST_END();
0314 rtems_test_exit(0);
0315 }
0316
0317
0318
0319 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0320 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0321
0322 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0323 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0324 #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 2
0325
0326 #define CONFIGURE_INIT
0327
0328 #include <rtems/confdefs.h>
0329