Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  This test checks rtems_cpu_usage_top command with
0005  *  30 tasks being created and deleted.  The command
0006  *  should show the task list grow to the top 20 tasks
0007  *  then shrink back down to 5 tasks.
0008  *
0009  *  Input parameters:
0010  *    argument - task argument
0011  *
0012  *  Output parameters:  NONE
0013  *
0014  *  COPYRIGHT (c) 2014.
0015  *  On-Line Applications Research Corporation (OAR).
0016  *
0017  * Redistribution and use in source and binary forms, with or without
0018  * modification, are permitted provided that the following conditions
0019  * are met:
0020  * 1. Redistributions of source code must retain the above copyright
0021  *    notice, this list of conditions and the following disclaimer.
0022  * 2. Redistributions in binary form must reproduce the above copyright
0023  *    notice, this list of conditions and the following disclaimer in the
0024  *    documentation and/or other materials provided with the distribution.
0025  *
0026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0036  * POSSIBILITY OF SUCH DAMAGE.
0037  */
0038 
0039 #ifdef HAVE_CONFIG_H
0040 #include "config.h"
0041 #endif
0042 
0043 #define CONFIGURE_INIT
0044 #include "system.h"
0045 
0046 #include <rtems/shell.h>
0047 
0048 const char rtems_test_name[] = "TOP";
0049 
0050 /*
0051  * This method is called by Task_3 to provide
0052  * a variable lengh run time for each instance
0053  * of the task.
0054  */
0055 
0056 void add_some(
0057   uint32_t  per_loop,
0058   uint32_t *sum,
0059   uint32_t *next
0060 )
0061 {
0062   int i;
0063 
0064   for ( i=0 ; i<per_loop ; i++ ) {
0065     *sum += *next;
0066     *next += 1;
0067   }
0068 }
0069 
0070 static void notification(int fd, int seconds_remaining, void *arg)
0071 {
0072   printf(
0073     "Press any key to enter top test (%is remaining)\n",
0074     seconds_remaining
0075   );
0076 }
0077 
0078 rtems_task Init(
0079   rtems_task_argument argument
0080 )
0081 {
0082   rtems_status_code status;
0083   rtems_time_of_day time;
0084 
0085   TEST_BEGIN();
0086 
0087   status = rtems_shell_wait_for_input(
0088     STDIN_FILENO,
0089     20,
0090     notification,
0091     NULL
0092   );
0093   if ( status != RTEMS_SUCCESSFUL ) {
0094     TEST_END();
0095 
0096     rtems_test_exit( 0 );
0097   }
0098 
0099   build_time( &time, 12, 31, 1988, 9, 15, 0, 0 );
0100 
0101   status = rtems_clock_set( &time );
0102   directive_failed( status, "rtems_clock_set" );
0103 
0104   TicksPerSecond = rtems_clock_get_ticks_per_second();
0105   if (TicksPerSecond <= 0) {
0106     printf(
0107       "Invalid ticks per second: %" PRIdrtems_interval "\n",
0108       TicksPerSecond
0109     );
0110     exit (1);
0111   }
0112 
0113   /* Create and start the task to run top command. */
0114   Task_name[ 2 ] =  rtems_build_name( 'T', 'A', '0', '2' );
0115   status = rtems_task_create(
0116      Task_name[ 2 ],
0117      2,
0118      RTEMS_MINIMUM_STACK_SIZE,
0119      RTEMS_TIMESLICE,
0120      RTEMS_FLOATING_POINT,
0121      &Task_id[ 2 ]
0122   );
0123   directive_failed( status, "rtems_task_create of TA02" );
0124   status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
0125   directive_failed( status, "rtems_task_start of TA2" );
0126 
0127   /* Create and start task to run the test. */
0128   Task_name[ 1 ] =  rtems_build_name( 'T', 'A', '0', '1' );
0129   status = rtems_task_create(
0130      Task_name[ 1 ],
0131      2,
0132      RTEMS_MINIMUM_STACK_SIZE,
0133      RTEMS_TIMESLICE,
0134      RTEMS_FLOATING_POINT,
0135      &Task_id[ 1 ]
0136   );
0137   directive_failed( status, "rtems_task_create of TA01" );
0138   status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
0139   directive_failed( status, "rtems_task_start of TA01" );
0140 
0141   /*
0142    * We suspend the Init task rather than delete it so it still
0143    * shows up in the output.
0144    */
0145   status = rtems_task_suspend( RTEMS_SELF );
0146   directive_failed( status, "rtems_task_suspend of RTEMS_SELF" );
0147 }