source: rtems/testsuites/sptests/sp42/init.c @ 072d2a09

4.104.115
Last change on this file since 072d2a09 was b84f1fdc, checked in by Joel Sherrill <joel.sherrill@…>, on 05/10/09 at 14:39:46

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • sp04/system.h, sp04/task1.c, sp04/tswitch.c, sp07/init.c, sp12/init.c, sp13/putbuff.c, sp13/system.h, sp13/task1.c, sp15/init.c, sp16/system.h, sp19/fptask.c, sp25/system.h, sp26/task1.c, sp27/init.c, sp28/init.c, sp29/init.c, sp31/task1.c, sp33/init.c, sp34/changepri.c, sp35/priinv.c, sp37/init.c, sp38/init.c, sp39/init.c, sp41/init.c, sp42/init.c, sp43/init.c, sp44/init.c, sp45/init.c, sp46/init.c, sp47/init.c, sp48/init.c, spfatal03/testcase.h, spfatal05/testcase.h, spfatal06/testcase.h, spfatal_support/system.h, spobjgetnext/init.c, spsize/getint.c, spsize/size.c: Fix warnings.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 *  Exercise thread queue enqueue and dequeue priority
3 *
4 *  COPYRIGHT (c) 1989-2009.
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
23rtems_task Init(rtems_task_argument argument);
24rtems_task Locker_task(rtems_task_argument unused);
25void do_test(
26  rtems_attribute attr,
27  bool            extract  /* TRUE if extract, not release */
28);
29
30/*
31 * Carefully chosen to exercise threadq enqueue/dequeue priority logic.
32 * Somewhat randomly sorted to ensure than if discipline is FIFO, run-time
33 * behavior won't be the same when released.
34 */
35#if (RTEMS_MAXIMUM_PRIORITY >= 64)
36rtems_task_priority Priorities[MAX_TASKS] = {
37  37, 37, 37, 37,       /* backward - more 2-n */
38  2, 2, 2, 2,           /* forward - multiple are on 2-n chain */
39  4, 3,                 /* forward - search forward arbitrary */
40  3, 3, 3, 3,           /* forward - more 2-n */
41  38, 37,               /* backward - search backward arbitrary */
42  34, 34, 34, 34,       /* backward - multple on 2-n chain */
43};
44#else
45rtems_task_priority Priorities[MAX_TASKS] = {
46  13, 13, 13, 13,       /* backward - more 2-n */
47  2, 2, 2, 2,           /* forward - multiple are on 2-n chain */
48  4, 3,                 /* forward - search forward arbitrary */
49  3, 3, 3, 3,           /* forward - more 2-n */
50  14, 13,               /* backward - search backward arbitrary */
51  12, 12, 12, 12,       /* backward - multple on 2-n chain */
52};
53#endif
54
55
56rtems_id   Semaphore;
57rtems_id   Task_id[ MAX_TASKS ];
58rtems_name Task_name[ MAX_TASKS ];
59
60rtems_task Locker_task(
61  rtems_task_argument unused
62)
63{
64  rtems_id          tid;
65  uint32_t          task_index;
66  rtems_status_code status;
67
68  status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid );
69  directive_failed( status, "rtems_task_ident" );
70
71  task_index = task_number( tid ) - 1;
72
73  status = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 0 );
74  directive_failed( status, "rtems_semaphore_obtain" );
75
76  put_name( Task_name[ task_index ], FALSE );
77  puts( " - unblocked - OK" );
78
79  (void) rtems_task_delete( RTEMS_SELF );
80}
81
82void do_test(
83  rtems_attribute attr,
84  bool            extract  /* TRUE if extract, not release */
85)
86{
87  rtems_status_code status;
88  int               i;
89
90  status = rtems_semaphore_create(
91    rtems_build_name( 'S', 'E', 'M', '0' ),  /* name = SEM0 */
92    0,                                       /* unlocked */
93    RTEMS_BINARY_SEMAPHORE | attr,           /* mutex w/desired discipline */
94    0,                                       /* IGNORED */
95    &Semaphore
96  );
97  directive_failed( status, "rtems_semaphore_create" );
98
99  for (i=0 ; i< MAX_TASKS ; i++ ) {
100   
101    Task_name[ i ] = rtems_build_name(
102       'T',
103       'A',
104       '0' + (char)(i/10),
105       '0' + (char)(i%10)
106    );
107
108    status = rtems_task_create(
109      Task_name[ i ],
110      Priorities[ i ],
111      RTEMS_MINIMUM_STACK_SIZE,
112      RTEMS_DEFAULT_MODES,
113      RTEMS_DEFAULT_ATTRIBUTES,
114      &Task_id[ i ]
115    );
116    directive_failed( status, "rtems_task_create" );
117
118    status = rtems_task_start(
119      Task_id[ i ], Locker_task, (rtems_task_argument)i );
120    directive_failed( status, "rtems_task_start" );
121
122    status = rtems_task_wake_after( 10 );
123    directive_failed( status, "rtems_task_wake_after" );
124  }
125
126  for (i=0 ; i< MAX_TASKS ; i++ ) {
127    if ( extract == FALSE ) {
128      status = rtems_semaphore_release( Semaphore );
129      directive_failed( status, "rtems_semaphore_release" );
130
131      status = rtems_task_wake_after( 100 );
132      directive_failed( status, "rtems_task_wake_after" );
133    } else {
134      status = rtems_task_delete( Task_id[ i ]  );
135      directive_failed( status, "rtems_task_delete" );
136    }
137  }
138 
139  /* one extra release for the initial state */
140  status = rtems_semaphore_release( Semaphore );
141  directive_failed( status, "rtems_semaphore_release" );
142
143  /* now delete the semaphore since no one is waiting and it is unlocked */
144  status = rtems_semaphore_delete( Semaphore );
145  directive_failed( status, "rtems_semaphore_delete" );
146}
147
148rtems_task Init(
149  rtems_task_argument argument
150)
151{
152  puts( "\n\n*** START OF TEST 40 ***" );
153
154  if ( sizeof( Priorities ) / sizeof( rtems_task_priority ) != MAX_TASKS ) {
155    puts( "Priorities table does not have right number of entries" );
156    exit( 0 );
157  }
158
159  puts( "Exercising blocking discipline w/extract in FIFO order " );
160  do_test( RTEMS_FIFO, TRUE );
161
162  puts( "Exercising blocking discipline w/unblock in FIFO order" );
163  do_test( RTEMS_FIFO, FALSE );
164
165  rtems_test_pause_and_screen_number( 2 );
166
167  puts( "Exercising blocking discipline w/extract in priority order " );
168  do_test( RTEMS_PRIORITY, TRUE );
169
170  puts( "Exercising blocking discipline w/unblock in priority order" );
171  do_test( RTEMS_PRIORITY, FALSE );
172
173  puts( "*** END OF TEST 42 ***" );
174  exit(0);
175}
176
177/**************** START OF CONFIGURATION INFORMATION ****************/
178
179#define CONFIGURE_INIT
180
181#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
182#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
183
184#define CONFIGURE_MAXIMUM_TASKS             MAX_TASKS+1
185#define CONFIGURE_MAXIMUM_SEMAPHORES        1
186
187#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
188
189#include <rtems/confdefs.h>
190
191/****************  END OF CONFIGURATION INFORMATION  ****************/
192
Note: See TracBrowser for help on using the repository browser.