source: rtems/testsuites/sptests/spsimplesched02/init.c @ 6b0a729b

Last change on this file since 6b0a729b was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 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#include <tmacros.h>
15
16#include <rtems/score/threadimpl.h>
17
18const char rtems_test_name[] = "SPSIMPLESCHED 2";
19
20/* forward declarations to avoid warnings */
21rtems_task Init(rtems_task_argument argument);
22rtems_task Test_task(rtems_task_argument argument);
23void ObtainRelease(bool suspendIdle);
24
25/*
26 *  Keep the names and IDs in global variables so another task can use them.
27 */
28rtems_id   Idle_id;
29rtems_id   Task_id[ 3 ];         /* array of task ids */
30rtems_name Task_name[ 3 ];       /* array of task names */
31rtems_name Semaphore_name[ 2 ];
32rtems_id   Semaphore_id[ 2 ];
33
34rtems_task Test_task(
35  rtems_task_argument unused
36)
37{
38  rtems_id          tid;
39  rtems_status_code status;
40
41  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
42  directive_failed( status, "wake after" );
43
44  for ( ; ; ) {
45    status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
46    directive_failed( status, "yield" );
47  }
48}
49
50void ObtainRelease( bool suspendIdle )
51{
52  rtems_status_code   status;
53
54  if (suspendIdle) {
55    puts( "INIT - Suspend Idle Task");
56    status = rtems_task_suspend( Idle_id );
57    directive_failed( status, "rtems_task_suspend idle" );
58  }
59
60  puts( "INIT - Obtain priority ceiling semaphore - priority increases" );
61  status= rtems_semaphore_obtain( Semaphore_id[1], RTEMS_DEFAULT_OPTIONS, 0 );
62  directive_failed( status, "rtems_semaphore_obtain" );
63
64  puts( "INIT - Obtain priority ceiling semaphore - priority decreases" );
65  status = rtems_semaphore_release( Semaphore_id[1] );
66  directive_failed( status, "rtems_semaphore_release" );
67
68  if (suspendIdle) {
69    puts( "INIT - Resume Idle Task");
70    status = rtems_task_resume( Idle_id );
71    directive_failed( status, "rtems_task_resume idle" );
72  }
73}
74
75rtems_task Init(
76  rtems_task_argument argument
77)
78{
79  rtems_status_code   status;
80
81  TEST_BEGIN();
82
83  status = _Objects_Name_to_id_u32(
84    &_Thread_Information.Objects,
85    rtems_build_name( 'I', 'D', 'L', 'E' ),
86    RTEMS_SEARCH_LOCAL_NODE,
87    &Idle_id
88  );
89  rtems_test_assert( status == RTEMS_SUCCESSFUL );
90
91  /*
92   * Create the semaphore. Then obtain and release the
93   * semaphore with no other tasks running.
94   */
95  puts( "INIT - Create priority ceiling semaphore" );
96  Semaphore_name[ 1 ] = rtems_build_name( 'S', 'M', '1', ' ' );
97  status = rtems_semaphore_create(
98    Semaphore_name[ 1 ],
99    1,
100    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY_CEILING | RTEMS_PRIORITY,
101    2,
102    &Semaphore_id[ 1 ]
103  );
104  directive_failed( status, "rtems_semaphore_create of SM1" );
105  ObtainRelease( false );
106
107  /*
108   * Create test task and obtain release the semaphore with
109   * one other task running.
110   */
111  puts( "INIT - create task 1" );
112  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
113  status = rtems_task_create(
114    Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
115    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ]
116  );
117  status = rtems_task_start( Task_id[ 1 ], Test_task, 1 );
118  ObtainRelease( false );
119
120  /*
121   * Create a a second test task and obtain release the semaphore
122   * with both tasks running.
123   */
124  puts( "INIT - create task 2" );
125  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '2', ' ' );
126  status = rtems_task_create(
127    Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES,
128    RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ]
129  );
130  status = rtems_task_start( Task_id[ 2 ], Test_task, 1 );
131  ObtainRelease( false );
132
133  /*
134   * Obtain and release the semaphore with the idle task suspended.
135   */
136  ObtainRelease( true );
137
138  /*  End the Test */
139  TEST_END();
140  rtems_test_exit(0);
141}
142
143/* configuration information */
144
145#define CONFIGURE_SCHEDULER_SIMPLE
146#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
147#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
148
149#define CONFIGURE_MAXIMUM_TASKS             3
150#define CONFIGURE_MAXIMUM_SEMAPHORES        2
151
152#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
153
154#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
155
156#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
157#define CONFIGURE_INIT_TASK_PRIORITY        4
158
159#define CONFIGURE_DISABLE_SMP_CONFIGURATION
160
161#define CONFIGURE_INIT
162#include <rtems/confdefs.h>
163/* end of include file */
Note: See TracBrowser for help on using the repository browser.