source: rtems/testsuites/sptests/spobjgetnext/init.c @ 474b9be

5
Last change on this file since 474b9be was 474b9be, checked in by Sebastian Huber <sebastian.huber@…>, on 03/15/16 at 14:42:57

score: Use allocator lock in _Objects_Get_next()

Use the object allocator lock in _Objects_Get_next() instead of disabled
thread dispatching since object creation and deletion is covered by this
lock.

Update #2555.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  Exercise SuperCore Object Get Next
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.org/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/rtems/tasksimpl.h>
20
21const char rtems_test_name[] = "SPOBJGETNEXT";
22
23/* prototypes */
24int scan_objects(
25  Objects_Information *information,
26  Objects_Id           start
27);
28
29#define MAX_SCAN 10
30
31int scan_objects(
32  Objects_Information *information,
33  Objects_Id           start
34)
35{
36  Objects_Control  *o[MAX_SCAN];
37  int               i;
38  Objects_Locations location;
39  Objects_Id        id;
40
41  memset( o, 1, sizeof(o) );
42
43  id = start;
44  for (i=0 ; i<MAX_SCAN ; i++ ) {
45    o[i] = _Objects_Get_next(
46      information,
47      id,
48      &location,
49      &id
50    );
51    if ( !o[i] )
52      break;
53    if ( location == OBJECTS_ERROR )
54      break;
55    /* XXX check dispatch level with macros */
56
57    /* XXX should be able to check that next Id is not one we have seen */
58  }
59  return i;
60}
61
62rtems_task Init(
63  rtems_task_argument argument
64)
65{
66  rtems_id              main_task;
67  int                   count;
68  Objects_Control      *o;
69  Objects_Locations     location;
70  Objects_Id            id;
71  Objects_Information  *info;
72  Objects_Maximum       active_count;
73
74  TEST_BEGIN();
75
76  info      = &_RTEMS_tasks_Information.Objects;
77  main_task = rtems_task_self();
78
79  puts( "Init - _Objects_Get_next - NULL object information" );
80  o = _Objects_Get_next( NULL, main_task, &location, &id );
81  rtems_test_assert( o == NULL );
82
83  puts( "Init - _Objects_Get_next - NULL location" );
84  o = _Objects_Get_next( info, main_task, NULL, &id );
85  rtems_test_assert( o == NULL );
86
87  puts( "Init - _Objects_Get_next - NULL id" );
88  o = _Objects_Get_next( info, main_task, &location, NULL );
89  rtems_test_assert( o == NULL );
90
91  /* XXX push the three NULL error cases */
92
93  /* simple case of only all tasks in the system, starting at initial */
94  count = scan_objects( info, OBJECTS_ID_INITIAL_INDEX );
95  printf( "%d RTEMS Task%s\n", count, ((count == 1) ? "" : "s") );
96  rtems_test_assert( count == 1 );
97
98  /* simple case of only 1 task in the system, starting at that task */
99  count = scan_objects( info, main_task );
100  printf( "%d RTEMS Task%s\n", count, ((count == 1) ? "" : "s") );
101  rtems_test_assert( count == 1 );
102
103  /* XXX create >= 1 task and make sure the counts are correct when */
104  /* XXX you start the search at initial, first id, arbitrary id */
105
106  /* XXX try with a manager with no objects created */
107
108  puts( "Init - _Objects_Active_count" );
109  _Objects_Allocator_lock();
110  active_count = _Objects_Active_count( info );
111  _Objects_Allocator_unlock();
112  rtems_test_assert( active_count == 1 );
113
114  TEST_END();
115  rtems_test_exit( 0 );
116}
Note: See TracBrowser for help on using the repository browser.