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

4.104.11
Last change on this file since b288588 was b288588, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 23, 2009 at 2:58:30 PM

2009-11-23 Joel Sherrill <joel.sherrill@…>

PR 1460/cpukit

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