Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Task_1_through_5
0004  *
0005  *  This routine serves as a test task for the period capabilities of the
0006  *  Rate Monotonic Manager.
0007  *
0008  *  Input parameters:
0009  *    argument - task argument
0010  *
0011  *  Output parameters:  NONE
0012  *
0013  *  COPYRIGHT (c) 1989-2007.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041 
0042 #include "system.h"
0043 
0044 #include <rtems/cpuuse.h>
0045 
0046 uint32_t      Periods[6]    = { 0,   2,   2,   2,   2, 100 };
0047 uint32_t      Iterations[6] = { 0,  50,  50,  50,  50,   1 };
0048 rtems_task_priority Priorities[6] = { 0,   1,   1,   3,   4,   5 };
0049 
0050 rtems_task Task_1_through_5(
0051   rtems_task_argument argument
0052 )
0053 {
0054   rtems_id          rmid;
0055   rtems_id          test_rmid;
0056   uint32_t          index;
0057   uint32_t          pass;
0058   uint32_t          failed;
0059   rtems_status_code status;
0060 
0061   status = rtems_rate_monotonic_create( argument, &rmid );
0062   directive_failed( status, "rtems_rate_monotonic_create" );
0063   put_name( Task_name[ argument ], FALSE );
0064   printf( "- rtems_rate_monotonic_create id = 0x%08" PRIxrtems_id "\n", rmid );
0065 
0066   status = rtems_rate_monotonic_ident( argument, &test_rmid );
0067   directive_failed( status, "rtems_rate_monotonic_ident" );
0068   put_name( Task_name[ argument ], FALSE );
0069   printf( "- rtems_rate_monotonic_ident id = 0x%08" PRIxrtems_id "\n", test_rmid );
0070 
0071   if ( rmid != test_rmid ) {
0072      printf( "RMID's DO NOT MATCH (0x%" PRIxrtems_id " and 0x%" PRIxrtems_id ")\n", rmid, test_rmid );
0073      rtems_test_exit( 0 );
0074   }
0075 
0076   put_name( Task_name[ argument ], FALSE );
0077   printf( "- (0x%08" PRIxrtems_id ") period %" PRIu32 "\n", rmid, Periods[ argument ] );
0078 
0079   status = rtems_task_wake_after( 2 );
0080   directive_failed( status, "rtems_task_wake_after" );
0081 
0082   switch ( argument ) {
0083     case 1:
0084     case 2:
0085     case 3:
0086     case 4:
0087       while ( FOREVER ) {
0088         status = rtems_rate_monotonic_period( rmid, Periods[ argument ] );
0089         directive_failed( status, "rtems_rate_monotonic_period" );
0090         Count.count[ argument ]++;
0091       }
0092       break;
0093     case 5:
0094       pass   = 0;
0095       failed = 0;
0096 
0097       status = rtems_rate_monotonic_period( rmid, Periods[ argument ] );
0098       directive_failed( status, "rtems_rate_monotonic_period 1 of TA5" );
0099 
0100       Get_all_counters();
0101 
0102       while ( FOREVER ) {
0103         status = rtems_rate_monotonic_period( rmid, Periods[ argument ] );
0104         directive_failed( status, "rtems_rate_monotonic_period 2 of TA5" );
0105 
0106         Get_all_counters();
0107 
0108         for( index = 1 ; index <= 4 ; index++ ) {
0109           if ( Temporary_count.count[ index ] != Iterations[ index ] ) {
0110             puts_nocr( "FAIL -- " );
0111             put_name ( Task_name[ index ], FALSE );
0112             printf   ( " Actual=%" PRIu32 ", Expected=%" PRIu32 "\n",
0113                        Temporary_count.count[ index ],
0114                        Iterations[ index ]
0115                      );
0116             failed += 1;
0117           }
0118         }
0119 
0120         if ( failed == 5 )
0121           rtems_test_exit( 0 );
0122 
0123         pass += 1;
0124 
0125         printf( "TA5 - PERIODS CHECK OK (%" PRIu32 ")\n", pass );
0126 
0127         if ( pass == 10 ) {
0128           puts( "" );
0129           rtems_rate_monotonic_report_statistics();
0130 
0131           rtems_rate_monotonic_reset_statistics( rmid );
0132           puts( "" );
0133           puts( "TA5 - PERIOD STATISTICS RESET" );
0134           puts( "" );
0135           rtems_rate_monotonic_report_statistics();
0136 
0137           rtems_rate_monotonic_reset_all_statistics();
0138           puts( "" );
0139           puts( "TA5 - ALL PERIOD STATISTICS RESET" );
0140           puts( "" );
0141           rtems_rate_monotonic_report_statistics();
0142 
0143           puts( "" );
0144           TEST_END();
0145 
0146           rtems_test_exit( 0 );
0147         }
0148 
0149       }
0150       break;
0151   }
0152 }