source: rtems/testsuites/sptests/sp40/init.c @ cdf30f05

4.115
Last change on this file since cdf30f05 was cdf30f05, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 19, 2015 at 12:57:44 PM

rtems: Add rtems_interrupt_local_disable|enable()

Add rtems_interrupt_local_disable|enable() as suggested by Pavel Pisa to
emphasize that interrupts are only disabled on the current processor.
Do not define the rtems_interrupt_disable|enable|flash() macros and
functions on SMP configurations since they don't ensure system wide
mutual exclusion.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 *  IO Manager Dynamic Registration
3 *
4 *  COPYRIGHT (c) 1989-2012.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  Copyright (c) 2009 embedded brains GmbH.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <tmacros.h>
19
20const char rtems_test_name[] = "SP 40";
21
22/* forward declarations to avoid warnings */
23rtems_task Init(rtems_task_argument argument);
24
25static rtems_device_driver test_open(
26     rtems_device_major_number  minor,
27     rtems_device_minor_number  major,
28     void                      *ignored
29)
30{
31  return RTEMS_IO_ERROR;
32}
33
34static rtems_driver_address_table test_driver = {
35  .initialization_entry = NULL,
36  .open_entry = test_open,
37  .close_entry = NULL,
38  .read_entry = NULL,
39  .write_entry = NULL,
40  .control_entry = NULL
41};
42
43#define test_interrupt_context_enter( level ) \
44  do { \
45    rtems_interrupt_local_disable( level ); \
46    ++_ISR_Nest_level; \
47  } while (0)
48
49#define test_interrupt_context_leave( level ) \
50  do { \
51    --_ISR_Nest_level; \
52    rtems_interrupt_local_enable( level ); \
53  } while (0)
54
55rtems_task Init(
56  rtems_task_argument argument
57)
58{
59  rtems_status_code         sc;
60  rtems_device_major_number registered;
61  rtems_device_major_number registered_not;
62  rtems_device_major_number invalid_major = _IO_Number_of_drivers + 1;
63  rtems_interrupt_level level;
64  bool do_interrupt_context_test = true;
65
66  TEST_BEGIN();
67
68  /* Ensure that this test works as expected */
69  test_interrupt_context_enter( level );
70  do_interrupt_context_test = rtems_interrupt_is_in_progress();
71  test_interrupt_context_leave( level );
72
73  /*
74   *  Register a driver with init == NULL and open != NULL
75   */
76
77  puts( "Init - rtems_io_register_driver - init == NULL, open != NULL OK" );
78  sc = rtems_io_register_driver( 0, &test_driver, &registered );
79  printf( "Init - Major slot returned = %d\n", (int) registered );
80  directive_failed( sc, "rtems_io_register_driver" );
81
82  puts( "Init - rtems_io_register_driver - init == NULL, open != NULL OK" );
83  sc = rtems_io_register_driver( 0, &test_driver, &registered_not );
84  printf( "Init - Major slot returned = %d\n", (int) registered_not );
85  fatal_directive_status(
86    sc,
87    RTEMS_TOO_MANY,
88    "rtems_io_register_driver too many"
89  );
90
91  puts( "Init - rtems_io_register_driver - used slot" );
92  sc = rtems_io_register_driver( registered, &test_driver, &registered_not );
93  fatal_directive_status(
94    sc,
95    RTEMS_RESOURCE_IN_USE,
96    "rtems_io_register_driver slot in use"
97  );
98
99  puts( "Init - rtems_io_unregister_driver - used slot" );
100  sc = rtems_io_unregister_driver( registered );
101  directive_failed( sc, "rtems_io_unregister_driver" );
102
103  puts( "Init - rtems_io_register_driver - free slot" );
104  sc = rtems_io_register_driver( registered, &test_driver, &registered );
105  directive_failed( sc, "rtems_io_register_driver" );
106
107  puts( "Init - rtems_io_register_driver - called from interrupt context" );
108  if ( do_interrupt_context_test ) {
109    test_interrupt_context_enter( level );
110    sc = rtems_io_register_driver( 0, NULL, NULL );
111    test_interrupt_context_leave( level );
112    fatal_directive_status(
113      sc,
114      RTEMS_CALLED_FROM_ISR,
115      "rtems_io_register_driver"
116    );
117  }
118
119  puts( "Init - rtems_io_register_driver - invalid registered major pointer" );
120  sc = rtems_io_register_driver( 0, NULL, NULL );
121  fatal_directive_status(
122    sc,
123    RTEMS_INVALID_ADDRESS,
124    "rtems_io_register_driver"
125  );
126
127  puts( "Init - rtems_io_register_driver - invalid driver table pointer" );
128  sc = rtems_io_register_driver( 0, NULL, &registered );
129  fatal_directive_status(
130    sc,
131    RTEMS_INVALID_ADDRESS,
132    "rtems_io_register_driver"
133  );
134
135  puts( "Init - rtems_io_register_driver - invalid empty driver table" );
136  test_driver.open_entry = NULL;
137  sc = rtems_io_register_driver( 0, &test_driver, &registered );
138  test_driver.open_entry = test_open;
139  fatal_directive_status(
140    sc,
141    RTEMS_INVALID_ADDRESS,
142    "rtems_io_register_driver"
143  );
144
145  puts( "Init - rtems_io_register_driver - invalid major" );
146  sc = rtems_io_register_driver( invalid_major, &test_driver, &registered );
147  fatal_directive_status(
148    sc,
149    RTEMS_INVALID_NUMBER,
150    "rtems_io_register_driver"
151  );
152
153  puts( "Init - rtems_io_unregister_driver - called from interrupt context" );
154  if ( do_interrupt_context_test ) {
155    test_interrupt_context_enter( level );
156    sc = rtems_io_unregister_driver( 0 );
157    test_interrupt_context_leave( level );
158    fatal_directive_status(
159      sc,
160      RTEMS_CALLED_FROM_ISR,
161      "rtems_io_unregister_driver"
162    );
163  }
164
165  puts( "Init - rtems_io_unregister_driver - invalid major number" );
166  sc = rtems_io_unregister_driver( invalid_major );
167  fatal_directive_status(
168    sc,
169    RTEMS_UNSATISFIED,
170    "rtems_io_unregister_driver"
171  );
172
173  TEST_END();
174  rtems_test_exit( 0 );
175}
176
177/* configuration information */
178
179#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
180#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
181
182/* more one more driver slot than are statically configured */
183#define CONFIGURE_MAXIMUM_DRIVERS 3
184
185#define CONFIGURE_MAXIMUM_TASKS  1
186#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
187
188#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
189
190#define CONFIGURE_INIT
191#include <rtems/confdefs.h>
192
193/* end of include file */
Note: See TracBrowser for help on using the repository browser.