Changeset 35663 in vbox for trunk/src/VBox/Storage/testcase
- Timestamp:
- Jan 20, 2011 9:00:56 PM (14 years ago)
- Location:
- trunk/src/VBox/Storage/testcase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/VDIoBackendMem.cpp
r35596 r35663 149 149 return VERR_NO_MEMORY; 150 150 151 Assert(cbData == sizeof(VDIOBACKENDREQ));151 Assert(cbData == (size_t)RT_OFFSETOF(VDIOBACKENDREQ, aSegs[cSegs])); 152 152 pReq->enmTxDir = enmTxDir; 153 153 pReq->cbTransfer = cbTransfer; … … 162 162 pReq->aSegs[i].cbSeg = paSegs[i].cbSeg; 163 163 } 164 RTCircBufReleaseWriteBlock(pIoBackend->pRequestRing, sizeof(VDIOBACKENDREQ));164 RTCircBufReleaseWriteBlock(pIoBackend->pRequestRing, RT_OFFSETOF(VDIOBACKENDREQ, aSegs[cSegs])); 165 165 vdIoBackendMemThreadPoke(pIoBackend); 166 166 -
trunk/src/VBox/Storage/testcase/tstVDIo.cpp
r35597 r35663 126 126 /** Number of bytes to transfer. */ 127 127 size_t cbIo; 128 /** Chance in percent to get a write. */ 128 129 unsigned uWriteChance; 130 /** Pointer to the I/O data generator. */ 129 131 PVDIORND pIoRnd; 130 uint64_t offNext; 132 /** Data dependent on the I/O mode (sequential or random). */ 133 union 134 { 135 /** Next offset for seuential access. */ 136 uint64_t offNext; 137 /** Data for random acess. */ 138 struct 139 { 140 /** Number of valid entries in the bitmap. */ 141 uint32_t cBlocks; 142 /** Pointer to the bitmap marking accessed blocks. */ 143 uint8_t *pbMapAccessed; 144 } Rnd; 145 } u; 131 146 } VDIOTEST, *PVDIOTEST; 132 147 … … 230 245 static DECLCALLBACK(int) vdScriptHandlerIoRngDestroy(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 231 246 static DECLCALLBACK(int) vdScriptHandlerSleep(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 247 static DECLCALLBACK(int) vdScriptHandlerDumpFile(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs); 232 248 233 249 /* create action */ … … 300 316 }; 301 317 318 /* Dump memory file */ 319 const VDSCRIPTARGDESC g_aArgDumpFile[] = 320 { 321 /* pcszName chId enmType fFlags */ 322 {"file", 'f', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 323 {"path", 'p', VDSCRIPTARGTYPE_STRING, VDSCRIPTARGDESC_FLAG_MANDATORY}, 324 }; 325 302 326 const VDSCRIPTACTION g_aScriptActions[] = 303 327 { … … 312 336 {"iorngdestroy", NULL, 0, vdScriptHandlerIoRngDestroy}, 313 337 {"sleep", g_aArgSleep, RT_ELEMENTS(g_aArgSleep), vdScriptHandlerSleep}, 338 {"dumpfile", g_aArgDumpFile, RT_ELEMENTS(g_aArgDumpFile), vdScriptHandlerDumpFile} 314 339 }; 315 340 … … 335 360 unsigned uWriteChance, unsigned uReadChance); 336 361 static bool tstVDIoTestRunning(PVDIOTEST pIoTest); 362 static void tstVDIoTestDestroy(PVDIOTEST pIoTest); 337 363 static bool tstVDIoTestReqOutstanding(PVDIOREQ pIoReq); 338 364 static int tstVDIoTestReqInit(PVDIOTEST pIoTest, PVDIOREQ pIoReq); … … 659 685 else 660 686 rc = VERR_NO_MEMORY; 687 688 tstVDIoTestDestroy(&IoTest); 661 689 } 662 690 } … … 816 844 } 817 845 846 static DECLCALLBACK(int) vdScriptHandlerDumpFile(PVDTESTGLOB pGlob, PVDSCRIPTARG paScriptArgs, unsigned cScriptArgs) 847 { 848 int rc = VINF_SUCCESS; 849 const char *pcszFile = NULL; 850 const char *pcszPathToDump = NULL; 851 852 for (unsigned i = 0; i < cScriptArgs; i++) 853 { 854 switch (paScriptArgs[i].chId) 855 { 856 case 'f': 857 { 858 pcszFile = paScriptArgs[i].u.pcszString; 859 break; 860 } 861 case 'p': 862 { 863 pcszPathToDump = paScriptArgs[i].u.pcszString; 864 break; 865 } 866 default: 867 AssertMsgFailed(("Invalid argument given!\n")); 868 } 869 } 870 871 /* Check for the file. */ 872 PVDFILE pIt = NULL; 873 bool fFound = false; 874 RTListForEach(&pGlob->ListFiles, pIt, VDFILE, Node) 875 { 876 if (!RTStrCmp(pIt->pszName, pcszFile)) 877 { 878 fFound = true; 879 break; 880 } 881 } 882 883 if (fFound) 884 { 885 RTPrintf("Dumping memory file %s to %s, this might take some time\n", pcszFile, pcszPathToDump); 886 rc = VDMemDiskWriteToFile(pIt->pMemDisk, pcszPathToDump); 887 } 888 else 889 rc = VERR_FILE_NOT_FOUND; 890 891 return rc; 892 } 893 818 894 static DECLCALLBACK(int) tstVDIoFileOpen(void *pvUser, const char *pszLocation, 819 895 uint32_t fOpen, … … 1091 1167 unsigned uWriteChance, unsigned uReadChance) 1092 1168 { 1169 int rc = VINF_SUCCESS; 1170 1093 1171 pIoTest->fRandomAccess = fRandomAcc; 1094 1172 pIoTest->cbIo = cbIo; … … 1098 1176 pIoTest->uWriteChance = uWriteChance; 1099 1177 pIoTest->pIoRnd = pGlob->pIoRnd; 1100 pIoTest->offNext = pIoTest->offEnd < pIoTest->offStart ? pIoTest->offEnd - cbBlkSize : 0; 1101 return VINF_SUCCESS; 1178 if (fRandomAcc) 1179 { 1180 pIoTest->u.Rnd.cBlocks = cbIo / cbBlkSize + ((cbIo % cbBlkSize) ? 1 : 0); 1181 pIoTest->u.Rnd.pbMapAccessed = (uint8_t *)RTMemAllocZ(pIoTest->u.Rnd.cBlocks / 8 1182 + ((pIoTest->u.Rnd.cBlocks % 8) 1183 ? 1 1184 : 0)); 1185 if (!pIoTest->u.Rnd.pbMapAccessed) 1186 rc = VERR_NO_MEMORY; 1187 } 1188 else 1189 pIoTest->u.offNext = pIoTest->offEnd < pIoTest->offStart ? pIoTest->offEnd - cbBlkSize : 0; 1190 1191 return rc; 1192 } 1193 1194 static void tstVDIoTestDestroy(PVDIOTEST pIoTest) 1195 { 1196 if (pIoTest->fRandomAccess) 1197 RTMemFree(pIoTest->u.Rnd.pbMapAccessed); 1102 1198 } 1103 1199 … … 1136 1232 pIoTest->cbIo -= pIoReq->cbReq; 1137 1233 pIoReq->DataSeg.cbSeg = pIoReq->cbReq; 1138 pIoReq->off = pIoTest->offNext;1139 1234 1140 1235 if (pIoReq->enmTxDir == VDIOREQTXDIR_WRITE) … … 1157 1252 if (pIoTest->fRandomAccess) 1158 1253 { 1159 /** @todo */ 1254 int idx = -1; 1255 1256 idx = ASMBitFirstClear(pIoTest->u.Rnd.pbMapAccessed, pIoTest->u.Rnd.cBlocks); 1257 1258 /* In case this is the last request we don't need to search further. */ 1259 if (pIoTest->cbIo > 0) 1260 { 1261 int idxIo; 1262 idxIo = VDIoRndGetU32Ex(pIoTest->pIoRnd, idx, pIoTest->u.Rnd.cBlocks - 1); 1263 1264 /* 1265 * If the bit is marked free use it, otherwise search for the next free bit 1266 * and if that doesn't work use the first free bit. 1267 */ 1268 if (ASMBitTest(pIoTest->u.Rnd.pbMapAccessed, idxIo)) 1269 { 1270 idxIo = ASMBitNextClear(pIoTest->u.Rnd.pbMapAccessed, pIoTest->u.Rnd.cBlocks, idxIo); 1271 if (idxIo != -1) 1272 idx = idxIo; 1273 } 1274 else 1275 idx = idxIo; 1276 } 1277 1278 Assert(idx != -1); 1279 pIoReq->off = idx * pIoTest->cbBlkIo; 1280 ASMBitSet(pIoTest->u.Rnd.pbMapAccessed, idx); 1160 1281 } 1161 1282 else 1162 1283 { 1163 pIoTest->offNext = pIoTest->offEnd < pIoTest->offStart 1164 ? RT_MAX(pIoTest->offEnd, pIoTest->offNext - pIoTest->cbBlkIo) 1165 : RT_MIN(pIoTest->offEnd, pIoTest->offNext + pIoTest->cbBlkIo); 1284 pIoReq->off = pIoTest->u.offNext; 1285 pIoTest->u.offNext = pIoTest->offEnd < pIoTest->offStart 1286 ? RT_MAX(pIoTest->offEnd, pIoTest->u.offNext - pIoTest->cbBlkIo) 1287 : RT_MIN(pIoTest->offEnd, pIoTest->u.offNext + pIoTest->cbBlkIo); 1166 1288 } 1167 1289 pIoReq->fOutstanding = true;
Note:
See TracChangeset
for help on using the changeset viewer.