Changes in tests/heap.cfa [3e91703d:58e280f4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/heap.cfa
r3e91703d r58e280f4 10 10 // Created On : Tue Nov 6 17:54:56 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 19 08:22:34201913 // Update Count : 1912 // Last Modified On : Sun Nov 24 12:34:51 2019 13 // Update Count : 28 14 14 // 15 15 … … 38 38 enum { NoOfAllocs = 5000, NoOfMmaps = 10 }; 39 39 char * locns[NoOfAllocs]; 40 int i; 40 size_t amount; 41 enum { limit = 64 * 1024 }; // check alignments up to here 41 42 42 43 // check alloc/free … … 74 75 size_t s = (i + 1) * 20; 75 76 char * area = (char *)malloc( s ); 76 if ( area == 0 ) abort( "malloc/free out of memory" );77 if ( area == 0p ) abort( "malloc/free out of memory" ); 77 78 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last 78 79 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte … … 83 84 size_t s = i + 1; // +1 to make initialization simpler 84 85 locns[i] = (char *)malloc( s ); 85 if ( locns[i] == 0 ) abort( "malloc/free out of memory" );86 if ( locns[i] == 0p ) abort( "malloc/free out of memory" ); 86 87 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 87 88 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte … … 99 100 size_t s = i + default_mmap_start(); // cross over point 100 101 char * area = (char *)malloc( s ); 101 if ( area == 0 ) abort( "malloc/free out of memory" );102 if ( area == 0p ) abort( "malloc/free out of memory" ); 102 103 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last 103 104 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte … … 108 109 size_t s = i + default_mmap_start(); // cross over point 109 110 locns[i] = (char *)malloc( s ); 110 if ( locns[i] == 0 ) abort( "malloc/free out of memory" );111 if ( locns[i] == 0p ) abort( "malloc/free out of memory" ); 111 112 locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last 112 113 locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte … … 124 125 size_t s = (i + 1) * 20; 125 126 char * area = (char *)calloc( 5, s ); 126 if ( area == 0 ) abort( "calloc/free out of memory" );127 if ( area == 0p ) abort( "calloc/free out of memory" ); 127 128 if ( area[0] != '\0' || area[s - 1] != '\0' || 128 129 area[malloc_usable_size( area ) - 1] != '\0' || … … 136 137 size_t s = i + 1; 137 138 locns[i] = (char *)calloc( 5, s ); 138 if ( locns[i] == 0 ) abort( "calloc/free out of memory" );139 if ( locns[i] == 0p ) abort( "calloc/free out of memory" ); 139 140 if ( locns[i][0] != '\0' || locns[i][s - 1] != '\0' || 140 141 locns[i][malloc_usable_size( locns[i] ) - 1] != '\0' || … … 155 156 size_t s = i + default_mmap_start(); // cross over point 156 157 char * area = (char *)calloc( 1, s ); 157 if ( area == 0 ) abort( "calloc/free out of memory" );158 if ( area == 0p ) abort( "calloc/free out of memory" ); 158 159 if ( area[0] != '\0' || area[s - 1] != '\0' ) abort( "calloc/free corrupt storage4.1" ); 159 160 if ( area[malloc_usable_size( area ) - 1] != '\0' ) abort( "calloc/free corrupt storage4.2" ); … … 167 168 size_t s = i + default_mmap_start(); // cross over point 168 169 locns[i] = (char *)calloc( 1, s ); 169 if ( locns[i] == 0 ) abort( "calloc/free out of memory" );170 if ( locns[i] == 0p ) abort( "calloc/free out of memory" ); 170 171 if ( locns[i][0] != '\0' || locns[i][s - 1] != '\0' || 171 172 locns[i][malloc_usable_size( locns[i] ) - 1] != '\0' || … … 183 184 // check memalign/free (sbrk) 184 185 185 enum { limit = 64 * 1024 }; // check alignments up to here186 187 186 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 188 187 //sout | alignments[a]; 189 188 for ( s; 1 ~ NoOfAllocs ) { // allocation of size 0 can return null 190 189 char * area = (char *)memalign( a, s ); 191 if ( area == 0 ) abort( "memalign/free out of memory" );192 //sout | i | " " |area;190 if ( area == 0p ) abort( "memalign/free out of memory" ); 191 //sout | i | area; 193 192 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 194 193 abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, s, area ); 195 194 } // if 196 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last byte195 area[0] = '\345'; area[s - 1] = '\345'; // fill first/last byte 197 196 area[malloc_usable_size( area ) - 1] = '\345'; // fill ultimate byte 198 197 free( area ); … … 207 206 size_t s = i + default_mmap_start(); // cross over point 208 207 char * area = (char *)memalign( a, s ); 209 if ( area == 0 ) abort( "memalign/free out of memory" );210 //sout | i | " " |area;208 if ( area == 0p ) abort( "memalign/free out of memory" ); 209 //sout | i | area; 211 210 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 212 211 abort( "memalign/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)s, area ); … … 223 222 // initial N byte allocation 224 223 char * area = (char *)calloc( 5, i ); 225 if ( area == 0 ) abort( "calloc/realloc/free out of memory" );224 if ( area == 0p ) abort( "calloc/realloc/free out of memory" ); 226 225 if ( area[0] != '\0' || area[i - 1] != '\0' || 227 226 area[malloc_usable_size( area ) - 1] != '\0' || … … 231 230 for ( s; i ~ 256 * 1024 ~ 26 ) { // start at initial memory request 232 231 area = (char *)realloc( area, s ); // attempt to reuse storage 233 if ( area == 0 ) abort( "calloc/realloc/free out of memory" );232 if ( area == 0p ) abort( "calloc/realloc/free out of memory" ); 234 233 if ( area[0] != '\0' || area[s - 1] != '\0' || 235 234 area[malloc_usable_size( area ) - 1] != '\0' || … … 245 244 size_t s = i + default_mmap_start(); // cross over point 246 245 char * area = (char *)calloc( 1, s ); 247 if ( area == 0 ) abort( "calloc/realloc/free out of memory" );246 if ( area == 0p ) abort( "calloc/realloc/free out of memory" ); 248 247 if ( area[0] != '\0' || area[s - 1] != '\0' || 249 248 area[malloc_usable_size( area ) - 1] != '\0' || … … 253 252 for ( r; i ~ 256 * 1024 ~ 26 ) { // start at initial memory request 254 253 area = (char *)realloc( area, r ); // attempt to reuse storage 255 if ( area == 0 ) abort( "calloc/realloc/free out of memory" );254 if ( area == 0p ) abort( "calloc/realloc/free out of memory" ); 256 255 if ( area[0] != '\0' || area[r - 1] != '\0' || 257 256 area[malloc_usable_size( area ) - 1] != '\0' || … … 263 262 // check memalign/realloc/free 264 263 265 size_tamount = 2;264 amount = 2; 266 265 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 267 266 // initial N byte allocation 268 267 char * area = (char *)memalign( a, amount ); // aligned N-byte allocation 269 if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ?270 //sout | alignments[a] | " " |area;268 if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ? 269 //sout | alignments[a] | area; 271 270 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 272 271 abort( "memalign/realloc/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)amount, area ); … … 278 277 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" ); 279 278 area = (char *)realloc( area, s ); // attempt to reuse storage 280 if ( area == 0 ) abort( "memalign/realloc/free out of memory" ); // no storage ?281 //sout | i | " " |area;279 if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ? 280 //sout | i | area; 282 281 if ( (size_t)area % a != 0 ) { // check for initial alignment 283 282 abort( "memalign/realloc/free bad alignment %p", area ); … … 294 293 for ( s; 1 ~ limit ) { // allocation of size 0 can return null 295 294 char * area = (char *)cmemalign( a, 1, s ); 296 if ( area == 0 ) abort( "cmemalign/free out of memory" );297 //sout | i | " " |area;295 if ( area == 0p ) abort( "cmemalign/free out of memory" ); 296 //sout | i | area; 298 297 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 299 298 abort( "cmemalign/free bad alignment : cmemalign(%d,%d) = %p", (int)a, s, area ); … … 313 312 // initial N byte allocation 314 313 char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation 315 if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?316 //sout | alignments[a] | " " |area;314 if ( area == 0p ) abort( "cmemalign/realloc/free out of memory" ); // no storage ? 315 //sout | alignments[a] | area; 317 316 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 318 317 abort( "cmemalign/realloc/free bad alignment : cmemalign(%d,%d) = %p", (int)a, (int)amount, area ); … … 327 326 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc/free corrupt storage2" ); 328 327 area = (char *)realloc( area, s ); // attempt to reuse storage 329 if ( area == 0 ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?330 //sout | i | " " |area;328 if ( area == 0p ) abort( "cmemalign/realloc/free out of memory" ); // no storage ? 329 //sout | i | area; 331 330 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 332 331 abort( "cmemalign/realloc/free bad alignment %p", area ); … … 339 338 free( area ); 340 339 } // for 340 341 // check memalign/realloc with align/free 342 343 amount = 2; 344 for ( a; libAlign() ~= limit ~ a ) { // generate powers of 2 345 // initial N byte allocation 346 char * area = (char *)memalign( a, amount ); // aligned N-byte allocation 347 if ( area == 0p ) abort( "memalign/realloc with align/free out of memory" ); // no storage ? 348 //sout | alignments[a] | area | endl; 349 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 350 abort( "memalign/realloc with align/free bad alignment : memalign(%d,%d) = %p", (int)a, (int)amount, area ); 351 } // if 352 area[0] = '\345'; area[amount - 2] = '\345'; // fill first/penultimate byte 353 354 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 355 for ( s; amount ~ 256 * 1024 ) { // start at initial memory request 356 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" ); 357 area = (char *)realloc( area, a * 2, s ); // attempt to reuse storage 358 if ( area == 0p ) abort( "memalign/realloc with align/free out of memory" ); // no storage ? 359 //sout | i | area | endl; 360 if ( (size_t)area % a * 2 != 0 ) { // check for initial alignment 361 abort( "memalign/realloc with align/free bad alignment %p", area ); 362 } // if 363 area[s - 1] = '\345'; // fill last byte 364 } // for 365 free( area ); 366 } // for 367 368 // check cmemalign/realloc with align/free 369 370 amount = 2; 371 for ( size_t a = libAlign() + libAlign(); a <= limit; a += a ) { // generate powers of 2 372 // initial N byte allocation 373 char *area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation 374 if ( area == 0p ) abort( "cmemalign/realloc with align/free out of memory" ); // no storage ? 375 //sout | alignments[a] | area | endl; 376 if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment 377 abort( "cmemalign/realloc with align/free bad alignment : cmemalign(%d,%d) = %p", (int)a, (int)amount, area ); 378 } // if 379 if ( area[0] != '\0' || area[amount - 1] != '\0' || 380 area[malloc_usable_size( area ) - 1] != '\0' || 381 ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc with align/free corrupt storage1" ); 382 area[0] = '\345'; area[amount - 2] = '\345'; // fill first/penultimate byte 383 384 // Do not start this loop index at 0 because realloc of 0 bytes frees the storage. 385 for ( int s = amount; s < 256 * 1024; s += 1 ) { // start at initial memory request 386 if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc with align/free corrupt storage2" ); 387 area = (char *)realloc( area, a * 2, s ); // attempt to reuse storage 388 if ( area == 0p ) abort( "cmemalign/realloc with align/free out of memory" ); // no storage ? 389 //sout | i | area | endl; 390 if ( (size_t)area % a * 2 != 0 || malloc_alignment( area ) != a * 2 ) { // check for initial alignment 391 abort( "cmemalign/realloc with align/free bad alignment %p %jd %jd", area, malloc_alignment( area ), a * 2 ); 392 } // if 393 if ( area[s - 1] != '\0' || area[s - 1] != '\0' || 394 area[malloc_usable_size( area ) - 1] != '\0' || 395 ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc/free corrupt storage3" ); 396 area[s - 1] = '\345'; // fill last byte 397 } // for 398 free( area ); 399 } // for 400 341 401 //sout | "worker" | thisTask() | "successful completion"; 342 402 } // Worker main
Note:
See TracChangeset
for help on using the changeset viewer.