source: rtems/testsuites/sptests/sp43/init.c @ 7c8830c7

4.115
Last change on this file since 7c8830c7 was 7c8830c7, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 28, 2013 at 11:48:17 AM

testsuites: Include missing header files

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