source: rtems/testsuites/sptests/sp40/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: 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.com/license/LICENSE.
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <tmacros.h>
19
20/* forward declarations to avoid warnings */
21rtems_task Init(rtems_task_argument argument);
22
23static rtems_device_driver test_open(
24     rtems_device_major_number  minor,
25     rtems_device_minor_number  major,
26     void                      *ignored
27)
28{
29  return RTEMS_IO_ERROR;
30}
31
32static rtems_driver_address_table test_driver = {
33  .initialization_entry = NULL,
34  .open_entry = test_open,
35  .close_entry = NULL,
36  .read_entry = NULL,
37  .write_entry = NULL,
38  .control_entry = NULL
39};
40
41#define test_interrupt_context_enter( level ) \
42  do { \
43    _Thread_Disable_dispatch(); \
44    rtems_interrupt_disable( level ); \
45    ++_ISR_Nest_level; \
46  } while (0)
47
48#define test_interrupt_context_leave( level ) \
49  do { \
50    --_ISR_Nest_level; \
51    rtems_interrupt_enable( level ); \
52    _Thread_Enable_dispatch(); \
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  puts( "\n\n*** TEST 40 ***" );
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  puts( "*** END OF TEST 40 ***" );
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_RTEMS_INIT_TASKS_TABLE
187
188#define CONFIGURE_INIT
189#include <rtems/confdefs.h>
190
191/* end of include file */
Note: See TracBrowser for help on using the repository browser.