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

4.115
Last change on this file since ae55da72 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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