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

4.104.115
Last change on this file since ea6eb431 was 7e29923, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/29/09 at 09:21:32

2009-10-29 Ralf Corsépius <ralf.corsepius@…>

  • sp43/init.c: Add local prototypes for rtems_object_api_minimum_class, rtems_object_api_maximum_class, rtems_build_id, rtems_build_name, rtems_object_id_api_maximum, rtems_object_id_api_minimum, rtems_object_id_get_api, rtems_object_id_get_class, rtems_object_id_get_index, rtems_object_id_get_node. Spray PRId32's into printf's for 16bit target complianance.
  • Property mode set to 100644
File size: 15.8 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/* HACK: API violation */
19extern uint32_t rtems_object_api_minimum_class(uint32_t api);
20extern unsigned int rtems_object_api_maximum_class(uint32_t api);
21
22/* These functions have both macro and function incarnations */
23#undef rtems_build_id
24extern rtems_id rtems_build_id(uint32_t api,uint32_t class,uint32_t node,uint32_t index);
25#undef rtems_build_name
26extern rtems_name rtems_build_name(char C1,char C2,char C3,char C4);
27#undef rtems_object_id_api_maximum
28extern uint32_t rtems_object_id_api_maximum(void);
29#undef rtems_object_id_api_minimum
30extern uint32_t rtems_object_id_api_minimum(void);
31#undef rtems_object_id_get_api
32extern uint32_t rtems_object_id_get_api(rtems_id id);
33#undef rtems_object_id_get_class
34extern uint32_t rtems_object_id_get_class(rtems_id id);
35#undef rtems_object_id_get_index
36extern uint32_t rtems_object_id_get_index(rtems_id id);
37#undef rtems_object_id_get_node
38extern uint32_t rtems_object_id_get_node(rtems_id id);
39
40void print_class_info(
41  uint32_t                            api,
42  uint32_t                            class,
43  rtems_object_api_class_information *info
44);
45
46void change_name(
47  rtems_id    id,
48  const char *newName,
49  bool        printable
50);
51
52rtems_id         main_task;
53rtems_name       main_name;
54
55void print_class_info(
56  uint32_t                            api,
57  uint32_t                            class,
58  rtems_object_api_class_information *info
59)
60{
61  printf(
62    "%s API %s Information\n"
63    "    minimum id  : 0x%08" PRIxrtems_id " 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(*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  uint32_t                            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  assert( tmpId == main_task );
279 
280  puts( "rtems_object_id_get_api - OK" );
281  part = rtems_object_id_get_api( main_task );
282  assert( part == OBJECTS_CLASSIC_API );
283
284  puts( "rtems_object_id_get_class - OK" );
285  part = rtems_object_id_get_class( main_task );
286  assert( part == OBJECTS_RTEMS_TASKS );
287
288  puts( "rtems_object_id_get_node - OK" );
289  part = rtems_object_id_get_node( main_task );
290  assert( part == 1 );
291
292  puts( "rtems_object_id_get_index - OK" );
293  part = rtems_object_id_get_index( main_task );
294  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 %" PRId32 "\n",
302          rtems_object_id_api_minimum() );
303  printf( "rtems_object_id_api_maximum returned %" PRId32 "\n",
304          rtems_object_id_api_maximum() );
305
306  printf( "rtems_object_api_minimum_class(0) returned %" PRId32 "\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 %" PRId32 "\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 %" PRId32 "\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 %" PRId32 "\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 %" PRId32 "\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  printf( "rtems_object_api_minimum_class(OBJECTS_ITRON_API) returned %" PRId32 "\n",
331          rtems_object_api_minimum_class(OBJECTS_ITRON_API) );
332  printf( "rtems_object_api_maximum_class(OBJECTS_ITRON_API) returned %d\n",
333          rtems_object_api_maximum_class(OBJECTS_ITRON_API) );
334
335  /*
336   *  Another screen break for the API and class name tests
337   */
338  rtems_test_pause();
339 
340  printf( "rtems_object_get_api_name(0) = %s\n", rtems_object_get_api_name(0) );
341  printf( "rtems_object_get_api_name(255) = %s\n",
342    rtems_object_get_api_name(255));
343
344  printf( "rtems_object_get_api_name(INTERNAL_API) = %s\n",
345     rtems_object_get_api_name(OBJECTS_INTERNAL_API) );
346  printf( "rtems_object_get_api_name(CLASSIC_API) = %s\n",
347     rtems_object_get_api_name(OBJECTS_CLASSIC_API) );
348  printf( "rtems_object_get_api_name(ITRON_API) = %s\n",
349     rtems_object_get_api_name(OBJECTS_ITRON_API) );
350
351  printf( "rtems_object_get_api_class_name(0, RTEMS_TASKS) = %s\n",
352    rtems_object_get_api_class_name( 0, OBJECTS_RTEMS_TASKS ) );
353  printf( "rtems_object_get_api_class_name(CLASSIC_API, 0) = %s\n",
354    rtems_object_get_api_class_name( OBJECTS_CLASSIC_API, 0 ) );
355  printf("rtems_object_get_api_class_name(INTERNAL_API, MUTEXES) = %s\n",
356    rtems_object_get_api_class_name(
357       OBJECTS_INTERNAL_API, OBJECTS_INTERNAL_MUTEXES));
358  printf("rtems_object_get_api_class_name(CLASSIC_API, RTEMS_BARRIERS) = %s\n",
359    rtems_object_get_api_class_name(
360       OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS));
361
362  /*
363   *  Another screen break for the information
364   */
365
366  rtems_test_pause();
367 
368  puts( "rtems_object_get_class_information - INVALID_ADDRESS" );
369  sc = rtems_object_get_class_information(
370             OBJECTS_INTERNAL_API, OBJECTS_INTERNAL_THREADS, NULL );
371  fatal_directive_status(
372    sc,
373    RTEMS_INVALID_ADDRESS,
374    "rtems_object_get_class_information"
375  );
376
377  puts( "rtems_object_get_class_information - INVALID_NUMBER (bad API)" );
378  sc =
379    rtems_object_get_class_information(0, OBJECTS_INTERNAL_THREADS, &info);
380  fatal_directive_status(
381    sc,
382    RTEMS_INVALID_NUMBER,
383    "rtems_object_get_class_information (API)"
384  );
385
386  puts( "rtems_object_get_class_information - INVALID_NUMBER (api=0xff)" );
387  sc = rtems_object_get_class_information( 0xff, 1, &info );
388  fatal_directive_status(
389    sc,
390    RTEMS_INVALID_NUMBER,
391    "rtems_object_get_class_information (api=0xff)"
392  );
393
394  puts( "rtems_object_get_class_information - INVALID_NUMBER (class=0)" );
395  sc = rtems_object_get_class_information(
396    OBJECTS_INTERNAL_API, 0, &info );
397  fatal_directive_status(
398    sc,
399    RTEMS_INVALID_NUMBER,
400    "rtems_object_get_class_information (class=0)"
401  );
402
403  puts(
404    "rtems_object_get_class_information - INVALID_NUMBER (class too high)" );
405  sc = rtems_object_get_class_information(
406    OBJECTS_INTERNAL_API, 0xff, &info);
407  fatal_directive_status(
408    sc,
409    RTEMS_INVALID_NUMBER,
410    "rtems_object_get_class_information (class #2)"
411  );
412
413  puts( "rtems_object_get_class_information - Classic Tasks - OK" );
414  sc = rtems_object_get_class_information(
415             OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, &info );
416  directive_failed( sc, "rtems_object_get_class_information" );
417  print_class_info( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, &info );
418
419  puts( "rtems_object_get_class_information - Classic Timers - OK" );
420  sc = rtems_object_get_class_information(
421             OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, &info );
422  directive_failed( sc, "rtems_object_get_class_information" );
423  print_class_info( OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, &info );
424
425  /*
426   *  Ugly hack to force a weird error.
427   *
428   *  The weird case is that we need to look up a thread Id where the
429   *  thread classes' object information table pointer is NULL.  Probably
430   *  impossible to really hit until registration is completely dynamically
431   *  configurable.
432   */
433  {
434    rtems_task_priority              old_priority;
435    void                            *tmp;
436    int                              class;
437    int                              api;
438
439    class = OBJECTS_INTERNAL_API;
440    api   = OBJECTS_INTERNAL_THREADS;
441
442    puts( "rtems_task_set_priority - use valid Idle thread id" );
443    sc = rtems_task_set_priority(
444      rtems_build_id( class, api, 1, 1 ),
445      RTEMS_CURRENT_PRIORITY,
446      &old_priority
447    );
448    directive_failed( sc, "rtems_task_set_priority" );
449
450    /* destroy class pointer */
451    puts( "rtems_task_set_priority - clobber internal thread class info" );
452    tmp = _Objects_Information_table[ class ][ api ];
453    _Objects_Information_table[ class ][ api ] = NULL;
454
455    puts( "rtems_task_set_priority - use valid Idle thread id again" );
456    sc = rtems_task_set_priority(
457      rtems_build_id( class, api, 1, 1 ),
458      RTEMS_CURRENT_PRIORITY,
459      &old_priority
460    );
461    fatal_directive_status( sc, RTEMS_INVALID_ID, "rtems_task_set_priority" );
462
463    /* restore pointer */
464    puts( "rtems_task_set_priority - restore internal thread class info" );
465    _Objects_Information_table[ class ][ api ] = tmp;
466  }
467
468  /*
469   *  Bad Id on an object which disables interrupts as part of translating
470   *  the Id into an object pointer.  Semaphore is the only object that
471   *  needs this. This is a "good" Id in that is it in range, but bad in
472   *  that it has not been allocated so the local_table pointer is NULL.
473   */
474  puts( "rtems_semaphore_obtain - good but uncreated ID - INVALID_ID - OK" );
475  sc = rtems_semaphore_obtain(
476    rtems_build_id(
477      OBJECTS_CLASSIC_API,
478      OBJECTS_RTEMS_SEMAPHORES,
479      1,
480      rtems_configuration_get_maximum_semaphores()
481    ),
482    RTEMS_DEFAULT_OPTIONS,
483    0
484  );
485  fatal_directive_status( sc, RTEMS_INVALID_ID, "rtems_semaphore_obtain" );
486
487  puts( "*** END OF TEST 43 ***" );
488  rtems_test_exit( 0 );
489}
Note: See TracBrowser for help on using the repository browser.