Changeset 31488 in vbox for trunk/src/VBox/Devices/Storage/testcase
- Timestamp:
- Aug 9, 2010 3:56:27 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 64573
- Location:
- trunk/src/VBox/Devices/Storage/testcase
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/Makefile.kmk
r31193 r31488 49 49 # 50 50 ifdef VBOX_WITH_TESTCASES 51 PROGRAMS += tstVD tstVD-2 tstVDCopy tstVDSnap tstVDShareable 51 PROGRAMS += tstVD tstVD-2 tstVDCopy tstVDSnap tstVDShareable tstVDSetUuid 52 52 ifeq ($(KBUILD_TARGET),l4) 53 53 tstVD_TEMPLATE = VBOXLNXHOSTR3EXE … … 56 56 tstVDSnap_TEMPLATE = VBOXLNXHOSTR3EXE 57 57 tstVDShareable_TEMPLATE = VBOXLNXHOSTR3EXE 58 tstVDSetUuid_TEMPLATE = VBOXLNXHOSTR3EXE 58 59 else 59 60 tstVD_TEMPLATE = VBOXR3TSTEXE … … 62 63 tstVDSnap_TEMPLATE = VBOXR3TSTEXE 63 64 tstVDShareable_TEMPLATE = VBOXR3TSTEXE 65 tstVDSetUuid_TEMPLATE = VBOXR3TSTEXE 64 66 endif 65 67 tstVD_LIBS = $(LIB_DDU) $(LIB_RUNTIME) … … 68 70 tstVDSnap_LIBS = $(LIB_DDU) $(LIB_RUNTIME) 69 71 tstVDShareable_LIBS = $(LIB_DDU) $(LIB_RUNTIME) 72 tstVDSetUuid_LIBS = $(LIB_DDU) $(LIB_RUNTIME) 70 73 tstVD_SOURCES = tstVD.cpp 71 74 tstVD-2_SOURCES = tstVD-2.cpp … … 73 76 tstVDSnap_SOURCES = tstVDSnap.cpp 74 77 tstVDShareable_SOURCES = tstVDShareable.cpp 78 tstVDSetUuid_SOURCES = tstVDSetUuid.cpp 75 79 endif 76 80 -
trunk/src/VBox/Devices/Storage/testcase/tstVDSetUuid.cpp
r31475 r31488 1 1 /* $Id$ */ 2 2 /** @file 3 * Simple VBox HDD container test utility for shareableimages.3 * Simple VBox HDD container test utility for changing the uuid of images. 4 4 */ 5 5 … … 21 21 #include <VBox/VBoxHDD.h> 22 22 #include <VBox/err.h> 23 #include < VBox/log.h>24 #include <iprt/ asm-amd64-x86.h>25 #include <iprt/ dir.h>23 #include <iprt/initterm.h> 24 #include <iprt/buildconfig.h> 25 #include <iprt/path.h> 26 26 #include <iprt/string.h> 27 #include <iprt/uuid.h> 27 28 #include <iprt/stream.h> 28 #include <iprt/file.h> 29 #include <iprt/mem.h> 30 #include <iprt/initterm.h> 31 #include <iprt/rand.h> 32 #include "stdio.h" 33 #include "stdlib.h" 34 35 #define VHD_TEST 36 #define VDI_TEST 37 #define VMDK_TEST 38 39 /******************************************************************************* 40 * Global Variables * 41 *******************************************************************************/ 42 /** The error count. */ 43 unsigned g_cErrors = 0; 44 45 46 static void tstVDError(void *pvUser, int rc, RT_SRC_POS_DECL, 47 const char *pszFormat, va_list va) 48 { 49 g_cErrors++; 50 RTPrintf("tstVD: Error %Rrc at %s:%u (%s): ", rc, RT_SRC_POS_ARGS); 51 RTPrintfV(pszFormat, va); 52 RTPrintf("\n"); 53 } 54 55 static int tstVDMessage(void *pvUser, const char *pszFormat, ...) 56 { 57 va_list va; 58 59 RTPrintf("tstVD: "); 60 va_start(va, pszFormat); 61 RTPrintfV(pszFormat, va); 62 va_end(va); 29 #include <iprt/message.h> 30 #include <iprt/getopt.h> 31 32 const char *g_pszProgName = ""; 33 34 static const RTGETOPTDEF s_aOptions[] = 35 { 36 { "--filename", 'f', RTGETOPT_REQ_STRING }, 37 { "--format", 'o', RTGETOPT_REQ_STRING }, 38 { "--uuid", 'u', RTGETOPT_REQ_UUID }, 39 { "--parentuuid", 'p', RTGETOPT_REQ_UUID }, 40 { "--zeroparentuuid", 'P', RTGETOPT_REQ_NOTHING } 41 }; 42 43 static void showUsage(void) 44 { 45 RTStrmPrintf(g_pStdErr, 46 "Usage: %s\n" 47 " --filename <filename>\n" 48 " [--format VDI|VMDK|VHD|...]\n" 49 " [--uuid <uuid>]\n" 50 " [--parentuuid <uuid>]\n" 51 " [--zeroparentuuid]\n", 52 g_pszProgName); 53 } 54 55 static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, 56 const char *pszFormat, va_list va) 57 { 58 NOREF(pvUser); 59 NOREF(rc); 60 RTMsgErrorV(pszFormat, va); 61 } 62 63 static int handleVDMessage(void *pvUser, const char *pszFormat, ...) 64 { 65 NOREF(pvUser); 66 va_list args; 67 va_start(args, pszFormat); 68 RTMsgWarningV(pszFormat, args); 69 va_end(args); 63 70 return VINF_SUCCESS; 64 }65 66 static int tstVDCreateShareDelete(const char *pszBackend, const char *pszFilename,67 uint64_t cbSize, unsigned uFlags)68 {69 int rc;70 PVBOXHDD pVD = NULL, pVD2 = NULL;71 PDMMEDIAGEOMETRY PCHS = { 0, 0, 0 };72 PDMMEDIAGEOMETRY LCHS = { 0, 0, 0 };73 PVDINTERFACE pVDIfs = NULL;74 VDINTERFACE VDIError;75 VDINTERFACEERROR VDIErrorCallbacks;76 77 #define CHECK(str) \78 do \79 { \80 RTPrintf("%s rc=%Rrc\n", str, rc); \81 if (RT_FAILURE(rc)) \82 { \83 VDDestroy(pVD); \84 return rc; \85 } \86 } while (0)87 88 /* Create error interface. */89 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);90 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;91 VDIErrorCallbacks.pfnError = tstVDError;92 VDIErrorCallbacks.pfnMessage = tstVDMessage;93 94 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks,95 NULL, &pVDIfs);96 AssertRC(rc);97 98 rc = VDCreate(&VDIError, &pVD);99 CHECK("VDCreate()");100 rc = VDCreate(&VDIError, &pVD2);101 CHECK("VDCreate() #2");102 103 rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize,104 uFlags, "Test image", &PCHS, &LCHS, NULL,105 VD_OPEN_FLAGS_NORMAL, NULL, NULL);106 CHECK("VDCreateBase()");107 108 VDClose(pVD, false);109 110 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);111 CHECK("VDOpen()");112 rc = VDOpen(pVD2, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);113 CHECK("VDOpen() #2");114 if (VDIsReadOnly(pVD2))115 rc = VERR_VD_IMAGE_READ_ONLY;116 117 VDClose(pVD2, false);118 VDClose(pVD, true);119 120 VDDestroy(pVD);121 VDDestroy(pVD2);122 #undef CHECK123 return 0;124 71 } 125 72 … … 128 75 RTR3Init(); 129 76 int rc; 130 131 RTPrintf("tstVD: TESTING...\n"); 132 133 /* 134 * Clean up potential leftovers from previous unsuccessful runs. 135 */ 136 RTFileDelete("tmpVDCreate.vdi"); 137 138 if (!RTDirExists("tmp")) 139 { 140 rc = RTDirCreate("tmp", RTFS_UNIX_IRWXU); 77 const char *pszFilename = NULL; 78 char *pszFormat = NULL; 79 RTUUID imageUuid; 80 RTUUID parentUuid; 81 bool fSetImageUuid = false; 82 bool fSetParentUuid = false; 83 84 g_pszProgName = RTPathFilename(argv[0]); 85 86 RTUuidClear(&imageUuid); 87 RTUuidClear(&parentUuid); 88 89 /* Parse the command line. */ 90 int ch; 91 RTGETOPTUNION ValueUnion; 92 RTGETOPTSTATE GetState; 93 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0 /* fFlags */); 94 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 95 { 96 switch (ch) 97 { 98 case 'f': // --filename 99 pszFilename = ValueUnion.psz; 100 break; 101 case 'o': // --format 102 pszFormat = RTStrDup(ValueUnion.psz); 103 break; 104 case 'u': // --uuid 105 imageUuid = ValueUnion.Uuid; 106 fSetImageUuid = true; 107 break; 108 case 'p': // --parentuuid 109 parentUuid = ValueUnion.Uuid; 110 fSetParentUuid = true; 111 break; 112 case 'P': // --zeroparentuuid 113 RTUuidClear(&parentUuid); 114 fSetParentUuid = true; 115 break; 116 case 'h': // --help 117 showUsage(); 118 return 0; 119 case 'V': // --version 120 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr()); 121 return 0; 122 default: 123 ch = RTGetOptPrintError(ch, &ValueUnion); 124 showUsage(); 125 return ch; 126 } 127 } 128 129 /* Check for mandatory parameters. */ 130 if (!pszFilename) 131 { 132 RTMsgError("Mandatory --filename option missing\n"); 133 showUsage(); 134 return 1; 135 } 136 137 /* Check for consistency of optional parameters. */ 138 if (fSetImageUuid && RTUuidIsNull(&imageUuid)) 139 { 140 RTMsgError("Invalid parameter to --uuid option\n"); 141 showUsage(); 142 return 1; 143 } 144 145 PVDINTERFACE pVDIfs = NULL; 146 VDINTERFACE vdInterfaceError; 147 VDINTERFACEERROR vdInterfaceErrorCallbacks; 148 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 149 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 150 vdInterfaceErrorCallbacks.pfnError = handleVDError; 151 vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage; 152 153 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR, 154 &vdInterfaceErrorCallbacks, NULL, &pVDIfs); 155 156 /* Autodetect image format. */ 157 if (!pszFormat) 158 { 159 /* Don't pass error interface, as that would triggers error messages 160 * because some backends fail to open the image. */ 161 rc = VDGetFormat(NULL, pszFilename, &pszFormat); 141 162 if (RT_FAILURE(rc)) 142 163 { 143 RTPrintf("tstVD: Failed to create 'tmp' directory! rc=%Rrc\n", rc); 144 g_cErrors++; 145 } 146 } 147 148 #ifdef VDI_TEST 149 rc = tstVDCreateShareDelete("VDI", "tmpVDCreate.vdi", 10 * _1M, 150 VD_IMAGE_FLAGS_FIXED); 151 if (RT_FAILURE(rc)) 152 { 153 RTPrintf("tstVD: VDI shareable test failed! rc=%Rrc\n", rc); 154 g_cErrors++; 155 } 156 #endif /* VDI_TEST */ 157 158 /* 159 * Clean up any leftovers. 160 */ 161 RTFileDelete("tmpVDCreate.vdi"); 164 RTMsgError("Format autodetect failed: %Rrc\n", rc); 165 return 1; 166 } 167 } 168 169 PVBOXHDD pVD = NULL; 170 rc = VDCreate(pVDIfs, &pVD); 171 if (RT_FAILURE(rc)) 172 { 173 RTMsgError("Cannot create the virtual disk container: %Rrc\n", rc); 174 return 1; 175 } 176 177 rc = VDOpen(pVD, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 178 if (RT_FAILURE(rc)) 179 { 180 RTMsgError("Cannot open the virtual disk image \"%s\": %Rrc\n", 181 pszFilename, rc); 182 return 1; 183 } 184 185 RTUUID oldImageUuid; 186 rc = VDGetUuid(pVD, VD_LAST_IMAGE, &oldImageUuid); 187 if (RT_FAILURE(rc)) 188 { 189 RTMsgError("Cannot get UUID of virtual disk image \"%s\": %Rrc\n", 190 pszFilename, rc); 191 return 1; 192 } 193 RTPrintf("Old image UUID: %RTuuid\n", &oldImageUuid); 194 195 RTUUID oldParentUuid; 196 rc = VDGetParentUuid(pVD, VD_LAST_IMAGE, &oldParentUuid); 197 if (RT_FAILURE(rc)) 198 { 199 RTMsgError("Cannot get parent UUID of virtual disk image \"%s\": %Rrc\n", 200 pszFilename, rc); 201 return 1; 202 } 203 RTPrintf("Old parent UUID: %RTuuid\n", &oldParentUuid); 204 205 if (fSetImageUuid) 206 { 207 RTPrintf("New image UUID: %RTuuid\n", &imageUuid); 208 rc = VDSetUuid(pVD, VD_LAST_IMAGE, &imageUuid); 209 if (RT_FAILURE(rc)) 210 { 211 RTMsgError("Cannot set UUID of virtual disk image \"%s\": %Rrc\n", 212 pszFilename, rc); 213 return 1; 214 } 215 } 216 217 if (fSetParentUuid) 218 { 219 RTPrintf("New parent UUID: %RTuuid\n", &parentUuid); 220 rc = VDSetParentUuid(pVD, VD_LAST_IMAGE, &parentUuid); 221 if (RT_FAILURE(rc)) 222 { 223 RTMsgError("Cannot set parent UUID of virtual disk image \"%s\": %Rrc\n", 224 pszFilename, rc); 225 return 1; 226 } 227 } 228 229 rc = VDCloseAll(pVD); 230 if (RT_FAILURE(rc)) 231 { 232 RTMsgError("Closing image failed! rc=%Rrc\n", rc); 233 return 1; 234 } 235 236 if (pszFormat) 237 { 238 RTStrFree(pszFormat); 239 pszFormat = NULL; 240 } 162 241 163 242 rc = VDShutdown(); 164 243 if (RT_FAILURE(rc)) 165 244 { 166 RTPrintf("tstVD: unloading backends failed! rc=%Rrc\n", rc); 167 g_cErrors++; 168 } 169 /* 170 * Summary 171 */ 172 if (!g_cErrors) 173 RTPrintf("tstVD: SUCCESS\n"); 174 else 175 RTPrintf("tstVD: FAILURE - %d errors\n", g_cErrors); 176 177 return !!g_cErrors; 178 } 179 245 RTMsgError("Unloading backends failed! rc=%Rrc\n", rc); 246 return 1; 247 } 248 249 return 0; 250 } 251
Note:
See TracChangeset
for help on using the changeset viewer.