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 <tmacros.h>
0034 
0035 #include <rtems/score/heapimpl.h>
0036 
0037 const char rtems_test_name[] = "SP 63";
0038 
0039 /* forward declarations to avoid warnings */
0040 rtems_task Init(rtems_task_argument argument);
0041 void test_case_one(void);
0042 void test_case_two(void);
0043 void test_case_three(void);
0044 
0045 uint32_t      Memory[256];
0046 Heap_Control  Heap;
0047 
0048 /*
0049  *  Exercise case in heapresize.c around line 125 when new_block_size
0050  *  < min_block_size
0051  */
0052 void test_case_one(void)
0053 {
0054   uint32_t           heap_size;
0055   void              *ptr1;
0056   uintptr_t          old;
0057   uintptr_t          avail;
0058   Heap_Resize_status hc;
0059 
0060   puts( "Init - _Heap_Initialize (for test one) - OK" );
0061   heap_size = _Heap_Initialize( &Heap, Memory, sizeof(Memory), 8 );
0062   printf( "Init - Heap size=%" PRIu32 "\n", heap_size );
0063   rtems_test_assert( heap_size );
0064 
0065   puts( "Init - _Heap_Allocate - too large size (overflow)- not OK");
0066   ptr1 = _Heap_Allocate( &Heap, UINTPTR_MAX );
0067   rtems_test_assert( !ptr1 );
0068 
0069   puts( "Init - _Heap_Allocate_aligned - OK");
0070   ptr1 = _Heap_Allocate_aligned( &Heap, 64, 32 );
0071   rtems_test_assert( ptr1 );
0072 
0073   puts( "Init - _Heap_Resize_block - OK");
0074   hc = _Heap_Resize_block( &Heap, ptr1, 4, &old, &avail );
0075   rtems_test_assert( !hc );
0076 }
0077 
0078 /*
0079  *  Exercise case in heapresize.c around line 140 when next_is_used AND
0080  *  free_block_size < min_block_size.
0081  */
0082 void test_case_two(void)
0083 {
0084   uint32_t           heap_size;
0085   void              *ptr1;
0086   uintptr_t          old;
0087   uintptr_t          avail;
0088   Heap_Resize_status hc;
0089 
0090   puts( "\nInit - _Heap_Initialize (for test two) - OK" );
0091   heap_size = _Heap_Initialize( &Heap, Memory, sizeof(Memory), 8 );
0092   printf( "Init - Heap size=%" PRIu32 "\n", heap_size );
0093   rtems_test_assert( heap_size );
0094 
0095   puts( "Init - _Heap_Allocate_aligned - OK");
0096   ptr1 = _Heap_Allocate_aligned( &Heap, 64, 4 );
0097   rtems_test_assert( ptr1 );
0098 
0099   puts( "Init - _Heap_Resize_block - OK");
0100   hc = _Heap_Resize_block( &Heap, ptr1, 56, &old, &avail );
0101   rtems_test_assert( !hc );
0102 }
0103 
0104 /*
0105  *  Exercise case in heapallocatealigned.c around line 223 when ...
0106  */
0107 void test_case_three(void)
0108 {
0109   uint32_t           heap_size;
0110   void              *ptr1;
0111 #if 0
0112   Heap_Resize_status hc;
0113 #endif
0114   int pg, al, alloc, sz;
0115 
0116   puts( "Init - _Heap_Allocate_aligned - request impossible - not OK");
0117 
0118 #if 0
0119   heap_size =
0120      _Heap_Initialize( &Heap, Memory[32], sizeof(Memory), 1 << 16 );
0121   ptr1 = _Heap_Allocate_aligned( &Heap, 4, 1 << 16 );
0122   ptr1 = _Heap_Allocate_aligned( &Heap, 256, 1 << 16 );
0123 #endif
0124 #if 1
0125   for ( sz=32 ; sz <= 80 ; sz+=4 ) {
0126     for ( pg=2 ; pg < 12 ; pg++ ) {
0127 
0128       for ( al=16 ; al >=4 ; al-- ) {
0129         for ( alloc=4 ; alloc < sizeof(Memory)/2  ; alloc+=4 ) {
0130           heap_size =
0131             _Heap_Initialize( &Heap, &Memory[sz], sizeof(Memory)/2, 1 << pg );
0132           if ( heap_size != 0 ) {
0133             do {
0134               ptr1 = _Heap_Allocate_aligned( &Heap, alloc, 1 <<al );
0135             } while ( ptr1 );
0136           }
0137         }
0138       }
0139    }
0140  }
0141 #endif
0142 }
0143 
0144 rtems_task Init(
0145   rtems_task_argument ignored
0146 )
0147 {
0148   TEST_BEGIN();
0149 
0150   test_case_one();
0151 
0152   test_case_two();
0153 
0154   test_case_three();
0155 
0156   TEST_END();
0157 
0158   rtems_test_exit(0);
0159 }
0160 
0161 /* configuration information */
0162 
0163 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0164 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0165 
0166 #define CONFIGURE_MAXIMUM_TASKS         1
0167 #define CONFIGURE_MAXIMUM_REGIONS       1
0168 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0169 
0170 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0171 
0172 #define CONFIGURE_INIT
0173 #include <rtems/confdefs.h>
0174 
0175 /* global variables */