source: rtems/testsuites/sptests/spintrcritical06/init.c @ 8d4434e

4.104.11
Last change on this file since 8d4434e was 8d4434e, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 11, 2009 at 6:49:59 PM

2009-08-11 Joel Sherrill <joel.sherrill@…>

  • spintrcritical01/init.c, spintrcritical06/init.c: Use 1 millisecond per tick.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
13#include <tmacros.h>
14#include <intrcritical.h>
15
16/* common parameters */
17#define SEMAPHORE_ATTRIBUTES     RTEMS_PRIORITY
18
19#if defined(PRIORITY_NO_TIMEOUT_FORWARD)
20  #define TEST_NAME          "06"
21  #define TEST_STRING        "Priority/Restart Search Task (Forward)"
22
23  #define INIT_PRIORITY      2
24  #define BLOCKER_PRIORITY   1
25  #define SEMAPHORE_OBTAIN_TIMEOUT 0
26
27#elif defined(PRIORITY_NO_TIMEOUT_REVERSE)
28  #define TEST_NAME          "07"
29  #define TEST_STRING        "Priority/Restart Search Task (Backward)"
30  #define INIT_PRIORITY      126
31  #define BLOCKER_PRIORITY   127
32  #define SEMAPHORE_OBTAIN_TIMEOUT 2
33
34#else
35
36  #error "Test Mode not defined"
37#endif
38
39rtems_id Main_task;
40rtems_id Secondary_task_id;
41rtems_id Semaphore;
42
43Thread_blocking_operation_States getState(void)
44{
45  Objects_Locations  location;
46  Semaphore_Control *sem;
47
48  sem = (Semaphore_Control *)_Objects_Get(
49    &_Semaphore_Information, Semaphore, &location ); 
50  if ( location != OBJECTS_LOCAL ) {
51    puts( "Bad object lookup" );
52    rtems_test_exit(0);
53  }
54  _Thread_Unnest_dispatch();
55
56  return sem->Core_control.semaphore.Wait_queue.sync_state;
57}
58
59rtems_timer_service_routine test_release_from_isr(
60  rtems_id  timer,
61  void     *arg
62)
63{
64  (void) rtems_task_restart( Secondary_task_id, 1 );
65}
66
67rtems_task Secondary_task(
68  rtems_task_argument arg
69)
70{
71  rtems_status_code     status;
72
73  if ( arg )
74    (void) rtems_semaphore_flush( Semaphore );
75
76  status = rtems_semaphore_obtain(
77    Semaphore,
78    RTEMS_DEFAULT_OPTIONS,
79    SEMAPHORE_OBTAIN_TIMEOUT
80  );
81  directive_failed( status, "rtems_semaphore_obtain" );
82}
83
84rtems_task Init(
85  rtems_task_argument ignored
86)
87{
88  rtems_status_code     status;
89  int                   resets;
90
91  puts( "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" );
92
93  puts( "Init - Trying to generate semaphore release from ISR while blocking" );
94  puts( "Init - There is no way for the test to know if it hits the case" );
95  puts( "Init - Variation is: " TEST_STRING );
96  status = rtems_semaphore_create(
97    rtems_build_name( 'S', 'M', '1', ' ' ),
98    0,
99    SEMAPHORE_ATTRIBUTES,
100    RTEMS_NO_PRIORITY,
101    &Semaphore
102  );
103  directive_failed( status, "rtems_semaphore_create of SM1" );
104
105  Main_task = rtems_task_self();
106
107  status = rtems_task_create(
108    rtems_build_name( 'B', 'L', 'C', 'K' ),
109    BLOCKER_PRIORITY,
110    RTEMS_MINIMUM_STACK_SIZE,
111    RTEMS_NO_PREEMPT,
112    RTEMS_DEFAULT_ATTRIBUTES,
113    &Secondary_task_id
114  );
115  directive_failed( status, "rtems_task_create" );
116
117  status = rtems_task_start( Secondary_task_id, Secondary_task, 0 );
118  directive_failed( status, "rtems_task_start" );
119
120  interrupt_critical_section_test_support_initialize( test_release_from_isr );
121
122  for (resets=0 ; resets< 2 ;) {
123    if ( interrupt_critical_section_test_support_delay() )
124      resets++;
125
126    status = rtems_semaphore_obtain(
127      Semaphore,
128      RTEMS_DEFAULT_OPTIONS,
129      SEMAPHORE_OBTAIN_TIMEOUT
130    );
131  }
132
133  puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" );
134  rtems_test_exit(0);
135}
136
137/* configuration information */
138
139#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
140#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
141
142#define CONFIGURE_MAXIMUM_TASKS       2
143#define CONFIGURE_MAXIMUM_TIMERS      1
144#define CONFIGURE_MAXIMUM_SEMAPHORES  1
145#define CONFIGURE_MICROSECONDS_PER_TICK  1000
146#define CONFIGURE_INIT_TASK_PRIORITY  INIT_PRIORITY
147#define CONFIGURE_INIT_TASK_MODE      RTEMS_PREEMPT
148#define CONFIGURE_MICROSECONDS_PER_TICK  2000
149#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
150
151#define CONFIGURE_INIT
152#include <rtems/confdefs.h>
153
154/* global variables */
Note: See TracBrowser for help on using the repository browser.