Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:41

0001 /*
0002  * SPDX-License-Identifier: BSD-2-Clause
0003  *
0004  * Copyright (C) 2018, Himanshu Sekhar Nayak
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <fcntl.h>
0033 #include <timesys.h>
0034 #include <rtems/btimer.h>
0035 #include <tmacros.h>
0036 #include "test_support.h"
0037 #include <sched.h>
0038 #include <pthread.h>
0039 #include <mqueue.h>
0040 #include <signal.h>
0041 
0042 const char rtems_test_name[] = "PSXTMMQRCVBLOCK 02";
0043 
0044 /* forward declarations to avoid warnings */
0045 void *POSIX_Init(void *argument);
0046 void *Middle(void *argument);
0047 void *Low(void *argument);
0048 
0049 #define MQ_MAXMSG     1
0050 #define MQ_MSGSIZE    sizeof(int)
0051 
0052 static mqd_t queue;
0053 int message[MQ_MAXMSG];
0054 const char *q_name;
0055 unsigned int priority;
0056 struct timespec timeout;
0057 
0058 void *POSIX_Init(
0059   void *argument
0060 )
0061 {
0062   int              i;
0063   int              status;
0064   int              oflag = O_CREAT |O_RDWR;
0065   pthread_t        threadId;
0066   struct mq_attr   attr;
0067 
0068   priority = 0;
0069   timeout.tv_sec  = 0;
0070   timeout.tv_nsec = 0;
0071   attr.mq_maxmsg  = MQ_MAXMSG;
0072   attr.mq_msgsize = MQ_MSGSIZE;
0073 
0074   TEST_BEGIN();
0075 
0076   for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
0077     status = pthread_create( &threadId, NULL, Middle, NULL );
0078     rtems_test_assert( !status );
0079   }
0080 
0081   status = pthread_create( &threadId, NULL, Low, NULL );
0082   rtems_test_assert( !status );
0083 
0084   queue = mq_open( "queue", oflag, 0x777, &attr );
0085 
0086   /* let other threads run */
0087   sched_yield();
0088 
0089   /* now run the benchmark */
0090   benchmark_timer_initialize();
0091   status = mq_timedreceive(
0092           queue, (char *)message, MQ_MSGSIZE, &priority, &timeout);
0093   return NULL;
0094 }
0095 
0096 void *Middle(
0097   void *argument
0098 )
0099 {
0100   sched_yield();
0101 
0102     /* let other threads run */
0103 
0104     (void) mq_timedreceive(
0105       queue, (char *)message, MQ_MSGSIZE, &priority, &timeout);
0106 
0107   return NULL;
0108 }
0109 
0110 void *Low(
0111   void *argument
0112 )
0113 {
0114   benchmark_timer_t end_time;
0115 
0116   sched_yield();
0117 
0118   end_time = benchmark_timer_read();
0119 
0120   put_time(
0121     "mq_timedreceive: not available: block",
0122     end_time,
0123     OPERATION_COUNT,
0124     0,
0125     0
0126   );
0127 
0128   TEST_END();
0129 
0130   rtems_test_exit( 0 );
0131   return NULL;
0132 }
0133 
0134 /* configuration information */
0135 
0136 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
0137 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0138 
0139 #define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
0140 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0141 
0142 #define CONFIGURE_INIT
0143 
0144 #include <rtems/confdefs.h>
0145   /* end of file */