Changeset c2b3243 for tests/alloc2.cfa
- Timestamp:
- Oct 18, 2022, 9:13:33 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 9511841
- Parents:
- 5408b59 (diff), ce7d197 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/alloc2.cfa
r5408b59 rc2b3243 1 #include <fstream.hfa> // sout 1 2 #include <malloc.h> // malloc_usable_size 2 3 #include <stdint.h> // uintptr_t … … 4 5 #include <string.h> // memcmp 5 6 6 int last_failed;7 7 int tests_total; 8 8 int tests_failed; … … 13 13 void test_base( void * ip, size_t size, size_t align ) { 14 14 tests_total += 1; 15 // printf( "DEBUG: starting test %d\n", tests_total);15 // sout | "DEBUG: starting test" | tests_total; 16 16 bool passed = (malloc_size( ip ) == size) && (malloc_usable_size( ip ) >= size) && (malloc_alignment( ip ) == align) && ((uintptr_t)ip % align == 0); 17 17 if ( ! passed ) { 18 printf( "failed test %3d: %4zu %4zu but got %4zu ( %3zu ) %4zu\n", tests_total, size, align, malloc_size( ip ), malloc_usable_size( ip ), malloc_alignment( ip ));18 sout | "base failed test" | tests_total | "ip" | ip | "size" | size | "align" | align | "but got size" | malloc_size( ip ) | "usable" | malloc_usable_size( ip ) | "align" | malloc_alignment( ip ); 19 19 tests_failed += 1; 20 20 } // if 21 // printf( "DEBUG: done test %d\n", tests_total);21 // sout | "DEBUG: done test" | tests_total; 22 22 } 23 23 24 24 void test_fill( void * ip_, size_t start, size_t end, char fill ) { 25 25 tests_total += 1; 26 // printf( "DEBUG: starting test %d\n", tests_total );26 // sout | "DEBUG: starting test" | tests_total; 27 27 bool passed = true; 28 28 char * ip = (char *) ip_; 29 29 for ( i; start ~ end ) passed = passed && (ip[i] == fill); 30 30 if ( ! passed ) { 31 printf( "failed test %3d: fill C\n", tests_total );31 sout | "fill1 failed test" | tests_total | "fill C"; 32 32 tests_failed += 1; 33 33 } // if 34 // printf( "DEBUG: done test %d\n", tests_total );34 // sout | "DEBUG: done test" | tests_total; 35 35 } 36 36 37 37 void test_fill( void * ip_, size_t start, size_t end, int fill ) { 38 38 tests_total += 1; 39 // printf( "DEBUG: starting test %d\n", tests_total );39 // sout | "DEBUG: starting test" tests_total; 40 40 bool passed = true; 41 41 int * ip = (int *)ip_; 42 for ( i; start ~ end ) passed = passed && (ip[i] == fill);42 for ( i; start ~ end ) passed = passed && (ip[i] == fill); 43 43 if ( ! passed ) { 44 printf( "failed test %3d: fill int\n", tests_total );44 sout | "fill2 failed test" | tests_total | "fill int"; 45 45 tests_failed += 1; 46 46 } // if 47 // printf( "DEBUG: done test %d\n", tests_total );47 // sout | "DEBUG: done test" | tests_total; 48 48 } 49 49 50 50 void test_fill( void * ip_, size_t start, size_t end, int * fill ) { 51 51 tests_total += 1; 52 // printf( "DEBUG: starting test %d\n", tests_total );52 // sout | "DEBUG: starting test" | tests_total; 53 53 bool passed = memcmp((void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0; 54 54 if ( ! passed ) { 55 printf( "failed test %3d: fill int A\n", tests_total );55 sout | "fill3 failed test" | tests_total | "fill int A"; 56 56 tests_failed += 1; 57 57 } // if 58 // printf( "DEBUG: done test %d\n", tests_total );58 // sout | "DEBUG: done test" | tests_total; 59 59 } 60 60 61 61 void test_fill( void * ip_, size_t start, size_t end, T1 fill ) { 62 62 tests_total += 1; 63 // printf( "DEBUG: starting test %d\n", tests_total );63 // sout | "DEBUG: starting test" | tests_total; 64 64 bool passed = true; 65 65 T1 * ip = (T1 *) ip_; 66 66 for ( i; start ~ end ) passed = passed && (ip[i].data == fill.data ); 67 67 if ( ! passed ) { 68 printf( "failed test %3d: fill T1\n", tests_total );68 sout | "fill4 failed test" | tests_total | "fill T1"; 69 69 tests_failed += 1; 70 70 } // if 71 // printf( "DEBUG: done test %d\n", tests_total );71 // sout | "DEBUG: done test" | tests_total; 72 72 } 73 73 74 74 void test_fill( void * ip_, size_t start, size_t end, T1 * fill ) { 75 75 tests_total += 1; 76 // printf( "DEBUG: starting test %d\n", tests_total );76 // sout | "DEBUG: starting test" | tests_total; 77 77 bool passed = memcmp( (void*)((uintptr_t )ip_ + start ), (void*)fill, end ) == 0; 78 78 if ( ! passed ) { 79 printf( "failed test %3d: fill T1 A\n", tests_total );79 sout | "fill5 failed test" | tests_total | "fill T1 A"; 80 80 tests_failed += 1; 81 81 } // if 82 // printf( "DEBUG: done test %d\n", tests_total );82 // sout | "DEBUG: done test" | tests_total; 83 83 } 84 84 85 85 void test_use( int * ip, size_t dim ) { 86 86 tests_total += 1; 87 // printf( "DEBUG: starting test %d\n", tests_total );87 // sout | "DEBUG: starting test" | tests_total; 88 88 bool passed = true; 89 89 for ( i; 0 ~ dim ) ip[i] = 0xdeadbeef; 90 90 for ( i; 0 ~ dim ) passed = passed && (ip[i] == 0xdeadbeef); 91 91 if ( ! passed ) { 92 printf( "failed test %3d: use int\n", tests_total );92 sout | "use1 failed test" | tests_total | "use int"; 93 93 tests_failed += 1; 94 94 } // if 95 // printf( "DEBUG: done test %d\n", tests_total );95 // sout | "DEBUG: done test" | tests_total; 96 96 } 97 97 98 98 void test_use( T1 * ip, size_t dim ) { 99 99 tests_total += 1; 100 // printf( "DEBUG: starting test %d\n", tests_total );100 // sout | "DEBUG: starting test" | tests_total; 101 101 bool passed = true; 102 102 for ( i; 0 ~ dim ) ip[i].data = 0xdeadbeef; 103 103 for ( i; 0 ~ dim ) passed = passed && (ip[i].data == 0xdeadbeef); 104 104 if ( ! passed ) { 105 printf( "failed test %3d: use T1\n", tests_total );105 sout | "use2 failed test" | tests_total | "use T1"; 106 106 tests_failed += 1; 107 107 } // if 108 // printf( "DEBUG: done test %d\n", tests_total );108 // sout | "DEBUG: done test" | tests_total; 109 109 } 110 110 … … 117 117 char FillC = 'a'; 118 118 int * FillA = calloc( dim / 4 ); 119 119 120 T1 FillT1 = { FillT }; 120 121 T1 * FillT1A = (T1 *)(void *) malloc( (dim / 4) * sizeof(T1) ); … … 129 130 // testing alloc 130 131 131 last_failed = -1;132 132 tests_total = 0; 133 133 tests_failed = 0; … … 153 153 free( ip ); 154 154 155 ip = alloc( ((double *)0p)`resize );155 ip = alloc( 0p`resize ); 156 156 test_base( ip, elemSize, libAlign ); 157 157 test_use( ip, elemSize / elemSize ); … … 495 495 free( ip ); 496 496 497 if ( tests_failed == 0 ) printf( "PASSED alloc tests\n\n" );498 else printf( "failed alloc tests : %d/%d\n\n", tests_failed, tests_total );499 500 // testing alloc ( aligned struct)497 if ( tests_failed == 0 ) sout | "PASSED alloc tests" | nl | nl; 498 else sout | "failed alloc tests :" | tests_failed | tests_total | nl | nl; 499 500 // testing alloc (aligned struct) 501 501 502 502 elemSize = sizeof(T1); 503 503 size = dim * elemSize; 504 last_failed = -1;505 504 tests_total = 0; 506 505 tests_failed = 0; … … 868 867 free( t1p ); 869 868 870 if ( tests_failed == 0) printf( "PASSED alloc tests (aligned struct)\n\n");871 else printf( "failed alloc tests ( aligned struct ) : %d/%d\n\n", tests_failed, tests_total );872 873 printf( "(if applicable) alignment error below indicates memory trashing caused by test_use.\n\n");869 if ( tests_failed == 0) sout | "PASSED alloc tests (aligned struct)" | nl | nl; 870 else sout | "failed alloc tests ( aligned struct ) :" | tests_failed | tests_total | nl; 871 872 sout | "(if applicable) alignment error below indicates memory trashing caused by test_use." | nl | nl; 874 873 free( FillA ); 875 874 free( FillT1A );
Note:
See TracChangeset
for help on using the changeset viewer.