Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:48

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Exercise SuperCore Object Get Next
0005  *
0006  *  COPYRIGHT (c) 1989-2009.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034 
0035 #define CONFIGURE_INIT
0036 #include "system.h"
0037 
0038 #include <rtems/rtems/tasksimpl.h>
0039 
0040 const char rtems_test_name[] = "SPOBJGETNEXT";
0041 
0042 /* prototypes */
0043 int scan_objects(
0044   Objects_Information *information,
0045   Objects_Id           start
0046 );
0047 
0048 #define MAX_SCAN 10
0049 
0050 int scan_objects(
0051   Objects_Information *information,
0052   Objects_Id           start
0053 )
0054 {
0055   Objects_Control  *o[MAX_SCAN];
0056   int               i;
0057   Objects_Id        id;
0058 
0059   memset( o, 1, sizeof(o) );
0060 
0061   id = start;
0062   for (i=0 ; i<MAX_SCAN ; i++ ) {
0063     o[i] = _Objects_Get_next(
0064       id,
0065       information,
0066       &id
0067     );
0068     if ( !o[i] )
0069       break;
0070     /* XXX check dispatch level with macros */
0071 
0072     /* XXX should be able to check that next Id is not one we have seen */
0073   }
0074   return i;
0075 }
0076 
0077 rtems_task Init(
0078   rtems_task_argument argument
0079 )
0080 {
0081   rtems_id              main_task;
0082   int                   count;
0083   Objects_Control      *o;
0084   Objects_Id            id;
0085   Objects_Information  *info;
0086   Objects_Maximum       active_count;
0087 
0088   TEST_BEGIN();
0089 
0090   info      = &_RTEMS_tasks_Information.Objects;
0091   main_task = rtems_task_self();
0092 
0093   puts( "Init - _Objects_Get_next - NULL object information" );
0094   o = _Objects_Get_next( main_task, NULL, &id );
0095   rtems_test_assert( o == NULL );
0096   rtems_test_assert( o == NULL );
0097 
0098   puts( "Init - _Objects_Get_next - NULL id" );
0099   o = _Objects_Get_next( main_task, info, NULL );
0100   rtems_test_assert( o == NULL );
0101 
0102   /* XXX push the three NULL error cases */
0103 
0104   /* simple case of only all tasks in the system, starting at initial */
0105   count = scan_objects( info, OBJECTS_ID_INITIAL_INDEX );
0106   printf( "%d RTEMS Task%s\n", count, ((count == 1) ? "" : "s") );
0107   rtems_test_assert( count == 1 );
0108 
0109   /* simple case of only 1 task in the system, starting at that task */
0110   count = scan_objects( info, main_task );
0111   printf( "%d RTEMS Task%s\n", count, ((count == 1) ? "" : "s") );
0112   rtems_test_assert( count == 1 );
0113 
0114   /* XXX create >= 1 task and make sure the counts are correct when */
0115   /* XXX you start the search at initial, first id, arbitrary id */
0116 
0117   /* XXX try with a manager with no objects created */
0118 
0119   puts( "Init - _Objects_Active_count" );
0120   _Objects_Allocator_lock();
0121   active_count = _Objects_Active_count( info );
0122   _Objects_Allocator_unlock();
0123   rtems_test_assert( active_count == 1 );
0124 
0125   TEST_END();
0126   rtems_test_exit( 0 );
0127 }