Changeset 13268 in vbox for trunk/src/VBox/Devices/Storage/testcase
- Timestamp:
- Oct 14, 2008 3:15:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp
r11444 r13268 22 22 #include <VBox/err.h> 23 23 #include <VBox/VBoxHDD-new.h> 24 #include <iprt/dir.h> 24 25 #include <iprt/string.h> 25 26 #include <iprt/stream.h> … … 91 92 92 93 VDClose(pVD, fDelete); 94 if (fDelete) 95 { 96 RTFILE File; 97 rc = RTFileOpen(&File, pszFilename, RTFILE_O_READ); 98 if (VBOX_SUCCESS(rc)) 99 { 100 RTFileClose(File); 101 return VERR_INTERNAL_ERROR; 102 } 103 } 104 105 #undef CHECK 106 return 0; 107 } 108 109 static int tstVDOpenDelete(const char *pszBackend, const char *pszFilename) 110 { 111 int rc; 112 PVBOXHDD pVD = NULL; 113 PDMMEDIAGEOMETRY PCHS = { 0, 0, 0 }; 114 PDMMEDIAGEOMETRY LCHS = { 0, 0, 0 }; 115 PVDINTERFACE pVDIfs = NULL; 116 VDINTERFACE VDIError; 117 VDINTERFACEERROR VDIErrorCallbacks; 118 119 #define CHECK(str) \ 120 do \ 121 { \ 122 RTPrintf("%s rc=%Vrc\n", str, rc); \ 123 if (VBOX_FAILURE(rc)) \ 124 { \ 125 VDCloseAll(pVD); \ 126 return rc; \ 127 } \ 128 } while (0) 129 130 /* Create error interface. */ 131 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 132 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 133 VDIErrorCallbacks.pfnError = tstVDError; 134 135 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks, 136 NULL, &pVDIfs); 137 AssertRC(rc); 138 139 rc = VDCreate(&VDIError, &pVD); 140 CHECK("VDCreate()"); 141 142 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 143 CHECK("VDOpen()"); 144 145 VDDumpImages(pVD); 146 147 VDClose(pVD, true); 148 RTFILE File; 149 rc = RTFileOpen(&File, pszFilename, RTFILE_O_READ); 150 if (VBOX_SUCCESS(rc)) 151 { 152 RTFileClose(File); 153 return VERR_INTERNAL_ERROR; 154 } 155 93 156 #undef CHECK 94 157 return 0; … … 623 686 } 624 687 688 static int tstVmdkRename(const char *src, const char *dst) 689 { 690 int rc; 691 PVBOXHDD pVD = NULL; 692 PVDINTERFACE pVDIfs = NULL; 693 VDINTERFACE VDIError; 694 VDINTERFACEERROR VDIErrorCallbacks; 695 696 #define CHECK(str) \ 697 do \ 698 { \ 699 RTPrintf("%s rc=%Vrc\n", str, rc); \ 700 if (VBOX_FAILURE(rc)) \ 701 { \ 702 VDCloseAll(pVD); \ 703 return rc; \ 704 } \ 705 } while (0) 706 707 /* Create error interface. */ 708 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 709 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 710 VDIErrorCallbacks.pfnError = tstVDError; 711 712 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks, 713 NULL, &pVDIfs); 714 AssertRC(rc); 715 716 rc = VDCreate(&VDIError, &pVD); 717 CHECK("VDCreate()"); 718 719 rc = VDOpen(pVD, "VMDK", src, VD_OPEN_FLAGS_NORMAL, NULL); 720 CHECK("VDOpen()"); 721 rc = VDCopy(pVD, 0, pVD, "VMDK", dst, true, 0, NULL, NULL, NULL); 722 CHECK("VDCopy()"); 723 724 VDCloseAll(pVD); 725 #undef CHECK 726 return 0; 727 } 728 729 static int tstVmdkCreateRenameOpen(const char *src, const char *dst, 730 uint64_t cbSize, VDIMAGETYPE enmType, 731 unsigned uFlags) 732 { 733 int rc = tstVDCreateDelete("VMDK", src, cbSize, enmType, uFlags, false); 734 if (VBOX_FAILURE(rc)) 735 return rc; 736 737 rc = tstVmdkRename(src, dst); 738 if (VBOX_FAILURE(rc)) 739 return rc; 740 741 PVBOXHDD pVD = NULL; 742 PVDINTERFACE pVDIfs = NULL; 743 VDINTERFACE VDIError; 744 VDINTERFACEERROR VDIErrorCallbacks; 745 746 #define CHECK(str) \ 747 do \ 748 { \ 749 RTPrintf("%s rc=%Vrc\n", str, rc); \ 750 if (VBOX_FAILURE(rc)) \ 751 { \ 752 VDCloseAll(pVD); \ 753 return rc; \ 754 } \ 755 } while (0) 756 757 /* Create error interface. */ 758 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 759 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 760 VDIErrorCallbacks.pfnError = tstVDError; 761 762 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks, 763 NULL, &pVDIfs); 764 AssertRC(rc); 765 766 rc = VDCreate(&VDIError, &pVD); 767 CHECK("VDCreate()"); 768 769 rc = VDOpen(pVD, "VMDK", dst, VD_OPEN_FLAGS_NORMAL, NULL); 770 CHECK("VDOpen()"); 771 772 VDClose(pVD, true); 773 CHECK("VDClose()"); 774 VDDestroy(pVD); 775 #undef CHECK 776 return rc; 777 } 778 779 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) 780 #define DST_PATH "tmp\\tmpVDRename.vmdk" 781 #else 782 #define DST_PATH "tmp/tmpVDRename.vmdk" 783 #endif 784 785 static void tstVmdk() 786 { 787 int rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", "tmpVDRename.vmdk", _4G, 788 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE); 789 if (VBOX_FAILURE(rc)) 790 { 791 RTPrintf("tstVD: VMDK rename (single extent, embedded descriptor, same dir) test failed! rc=%Vrc\n", rc); 792 g_cErrors++; 793 } 794 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", "tmpVDRename.vmdk", _4G, 795 VD_IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 796 if (VBOX_FAILURE(rc)) 797 { 798 RTPrintf("tstVD: VMDK rename (multiple extent, separate descriptor, same dir) test failed! rc=%Vrc\n", rc); 799 g_cErrors++; 800 } 801 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 802 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE); 803 if (VBOX_FAILURE(rc)) 804 { 805 RTPrintf("tstVD: VMDK rename (single extent, embedded descriptor, another dir) test failed! rc=%Vrc\n", rc); 806 g_cErrors++; 807 } 808 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 809 VD_IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 810 if (VBOX_FAILURE(rc)) 811 { 812 RTPrintf("tstVD: VMDK rename (multiple extent, separate descriptor, another dir) test failed! rc=%Vrc\n", rc); 813 g_cErrors++; 814 } 815 816 RTFILE File; 817 rc = RTFileOpen(&File, DST_PATH, RTFILE_O_CREATE | RTFILE_O_WRITE); 818 if (VBOX_SUCCESS(rc)) 819 RTFileClose(File); 820 821 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 822 VD_IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 823 if (VBOX_SUCCESS(rc)) 824 { 825 RTPrintf("tstVD: VMDK rename (multiple extent, separate descriptor, another dir, already exists) test failed!\n"); 826 g_cErrors++; 827 } 828 RTFileDelete(DST_PATH); 829 RTFileDelete("tmpVDCreate.vmdk"); 830 RTFileDelete("tmpVDCreate-s001.vmdk"); 831 RTFileDelete("tmpVDCreate-s002.vmdk"); 832 RTFileDelete("tmpVDCreate-s003.vmdk"); 833 } 625 834 626 835 int main(int argc, char *argv[]) … … 653 862 RTFileDelete("tmpVDBase.vhd"); 654 863 RTFileDelete("tmpVDDiff.vhd"); 864 RTFileDelete("tmpVDCreate-s001.vmdk"); 865 RTFileDelete("tmpVDCreate-s002.vmdk"); 866 RTFileDelete("tmpVDCreate-s003.vmdk"); 867 RTFileDelete("tmpVDRename.vmdk"); 868 RTFileDelete("tmpVDRename-s001.vmdk"); 869 RTFileDelete("tmpVDRename-s002.vmdk"); 870 RTFileDelete("tmpVDRename-s003.vmdk"); 871 RTFileDelete("tmp/tmpVDRename.vmdk"); 872 RTFileDelete("tmp/tmpVDRename-s001.vmdk"); 873 RTFileDelete("tmp/tmpVDRename-s002.vmdk"); 874 RTFileDelete("tmp/tmpVDRename-s003.vmdk"); 875 876 if (!RTDirExists("tmp")) 877 { 878 rc = RTDirCreate("tmp", RTFS_UNIX_IRWXU); 879 if (VBOX_FAILURE(rc)) 880 { 881 RTPrintf("tstVD: Failed to create 'tmp' directory! rc=%Vrc\n", rc); 882 g_cErrors++; 883 } 884 } 885 886 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 887 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 888 true); 889 if (VBOX_FAILURE(rc)) 890 { 891 RTPrintf("tstVD: dynamic VMDK create test failed! rc=%Vrc\n", rc); 892 g_cErrors++; 893 } 894 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 895 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 896 false); 897 if (VBOX_FAILURE(rc)) 898 { 899 RTPrintf("tstVD: dynamic VMDK create test failed! rc=%Vrc\n", rc); 900 g_cErrors++; 901 } 902 rc = tstVDOpenDelete("VMDK", "tmpVDCreate.vmdk"); 903 if (VBOX_FAILURE(rc)) 904 { 905 RTPrintf("tstVD: VMDK delete test failed! rc=%Vrc\n", rc); 906 g_cErrors++; 907 } 908 #if 1 909 tstVmdk(); 910 #endif 655 911 #if 1 656 912 rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G, … … 670 926 g_cErrors++; 671 927 } 928 #endif 672 929 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 673 930 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, … … 702 959 g_cErrors++; 703 960 } 961 #if 1 704 962 rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G, 705 963 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, … … 743 1001 g_cErrors++; 744 1002 } 1003 1004 rc = tstVDCreateWriteOpenRead("VHD", "tmpVDCreate.vhd", u32Seed); 1005 if (VBOX_FAILURE(rc)) 1006 { 1007 RTPrintf("tstVD: VHD test failed (creating image)! rc=%Vrc\n", rc); 1008 g_cErrors++; 1009 } 1010 1011 rc = tstVDOpenCreateWriteMerge("VHD", "tmpVDBase.vhd", "tmpVDDiff.vhd", u32Seed); 1012 if (VBOX_FAILURE(rc)) 1013 { 1014 RTPrintf("tstVD: VHD test failed (existing image)! rc=%Vrc\n", rc); 1015 g_cErrors++; 1016 } 745 1017 #endif 746 747 rc = tstVDCreateWriteOpenRead("VHD", "tmpVDCreate.vhd", u32Seed);748 if (VBOX_FAILURE(rc))749 {750 RTPrintf("tstVD: VHD test failed (creating image)! rc=%Vrc\n", rc);751 g_cErrors++;752 }753 754 rc = tstVDOpenCreateWriteMerge("VHD", "tmpVDBase.vhd", "tmpVDDiff.vhd", u32Seed);755 if (VBOX_FAILURE(rc))756 {757 RTPrintf("tstVD: VHD test failed (existing image)! rc=%Vrc\n", rc);758 g_cErrors++;759 }760 1018 761 1019 /* … … 771 1029 RTFileDelete("tmpVDBase.vhd"); 772 1030 RTFileDelete("tmpVDDiff.vhd"); 1031 RTFileDelete("tmpVDCreate-s001.vmdk"); 1032 RTFileDelete("tmpVDCreate-s002.vmdk"); 1033 RTFileDelete("tmpVDCreate-s003.vmdk"); 1034 RTFileDelete("tmpVDRename.vmdk"); 1035 RTFileDelete("tmpVDRename-s001.vmdk"); 1036 RTFileDelete("tmpVDRename-s002.vmdk"); 1037 RTFileDelete("tmpVDRename-s003.vmdk"); 773 1038 774 1039 /*
Note:
See TracChangeset
for help on using the changeset viewer.