Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <rtems/libcsupport.h>
0034 
0035 #include "tmacros.h"
0036 
0037 const char rtems_test_name[] = "SP 64";
0038 
0039 /* forward declarations to avoid warnings */
0040 rtems_task Init(rtems_task_argument argument);
0041 
0042 uint32_t Area1[50] CPU_STRUCTURE_ALIGNMENT;
0043 uint32_t Area2[50] CPU_STRUCTURE_ALIGNMENT;
0044 
0045 rtems_task Init(
0046   rtems_task_argument ignored
0047 )
0048 {
0049   rtems_id                region1;
0050   rtems_id                region2;
0051   rtems_status_code       sc;
0052   bool                    ok;
0053   uintptr_t               to_alloc;
0054   void                   *alloced;
0055   rtems_resource_snapshot snapshot;
0056   void                   *greedy;
0057 
0058   TEST_BEGIN();
0059 
0060   puts( "Allocate one region -- so second auto extends" );
0061   sc = rtems_region_create(
0062     rtems_build_name( 'R', 'N', '1', ' ' ),
0063     Area1,
0064     sizeof(Area1),
0065     8,
0066     RTEMS_DEFAULT_ATTRIBUTES,
0067     &region1
0068   );
0069   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0070 
0071   greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc );
0072   rtems_resource_snapshot_take( &snapshot );
0073 
0074   puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" );
0075   while ( to_alloc > 8 ) {
0076     ok = rtems_workspace_allocate( to_alloc, &alloced );
0077     rtems_test_assert( ok );
0078 
0079     sc = rtems_region_create(
0080       rtems_build_name( 'R', 'N', '2', ' ' ),
0081       Area2,
0082       sizeof(Area2),
0083       8,
0084       RTEMS_DEFAULT_ATTRIBUTES,
0085       &region2
0086     );
0087 
0088     rtems_workspace_free( alloced );
0089 
0090     if ( sc == RTEMS_SUCCESSFUL )
0091       break;
0092 
0093     rtems_test_assert( sc == RTEMS_TOO_MANY );
0094 
0095     /*
0096      * Verify heap is still in same shape if we couldn't allocate a region
0097      */
0098     ok = rtems_resource_snapshot_check( &snapshot );
0099     rtems_test_assert( ok );
0100 
0101     to_alloc -= 8;
0102   }
0103 
0104   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0105 
0106   /*
0107    * Verify heap is still in same shape after we free the region
0108    */
0109   puts( "Init - rtems_region_delete - OK" );
0110   sc = rtems_region_delete( region2 );
0111   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0112 
0113   puts( "Init - verify workspace has same memory" );
0114   ok = rtems_resource_snapshot_check( &snapshot );
0115   rtems_test_assert( ok );
0116   rtems_workspace_greedy_free( greedy );
0117 
0118   TEST_END();
0119   rtems_test_exit(0);
0120 }
0121 
0122 /* configuration information */
0123 
0124 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0125 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0126 
0127 #define CONFIGURE_MAXIMUM_TASKS         1
0128 #define CONFIGURE_MAXIMUM_REGIONS       rtems_resource_unlimited( 2 )
0129 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0130 
0131 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0132 
0133 #define CONFIGURE_MEMORY_OVERHEAD 1
0134 
0135 #define CONFIGURE_INIT
0136 #include <rtems/confdefs.h>
0137 
0138 /* global variables */