source: rtems/testsuites/sptests/sp43/init.c @ cd4884a

4.104.11
Last change on this file since cd4884a was cd4884a, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 13, 2009 at 8:37:54 PM

2009-09-13 Joel Sherrill <joel.sherrill@…>

  • sp43/Makefile.am, sp43/init.c, sp43/sp43.scn, sp43/system.h: Add test for Id which is in range for the object class but not allocated yet.
  • Property mode set to 100644
File size: 14.7 KB
Line 
1/*
2 *  Exercise Object Manager Services
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
15#define CONFIGURE_INIT
16#include "system.h"
17
18#undef rtems_build_id
19#undef rtems_build_name
20#undef rtems_object_id_api_maximum
21#undef rtems_object_id_api_minimum
22#undef rtems_object_id_get_api
23#undef rtems_object_id_get_class
24#undef rtems_object_id_get_index
25#undef rtems_object_id_get_node
26
27void print_class_info(
28  uint32_t                            api,
29  uint32_t                            class,
30  rtems_object_api_class_information *info
31);
32void change_name(
33  rtems_id    id,
34  const char *newName,
35  bool        printable
36);
37
38rtems_id         main_task;
39rtems_name       main_name;
40
41void print_class_info(
42  uint32_t                            api,
43  uint32_t                            class,
44  rtems_object_api_class_information *info
45)
46{
47  printf(
48    "%s API %s Information\n"
49    "    minimum id  : 0x%08x maximum id: 0x%08x\n"
50    "    maximum     :    %7d available : %d\n"
51    "    auto_extend : %s\n",
52    rtems_object_get_api_name(api),
53    rtems_object_get_api_class_name(api, class),
54    info->minimum_id,
55    info->maximum_id,
56    info->maximum,
57    info->unallocated,
58    ((info->auto_extend) ? "yes" : "no")
59  );
60}
61
62void change_name(
63  rtems_id    id,
64  const char *newName,
65  bool        printable
66)
67{
68  rtems_status_code    sc;
69  char                 name[ 5 ];
70  char                *ptr;
71  const char          *c;
72
73  printf( "rtems_object_set_name - change name of init task to " );
74  if ( printable )
75    printf( "(%s)\n", newName );
76  else {
77    printf( "(" );
78    for (c=newName ; *c ; ) {
79       if (isprint(*c)) printf( "%c", *c );
80       else             printf( "0x%02x", *c );
81       c++;
82       if ( *c )
83         printf( "-" );
84    }
85    printf( ")\n" );
86  }
87
88  sc = rtems_object_set_name( id, newName );
89  directive_failed( sc, "rtems_object_set_name" );
90
91  sc = rtems_object_get_classic_name( id, &main_name );
92  directive_failed( sc, "rtems_object_get_classic_name" );
93  put_name( main_name, FALSE );
94  puts( " - name returned by rtems_object_get_classic_name" );
95
96  ptr = rtems_object_get_name( id, 5, name );
97  rtems_test_assert(ptr != NULL);
98  printf( "rtems_object_get_name returned (%s) for init task\n", ptr );
99}
100
101rtems_task Init(
102  rtems_task_argument argument
103)
104{
105  rtems_status_code                   sc;
106  rtems_id                            tmpId;
107  rtems_name                          tmpName;
108  char                                name[5];
109  char                               *ptr;
110  const char                          newName[5] = "New1";
111  char                                tmpNameString[5];
112  uint32_t                            part;
113  rtems_object_api_class_information  info;
114
115  puts( "\n\n*** TEST 43 ***" );
116
117  printf( "RTEMS Version: %s\n", rtems_get_version_string() );
118
119  main_task = rtems_task_self();
120
121  puts( "rtems_object_get_classic_name - INVALID_ADDRESS" );
122  sc = rtems_object_get_classic_name( main_task, NULL );
123  fatal_directive_status(
124    sc,
125    RTEMS_INVALID_ADDRESS,
126    "rtems_object_get_classic_name #1"
127  );
128
129  puts( "rtems_object_get_classic_name - INVALID_ID (bad index)" );
130  sc = rtems_object_get_classic_name( main_task + 5, &main_name );
131  fatal_directive_status(
132    sc,
133    RTEMS_INVALID_ID,
134    "rtems_object_get_classic_name #2"
135  );
136
137  puts( "rtems_object_get_classic_name - INVALID_ID (unallocated index)" );
138  sc = rtems_object_get_classic_name( main_task + 1, &main_name );
139  fatal_directive_status(
140    sc,
141    RTEMS_INVALID_ID,
142    "rtems_object_get_classic_name #4"
143  );
144
145  puts( "rtems_object_get_classic_name - INVALID_ID (bad API)" );
146  tmpId = rtems_build_id( 0xff, OBJECTS_RTEMS_TASKS, 1, 1 ),
147  sc = rtems_object_get_classic_name( tmpId, &main_name );
148  fatal_directive_status(
149    sc,
150    RTEMS_INVALID_ID,
151    "rtems_object_get_classic_name #5"
152  );
153
154  sc = rtems_object_get_classic_name( main_task, &main_name );
155  directive_failed( sc, "rtems_object_get_classic_name" );
156  put_name( main_name, FALSE );
157  puts( " - name returned by rtems_object_get_classic_name for Init task id" );
158
159  sc = rtems_object_get_classic_name( RTEMS_SELF, &main_name );
160  directive_failed( sc, "rtems_object_get_classic_name" );
161  put_name( main_name, FALSE );
162  puts( " - name returned by rtems_object_get_classic_name for RTEMS_SELF" );
163
164  tmpName = rtems_build_name( 'T', 'E', 'M', 'P' );
165  put_name( tmpName, FALSE );
166  puts( " - rtems_build_name for TEMP" );
167
168 
169  /*
170   * rtems_object_get_name - cases
171   */
172  puts( "rtems_object_get_name - bad id for class with instances" );
173  ptr = rtems_object_get_name( main_task + 5, 5, name );
174  rtems_test_assert(ptr == NULL);
175
176  puts( "rtems_object_get_name - bad id for class without instances" );
177  ptr = rtems_object_get_name(
178    rtems_build_id( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS, 1, 1 ),
179    5,
180    name
181  );
182  rtems_test_assert(ptr == NULL);
183
184  puts( "rtems_object_get_name - bad length" );
185  ptr = rtems_object_get_name( main_task, 0, name );
186  rtems_test_assert(ptr == NULL);
187
188  puts( "rtems_object_get_name - bad pointer" );
189  ptr = rtems_object_get_name( main_task, 5, NULL );
190  rtems_test_assert(ptr == NULL);
191
192  ptr = rtems_object_get_name( main_task, 5, name );
193  rtems_test_assert(ptr != NULL);
194  printf( "rtems_object_get_name returned (%s) for init task id\n", ptr );
195
196  ptr = rtems_object_get_name( RTEMS_SELF, 5, name );
197  rtems_test_assert(ptr != NULL);
198  printf( "rtems_object_get_name returned (%s) for RTEMS_SELF\n", ptr );
199
200  /*
201   * rtems_object_set_name - errors
202   */
203
204  puts( "rtems_object_set_name - INVALID_ID (bad API)" );
205  tmpId = rtems_build_id( 0xff, OBJECTS_RTEMS_TASKS, 1, 1 ),
206  sc = rtems_object_set_name( tmpId, newName );
207  fatal_directive_status(
208    sc,
209    RTEMS_INVALID_ID,
210    "rtems_object_set_name #1"
211  );
212
213  puts( "rtems_object_set_name - INVALID_ID (bad index)" );
214  sc = rtems_object_set_name( main_task + 10, newName );
215  fatal_directive_status(
216    sc,
217    RTEMS_INVALID_ID,
218    "rtems_object_set_name #2"
219  );
220
221  /*
222   * rtems_object_set_name - change name of init task in various ways.
223   *
224   * This is strange but pushes the SuperCore code to do different things.
225   */
226
227  change_name( main_task,  "New1", TRUE );
228  change_name( main_task, "Ne1", TRUE );
229  change_name( main_task, "N1", TRUE );
230  change_name( main_task, "N", TRUE );
231  change_name( main_task, "", TRUE );
232  tmpNameString[0] = 'N';
233  tmpNameString[1] = 0x07;
234  tmpNameString[2] = 0x09;
235  tmpNameString[3] = '1';
236  tmpNameString[4] = '\0';
237  change_name( main_task, tmpNameString, FALSE );
238
239  /*
240   * Change object name using SELF ID
241   */
242
243  change_name( RTEMS_SELF,  "SELF", TRUE );
244
245  ptr = rtems_object_get_name( main_task, 5, name );
246  rtems_test_assert(ptr != NULL);
247  printf( "rtems_object_get_name returned (%s) for init task id\n", ptr );
248
249
250  /*
251   * Exercise id build and extraction routines
252   */
253
254  puts( "rtems_build_id - build an id to match init task" );
255  tmpId = rtems_build_id( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, 1, 1 ),
256  assert( tmpId == main_task );
257 
258  puts( "rtems_object_id_get_api - OK" );
259  part = rtems_object_id_get_api( main_task );
260  assert( part == OBJECTS_CLASSIC_API );
261
262  puts( "rtems_object_id_get_class - OK" );
263  part = rtems_object_id_get_class( main_task );
264  assert( part == OBJECTS_RTEMS_TASKS );
265
266  puts( "rtems_object_id_get_node - OK" );
267  part = rtems_object_id_get_node( main_task );
268  assert( part == 1 );
269
270  puts( "rtems_object_id_get_index - OK" );
271  part = rtems_object_id_get_index( main_task );
272  assert( part == 1 );
273
274  /*
275   * Start another screen and do the API/Class min/max routines
276   */
277  rtems_test_pause();
278
279  printf( "rtems_object_id_api_minimum returned %d\n",
280          rtems_object_id_api_minimum() );
281  printf( "rtems_object_id_api_maximum returned %d\n",
282          rtems_object_id_api_maximum() );
283
284  printf( "rtems_object_api_minimum_class(0) returned %d\n",
285          rtems_object_api_minimum_class(0) );
286  printf( "rtems_object_api_maximum_class(0) returned %d\n",
287          rtems_object_api_maximum_class(0) );
288
289  printf( "rtems_object_api_minimum_class(0) returned %d\n",
290          rtems_object_api_minimum_class(0) );
291  printf( "rtems_object_api_maximum_class(0) returned %d\n",
292          rtems_object_api_maximum_class(0) );
293  printf( "rtems_object_api_minimum_class(255) returned %d\n",
294          rtems_object_api_minimum_class(255) );
295  printf( "rtems_object_api_maximum_class(255) returned %d\n",
296          rtems_object_api_maximum_class(255) );
297
298  printf( "rtems_object_api_minimum_class(OBJECTS_INTERNAL_API) returned %d\n",
299          rtems_object_api_minimum_class(OBJECTS_INTERNAL_API) );
300  printf( "rtems_object_api_maximum_class(OBJECTS_INTERNAL_API) returned %d\n",
301          rtems_object_api_maximum_class(OBJECTS_INTERNAL_API) );
302
303  printf( "rtems_object_api_minimum_class(OBJECTS_CLASSIC_API) returned %d\n",
304          rtems_object_api_minimum_class(OBJECTS_CLASSIC_API) );
305  printf( "rtems_object_api_maximum_class(OBJECTS_CLASSIC_API) returned %d\n",
306          rtems_object_api_maximum_class(OBJECTS_CLASSIC_API) );
307
308  printf( "rtems_object_api_minimum_class(OBJECTS_ITRON_API) returned %d\n",
309          rtems_object_api_minimum_class(OBJECTS_ITRON_API) );
310  printf( "rtems_object_api_maximum_class(OBJECTS_ITRON_API) returned %d\n",
311          rtems_object_api_maximum_class(OBJECTS_ITRON_API) );
312
313  /*
314   *  Another screen break for the API and class name tests
315   */
316  rtems_test_pause();
317 
318  printf( "rtems_object_get_api_name(0) = %s\n", rtems_object_get_api_name(0) );
319  printf( "rtems_object_get_api_name(255) = %s\n",
320    rtems_object_get_api_name(255));
321
322  printf( "rtems_object_get_api_name(INTERNAL_API) = %s\n",
323     rtems_object_get_api_name(OBJECTS_INTERNAL_API) );
324  printf( "rtems_object_get_api_name(CLASSIC_API) = %s\n",
325     rtems_object_get_api_name(OBJECTS_CLASSIC_API) );
326  printf( "rtems_object_get_api_name(ITRON_API) = %s\n",
327     rtems_object_get_api_name(OBJECTS_ITRON_API) );
328
329  printf( "rtems_object_get_api_class_name(0, RTEMS_TASKS) = %s\n", 
330    rtems_object_get_api_class_name( 0, OBJECTS_RTEMS_TASKS ) );
331  printf( "rtems_object_get_api_class_name(CLASSIC_API, 0) = %s\n", 
332    rtems_object_get_api_class_name( OBJECTS_CLASSIC_API, 0 ) );
333  printf("rtems_object_get_api_class_name(INTERNAL_API, MUTEXES) = %s\n", 
334    rtems_object_get_api_class_name(
335       OBJECTS_INTERNAL_API, OBJECTS_INTERNAL_MUTEXES));
336  printf("rtems_object_get_api_class_name(CLASSIC_API, RTEMS_BARRIERS) = %s\n", 
337    rtems_object_get_api_class_name(
338       OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS));
339
340  /*
341   *  Another screen break for the information
342   */
343
344  rtems_test_pause();
345 
346  puts( "rtems_object_get_class_information - INVALID_ADDRESS" );
347  sc = rtems_object_get_class_information(
348             OBJECTS_INTERNAL_API, OBJECTS_INTERNAL_THREADS, NULL );
349  fatal_directive_status(
350    sc,
351    RTEMS_INVALID_ADDRESS,
352    "rtems_object_get_class_information"
353  );
354
355  puts( "rtems_object_get_class_information - INVALID_NUMBER (bad API)" );
356  sc =
357    rtems_object_get_class_information(0, OBJECTS_INTERNAL_THREADS, &info);
358  fatal_directive_status(
359    sc,
360    RTEMS_INVALID_NUMBER,
361    "rtems_object_get_class_information (API)"
362  );
363
364  puts( "rtems_object_get_class_information - INVALID_NUMBER (api=0xff)" );
365  sc = rtems_object_get_class_information( 0xff, 1, &info );
366  fatal_directive_status(
367    sc,
368    RTEMS_INVALID_NUMBER,
369    "rtems_object_get_class_information (api=0xff)"
370  );
371
372  puts( "rtems_object_get_class_information - INVALID_NUMBER (class=0)" );
373  sc = rtems_object_get_class_information(
374    OBJECTS_INTERNAL_API, 0, &info );
375  fatal_directive_status(
376    sc,
377    RTEMS_INVALID_NUMBER,
378    "rtems_object_get_class_information (class=0)"
379  );
380
381  puts(
382    "rtems_object_get_class_information - INVALID_NUMBER (class too high)" );
383  sc = rtems_object_get_class_information(
384    OBJECTS_INTERNAL_API, 0xff, &info);
385  fatal_directive_status(
386    sc,
387    RTEMS_INVALID_NUMBER,
388    "rtems_object_get_class_information (class #2)"
389  );
390
391  puts( "rtems_object_get_class_information - Classic Tasks - OK" );
392  sc = rtems_object_get_class_information(
393             OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, &info );
394  directive_failed( sc, "rtems_object_get_class_information" );
395  print_class_info( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, &info );
396
397  puts( "rtems_object_get_class_information - Classic Timers - OK" );
398  sc = rtems_object_get_class_information(
399             OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, &info );
400  directive_failed( sc, "rtems_object_get_class_information" );
401  print_class_info( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, &info );
402
403  /*
404   *  Ugly hack to force a weird error.
405   *
406   *  The weird case is that we need to look up a thread Id where the
407   *  thread classes' object information table pointer is NULL.  Probably
408   *  impossible to really hit until registration is completely dynamically
409   *  configurable.
410   */
411  {
412    rtems_task_priority              old_priority;
413    void                            *tmp;
414    int                              class;
415    int                              api;
416
417    class = OBJECTS_INTERNAL_API;
418    api   = OBJECTS_INTERNAL_THREADS;
419
420    puts( "rtems_task_set_priority - use valid Idle thread id" );
421    sc = rtems_task_set_priority(
422      rtems_build_id( class, api, 1, 1 ),
423      RTEMS_CURRENT_PRIORITY,
424      &old_priority
425    );
426    directive_failed( sc, "rtems_task_set_priority" );
427
428    /* destroy class pointer */
429    puts( "rtems_task_set_priority - clobber internal thread class info" );
430    tmp = _Objects_Information_table[ class ][ api ];
431    _Objects_Information_table[ class ][ api ] = NULL;
432
433    puts( "rtems_task_set_priority - use valid Idle thread id again" );
434    sc = rtems_task_set_priority(
435      rtems_build_id( class, api, 1, 1 ),
436      RTEMS_CURRENT_PRIORITY,
437      &old_priority
438    );
439    fatal_directive_status( sc, RTEMS_INVALID_ID, "rtems_task_set_priority" );
440
441    /* restore pointer */
442    puts( "rtems_task_set_priority - restore internal thread class info" );
443    _Objects_Information_table[ class ][ api ] = tmp;
444  }
445
446  /*
447   *  Bad Id on an object which disables interrupts as part of translating
448   *  the Id into an object pointer.  Semaphore is the only object that
449   *  needs this. This is a "good" Id in that is it in range, but bad in
450   *  that it has not been allocated so the local_table pointer is NULL.
451   */
452  puts( "rtems_semaphore_release - good but uncreated ID - INVALID_ID - OK" );
453  sc = rtems_semaphore_release(
454    rtems_build_id(
455      OBJECTS_CLASSIC_API,
456      OBJECTS_RTEMS_SEMAPHORES,
457      1,
458      rtems_configuration_get_maximum_semaphores()
459    )
460  );
461  fatal_directive_status( sc, RTEMS_INVALID_ID, "rtems_semaphore_obtain" );
462
463  puts( "*** END OF TEST 43 ***" );
464  rtems_test_exit( 0 );
465}
Note: See TracBrowser for help on using the repository browser.