source: rtems/testsuites/sptests/sp21/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: 8.5 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 <tmacros.h>
15#include <rtems/devnull.h>
16#include <rtems/devzero.h>
17#include <rtems/libio.h>
18
19const char rtems_test_name[] = "SP 21";
20
21/* forward declarations to avoid warnings */
22rtems_task Init(rtems_task_argument argument);
23void do_test_io_manager(void);
24void do_test_io_lookup_name(void);
25void do_test_zero_driver(void);
26
27#define PRIurtems_device_major_number PRIu32
28
29#define STUB_DRIVER_MAJOR     1
30#define ZERO_DRIVER_MAJOR     2
31#define NO_DRIVER_MAJOR       3
32#define INVALID_DRIVER_MAJOR  UINT32_MAX
33
34/* driver entries to use with io_register */
35rtems_driver_address_table GoodDriver = DEVNULL_DRIVER_TABLE_ENTRY;
36rtems_driver_address_table BadDriver_Nothing = {
37  NULL, NULL, NULL, NULL, NULL, NULL
38};
39
40void do_test_io_manager(void)
41{
42  rtems_status_code         status;
43  rtems_device_major_number registered;
44  rtems_device_major_number registered_worked;
45
46  puts( "-----  TESTING THE NULL DRIVER CHECKS  -----" );
47
48  status = rtems_io_initialize( NO_DRIVER_MAJOR, 0, NULL );
49  directive_failed( status, "rtems_io_initialize" );
50  puts( "rtems_io_initialize  - NULL DRIVER RTEMS_SUCCESSFUL" );
51
52  status = rtems_io_open( NO_DRIVER_MAJOR, 0, NULL );
53  directive_failed( status, "rtems_io_open" );
54  puts( "rtems_io_open        - NULL DRIVER RTEMS_SUCCESSFUL" );
55
56  status = rtems_io_close( NO_DRIVER_MAJOR, 0, NULL );
57  directive_failed( status, "rtems_io_close" );
58  puts( "rtems_io_close       - NULL DRIVER RTEMS_SUCCESSFUL" );
59
60  status = rtems_io_read( NO_DRIVER_MAJOR, 0, NULL );
61  directive_failed( status, "rtems_io_read" );
62  puts( "rtems_io_read        - NULL DRIVER RTEMS_SUCCESSFUL" );
63
64  status = rtems_io_write( NO_DRIVER_MAJOR, 0, NULL );
65  directive_failed( status, "rtems_io_write" );
66  puts( "rtems_io_write       - NULL DRIVER RTEMS_SUCCESSFUL" );
67
68  status = rtems_io_control( NO_DRIVER_MAJOR, 0, NULL );
69  directive_failed( status, "rtems_io_control" );
70  puts( "rtems_io_control     - NULL DRIVER RTEMS_SUCCESSFUL" );
71
72  puts( "-----  TESTING THE I/O MANAGER DIRECTIVES  -----" );
73
74  status = rtems_io_initialize( STUB_DRIVER_MAJOR, 0, NULL );
75  directive_failed( status, "rtems_io_initialize" );
76  puts( "rtems_io_initialize  - STUB DRIVER RTEMS_SUCCESSFUL" );
77
78  status = rtems_io_open( STUB_DRIVER_MAJOR, 0, NULL );
79  directive_failed( status, "rtems_io_open" );
80  puts( "rtems_io_open        - STUB DRIVER RTEMS_SUCCESSFUL" );
81
82  status = rtems_io_close( STUB_DRIVER_MAJOR, 0, NULL );
83  directive_failed( status, "rtems_io_close" );
84  puts( "rtems_io_close       - STUB DRIVER RTEMS_SUCCESSFUL" );
85
86  status = rtems_io_read( STUB_DRIVER_MAJOR, 0, NULL );
87  directive_failed( status, "rtems_io_read" );
88  puts( "rtems_io_read        - STUB DRIVER RTEMS_SUCCESSFUL" );
89
90  status = rtems_io_write( STUB_DRIVER_MAJOR, 0, NULL );
91  directive_failed( status, "rtems_io_write" );
92  puts( "rtems_io_write       - STUB DRIVER RTEMS_SUCCESSFUL" );
93
94  status = rtems_io_control( STUB_DRIVER_MAJOR, 0, NULL );
95  directive_failed( status, "rtems_io_control" );
96  puts( "rtems_io_control     - STUB DRIVER RTEMS_SUCCESSFUL" );
97
98  /*
99   *  Invalid major number
100   */
101  puts( "-----  RETURNING INVALID MAJOR NUMBER -----" );
102
103  status = rtems_io_initialize( INVALID_DRIVER_MAJOR, 0, NULL );
104  fatal_directive_status(
105    status,
106    RTEMS_INVALID_NUMBER,
107    "rtems_io_initialize"
108  );
109  puts( "rtems_io_initialize  - RTEMS_INVALID_NUMBER" );
110
111  status = rtems_io_open( INVALID_DRIVER_MAJOR, 0, NULL );
112  fatal_directive_status(
113    status,
114    RTEMS_INVALID_NUMBER,
115    "rtems_io_open"
116  );
117  puts( "rtems_io_open        - RTEMS_INVALID_NUMBER" );
118
119  /*
120   *  Exercise the io register driver directive
121   */
122  puts( "-----  EXERCISE DRIVER REGISTER -----" );
123
124  status = rtems_io_register_driver( 0, &GoodDriver, NULL );
125  fatal_directive_status(
126    status,
127    RTEMS_INVALID_ADDRESS,
128    "rtems_io_register_driver"
129  );
130  puts(
131   "rtems_io_register_driver - RTEMS_INVALID_ADDRESS - NULL registered"
132  );
133
134  status = rtems_io_register_driver( 0, NULL, &registered );
135  fatal_directive_status(
136    status,
137    RTEMS_INVALID_ADDRESS,
138    "rtems_io_register_driver"
139  );
140  puts(
141    "rtems_io_register_driver - RTEMS_INVALID_ADDRESS - NULL device"
142  );
143
144  status = rtems_io_register_driver( 0, &BadDriver_Nothing, &registered );
145  fatal_directive_status(
146    status,
147    RTEMS_INVALID_ADDRESS,
148    "rtems_io_register_driver"
149  );
150  puts(
151    "rtems_io_register_driver - RTEMS_INVALID_ADDRESS - no callouts"
152  );
153
154  status = rtems_io_register_driver(
155    INVALID_DRIVER_MAJOR, &GoodDriver, &registered );
156  fatal_directive_status(
157    status,
158    RTEMS_INVALID_NUMBER,
159    "rtems_io_register_driver"
160  );
161  puts( "rtems_io_register_driver - RTEMS_INVALID_NUMBER - bad major" );
162
163  /* this has to succeed to overwrite NULL driver entry required above. */
164  status = rtems_io_register_driver( 0, &GoodDriver, &registered_worked );
165  directive_failed( status, "rtems_io_register_driver" );
166  puts( "rtems_io_register_driver - RTEMS_SUCCESSFUL - overwrite NULL" );
167
168  status = rtems_io_register_driver( 0, &GoodDriver, &registered );
169  if ( status == RTEMS_SUCCESSFUL )
170    printf(
171      "registered major = %" PRIurtems_device_major_number "\n", registered );
172  fatal_directive_status(
173    status,
174    RTEMS_TOO_MANY,
175    "rtems_io_register_driver"
176  );
177  puts( "rtems_io_register_driver - RTEMS_TOO_MANY - no slots" );
178
179  /* there should be a driver at major 1 -- clock, console, or stub */
180  status = rtems_io_register_driver( 1, &GoodDriver, &registered );
181  fatal_directive_status(
182    status,
183    RTEMS_RESOURCE_IN_USE,
184    "rtems_io_register_driver"
185  );
186  puts(
187    "rtems_io_register_driver - RTEMS_RESOURCE_IN_USE - major in use"
188  );
189
190  /* this should unregister the device driver we registered above */
191  status = rtems_io_unregister_driver( registered_worked );
192  directive_failed( status, "rtems_io_unregister_driver" );
193  puts( "rtems_io_unregister_driver - RTEMS_SUCCESSFUL" );
194}
195
196void do_test_io_lookup_name(void)
197{
198  rtems_status_code    sc;
199  rtems_driver_name_t  info;
200
201  puts( "rtems_io_lookup_name( \"\", &info ) - RTEMS_UNSATISFIED" );
202  sc = rtems_io_lookup_name( "", &info );
203  fatal_directive_status( sc, RTEMS_UNSATISFIED, "lookup empty string" );
204 
205  puts( "rtems_io_lookup_name( \"/dev\", &info ) - RTEMS_UNSATISFIED" );
206  sc = rtems_io_lookup_name( "/dev", &info );
207  fatal_directive_status( sc, RTEMS_UNSATISFIED, "lookup empty string" );
208
209  puts( "rtems_io_lookup_name( \"/dev/null\", &info ) - RTEMS_SUCCESSFUL" );
210  sc = rtems_io_lookup_name( "/dev/null", &info );
211  directive_failed( sc, "lookup /dev/null" );
212}
213
214void do_test_zero_driver(void)
215{
216  rtems_status_code sc = RTEMS_SUCCESSFUL;
217  char in = 'I';
218  rtems_libio_rw_args_t rw_in = {
219    .buffer = &in,
220    .count = sizeof(in)
221  };
222  char out = 'O';
223  rtems_libio_rw_args_t rw_out = {
224    .buffer = &out,
225    .count = sizeof(out)
226  };
227
228  puts( "-----  TESTING THE ZERO DRIVER CHECKS  -----" );
229
230  sc = rtems_io_initialize( ZERO_DRIVER_MAJOR, 0, NULL );
231  rtems_test_assert( sc == RTEMS_TOO_MANY );
232
233  sc = rtems_io_open( ZERO_DRIVER_MAJOR, 0, NULL );
234  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
235
236  sc = rtems_io_close( ZERO_DRIVER_MAJOR, 0, NULL );
237  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
238
239  sc = rtems_io_read( ZERO_DRIVER_MAJOR, 0, &rw_in );
240  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
241  rtems_test_assert( in == 0 );
242  rtems_test_assert( rw_in.bytes_moved == sizeof(in) );
243
244  sc = rtems_io_write( ZERO_DRIVER_MAJOR, 0, &rw_out );
245  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
246  rtems_test_assert( out == 'O' );
247  rtems_test_assert( rw_out.bytes_moved == sizeof(out) );
248
249  sc = rtems_io_control( ZERO_DRIVER_MAJOR, 0, NULL );
250  rtems_test_assert( sc == RTEMS_IO_ERROR );
251}
252
253rtems_task Init(
254  rtems_task_argument argument
255)
256{
257  TEST_BEGIN();
258
259  do_test_io_manager();
260
261  do_test_io_lookup_name();
262
263  do_test_zero_driver();
264
265  TEST_END();
266  rtems_test_exit( 0 );
267}
268
269/* configuration information */
270
271#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
272#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
273#define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER
274#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
275#define CONFIGURE_APPLICATION_NEEDS_NULL_DRIVER
276
277#define CONFIGURE_MAXIMUM_TASKS             1
278#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
279
280#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
281
282#define CONFIGURE_INIT
283#include <rtems/confdefs.h>
284/* end of file */
Note: See TracBrowser for help on using the repository browser.