- Timestamp:
- Jan 25, 2007 5:14:15 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 17834
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstHeapSimple.cpp
r283 r288 68 68 } aOps[] = 69 69 { 70 { 16, 0, NULL, 0 }, 70 { 16, 0, NULL, 0 }, // 0 71 71 { 16, 4, NULL, 1 }, 72 72 { 16, 8, NULL, 2 }, 73 73 { 16, 16, NULL, 5 }, 74 74 { 16, 32, NULL, 4 }, 75 { 32, 0, NULL, 3 }, 75 { 32, 0, NULL, 3 }, // 5 76 76 { 31, 0, NULL, 6 }, 77 77 { 1024, 0, NULL, 8 }, 78 78 { 1024, 32, NULL, 10 }, 79 79 { 1024, 32, NULL, 12 }, 80 { PAGE_SIZE, PAGE_SIZE, NULL, 13 }, 80 { PAGE_SIZE, PAGE_SIZE, NULL, 13 }, // 10 81 81 { 1024, 32, NULL, 9 }, 82 82 { PAGE_SIZE, 32, NULL, 11 }, 83 83 { PAGE_SIZE, PAGE_SIZE, NULL, 14 }, 84 84 { 16, 0, NULL, 15 }, 85 { 9, 0, NULL, 7 }, 85 { 9, 0, NULL, 7 }, // 15 86 86 { 16, 0, NULL, 7 }, 87 87 { 36, 0, NULL, 7 }, 88 88 { 16, 0, NULL, 7 }, 89 89 { 12344, 0, NULL, 7 }, 90 { 50, 0, NULL, 7 }, 90 { 50, 0, NULL, 7 }, // 20 91 91 { 16, 0, NULL, 7 }, 92 92 }; 93 93 unsigned i; 94 #ifdef DEBUG 95 RTHeapSimpleDump(Heap); 96 #endif 97 // size_t cbBefore = RTHeapSimpleGetFreeSize(Heap); 98 size_t cbBefore = 0; 94 RTHeapSimpleDump(Heap, (PFNRTHEAPSIMPLEPRINTF)RTPrintf); 95 size_t cbBefore = RTHeapSimpleGetFreeSize(Heap); 99 96 static char szFill[] = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 100 97 … … 119 116 for (i = 0; i < ELEMENTS(aOps); i++) 120 117 { 121 if ( !aOps[i].pvAlloc 122 || aOps[i].uAlignment == PAGE_SIZE) 118 if (!aOps[i].pvAlloc) 123 119 continue; 124 //size_t cbBeforeSub = RTHeapSimpleGetFreeSize(Heap); 120 //RTPrintf("debug: i=%d pv=%#x cb=%#zx align=%#zx cbReal=%#zx\n", i, aOps[i].pvAlloc, 121 // aOps[i].cb, aOps[i].uAlignment, RTHeapSimpleSize(Heap, aOps[i].pvAlloc)); 122 size_t cbBeforeSub = RTHeapSimpleGetFreeSize(Heap); 125 123 RTHeapSimpleFree(Heap, aOps[i].pvAlloc); 124 size_t cbAfterSubFree = RTHeapSimpleGetFreeSize(Heap); 126 125 127 //RTPrintf("debug: i=%d cbBeforeSub=%d now=%d\n", i, cbBeforeSub, RTHeapSimpleGetFreeSize(Heap));128 126 void *pv; 129 127 pv = RTHeapSimpleAlloc(Heap, aOps[i].cb, aOps[i].uAlignment); 130 if ( pv)128 if (!pv) 131 129 { 132 130 RTPrintf("Failure: RTHeapSimpleAlloc(%p, %#x, %#x,) -> NULL i=%d\n", (void *)Heap, aOps[i].cb, aOps[i].uAlignment, i); 133 131 return 1; 134 132 } 133 //RTPrintf("debug: i=%d pv=%p cbReal=%#zx cbBeforeSub=%#zx cbAfterSubFree=%#zx cbAfterSubAlloc=%#zx \n", i, pv, RTHeapSimpleSize(Heap, pv), 134 // cbBeforeSub, cbAfterSubFree, RTHeapSimpleGetFreeSize(Heap)); 135 135 if (pv != aOps[i].pvAlloc) 136 RTPrintf("Warning: Free+Alloc returned different address. new=%p old=%p i=%d\n", pv, aOps[i].pvAlloc, i); 137 aOps[i].pvAlloc = pv; 138 size_t cbAfterSubAlloc = RTHeapSimpleGetFreeSize(Heap); 139 if (cbBeforeSub != cbAfterSubAlloc) 136 140 { 137 RTPrintf("Failure: Free+Alloc returned different address. new=%p old=%p i=%d (doesn't work with delayed free)\n", pv, aOps[i].pvAlloc, i); 138 //return 1; 141 RTPrintf("Warning: cbBeforeSub=%#zx cbAfterSubFree=%#zx cbAfterSubAlloc=%#zx. i=%d\n", 142 cbBeforeSub, cbAfterSubFree, cbAfterSubAlloc, i); 143 //return 1; - won't work correctly until we start creating free block instead of donating memory on alignment. 139 144 } 140 aOps[i].pvAlloc = pv;141 #if 0 /* won't work :/ */142 size_t cbAfterSub = RTHeapSimpleGetFreeSize(Heap);143 if (cbBeforeSub != cbAfterSub)144 {145 RTPrintf("Failure: cbBeforeSub=%d cbAfterSub=%d. i=%d\n", cbBeforeSub, cbAfterSub, i);146 return 1;147 }148 #endif149 145 } 150 146 … … 160 156 continue; 161 157 //RTPrintf("j=%d i=%d free=%d cb=%d pv=%p\n", j, i, RTHeapSimpleGetFreeSize(Heap), aOps[j].cb, aOps[j].pvAlloc); 162 if (aOps[j].uAlignment == PAGE_SIZE) 163 cbBefore -= aOps[j].cb; 164 else 165 RTHeapSimpleFree(Heap, aOps[j].pvAlloc); 158 RTHeapSimpleFree(Heap, aOps[j].pvAlloc); 166 159 aOps[j].pvAlloc = NULL; 167 160 cFreed++; … … 169 162 } 170 163 Assert(cFreed == RT_ELEMENTS(aOps)); 171 //RTPrintf("i=done free=%d\n", RTHeapSimpleGetFreeSize(Heap));164 RTPrintf("i=done free=%d\n", RTHeapSimpleGetFreeSize(Heap)); 172 165 173 #if 0174 166 /* check that we're back at the right amount of free memory. */ 175 //size_t cbAfter = RTHeapSimpleGetFreeSize(Heap);167 size_t cbAfter = RTHeapSimpleGetFreeSize(Heap); 176 168 if (cbBefore != cbAfter) 177 169 { 178 170 RTPrintf("Warning: Either we've split out an alignment chunk at the start, or we've got\n" 179 171 " an alloc/free accounting bug: cbBefore=%d cbAfter=%d\n", cbBefore, cbAfter); 180 #ifdef DEBUG 181 RTHeapSimpleDump(Heap); 182 #endif 172 RTHeapSimpleDump(Heap, (PFNRTHEAPSIMPLEPRINTF)RTPrintf); 183 173 } 184 #endif185 174 186 175 RTPrintf("tstHeapSimple: Success\n");
Note:
See TracChangeset
for help on using the changeset viewer.