source: rtems/testsuites/sptests/spintrcritical16/init.c @ ae75429

4.115
Last change on this file since ae75429 was ae75429, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 6, 2013 at 2:10:26 PM

PR766: Delete RTEMS_VIOLATE_KERNEL_VISIBILITY

  • Property mode set to 100644
File size: 3.1 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
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include <intrcritical.h>
16
17#include <rtems/rtems/semimpl.h>
18
19/* forward declarations to avoid warnings */
20rtems_task Init(rtems_task_argument argument);
21rtems_timer_service_routine test_release_from_isr(rtems_id  timer, void *arg);
22Thread_blocking_operation_States getState(void);
23
24#define TEST_NAME          "16"
25
26Thread_Control *Main_TCB;
27rtems_id        Main_task;
28rtems_id        Semaphore;
29volatile bool   case_hit;
30
31Thread_blocking_operation_States getState(void)
32{
33  Objects_Locations  location;
34  Semaphore_Control *sem;
35
36  sem = (Semaphore_Control *)_Objects_Get(
37    &_Semaphore_Information, Semaphore, &location );
38  if ( location != OBJECTS_LOCAL ) {
39    puts( "Bad object lookup" );
40    rtems_test_exit(0);
41  }
42  _Thread_Unnest_dispatch();
43
44  return sem->Core_control.semaphore.Wait_queue.sync_state;
45}
46
47rtems_timer_service_routine test_release_from_isr(
48  rtems_id  timer,
49  void     *arg
50)
51{
52  if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
53    case_hit = true;
54    (void) rtems_semaphore_release( Semaphore );
55  }
56
57  if ( Main_TCB->Wait.queue != NULL ) {
58    _Thread_queue_Process_timeout( Main_TCB );
59  }
60}
61
62rtems_task Init(
63  rtems_task_argument ignored
64)
65{
66  rtems_status_code     sc;
67  int                   resets;
68
69  puts(
70    "\n\n*** TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***\n"
71    "Init - Trying to generate timeout of a thread that had its blocking\n"
72    "Init -   request satisfied while blocking but before time timeout"
73  );
74
75  puts( "Init - rtems_semaphore_create - OK" );
76  sc = rtems_semaphore_create(
77    rtems_build_name( 'S', 'M', '1', ' ' ),
78    0,
79    RTEMS_DEFAULT_ATTRIBUTES,
80    RTEMS_NO_PRIORITY,
81    &Semaphore
82  );
83  directive_failed( sc, "rtems_semaphore_create of SM1" );
84
85  Main_task = rtems_task_self();
86  Main_TCB  = _Thread_Get_executing();
87
88  interrupt_critical_section_test_support_initialize( test_release_from_isr );
89
90  case_hit = false;
91
92  for (resets=0 ; !case_hit && resets<10 ;) {
93    if ( interrupt_critical_section_test_support_delay() )
94      resets++;
95
96    sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
97    if ( sc == RTEMS_SUCCESSFUL )
98      break;
99    fatal_directive_status( sc, RTEMS_TIMEOUT, "rtems_semaphore_obtain" );
100  }
101
102  if ( case_hit ) {
103    puts( "Init - Case hit" );
104    puts( "*** END OF TEST INTERRUPT CRITICAL SECTION " TEST_NAME " ***" );
105  } else
106    puts( "Init - Case not hit - ran too long" );
107
108
109  rtems_test_exit(0);
110}
111
112/* configuration information */
113
114#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
115#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
116
117#define CONFIGURE_MAXIMUM_TASKS          1
118#define CONFIGURE_MAXIMUM_TIMERS         1
119#define CONFIGURE_MAXIMUM_SEMAPHORES     1
120#define CONFIGURE_MICROSECONDS_PER_TICK  1000
121#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
122
123#define CONFIGURE_INIT
124#include <rtems/confdefs.h>
125
126/* global variables */
Note: See TracBrowser for help on using the repository browser.