Back to home page

LXR

 
 

    


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

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