儲存庫 vbox 的更動 18367
- 時間撮記:
- 2009-3-27 上午03:19:09 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/testcase/tstBitOperations.cpp
r18365 r18367 41 41 42 42 43 /* 44 * Test 2 - ID allocation using a bitmap. 45 */ 46 47 #define NIL_TEST2_ID 0 48 #define TEST2_ID_LAST (RT_BIT_32(28) - 1 >> 8) 49 50 struct TestMap2 51 { 52 uint32_t idNil; 53 uint32_t idLast; 54 uint32_t idChunkPrev; 55 uint32_t bmChunkId[(TEST2_ID_LAST + 1 + 31) / 32]; 56 }; 57 58 static uint32_t test2AllocId(struct TestMap2 *p2) 59 { 60 /* 61 * Scan sequentially from the last one + 1. 62 */ 63 int32_t idChunk = ++p2->idChunkPrev; 64 if ( (uint32_t)idChunk < TEST2_ID_LAST 65 && idChunk > NIL_TEST2_ID) 66 { 67 idChunk = ASMBitNextClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1, idChunk); 68 if (idChunk > NIL_TEST2_ID) 69 { 70 if (ASMAtomicBitTestAndSet(&p2->bmChunkId[0], idChunk)) 71 { 72 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk); 73 return NIL_TEST2_ID; 74 } 75 return p2->idChunkPrev = idChunk; 76 } 77 } 78 79 /* 80 * Ok, scan from the start. 81 */ 82 idChunk = ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1); 83 if (idChunk <= NIL_TEST2_ID) 84 { 85 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk); 86 return NIL_TEST2_ID; 87 } 88 if (ASMAtomicBitTestAndSet(&p2->bmChunkId[0], idChunk)) 89 { 90 RTTestFailed(NIL_RTTEST, "line %d: idChunk=%#x", __LINE__, idChunk); 91 return NIL_TEST2_ID; 92 } 93 94 return p2->idChunkPrev = idChunk; 95 } 96 97 98 static void test2(RTTEST hTest) 99 { 100 struct TestMap2 *p2 = (struct TestMap2 *)RTTestGuardedAllocTail(hTest, sizeof(TestMap2)); 101 p2->idNil = NIL_TEST2_ID; 102 p2->idLast = TEST2_ID_LAST; 103 104 /* Some simple tests first. */ 105 memset(&p2->bmChunkId[0], 0, sizeof(p2->bmChunkId)); 106 RTTEST_CHECK(hTest, ASMBitFirstSet(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1); 107 for (uint32_t iBit = 0; iBit <= TEST2_ID_LAST; iBit++) 108 RTTEST_CHECK(hTest, !ASMBitTest(&p2->bmChunkId[0], iBit)); 109 110 memset(&p2->bmChunkId[0], 0xff, sizeof(p2->bmChunkId)); 111 RTTEST_CHECK(hTest, ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1); 112 for (uint32_t iBit = 0; iBit <= TEST2_ID_LAST; iBit++) 113 RTTEST_CHECK(hTest, ASMBitTest(&p2->bmChunkId[0], iBit)); 114 115 /* The real test. */ 116 p2->idChunkPrev = 0; 117 memset(&p2->bmChunkId[0], 0, sizeof(p2->bmChunkId)); 118 ASMBitSet(p2->bmChunkId, NIL_TEST2_ID); 119 uint32_t cLeft = TEST2_ID_LAST; 120 while (cLeft-- > 0) 121 test2AllocId(p2); 122 123 RTTEST_CHECK(hTest, ASMBitFirstClear(&p2->bmChunkId[0], TEST2_ID_LAST + 1) == -1); 124 } 125 126 43 127 int main() 44 128 { … … 318 402 319 403 /* 404 * Special tests. 405 */ 406 test2(hTest); 407 408 /* 320 409 * Summary 321 410 */ 322 411 return RTTestSummaryAndDestroy(hTest); 323 412 } 413
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器