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

5
Last change on this file since bb99cd0d was bb99cd0d, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 5, 2019 at 6:22:33 PM

clock: Simplify driver initialization

Use a system initialization handler instead of a legacy IO driver.

Update #3834.

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