source: rtems/testsuites/sptests/sp42/init.c @ 6e315132

4.104.114.95
Last change on this file since 6e315132 was 6e315132, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 21:53:04

2008-01-29 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac, sp02/task1.c, sp24/resume.c, sp30/resume.c, sp41/init.c, sp42/init.c: Add new Object Services collection. This changed the name of a few previously public but undocumented services and added a some new services.
  • sp43/.cvsignore, sp43/Makefile.am, sp43/init.c, sp43/sp43.scn, sp43/system.h: New files.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Exercise thread queue enqueue and dequeue priority
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16
17#include <bsp.h>
18
19#include "tmacros.h"
20
21#define MAX_TASKS 20
22
23/*
24 * Carefully chosen to exercise threadq enqueue/dequeue priority logic.
25 * Somewhat randomly sorted to ensure than if discipline is FIFO, run-time
26 * behavior won't be the same when released.
27 */
28rtems_task_priority Priorities[MAX_TASKS] = {
29  37, 37, 37, 37,       /* backward - more 2-n */
30  2, 2, 2, 2,           /* forward - multiple are on 2-n chain */
31  4, 3,                 /* forward - search forward arbitrary */
32  3, 3, 3, 3,           /* forward - more 2-n */
33  38, 37,               /* backward - search backward arbitrary */
34  34, 34, 34, 34,       /* backward - multple on 2-n chain */
35};
36
37
38rtems_id   Semaphore;
39rtems_id   Task_id[ MAX_TASKS ];
40rtems_name Task_name[ MAX_TASKS ];
41
42rtems_task Locker_task(
43  rtems_task_argument unused
44)
45{
46  rtems_id          tid;
47  uint32_t          task_index;
48  rtems_status_code status;
49
50  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
51  directive_failed( status, "rtems_task_ident" );
52
53  task_index = task_number( tid ) - 1;
54
55  status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 );
56  directive_failed( status, "rtems_semaphore_obtain" );
57
58  put_name( Task_name[ task_index ], FALSE );
59  puts( " - unblocked - OK" );
60
61  (void) rtems_task_delete( RTEMS_SELF );
62}
63
64void do_test(
65  rtems_attribute attr,
66  boolean         extract  /* TRUE if extract, not release */
67)
68{
69  rtems_status_code status;
70  int               i;
71
72  status = rtems_semaphore_create(
73    rtems_build_name( 'S', 'E', 'M', '0' ),  /* name = SEM0 */
74    0,                                       /* unlocked */
75    RTEMS_BINARY_SEMAPHORE | attr,           /* mutex w/desired discipline */
76    0,                                       /* IGNORED */
77    &Semaphore
78  );
79  directive_failed( status, "rtems_semaphore_create" );
80
81  for (i=0 ; i< MAX_TASKS ; i++ ) {
82   
83    Task_name[ i ] = rtems_build_name(
84       'T',
85       'A',
86       '0' + (char)(i/10),
87       '0' + (char)(i%10)
88    );
89
90    status = rtems_task_create(
91      Task_name[ i ],
92      Priorities[ i ],
93      RTEMS_MINIMUM_STACK_SIZE,
94      RTEMS_DEFAULT_MODES,
95      RTEMS_DEFAULT_ATTRIBUTES,
96      &Task_id[ i ]
97    );
98    directive_failed( status, "rtems_task_create" );
99
100    status = rtems_task_start( Task_id[ i ], Locker_task, i );
101    directive_failed( status, "rtems_task_start" );
102
103    status = rtems_task_wake_after( 10 );
104    directive_failed( status, "rtems_task_wake_after" );
105  }
106
107  for (i=0 ; i< MAX_TASKS ; i++ ) {
108    if ( extract == FALSE ) {
109      status = rtems_semaphore_release( Semaphore );
110      directive_failed( status, "rtems_semaphore_release" );
111
112      status = rtems_task_wake_after( 100 );
113      directive_failed( status, "rtems_task_wake_after" );
114    } else {
115      status = rtems_task_delete( Task_id[ i ]  );
116      directive_failed( status, "rtems_task_delete" );
117    }
118  }
119 
120  /* one extra release for the initial state */
121  status = rtems_semaphore_release( Semaphore );
122  directive_failed( status, "rtems_semaphore_release" );
123
124  /* now delete the semaphore since no one is waiting and it is unlocked */
125  status = rtems_semaphore_delete( Semaphore );
126  directive_failed( status, "rtems_semaphore_delete" );
127}
128
129rtems_task Init(
130  rtems_task_argument argument
131)
132{
133  puts( "\n\n*** START OF TEST 40 ***" );
134
135  if ( sizeof( Priorities ) / sizeof( rtems_task_priority ) != MAX_TASKS ) {
136    puts( "Priorities table does not have right number of entries" );
137    exit( 0 );
138  }
139
140  puts( "Exercising blocking discipline w/extract in FIFO order " );
141  do_test( RTEMS_FIFO, TRUE );
142
143  puts( "Exercising blocking discipline w/unblock in FIFO order" );
144  do_test( RTEMS_FIFO, FALSE );
145
146  rtems_test_pause_and_screen_number( 2 );
147
148  puts( "Exercising blocking discipline w/extract in priority order " );
149  do_test( RTEMS_PRIORITY, TRUE );
150
151  puts( "Exercising blocking discipline w/unblock in priority order" );
152  do_test( RTEMS_PRIORITY, FALSE );
153
154  puts( "*** END OF TEST 42 ***" );
155  exit(0);
156}
157
158/**************** START OF CONFIGURATION INFORMATION ****************/
159
160#define CONFIGURE_INIT
161
162#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
163#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
164
165#define CONFIGURE_MAXIMUM_TASKS             MAX_TASKS+1
166#define CONFIGURE_MAXIMUM_SEMAPHORES        1
167
168#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
169
170#include <rtems/confdefs.h>
171
172/****************  END OF CONFIGURATION INFORMATION  ****************/
173
Note: See TracBrowser for help on using the repository browser.