source: rtems/testsuites/sptests/spintrcritical06/init.c @ 4e4f06b

4.104.115
Last change on this file since 4e4f06b was 4e4f06b, checked in by Joel Sherrill <joel.sherrill@…>, on 07/23/09 at 16:12:53

2009-07-23 Joel Sherrill <joel.sherrill@…>

  • spintrcritical06/init.c: Test now hits forward and reverse cases.
  • Property mode set to 100644
File size: 3.7 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 - Variation is: " TEST_STRING );
95  status = rtems_semaphore_create(
96    rtems_build_name( 'S', 'M', '1', ' ' ),
97    0,
98    SEMAPHORE_ATTRIBUTES,
99    RTEMS_NO_PRIORITY,
100    &Semaphore
101  );
102  directive_failed( status, "rtems_semaphore_create of SM1" );
103
104  Main_task = rtems_task_self();
105
106  status = rtems_task_create(
107    rtems_build_name( 'B', 'L', 'C', 'K' ),
108    BLOCKER_PRIORITY,
109    RTEMS_MINIMUM_STACK_SIZE,
110    RTEMS_NO_PREEMPT,
111    RTEMS_DEFAULT_ATTRIBUTES,
112    &Secondary_task_id
113  );
114  directive_failed( status, "rtems_task_create" );
115
116  status = rtems_task_start( Secondary_task_id, Secondary_task, 0 );
117  directive_failed( status, "rtems_task_start" );
118
119  interrupt_critical_section_test_support_initialize( test_release_from_isr );
120
121  for (resets=0 ; resets< 2 ;) {
122    if ( interrupt_critical_section_test_support_delay() )
123      resets++;
124
125    status = rtems_semaphore_obtain(
126      Semaphore,
127      RTEMS_DEFAULT_OPTIONS,
128      SEMAPHORE_OBTAIN_TIMEOUT
129    );
130  }
131
132  puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" );
133  rtems_test_exit(0);
134}
135
136/* configuration information */
137
138#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
140
141#define CONFIGURE_MAXIMUM_TASKS       2
142#define CONFIGURE_MAXIMUM_TIMERS      1
143#define CONFIGURE_MAXIMUM_SEMAPHORES  1
144#define CONFIGURE_INIT_TASK_PRIORITY  INIT_PRIORITY
145#define CONFIGURE_INIT_TASK_MODE      RTEMS_PREEMPT
146#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
147
148#define CONFIGURE_INIT
149#include <rtems/confdefs.h>
150
151/* global variables */
Note: See TracBrowser for help on using the repository browser.