source: rtems/testsuites/psxtests/psxcancel01/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

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