Changeset 80228a7
- Timestamp:
- Nov 8, 2018, 9:00:59 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 1e995d6
- Parents:
- 303d866
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/heap.cfa
r303d866 r80228a7 10 10 // Created On : Tue Nov 6 17:54:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Nov 6 17:55:39201813 // Update Count : 212 // Last Modified On : Thu Nov 8 09:03:54 2018 13 // Update Count : 17 14 14 // 15 15 16 16 #include <thread.hfa> 17 #include <kernel.hfa> 18 #include <stdlib.hfa> 17 #include <kernel.hfa> // processor 18 #include <stdlib.hfa> // *allocs 19 19 #include <malloc.h> // malloc_* 20 20 … … 37 37 void main( Worker & ) { 38 38 enum { NoOfAllocs = 5000, NoOfMmaps = 10 }; 39 char * locns[NoOfAllocs];39 char * locns[NoOfAllocs]; 40 40 int i; 41 41 42 42 // check alloc/free 43 43 44 for ( int j = 0; j < 40; j += 1) {45 for ( i = 0; i < NoOfAllocs; i += 1) {44 for ( j; 40 ) { 45 for ( i; NoOfAllocs ) { 46 46 locns[i] = alloc( i ); 47 47 //sout | (void *)locns[i] | endl; 48 for ( int k = 0; k < i; k += 1) locns[i][k] = '\345';48 for ( k; i ) locns[i][k] = '\345'; 49 49 } // for 50 50 //sout | (char *)sbrk(0) - start | " bytes" | endl; 51 51 52 for ( i = 0; i < NoOfAllocs; i += 1) {52 for ( i; NoOfAllocs ) { 53 53 //sout | (void *)locns[i] | endl; 54 for ( int k = 0; k < i; k += 1) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" );54 for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage1" ); 55 55 free( locns[i] ); 56 56 } // for 57 57 //sout | (char *)sbrk(0) - start | " bytes" | endl; 58 58 59 for ( i = 0; i < NoOfAllocs; i += 1) {59 for ( i; NoOfAllocs ) { 60 60 locns[i] = alloc( i ); 61 61 //sout | (void *)locns[i] | endl; 62 for ( int k = 0; k < i; k += 1) locns[i][k] = '\345';63 } // for 64 for ( i = NoOfAllocs - 1; i >=0 ; i -= 1) {62 for ( k; i ) locns[i][k] = '\345'; 63 } // for 64 for ( i; NoOfAllocs - 1 -~= 0 ) { 65 65 //sout | (void *)locns[i] | endl; 66 for ( int k = 0; k < i; k += 1) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" );66 for ( k; i ) if ( locns[i][k] != '\345' ) abort( "new/delete corrupt storage2" ); 67 67 free( locns[i] ); 68 68 } // for … … 71 71 // check malloc/free (sbrk) 72 72 73 for ( i = 0; i < NoOfAllocs; i += 1) {73 for ( i; NoOfAllocs ) { 74 74 size_t s = (i + 1) * 20; 75 char * area = (char *)malloc( s );75 char * area = (char *)malloc( s ); 76 76 if ( area == 0 ) abort( "malloc/free out of memory" ); 77 77 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last … … 80 80 } // for 81 81 82 for ( i = 0; i < NoOfAllocs; i += 1) {83 size_t s = i + 1; // +1 to make initialization simpler82 for ( i; NoOfAllocs ) { 83 size_t s = i + 1; // +1 to make initialization simpler 84 84 locns[i] = (char *)malloc( s ); 85 85 if ( locns[i] == 0 ) abort( "malloc/free out of memory" ); … … 87 87 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 88 88 } // for 89 for ( i = 0; i < NoOfAllocs; i += 1) {89 for ( i; NoOfAllocs ) { 90 90 size_t s = i + 1; 91 91 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || … … 96 96 // check malloc/free (mmap) 97 97 98 for ( i = 0; i < NoOfMmaps; i += 1) {99 size_t s = i + default_mmap_start(); 100 char * area = (char *)malloc( s );98 for ( i; NoOfMmaps ) { 99 size_t s = i + default_mmap_start(); // cross over point 100 char * area = (char *)malloc( s ); 101 101 if ( area == 0 ) abort( "malloc/free out of memory" ); 102 102 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last … … 105 105 } // for 106 106 107 for ( i = 0; i < NoOfMmaps; i += 1) {108 size_t s = i + default_mmap_start(); 107 for ( i; NoOfMmaps ) { 108 size_t s = i + default_mmap_start(); // cross over point 109 109 locns[i] = (char *)malloc( s ); 110 110 if ( locns[i] == 0 ) abort( "malloc/free out of memory" ); … … 112 112 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 113 113 } // for 114 for ( i = 0; i < NoOfMmaps; i += 1) {115 size_t s = i + default_mmap_start(); 114 for ( i; NoOfMmaps ) { 115 size_t s = i + default_mmap_start(); // cross over point 116 116 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 117 117 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "malloc/free corrupt storage" ); … … 121 121 // check calloc/free (sbrk) 122 122 123 for ( i = 0; i < NoOfAllocs; i += 1) {123 for ( i; NoOfAllocs ) { 124 124 size_t s = (i + 1) * 20; 125 char * area = (char *)calloc( 5, s );125 char * area = (char *)calloc( 5, s ); 126 126 if ( area == 0 ) abort( "calloc/free out of memory" ); 127 127 if ( area[0] != '\0' || area[s - 1] != '\0' || … … 133 133 } // for 134 134 135 for ( i = 0; i < NoOfAllocs; i += 1) {135 for ( i; NoOfAllocs ) { 136 136 size_t s = i + 1; 137 137 locns[i] = (char *)calloc( 5, s ); … … 143 143 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 144 144 } // for 145 for ( i = 0; i < NoOfAllocs; i += 1) {145 for ( i; NoOfAllocs ) { 146 146 size_t s = i + 1; 147 147 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || … … 152 152 // check calloc/free (mmap) 153 153 154 for ( i = 0; i < NoOfMmaps; i += 1) {155 size_t s = i + default_mmap_start(); 156 char * area = (char *)calloc( 1, s );154 for ( i; NoOfMmaps ) { 155 size_t s = i + default_mmap_start(); // cross over point 156 char * area = (char *)calloc( 1, s ); 157 157 if ( area == 0 ) abort( "calloc/free out of memory" ); 158 158 if ( area[0] != '\0' || area[s - 1] != '\0' ) abort( "calloc/free corrupt storage4.1" ); … … 164 164 } // for 165 165 166 for ( i = 0; i < NoOfMmaps; i += 1) {167 size_t s = i + default_mmap_start(); 166 for ( i; NoOfMmaps ) { 167 size_t s = i + default_mmap_start(); // cross over point 168 168 locns[i] = (char *)calloc( 1, s ); 169 169 if ( locns[i] == 0 ) abort( "calloc/free out of memory" ); … … 174 174 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte 175 175 } // for 176 for ( i = 0; i < NoOfMmaps; i += 1) {177 size_t s = i + default_mmap_start(); 176 for ( i; NoOfMmaps ) { 177 size_t s = i + default_mmap_start(); // cross over point 178 178 if ( locns[i][0] != '\345' || locns[i][s - 1] != '\345' || 179 179 locns[i][malloc_usable_size( locns[i] ) - 1] != '\345' ) abort( "calloc/free corrupt storage6" ); … … 185 185 enum { limit = 64 * 1024 }; // check alignments up to here 186 186 187 for ( size_t a = libAlign(); a <= limit; a += a ) {// generate powers of 2187 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 188 188 //sout | alignments[a] | endl; 189 for ( int s = 1; s < NoOfAllocs; s += 1 ) {// allocation of size 0 can return null190 char * area = (char *)memalign( a, s );189 for ( s; 1 ~ NoOfAllocs ) { // allocation of size 0 can return null 190 char * area = (char *)memalign( a, s ); 191 191 if ( area == 0 ) abort( "memalign/free out of memory" ); 192 192 //sout | i | " " | area | endl; … … 202 202 // check memalign/free (mmap) 203 203 204 for ( size_t a = libAlign(); a <= limit; a += a ) {// generate powers of 2204 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 205 205 //sout | alignments[a] | endl; 206 for ( i = 1; i < NoOfMmaps; i += 1) {207 size_t s = i + default_mmap_start(); 208 char * area = (char *)memalign( a, s );206 for ( i; 1 ~ NoOfMmaps ) { 207 size_t s = i + default_mmap_start(); // cross over point 208 char * area = (char *)memalign( a, s ); 209 209 if ( area == 0 ) abort( "memalign/free out of memory" ); 210 210 //sout | i | " " | area | endl; … … 220 220 // check calloc/realloc/free (sbrk) 221 221 222 for ( i = 1; i < 10000; i +=12 ) {222 for ( i; 1 ~ 10_000 ~ 12 ) { 223 223 // initial N byte allocation 224 char * area = (char *)calloc( 5, i );224 char * area = (char *)calloc( 5, i ); 225 225 if ( area == 0 ) abort( "calloc/realloc/free out of memory" ); 226 226 if ( area[0] != '\0' || area[i - 1] != '\0' || … … 229 229 230 230 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 231 for ( int s = i; s < 256 * 1024; s += 26 ) {// start at initial memory request231 for ( s; i ~ 256 * 1024 ~ 26 ) { // start at initial memory request 232 232 area = (char *)realloc( area, s ); // attempt to reuse storage 233 233 if ( area == 0 ) abort( "calloc/realloc/free out of memory" ); … … 241 241 // check calloc/realloc/free (mmap) 242 242 243 for ( i = 1; i < 1000; i +=12 ) {243 for ( i; 1 ~ 10_000 ~ 12 ) { 244 244 // initial N byte allocation 245 size_t s = i + default_mmap_start(); 246 char * area = (char *)calloc( 1, s );245 size_t s = i + default_mmap_start(); // cross over point 246 char * area = (char *)calloc( 1, s ); 247 247 if ( area == 0 ) abort( "calloc/realloc/free out of memory" ); 248 248 if ( area[0] != '\0' || area[s - 1] != '\0' || … … 251 251 252 252 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 253 for ( int r = i; r < 256 * 1024; r += 26 ) {// start at initial memory request254 area = (char *)realloc( area, r ); // attempt to reuse storage253 for ( r; i ~ 256 * 1024 ~ 26 ) { // start at initial memory request 254 area = (char *)realloc( area, r ); // attempt to reuse storage 255 255 if ( area == 0 ) abort( "calloc/realloc/free out of memory" ); 256 256 if ( area[0] != '\0' || area[r - 1] != '\0' || … … 264 264 265 265 size_t amount = 2; 266 for ( size_t a = libAlign(); a <= limit; a += a ) {// generate powers of 2266 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 267 267 // initial N byte allocation 268 char * area = (char *)memalign( a, amount );// aligned N-byte allocation268 char * area = (char *)memalign( a, amount ); // aligned N-byte allocation 269 269 if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ? 270 270 //sout | alignments[a] | " " | area | endl; … … 275 275 276 276 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 277 for ( int s = amount; s < 256 * 1024; s += 1 ) {// start at initial memory request277 for ( s; amount ~ 256 * 1024 ) { // start at initial memory request 278 278 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" ); 279 279 area = (char *)realloc( area, s ); // attempt to reuse storage … … 290 290 // check cmemalign/free 291 291 292 for ( size_t a = libAlign(); a <= limit; a += a ) {// generate powers of 2292 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 293 293 //sout | alignments[a] | endl; 294 for ( int s = 1; s < limit; s += 1 ) {// allocation of size 0 can return null295 char * area = (char *)cmemalign( a, 1, s );294 for ( s; 1 ~ limit ) { // allocation of size 0 can return null 295 char * area = (char *)cmemalign( a, 1, s ); 296 296 if ( area == 0 ) abort( "cmemalign/free out of memory" ); 297 297 //sout | i | " " | area | endl; … … 310 310 311 311 amount = 2; 312 for ( size_t a = libAlign() + libAlign(); a <= limit; a += a ) {// generate powers of 2312 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 313 313 // initial N byte allocation 314 char * area = (char *)cmemalign( a, 1, amount );// aligned N-byte allocation314 char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation 315 315 if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ? 316 316 //sout | alignments[a] | " " | area | endl; … … 324 324 325 325 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 326 for ( int s = amount; s < 256 * 1024; s += 1 ) {// start at initial memory request326 for ( s; amount ~ 256 * 1024 ) { // start at initial memory request 327 327 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc/free corrupt storage2" ); 328 328 area = (char *)realloc( area, s ); // attempt to reuse storage
Note: See TracChangeset
for help on using the changeset viewer.