Changeset 25791 in vbox
- Timestamp:
- Jan 12, 2010 10:57:57 PM (15 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp
r25748 r25791 1347 1347 { 1348 1348 pChunk->aRefs[i].fAutodidacticism = fAutodidacticism; 1349 rtLockValidatorClassRetain(pPriorClass); 1349 1350 rc = VINF_SUCCESS; 1350 1351 break; … … 1378 1379 1379 1380 ASMAtomicWritePtr((void * volatile *)&pChunk->pNext, pNew); 1381 rtLockValidatorClassRetain(pPriorClass); 1380 1382 rc = VINF_SUCCESS; 1381 1383 break; … … 3374 3376 3375 3377 ASMAtomicWriteU32(&pRec->Core.u32Magic, RTLOCKVALRECSHRD_MAGIC_DEAD); 3376 ASMAtomicUoWriteHandle(&pRec->hClass, NIL_RTLOCKVALCLASS); 3378 RTLOCKVALCLASS hClass; 3379 ASMAtomicXchgHandle(&pRec->hClass, NIL_RTLOCKVALCLASS, &hClass); 3377 3380 if (pRec->papOwners) 3378 3381 { … … 3388 3391 3389 3392 rtLockValidatorSerializeDestructLeave(); 3393 3394 if (hClass != NIL_RTLOCKVALCLASS) 3395 RTLockValidatorClassRelease(hClass); 3390 3396 } 3391 3397 -
trunk/src/VBox/Runtime/testcase/tstRTLockValidator.cpp
r25759 r25791 952 952 953 953 /* clean up */ 954 //for (int i = RT_ELEMENTS(g_ahClasses) - 1; i >= 0; i--) 954 955 for (unsigned i = 0; i < RT_ELEMENTS(g_ahClasses); i++) 955 956 { 957 uint32_t c; 956 958 if (i <= 3) 957 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); 959 RTTEST_CHECK_MSG(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == 5 - i, 960 (g_hTest, "c=%u i=%u\n", c, i)); 958 961 else 959 962 { 960 963 uint32_t cExpect = 1 + (RT_ELEMENTS(g_ahClasses) - i) * 2 - 1; 961 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == cExpect); 964 RTTEST_CHECK(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == cExpect, 965 (g_hTest, "c=%u e=%u i=%u\n", c, cExpect, i)); 962 966 } 963 967 g_ahClasses[i] = NIL_RTLOCKVALCLASS; … … 1018 1022 1019 1023 /* clean up */ 1020 for ( unsigned i = 0; i < 4; i++)1024 for (int i = 4 - 1; i >= 0; i--) 1021 1025 { 1022 1026 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); … … 1108 1112 1109 1113 /* clean up */ 1110 for (unsigned i = 0; i < 6; i++) 1111 { 1112 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 2); 1114 for (int i = 6 - 1; i >= 0; i--) 1115 { 1116 uint32_t c; 1117 RTTEST_CHECK_MSG(g_hTest, (c = RTLockValidatorClassRelease(g_ahClasses[i])) == 2, (g_hTest, "c=%u i=%u\n", c, i)); 1113 1118 g_ahClasses[i] = NIL_RTLOCKVALCLASS; 1114 1119 RTTEST_CHECK_RC_RETV(g_hTest, RTSemRWDestroy(g_ahSemRWs[i]), VINF_SUCCESS); … … 1171 1176 1172 1177 /* clean up */ 1173 for ( unsigned i = 0; i < 4; i++)1178 for (int i = 4 - 1; i >= 0; i--) 1174 1179 { 1175 1180 RTTEST_CHECK(g_hTest, RTLockValidatorClassRelease(g_ahClasses[i]) == 1); … … 1182 1187 1183 1188 1184 static bool testIsLockValidationCompiledIn(void)1189 static const char *testCheckIfLockValidationIsCompiledIn(void) 1185 1190 { 1186 1191 RTCRITSECT CritSect; 1187 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectInit(&CritSect), false);1188 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectEnter(&CritSect), false);1192 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectInit(&CritSect), ""); 1193 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectEnter(&CritSect), ""); 1189 1194 bool fRet = CritSect.pValidatorRec 1190 1195 && CritSect.pValidatorRec->hThread == RTThreadSelf(); 1191 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectLeave(&CritSect), false); 1192 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectDelete(&CritSect), false); 1193 1196 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectLeave(&CritSect), ""); 1197 RTTEST_CHECK_RC_OK_RET(g_hTest, RTCritSectDelete(&CritSect), ""); 1198 if (!fRet) 1199 return "Lock validation is not enabled for critical sections"; 1200 1201 /* deadlock detection for RTSemRW */ 1194 1202 RTSEMRW hSemRW; 1195 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreate(&hSemRW), false); 1196 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), false); 1203 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreateEx(&hSemRW, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, 1204 RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW-1"), false); 1205 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), ""); 1197 1206 int rc = RTSemRWRequestWrite(hSemRW, 1); 1207 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), ""); 1208 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), ""); 1209 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), ""); 1198 1210 if (rc != VERR_SEM_LV_ILLEGAL_UPGRADE) 1199 fRet = false; 1200 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false); 1201 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), false); 1202 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), false); 1203 1204 #if 0 /** @todo detect it on RTSemMutex... wrong locking order? */ 1205 RTSEMMUTEX hSemMtx; 1206 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreate(&hSemRW), false); 1207 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemRW, 50), false); 1208 /*??*/ 1209 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false); 1210 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRelease(hSemRW), false); 1211 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), false); 1212 #endif 1213 1211 return "Deadlock detection is not enabled for the read/write semaphores"; 1212 1213 /* lock order for RTSemRW */ 1214 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWCreateEx(&hSemRW, 0 /*fFlags*/, 1215 RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL), 1216 RTLOCKVAL_SUB_CLASS_NONE, "RTSemRW-2"), ""); 1217 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWRequestRead(hSemRW, 50), ""); 1218 rc = RTSemRWRequestWrite(hSemRW, 1); 1219 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), ""); 1220 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWReleaseRead(hSemRW), ""); 1221 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemRWDestroy(hSemRW), ""); 1222 if (rc != VERR_SEM_LV_WRONG_ORDER) 1223 { 1224 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "%Rrc\n", rc); 1225 return "Lock order validation is not enabled for the read/write semaphores"; 1226 } 1227 1228 /* lock order for RTSemMutex */ 1229 RTSEMMUTEX hSemMtx1; 1230 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreateEx(&hSemMtx1, 0 /*fFlags*/, 1231 RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL), 1232 RTLOCKVAL_SUB_CLASS_NONE, "RTSemMtx-1"), ""); 1233 RTSEMMUTEX hSemMtx2; 1234 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexCreateEx(&hSemMtx2, 0 /*fFlags*/, 1235 RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL), 1236 RTLOCKVAL_SUB_CLASS_NONE, "RTSemMtx-2"), ""); 1237 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx1, 50), ""); 1238 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx2, 50), ""); 1239 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx2), ""); 1240 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx1), ""); 1241 1242 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRequest(hSemMtx2, 50), ""); 1243 rc = RTSemMutexRequest(hSemMtx1, 50); 1244 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), ""); 1245 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexRelease(hSemMtx2), ""); 1246 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexDestroy(hSemMtx2), ""); hSemMtx2 = NIL_RTSEMMUTEX; 1247 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemMutexDestroy(hSemMtx1), ""); hSemMtx1 = NIL_RTSEMMUTEX; 1248 if (rc != VERR_SEM_LV_WRONG_ORDER) 1249 return "Lock order validation is not enabled for the mutex semaphores"; 1250 1251 /* signaller checks on event sems. */ 1214 1252 RTSEMEVENT hSemEvt; 1215 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventCreate(&hSemEvt), false);1253 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventCreate(&hSemEvt), ""); 1216 1254 RTSemEventSetSignaller(hSemEvt, RTThreadSelf()); 1217 1255 RTSemEventSetSignaller(hSemEvt, NIL_RTTHREAD); 1218 1256 rc = RTSemEventSignal(hSemEvt); 1257 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), ""); 1258 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventDestroy(hSemEvt), ""); 1219 1259 if (rc != VERR_SEM_LV_NOT_SIGNALLER) 1220 fRet = false; 1221 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false); 1222 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventDestroy(hSemEvt), false); 1223 1260 return "Signalling checks are not enabled for the event semaphores"; 1261 1262 /* signaller checks on multiple release event sems. */ 1224 1263 RTSEMEVENTMULTI hSemEvtMulti; 1225 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiCreate(&hSemEvtMulti), false);1264 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiCreate(&hSemEvtMulti), ""); 1226 1265 RTSemEventMultiSetSignaller(hSemEvtMulti, RTThreadSelf()); 1227 1266 RTSemEventMultiSetSignaller(hSemEvtMulti, NIL_RTTHREAD); 1228 1267 rc = RTSemEventMultiSignal(hSemEvtMulti); 1268 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), ""); 1269 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiDestroy(hSemEvtMulti), ""); 1229 1270 if (rc != VERR_SEM_LV_NOT_SIGNALLER) 1230 fRet = false; 1231 RTTEST_CHECK_RET(g_hTest, RT_FAILURE_NP(rc), false); 1232 RTTEST_CHECK_RC_OK_RET(g_hTest, RTSemEventMultiDestroy(hSemEvtMulti), false); 1233 1234 return fRet; 1271 return "Signalling checks are not enabled for the multiple release event semaphores"; 1272 1273 /* we're good */ 1274 return NULL; 1235 1275 } 1236 1276 … … 1249 1289 RTLockValidatorSetMayPanic(false); 1250 1290 RTLockValidatorSetQuiet(true); 1251 if (!testIsLockValidationCompiledIn()) 1291 const char *pszWhyDisabled = testCheckIfLockValidationIsCompiledIn(); 1292 if (pszWhyDisabled) 1252 1293 return RTTestErrorCount(g_hTest) > 0 1253 1294 ? RTTestSummaryAndDestroy(g_hTest) 1254 : RTTestSkipAndDestroy(g_hTest, "deadlock detection is not compiled in");1295 : RTTestSkipAndDestroy(g_hTest, pszWhyDisabled); 1255 1296 RTLockValidatorSetQuiet(false); 1256 1297
Note:
See TracChangeset
for help on using the changeset viewer.