File indexing completed on 2025-05-11 08:24:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
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
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
0050
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
0080
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
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
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