Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #define CONFIGURE_INIT
0034 #include "system.h"
0035 
0036 #include <fcntl.h>           /* For O_* constants */
0037 #include <sys/stat.h>        /* For mode constants */
0038 #include <mqueue.h>
0039 
0040 #include "test_support.h"
0041 
0042 const char rtems_test_name[] = "PSXMSGQ 3";
0043 
0044 /* forward declarations to avoid warnings */
0045 rtems_timer_service_routine mq_send_timer(rtems_id timer, void *arg);
0046 
0047 mqd_t Queue;
0048 volatile bool tsr_fired;
0049 volatile int  tsr_status;
0050 volatile int  tsr_errno;
0051 
0052 rtems_timer_service_routine mq_send_timer(
0053   rtems_id  timer,
0054   void     *arg
0055 )
0056 {
0057   int msg = 4;
0058 
0059   tsr_fired = true;
0060 
0061   tsr_status = mq_send( Queue, (const char *)&msg, sizeof(int), 1 );
0062   tsr_errno = errno;
0063 }
0064 
0065 void *POSIX_Init(
0066   void *argument
0067 )
0068 {
0069   struct mq_attr     attr;
0070   int                status;
0071   rtems_id           timer;
0072   rtems_status_code  rc;
0073 
0074   TEST_BEGIN();
0075 
0076   attr.mq_maxmsg  = 1;
0077   attr.mq_msgsize = sizeof(int);
0078 
0079   puts( "Init - Open message queue" );
0080   Queue = mq_open( "Qsend", O_CREAT | O_RDWR, 0x777, &attr );
0081   if ( Queue == (-1) ) {
0082     perror( "mq_open failed" );
0083   }
0084   rtems_test_assert( Queue != (-1) );
0085 
0086   puts( "Init - send to message queue" );
0087   status = mq_send( Queue, (const char *)&status, sizeof(int), 1 );
0088   if ( status == (-1) ) {
0089     perror( "mq_status failed" );
0090   }
0091   rtems_test_assert( status != (-1) );
0092 
0093   /*
0094    * Now create the timer we will send to a full queue from.
0095    */
0096   puts( "Init - Create Classic API Timer" );
0097   rc = rtems_timer_create( 1, &timer );
0098   directive_failed( rc, "rtems_timer_create" );
0099 
0100   puts( "Init - Fire After Classic API Timer" );
0101   tsr_fired = false;
0102 
0103   rc = rtems_timer_fire_after(
0104     timer,
0105     rtems_clock_get_ticks_per_second(),
0106     mq_send_timer,
0107     NULL
0108   );
0109   directive_failed( rc, "rtems_timer_fire_after" );
0110 
0111   sleep(2);
0112 
0113   if ( tsr_fired == false ) {
0114     puts( "ERROR -- TSR DID NOT FIRE" );
0115     rtems_test_exit( 0 );
0116   }
0117   if ( (tsr_status != -1) || (tsr_errno != EAGAIN) ) {
0118     puts( "ERROR -- TSR DID NOT RETURN CORRECT STATUS" );
0119     printf(
0120       "status=%d errno=%d --> %s\n",
0121       tsr_status,
0122       tsr_errno,
0123       strerror(tsr_errno)
0124     );
0125     rtems_test_exit( 0 );
0126   }
0127 
0128   puts( "Init - mq_send from ISR returned correct status" );
0129 
0130   TEST_END();
0131   rtems_test_exit( 0 );
0132 
0133   return NULL; /* just so the compiler thinks we returned something */
0134 }