Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *
0005  *  COPYRIGHT (c) 1989-2013.
0006  *  On-Line Applications Research Corporation (OAR).
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions
0010  * are met:
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  *
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0027  * POSSIBILITY OF SUCH DAMAGE.
0028  */
0029 
0030 #if !defined(OPERATION_COUNT)
0031 #define OPERATION_COUNT 100
0032 #endif
0033 
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037 
0038 #include <rtems/btimer.h>
0039 
0040 #define CONFIGURE_INIT
0041 #include "system.h"
0042 
0043 const char rtems_test_name[] = "TIME TEST 22";
0044 
0045 rtems_id Queue_id;
0046 
0047 long Buffer[4];
0048 
0049 rtems_task Low_task(
0050   rtems_task_argument argument
0051 );
0052 
0053 rtems_task High_task(
0054   rtems_task_argument argument
0055 );
0056 
0057 rtems_task Preempt_task(
0058   rtems_task_argument argument
0059 );
0060 
0061 rtems_task Init(
0062   rtems_task_argument argument
0063 )
0064 {
0065   rtems_id          id;
0066   rtems_status_code status;
0067 
0068   Print_Warning();
0069 
0070   TEST_BEGIN();
0071 
0072   status = rtems_message_queue_create(
0073     rtems_build_name( 'M', 'Q', '1', ' '),
0074     100,
0075     MESSAGE_SIZE,
0076     RTEMS_DEFAULT_ATTRIBUTES,
0077     &Queue_id
0078   );
0079   directive_failed( status, "rtems_message_queue_create" );
0080 
0081   status = rtems_task_create(
0082     rtems_build_name( 'L', 'O', 'W', ' ' ),
0083     10,
0084     RTEMS_MINIMUM_STACK_SIZE,
0085     RTEMS_NO_PREEMPT,
0086     RTEMS_DEFAULT_ATTRIBUTES,
0087     &id
0088   );
0089   directive_failed( status, "rtems_task_create" );
0090 
0091   status = rtems_task_start( id, Low_task, 0 );
0092   directive_failed( status, "rtems_task_start LOW" );
0093 
0094   status = rtems_task_create(
0095     1,
0096     11,
0097     RTEMS_MINIMUM_STACK_SIZE,
0098     RTEMS_DEFAULT_MODES,
0099     RTEMS_DEFAULT_ATTRIBUTES,
0100     &id
0101   );
0102   directive_failed( status, "rtems_task_create RTEMS_PREEMPT" );
0103 
0104   status = rtems_task_start( id, Preempt_task, 0 );
0105   directive_failed( status, "rtems_task_start RTEMS_PREEMPT" );
0106 
0107   rtems_task_exit();
0108 }
0109 
0110 rtems_task High_task(
0111   rtems_task_argument argument
0112 )
0113 {
0114   uint32_t    count;
0115   rtems_status_code status;
0116 
0117   benchmark_timer_initialize();
0118     (void) rtems_message_queue_broadcast(
0119              Queue_id,
0120              Buffer,
0121              MESSAGE_SIZE,
0122              &count
0123            );
0124   end_time = benchmark_timer_read();
0125 
0126   put_time(
0127     "rtems_message_queue_broadcast: task readied returns to caller",
0128     end_time,
0129     1,
0130     0,
0131     0
0132   );
0133 
0134   status = rtems_task_suspend(RTEMS_SELF);
0135   directive_failed( status, "rtems_task_suspend" );
0136 }
0137 
0138 rtems_task Low_task(
0139   rtems_task_argument argument
0140 )
0141 {
0142   rtems_id          id;
0143   uint32_t          index;
0144   uint32_t          count;
0145   size_t            size;
0146   rtems_status_code status;
0147 
0148   status = rtems_task_create(
0149     rtems_build_name( 'H', 'I', 'G', 'H' ),
0150     5,
0151     RTEMS_MINIMUM_STACK_SIZE,
0152     RTEMS_NO_PREEMPT,
0153     RTEMS_DEFAULT_ATTRIBUTES,
0154     &id
0155   );
0156   directive_failed( status, "rtems_task_create" );
0157 
0158   status = rtems_task_start( id, High_task, 0 );
0159   directive_failed( status, "rtems_task_start HIGH" );
0160 
0161   status = rtems_message_queue_receive(
0162     Queue_id,
0163     (long (*)[4]) Buffer,
0164     &size,
0165     RTEMS_DEFAULT_OPTIONS,
0166     RTEMS_NO_TIMEOUT
0167   );
0168   directive_failed( status, "message_queu_receive" );
0169 
0170   benchmark_timer_initialize();
0171     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0172       (void) rtems_message_queue_broadcast(
0173                Queue_id,
0174                Buffer,
0175                MESSAGE_SIZE,
0176                &count
0177              );
0178   end_time = benchmark_timer_read();
0179 
0180   put_time(
0181     "rtems_message_queue_broadcast: no waiting tasks",
0182     end_time,
0183     OPERATION_COUNT,
0184     1,
0185     0
0186   );
0187 
0188   (void) rtems_message_queue_receive(
0189            Queue_id,
0190            (long (*)[4]) Buffer,
0191            &size,
0192            RTEMS_DEFAULT_OPTIONS,
0193            RTEMS_NO_TIMEOUT
0194          );
0195 
0196   /* should go to Preempt_task here */
0197 
0198   end_time = benchmark_timer_read();
0199 
0200   put_time(
0201     "rtems_message_queue_broadcast: task readied -- preempts caller",
0202     end_time,
0203     1,
0204     0,
0205     0
0206   );
0207 
0208   TEST_END();
0209   rtems_test_exit( 0 );
0210 }
0211 
0212 rtems_task Preempt_task(
0213   rtems_task_argument argument
0214 )
0215 {
0216   uint32_t    count;
0217 
0218   benchmark_timer_initialize();
0219     (void) rtems_message_queue_broadcast(
0220              Queue_id,
0221              Buffer,
0222              MESSAGE_SIZE,
0223              &count
0224            );
0225 
0226  /* should be preempted by low task */
0227 }