Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
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 <stdio.h>
0037 #include <inttypes.h>
0038 
0039 const char rtems_test_name[] = "SMP 3";
0040 
0041 static void success(void)
0042 {
0043   TEST_END();
0044   rtems_test_exit( 0 );
0045 }
0046 
0047 void Loop() {
0048   volatile int i;
0049 
0050   for (i=0; i<300000; i++);
0051 }
0052 
0053 void PrintTaskInfo(
0054   const char *task_name
0055 )
0056 {
0057   uint32_t cpu_num;
0058 
0059   cpu_num = rtems_scheduler_get_processor();
0060 
0061   locked_printf("  CPU %" PRIu32 " running task %s\n", cpu_num, task_name );
0062 }
0063 
0064 rtems_task Init(
0065   rtems_task_argument argument
0066 )
0067 {
0068   uint32_t          i;
0069   char              ch = '0';
0070   rtems_id          id;
0071   rtems_status_code status;
0072   uint32_t          cpu_max;
0073 
0074   Loop();
0075 
0076   TEST_BEGIN();
0077 
0078   locked_print_initialize();
0079   cpu_max = rtems_scheduler_get_processor_maximum();
0080 
0081   if ( cpu_max == 1 ) {
0082     success();
0083   }
0084 
0085   /* Initialize the TaskRan array */
0086   TaskRan[0] = true;
0087   for ( i=1; i<cpu_max ; i++ ) {
0088     TaskRan[i] = false;
0089   }
0090 
0091   /* Show that the init task is running on this cpu */
0092   PrintTaskInfo( "Init" );
0093 
0094   /* for each remaining cpu create and start a task */
0095   for ( i=1; i < cpu_max; i++ ){
0096 
0097     ch = '0' + i;
0098 
0099     status = rtems_task_create(
0100       rtems_build_name( 'T', 'A', ch, ' ' ),
0101       CONFIGURE_INIT_TASK_PRIORITY + (2*i),
0102       RTEMS_MINIMUM_STACK_SIZE,
0103       RTEMS_PREEMPT,
0104       RTEMS_FLOATING_POINT,
0105       &id
0106     );
0107     directive_failed( status, "rtems_task_create" );
0108     status = rtems_task_start( id, Test_task, i );
0109     directive_failed( status, "rtems_task_start" );
0110     
0111     /* Allow task to start before starting next task.
0112      * This is necessary on some simulators.
0113      */ 
0114     while (TaskRan[i] == false)
0115       ;
0116   }
0117 
0118   /* Create/Start an aditional task with the highest priority */
0119   status = rtems_task_create(
0120     rtems_build_name( 'T', 'A', ch + 1, ' ' ),
0121     3,
0122     RTEMS_MINIMUM_STACK_SIZE,
0123     RTEMS_PREEMPT,
0124     RTEMS_FLOATING_POINT,
0125     &id
0126   );
0127   directive_failed( status, "rtems_task_create" );
0128   status = rtems_task_start(id,Test_task,cpu_max);
0129   directive_failed( status, "rtems_task_start" );
0130 
0131   /* Wait on all tasks to run */
0132   while (1) {
0133     TestFinished = true;
0134     for ( i=1; i < (cpu_max+1) ; i++ ) {
0135       if (TaskRan[i] == false)
0136         TestFinished = false;
0137     }
0138     if (TestFinished) {
0139       success();
0140     }
0141   }
0142 
0143   rtems_test_exit( 0 );    
0144 }