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.org/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 | const char rtems_test_name[] = "SPINTRCRITICAL 16"; |
---|
20 | |
---|
21 | /* forward declarations to avoid warnings */ |
---|
22 | rtems_task Init(rtems_task_argument argument); |
---|
23 | rtems_timer_service_routine test_release_from_isr(rtems_id timer, void *arg); |
---|
24 | Thread_blocking_operation_States getState(void); |
---|
25 | |
---|
26 | Thread_Control *Main_TCB; |
---|
27 | rtems_id Semaphore; |
---|
28 | volatile bool case_hit = false; |
---|
29 | |
---|
30 | Thread_blocking_operation_States getState(void) |
---|
31 | { |
---|
32 | Objects_Locations location; |
---|
33 | Semaphore_Control *sem; |
---|
34 | |
---|
35 | sem = (Semaphore_Control *)_Objects_Get( |
---|
36 | &_Semaphore_Information, Semaphore, &location ); |
---|
37 | if ( location != OBJECTS_LOCAL ) { |
---|
38 | puts( "Bad object lookup" ); |
---|
39 | rtems_test_exit(0); |
---|
40 | } |
---|
41 | _Thread_Unnest_dispatch(); |
---|
42 | |
---|
43 | return sem->Core_control.semaphore.Wait_queue.sync_state; |
---|
44 | } |
---|
45 | |
---|
46 | rtems_timer_service_routine test_release_from_isr( |
---|
47 | rtems_id timer, |
---|
48 | void *arg |
---|
49 | ) |
---|
50 | { |
---|
51 | if ( getState() == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
52 | case_hit = true; |
---|
53 | (void) rtems_semaphore_release( Semaphore ); |
---|
54 | } |
---|
55 | |
---|
56 | if ( Main_TCB->Wait.queue != NULL ) { |
---|
57 | _Thread_queue_Process_timeout( Main_TCB ); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | static bool test_body( void *arg ) |
---|
62 | { |
---|
63 | rtems_status_code sc; |
---|
64 | |
---|
65 | (void) arg; |
---|
66 | |
---|
67 | sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 ); |
---|
68 | rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT ); |
---|
69 | |
---|
70 | return case_hit; |
---|
71 | } |
---|
72 | |
---|
73 | rtems_task Init( |
---|
74 | rtems_task_argument ignored |
---|
75 | ) |
---|
76 | { |
---|
77 | rtems_status_code sc; |
---|
78 | |
---|
79 | TEST_BEGIN(); |
---|
80 | puts( |
---|
81 | "Init - Trying to generate timeout of a thread that had its blocking\n" |
---|
82 | "Init - request satisfied while blocking but before time timeout" |
---|
83 | ); |
---|
84 | |
---|
85 | puts( "Init - rtems_semaphore_create - OK" ); |
---|
86 | sc = rtems_semaphore_create( |
---|
87 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
88 | 0, |
---|
89 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
90 | RTEMS_NO_PRIORITY, |
---|
91 | &Semaphore |
---|
92 | ); |
---|
93 | directive_failed( sc, "rtems_semaphore_create of SM1" ); |
---|
94 | |
---|
95 | Main_TCB = _Thread_Get_executing(); |
---|
96 | |
---|
97 | interrupt_critical_section_test( test_body, NULL, test_release_from_isr ); |
---|
98 | |
---|
99 | if ( case_hit ) { |
---|
100 | puts( "Init - Case hit" ); |
---|
101 | TEST_END(); |
---|
102 | } else |
---|
103 | puts( "Init - Case not hit - ran too long" ); |
---|
104 | |
---|
105 | |
---|
106 | rtems_test_exit(0); |
---|
107 | } |
---|
108 | |
---|
109 | /* configuration information */ |
---|
110 | |
---|
111 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
112 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
113 | |
---|
114 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
115 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
116 | #define CONFIGURE_MAXIMUM_SEMAPHORES 1 |
---|
117 | #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 |
---|
118 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 |
---|
119 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
120 | |
---|
121 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
122 | |
---|
123 | #define CONFIGURE_INIT |
---|
124 | #include <rtems/confdefs.h> |
---|
125 | |
---|
126 | /* global variables */ |
---|