- Timestamp:
- Jun 5, 2008 12:58:01 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp
r9264 r9418 83 83 } 84 84 85 #if 086 static int tstVDOpenCreateWriteMerge(const char *pszBackend,87 const char *pszBaseFilename,88 const char *pszDiffFilename)89 {90 int rc;91 PVBOXHDD pVD = NULL;92 char *pszFormat;93 PDMMEDIAGEOMETRY PCHS = { 0, 0, 0 };94 PDMMEDIAGEOMETRY LCHS = { 0, 0, 0 };95 96 #define CHECK(str) \97 do \98 { \99 RTPrintf("%s rc=%Vrc\n", str, rc); \100 if (VBOX_FAILURE(rc)) \101 { \102 VDCloseAll(pVD); \103 return rc; \104 } \105 } while (0)106 107 rc = VDCreate(tstVDError, NULL, &pVD);108 CHECK("VDCreate()");109 110 RTFILE File;111 rc = RTFileOpen(&File, pszBaseFilename, RTFILE_O_READ);112 if (VBOX_SUCCESS(rc))113 {114 RTFileClose(File);115 rc = VDGetFormat(pszBaseFilename, &pszFormat);116 RTPrintf("VDGetFormat() pszFormat=%s rc=%Vrc\n", pszFormat, rc);117 if (VBOX_SUCCESS(rc) && strcmp(pszFormat, pszBackend))118 {119 rc = VERR_GENERAL_FAILURE;120 RTPrintf("VDGetFormat() returned incorrect backend name\n");121 }122 RTStrFree(pszFormat);123 CHECK("VDGetFormat()");124 125 rc = VDOpen(pVD, pszBackend, pszBaseFilename, VD_OPEN_FLAGS_NORMAL);126 CHECK("VDOpen()");127 }128 else129 {130 rc = VDCreateBase(pVD, pszBackend, pszBaseFilename,131 VD_IMAGE_TYPE_NORMAL, 1000 * _1M,132 VD_IMAGE_FLAGS_NONE, "Test image",133 &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,134 NULL, NULL);135 CHECK("VDCreateBase()");136 }137 138 void *pvBuf = RTMemAlloc(_1M);139 140 memset(pvBuf, 0x33, _1M);141 rc = VDWrite(pVD, 20 * _1M + 594432, pvBuf, _1M);142 CHECK("VDWrite()");143 144 memset(pvBuf, 0x46, _1M);145 rc = VDWrite(pVD, 20 * _1M + 594432, pvBuf, _1K);146 CHECK("VDWrite()");147 148 memset(pvBuf, 0x51, _1M);149 rc = VDWrite(pVD, 40 * _1M + 594432, pvBuf, _1K);150 CHECK("VDWrite()");151 152 rc = VDCreateDiff(pVD, pszBackend, pszDiffFilename,153 VD_IMAGE_FLAGS_NONE, "Test diff image",154 VD_OPEN_FLAGS_NORMAL, NULL, NULL);155 CHECK("VDCreateDiff()");156 157 memset(pvBuf, '_', _1M);158 rc = VDWrite(pVD, 20 * _1M + 594432, pvBuf, 512);159 CHECK("VDWrite()");160 161 rc = VDWrite(pVD, 22 * _1M + 594432, pvBuf, 78336);162 CHECK("VDWrite()");163 rc = VDWrite(pVD, 13 * _1M + 594432, pvBuf, 783360);164 CHECK("VDWrite()");165 rc = VDWrite(pVD, 44 * _1M + 594432, pvBuf, 68096);166 CHECK("VDWrite()");167 168 VDDumpImages(pVD);169 170 RTPrintf("Merging diff into base..\n");171 rc = VDMerge(pVD, -1, 0, NULL, NULL);172 CHECK("VDMerge()");173 174 VDDumpImages(pVD);175 176 VDCloseAll(pVD);177 #undef CHECK178 return 0;179 }180 #else181 85 182 86 #undef RTDECL … … 408 312 pSegment[i].u32Length = RTPRandU32Ex(pCtx, 1, RT_MIN(pSegment[i+1].u64Offset - pSegment[i].u64Offset, 409 313 u32MaxSegmentSize) / u32SectorSize) * u32SectorSize; 314 Assert(pSegment[i].u32Length <= u32MaxSegmentSize); 410 315 pSegment[i].u8Value = RTPRandU32Ex(pCtx, (uint32_t)u8ValueLow, (uint32_t)u8ValueHigh); 411 316 } 412 317 } 413 318 414 static void mergeSegments(PSEGMENT pBaseSegment, PSEGMENT pDiffSegment, PSEGMENT pMergeSegment )319 static void mergeSegments(PSEGMENT pBaseSegment, PSEGMENT pDiffSegment, PSEGMENT pMergeSegment, uint32_t u32MaxLength) 415 320 { 416 321 while (pBaseSegment->u32Length > 0 || pDiffSegment->u32Length > 0) … … 424 329 { 425 330 pMergeSegment->u32Length = pDiffSegment->u64Offset - pMergeSegment->u64Offset; 331 Assert(pMergeSegment->u32Length <= u32MaxLength); 426 332 if (pBaseSegment->u64Offset + pBaseSegment->u32Length > 427 333 pDiffSegment->u64Offset + pDiffSegment->u32Length) 428 334 { 429 pBaseSegment->u32Length -= pBaseSegment->u64Offset -pDiffSegment->u64Offset - pDiffSegment->u32Length; 335 pBaseSegment->u32Length -= pDiffSegment->u64Offset + pDiffSegment->u32Length - pBaseSegment->u64Offset; 336 Assert(pBaseSegment->u32Length <= u32MaxLength); 430 337 pBaseSegment->u64Offset = pDiffSegment->u64Offset + pDiffSegment->u32Length; 431 338 } … … 448 355 { 449 356 pBaseSegment->u32Length -= pDiffSegment->u64Offset + pDiffSegment->u32Length - pBaseSegment->u64Offset; 357 Assert(pBaseSegment->u32Length <= u32MaxLength); 450 358 pBaseSegment->u64Offset = pDiffSegment->u64Offset + pDiffSegment->u32Length; 451 359 pDiffSegment++; … … 555 463 } 556 464 557 int nSegments = 10 ;465 int nSegments = 100; 558 466 /* Allocate one extra element for a sentinel. */ 559 467 PSEGMENT paBaseSegments = (PSEGMENT)RTMemAllocZ(sizeof(struct Segment) * (nSegments + 1)); … … 590 498 CHECK("VDMerge()"); 591 499 592 mergeSegments(paBaseSegments, paDiffSegments, paMergeSegments );500 mergeSegments(paBaseSegments, paDiffSegments, paMergeSegments, _1M); 593 501 /*RTPrintf("\nMerged segments:\n"); 594 502 for (pSegment = paMergeSegments; pSegment->u32Length; pSegment++) … … 607 515 return 0; 608 516 } 609 #endif 517 518 static int tstVDCreateWriteOpenRead(const char *pszBackend, 519 const char *pszFilename, 520 uint32_t u32Seed) 521 { 522 int rc; 523 PVBOXHDD pVD = NULL; 524 PDMMEDIAGEOMETRY PCHS = { 0, 0, 0 }; 525 PDMMEDIAGEOMETRY LCHS = { 0, 0, 0 }; 526 uint64_t u64DiskSize = 1000 * _1M; 527 uint32_t u32SectorSize = 512; 528 529 #define CHECK(str) \ 530 do \ 531 { \ 532 RTPrintf("%s rc=%Vrc\n", str, rc); \ 533 if (VBOX_FAILURE(rc)) \ 534 { \ 535 VDCloseAll(pVD); \ 536 return rc; \ 537 } \ 538 } while (0) 539 540 rc = VDCreate(tstVDError, NULL, &pVD); 541 CHECK("VDCreate()"); 542 543 RTFILE File; 544 rc = RTFileOpen(&File, pszFilename, RTFILE_O_READ); 545 if (VBOX_SUCCESS(rc)) 546 { 547 RTFileClose(File); 548 RTFileDelete(pszFilename); 549 } 550 551 rc = VDCreateBase(pVD, pszBackend, pszFilename, 552 VD_IMAGE_TYPE_NORMAL, u64DiskSize, 553 VD_IMAGE_FLAGS_NONE, "Test image", 554 &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL, 555 NULL, NULL); 556 CHECK("VDCreateBase()"); 557 558 int nSegments = 100; 559 /* Allocate one extra element for a sentinel. */ 560 PSEGMENT paSegments = (PSEGMENT)RTMemAllocZ(sizeof(struct Segment) * (nSegments + 1)); 561 562 void *pvBuf = RTMemAlloc(_1M); 563 564 RNDCTX ctx; 565 initializeRandomGenerator(&ctx, u32Seed); 566 generateRandomSegments(&ctx, paSegments, nSegments, _1M, u64DiskSize, u32SectorSize, 0u, 127u); 567 568 writeSegmentsToDisk(pVD, pvBuf, paSegments); 569 570 VDCloseAll(pVD); 571 572 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_NORMAL); 573 CHECK("VDOpen()"); 574 rc = readAndCompareSegments(pVD, pvBuf, paSegments); 575 CHECK("readAndCompareSegments()"); 576 577 RTMemFree(paSegments); 578 579 VDCloseAll(pVD); 580 #undef CHECK 581 return 0; 582 } 610 583 611 584 int main(int argc, char *argv[]) … … 631 604 RTFileDelete("tmpVDCreate.vdi"); 632 605 RTFileDelete("tmpVDCreate.vmdk"); 606 RTFileDelete("tmpVDCreate.vhd"); 633 607 RTFileDelete("tmpVDBase.vdi"); 634 608 RTFileDelete("tmpVDDiff.vdi"); 635 609 RTFileDelete("tmpVDBase.vmdk"); 636 610 RTFileDelete("tmpVDDiff.vmdk"); 611 RTFileDelete("tmpVDBase.vhd"); 612 RTFileDelete("tmpVDDiff.vhd"); 637 613 638 614 rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G, … … 684 660 g_cErrors++; 685 661 } 662 rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G, 663 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 664 true); 665 if (VBOX_FAILURE(rc)) 666 { 667 RTPrintf("tstVD: dynamic VHD create test failed! rc=%Vrc\n", rc); 668 g_cErrors++; 669 } 670 rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G, 671 VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE, 672 true); 673 if (VBOX_FAILURE(rc)) 674 { 675 RTPrintf("tstVD: fixed VHD create test failed! rc=%Vrc\n", rc); 676 g_cErrors++; 677 } 686 678 687 679 rc = tstVDOpenCreateWriteMerge("VDI", "tmpVDBase.vdi", "tmpVDDiff.vdi", u32Seed); … … 710 702 } 711 703 704 rc = tstVDCreateWriteOpenRead("VHD", "tmpVDCreate.vhd", u32Seed); 705 if (VBOX_FAILURE(rc)) 706 { 707 RTPrintf("tstVD: VHD test failed (creating image)! rc=%Vrc\n", rc); 708 g_cErrors++; 709 } 710 #if 0 711 rc = tstVDOpenCreateWriteMerge("VHD", "tmpVDBase.vhd", "tmpVDDiff.vhd", u32Seed); 712 if (VBOX_FAILURE(rc)) 713 { 714 RTPrintf("tstVD: VHD test failed (existing image)! rc=%Vrc\n", rc); 715 g_cErrors++; 716 } 717 #endif 712 718 /* 713 719 * Clean up any leftovers. … … 715 721 RTFileDelete("tmpVDCreate.vdi"); 716 722 RTFileDelete("tmpVDCreate.vmdk"); 723 RTFileDelete("tmpVDCreate.vhd"); 717 724 RTFileDelete("tmpVDBase.vdi"); 718 725 RTFileDelete("tmpVDDiff.vdi"); 719 726 RTFileDelete("tmpVDBase.vmdk"); 720 727 RTFileDelete("tmpVDDiff.vmdk"); 721 #if 0 722 rc = tstVDOpenCreateWriteMerge("VDI", "tmpVDBase.vdi", "tmpVDDiff.vdi", u32Seed); 723 if (VBOX_FAILURE(rc)) 724 { 725 RTPrintf("tstVD: VHD test failed (existing image)! rc=%Vrc\n", rc); 726 g_cErrors++; 727 } 728 RTFileDelete("tmpVDBase.vdi"); 729 RTFileDelete("tmpVDDiff.vdi"); 730 //RTFileDelete("tmpVDDiff.vhd"); 731 #endif 728 RTFileDelete("tmpVDBase.vhd"); 729 RTFileDelete("tmpVDDiff.vhd"); 732 730 733 731 /*
Note:
See TracChangeset
for help on using the changeset viewer.