source: rtems/testsuites/sptests/sp42/init.c @ a986c07

4.104.11
Last change on this file since a986c07 was a986c07, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 14, 2008 at 6:36:00 PM

2008-12-14 Joel Sherrill <joel.sherrill@…>

  • sp07/init.c, sp12/init.c, sp12/pridrv.c, sp12/pritask.c, sp12/system.h, sp16/system.h, sp25/system.h, sp26/task1.c, sp28/init.c, sp29/init.c, sp35/priinv.c, sp42/init.c: Run all tests successfully with maxixum number of priorities as 16 instead of 256. This was done by temporarily modifying the score priority.h maximum. This allowed testing of all API code to ensure that it worked properly with a reduced number of priorities. Most modifications were to switch from hard-coded maximum to using the API provided methods to determine maximum number of priority levels.
  • Property mode set to 100644
File size: 5.2 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 */
28#if (RTEMS_MAXIMUM_PRIORITY >= 64)
29rtems_task_priority Priorities[MAX_TASKS] = {
30  37, 37, 37, 37,       /* backward - more 2-n */
31  2, 2, 2, 2,           /* forward - multiple are on 2-n chain */
32  4, 3,                 /* forward - search forward arbitrary */
33  3, 3, 3, 3,           /* forward - more 2-n */
34  38, 37,               /* backward - search backward arbitrary */
35  34, 34, 34, 34,       /* backward - multple on 2-n chain */
36};
37#else
38rtems_task_priority Priorities[MAX_TASKS] = {
39  13, 13, 13, 13,       /* backward - more 2-n */
40  2, 2, 2, 2,           /* forward - multiple are on 2-n chain */
41  4, 3,                 /* forward - search forward arbitrary */
42  3, 3, 3, 3,           /* forward - more 2-n */
43  14, 13,               /* backward - search backward arbitrary */
44  12, 12, 12, 12,       /* backward - multple on 2-n chain */
45};
46#endif
47
48
49rtems_id   Semaphore;
50rtems_id   Task_id[ MAX_TASKS ];
51rtems_name Task_name[ MAX_TASKS ];
52
53rtems_task Locker_task(
54  rtems_task_argument unused
55)
56{
57  rtems_id          tid;
58  uint32_t          task_index;
59  rtems_status_code status;
60
61  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
62  directive_failed( status, "rtems_task_ident" ); 
63
64  task_index = task_number( tid ) - 1;
65
66  status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 );
67  directive_failed( status, "rtems_semaphore_obtain" ); 
68
69  put_name( Task_name[ task_index ], FALSE );
70  puts( " - unblocked - OK" );
71
72  (void) rtems_task_delete( RTEMS_SELF );
73}
74
75void do_test(
76  rtems_attribute attr,
77  bool            extract  /* TRUE if extract, not release */
78)
79{
80  rtems_status_code status;
81  int               i;
82
83  status = rtems_semaphore_create(
84    rtems_build_name( 'S', 'E', 'M', '0' ),  /* name = SEM0 */
85    0,                                       /* unlocked */
86    RTEMS_BINARY_SEMAPHORE | attr,           /* mutex w/desired discipline */
87    0,                                       /* IGNORED */
88    &Semaphore
89  );
90  directive_failed( status, "rtems_semaphore_create" ); 
91
92  for (i=0 ; i< MAX_TASKS ; i++ ) {
93   
94    Task_name[ i ] = rtems_build_name(
95       'T',
96       'A',
97       '0' + (char)(i/10),
98       '0' + (char)(i%10)
99    );
100
101    status = rtems_task_create(
102      Task_name[ i ],
103      Priorities[ i ],
104      RTEMS_MINIMUM_STACK_SIZE,
105      RTEMS_DEFAULT_MODES,
106      RTEMS_DEFAULT_ATTRIBUTES,
107      &Task_id[ i ]
108    );
109    directive_failed( status, "rtems_task_create" ); 
110
111    status = rtems_task_start( Task_id[ i ], Locker_task, i );
112    directive_failed( status, "rtems_task_start" ); 
113
114    status = rtems_task_wake_after( 10 );
115    directive_failed( status, "rtems_task_wake_after" ); 
116  }
117
118  for (i=0 ; i< MAX_TASKS ; i++ ) {
119    if ( extract == FALSE ) {
120      status = rtems_semaphore_release( Semaphore );
121      directive_failed( status, "rtems_semaphore_release" ); 
122
123      status = rtems_task_wake_after( 100 );
124      directive_failed( status, "rtems_task_wake_after" ); 
125    } else {
126      status = rtems_task_delete( Task_id[ i ]  );
127      directive_failed( status, "rtems_task_delete" ); 
128    }
129  }
130 
131  /* one extra release for the initial state */
132  status = rtems_semaphore_release( Semaphore );
133  directive_failed( status, "rtems_semaphore_release" ); 
134
135  /* now delete the semaphore since no one is waiting and it is unlocked */
136  status = rtems_semaphore_delete( Semaphore );
137  directive_failed( status, "rtems_semaphore_delete" ); 
138}
139
140rtems_task Init(
141  rtems_task_argument argument
142)
143{
144  puts( "\n\n*** START OF TEST 40 ***" );
145
146  if ( sizeof( Priorities ) / sizeof( rtems_task_priority ) != MAX_TASKS ) {
147    puts( "Priorities table does not have right number of entries" );
148    exit( 0 );
149  }
150
151  puts( "Exercising blocking discipline w/extract in FIFO order " );
152  do_test( RTEMS_FIFO, TRUE );
153
154  puts( "Exercising blocking discipline w/unblock in FIFO order" );
155  do_test( RTEMS_FIFO, FALSE );
156
157  rtems_test_pause_and_screen_number( 2 );
158
159  puts( "Exercising blocking discipline w/extract in priority order " );
160  do_test( RTEMS_PRIORITY, TRUE );
161
162  puts( "Exercising blocking discipline w/unblock in priority order" );
163  do_test( RTEMS_PRIORITY, FALSE );
164
165  puts( "*** END OF TEST 42 ***" );
166  exit(0);
167}
168
169/**************** START OF CONFIGURATION INFORMATION ****************/
170
171#define CONFIGURE_INIT
172
173#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
174#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
175
176#define CONFIGURE_MAXIMUM_TASKS             MAX_TASKS+1
177#define CONFIGURE_MAXIMUM_SEMAPHORES        1
178
179#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
180
181#include <rtems/confdefs.h>
182
183/****************  END OF CONFIGURATION INFORMATION  ****************/
184
Note: See TracBrowser for help on using the repository browser.