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 2";
0040 
0041 static void success(void)
0042 {
0043   TEST_END();
0044   rtems_test_exit( 0 );
0045 }
0046 
0047 rtems_task Init(
0048   rtems_task_argument argument
0049 )
0050 {
0051   int               i;
0052   char              ch;
0053   uint32_t          cpu_num;
0054   rtems_id          id;
0055   rtems_status_code status;
0056   char              str[80];
0057 
0058   TEST_BEGIN();
0059 
0060   locked_print_initialize();
0061 
0062   if ( rtems_scheduler_get_processor_maximum() == 1 ) {
0063     success();
0064   }
0065 
0066   /* Create/verify synchronisation semaphore */
0067   status = rtems_semaphore_create(
0068     rtems_build_name ('S', 'E', 'M', '1'),
0069     1,                                             
0070     RTEMS_LOCAL                   |
0071     RTEMS_SIMPLE_BINARY_SEMAPHORE |
0072     RTEMS_PRIORITY,
0073     1,
0074     &Semaphore);
0075   directive_failed( status, "rtems_semaphore_create" );
0076 
0077   /* Lock semaphore */
0078   status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
0079   directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
0080 
0081   for ( i=1; i < rtems_scheduler_get_processor_maximum(); i++ ){
0082 
0083     /* Create and start tasks for each CPU */
0084     ch = '0' + i;
0085 
0086     status = rtems_task_create(
0087       rtems_build_name( 'T', 'A', ch, ' ' ),
0088       1,
0089       RTEMS_MINIMUM_STACK_SIZE,
0090       RTEMS_DEFAULT_MODES,
0091       RTEMS_DEFAULT_ATTRIBUTES,
0092       &id
0093     );
0094 
0095     cpu_num = rtems_scheduler_get_processor();
0096     locked_printf(" CPU %" PRIu32 " start task TA%c\n", cpu_num, ch);
0097     status = rtems_task_start( id, Test_task, i+1 );
0098     directive_failed( status, str );
0099   }
0100 
0101   /*
0102    * Release the semaphore, allowing the blocked tasks to start.
0103    */
0104   status = rtems_semaphore_release( Semaphore );
0105   directive_failed( status,"rtems_semaphore_release of SEM1\n");
0106   
0107 
0108   /* 
0109    * Wait for log full. print the log and end the program.
0110    */  
0111   while (Log_index < LOG_SIZE)
0112     ;
0113  
0114   for (i=0; i< LOG_SIZE; i++) {
0115     if ( Log[i].IsLocked ) {
0116       locked_printf(
0117         " CPU %d Task TA%" PRIu32 " Obtain\n", 
0118         Log[i].cpu_num,
0119         Log[i].task_index
0120       );
0121     } else {
0122       locked_printf(
0123         " CPU %d Task TA%" PRIu32 " Release\n", 
0124         Log[i].cpu_num,
0125         Log[i].task_index
0126       );
0127     }
0128   }
0129 
0130   success();
0131 }