source: rtems/testsuites/smptests/smp02/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16
17#include <stdio.h>
18#include <inttypes.h>
19
20const char rtems_test_name[] = "SMP 2";
21
22static void success(void)
23{
24  TEST_END();
25  rtems_test_exit( 0 );
26}
27
28rtems_task Init(
29  rtems_task_argument argument
30)
31{
32  int               i;
33  char              ch;
34  uint32_t          cpu_num;
35  rtems_id          id;
36  rtems_status_code status;
37  char              str[80];
38
39  TEST_BEGIN();
40
41  locked_print_initialize();
42
43  if ( rtems_smp_get_processor_count() == 1 ) {
44    success();
45  }
46
47  /* Create/verify synchronisation semaphore */
48  status = rtems_semaphore_create(
49    rtems_build_name ('S', 'E', 'M', '1'),
50    1,                                             
51    RTEMS_LOCAL                   |
52    RTEMS_SIMPLE_BINARY_SEMAPHORE |
53    RTEMS_PRIORITY,
54    1,
55    &Semaphore);
56  directive_failed( status, "rtems_semaphore_create" );
57
58  /* Lock semaphore */
59  status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0);
60  directive_failed( status,"rtems_semaphore_obtain of SEM1\n");
61
62  for ( i=1; i < rtems_smp_get_processor_count(); i++ ){
63
64    /* Create and start tasks for each CPU */
65    ch = '0' + i;
66
67    status = rtems_task_create(
68      rtems_build_name( 'T', 'A', ch, ' ' ),
69      1,
70      RTEMS_MINIMUM_STACK_SIZE,
71      RTEMS_DEFAULT_MODES,
72      RTEMS_DEFAULT_ATTRIBUTES,
73      &id
74    );
75
76    cpu_num = rtems_smp_get_current_processor();
77    locked_printf(" CPU %" PRIu32 " start task TA%c\n", cpu_num, ch);
78    status = rtems_task_start( id, Test_task, i+1 );
79    directive_failed( status, str );
80  }
81
82  /*
83   * Release the semaphore, allowing the blocked tasks to start.
84   */
85  status = rtems_semaphore_release( Semaphore );
86  directive_failed( status,"rtems_semaphore_release of SEM1\n");
87 
88
89  /*
90   * Wait for log full. print the log and end the program.
91   */ 
92  while (Log_index < LOG_SIZE)
93    ;
94 
95  for (i=0; i< LOG_SIZE; i++) {
96    if ( Log[i].IsLocked ) {
97      locked_printf(
98        " CPU %d Task TA%" PRIu32 " Obtain\n",
99        Log[i].cpu_num,
100        Log[i].task_index
101      );
102    } else {
103      locked_printf(
104        " CPU %d Task TA%" PRIu32 " Release\n",
105        Log[i].cpu_num,
106        Log[i].task_index
107      );
108    }
109  }
110
111  success();
112}
Note: See TracBrowser for help on using the repository browser.