1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
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 <pmacros.h> |
---|
15 | #include <errno.h> |
---|
16 | |
---|
17 | /* forward declarations to avoid warnings */ |
---|
18 | void *POSIX_Init(void *argument); |
---|
19 | rtems_timer_service_routine Cancel_duringISR_TSR( |
---|
20 | rtems_id ignored_id, |
---|
21 | void *ignored_address |
---|
22 | ); |
---|
23 | rtems_timer_service_routine SetState_duringISR_TSR( |
---|
24 | rtems_id ignored_id, |
---|
25 | void *ignored_address |
---|
26 | ); |
---|
27 | rtems_timer_service_routine SetType_duringISR_TSR( |
---|
28 | rtems_id ignored_id, |
---|
29 | void *ignored_address |
---|
30 | ); |
---|
31 | void doit( |
---|
32 | rtems_timer_service_routine (*TSR)(rtems_id, void *), |
---|
33 | const char *method |
---|
34 | ); |
---|
35 | |
---|
36 | volatile int TSR_occurred; |
---|
37 | volatile int TSR_status; |
---|
38 | |
---|
39 | rtems_id timer_id; |
---|
40 | |
---|
41 | rtems_timer_service_routine Cancel_duringISR_TSR( |
---|
42 | rtems_id ignored_id, |
---|
43 | void *ignored_address |
---|
44 | ) |
---|
45 | { |
---|
46 | TSR_status = pthread_cancel( pthread_self() ); |
---|
47 | TSR_occurred = 1; |
---|
48 | } |
---|
49 | |
---|
50 | rtems_timer_service_routine SetState_duringISR_TSR( |
---|
51 | rtems_id ignored_id, |
---|
52 | void *ignored_address |
---|
53 | ) |
---|
54 | { |
---|
55 | int oldstate; |
---|
56 | |
---|
57 | TSR_status = pthread_setcancelstate( 0, &oldstate ); |
---|
58 | TSR_occurred = 1; |
---|
59 | } |
---|
60 | |
---|
61 | rtems_timer_service_routine SetType_duringISR_TSR( |
---|
62 | rtems_id ignored_id, |
---|
63 | void *ignored_address |
---|
64 | ) |
---|
65 | { |
---|
66 | int oldtype; |
---|
67 | |
---|
68 | TSR_status = pthread_setcanceltype( 0, &oldtype ); |
---|
69 | TSR_occurred = 1; |
---|
70 | } |
---|
71 | |
---|
72 | void doit( |
---|
73 | rtems_timer_service_routine (*TSR)(rtems_id, void *), |
---|
74 | const char *method |
---|
75 | ) |
---|
76 | { |
---|
77 | rtems_interval start; |
---|
78 | rtems_interval end; |
---|
79 | rtems_status_code status; |
---|
80 | |
---|
81 | printf( "Init: schedule %s from a TSR\n", method ); |
---|
82 | |
---|
83 | TSR_occurred = 0; |
---|
84 | TSR_status = 0; |
---|
85 | |
---|
86 | status = rtems_timer_fire_after( timer_id, 10, TSR, NULL ); |
---|
87 | rtems_test_assert( !status ); |
---|
88 | |
---|
89 | start = rtems_clock_get_ticks_since_boot(); |
---|
90 | do { |
---|
91 | end = rtems_clock_get_ticks_since_boot(); |
---|
92 | } while ( !TSR_occurred && ((end - start) <= 800)); |
---|
93 | |
---|
94 | if ( !TSR_occurred ) { |
---|
95 | printf( "%s did not occur\n", method ); |
---|
96 | rtems_test_exit(0); |
---|
97 | } |
---|
98 | if ( TSR_status != EPROTO ) { |
---|
99 | printf( "%s returned %s\n", method, strerror(TSR_status) ); |
---|
100 | rtems_test_exit(0); |
---|
101 | } |
---|
102 | printf( "%s - from ISR returns EPROTO - OK\n", method ); |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | void *POSIX_Init( |
---|
107 | void *argument |
---|
108 | ) |
---|
109 | { |
---|
110 | rtems_status_code status; |
---|
111 | |
---|
112 | puts( "\n\n*** POSIX TEST CANCEL 01 ***" ); |
---|
113 | |
---|
114 | status = rtems_timer_create( |
---|
115 | rtems_build_name( 'T', 'M', '1', ' ' ), |
---|
116 | &timer_id |
---|
117 | ); |
---|
118 | rtems_test_assert( !status ); |
---|
119 | |
---|
120 | doit( Cancel_duringISR_TSR, "pthread_cancel" ); |
---|
121 | doit( SetState_duringISR_TSR, "pthread_setcancelstate" ); |
---|
122 | doit( SetType_duringISR_TSR, "pthread_setcanceltype" ); |
---|
123 | |
---|
124 | puts( "*** END OF POSIX TEST CANCEL 01 ***" ); |
---|
125 | rtems_test_exit(0); |
---|
126 | return NULL; /* just so the compiler thinks we returned something */ |
---|
127 | } |
---|
128 | |
---|
129 | /* configuration information */ |
---|
130 | |
---|
131 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
132 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
133 | |
---|
134 | #define CONFIGURE_MAXIMUM_TIMERS 1 |
---|
135 | |
---|
136 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
137 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
138 | |
---|
139 | #define CONFIGURE_INIT |
---|
140 | #include <rtems/confdefs.h> |
---|