VirtualBox

source: vbox/trunk/src/VBox/Storage/testcase/tstVDShareable.cpp@ 38352

Last change on this file since 38352 was 33567, checked in by vboxsync, 14 years ago

VD: Move the generic virtual disk framework + backends to src/VBox/Storage and rename the files to get rid of the HDD part because it supports floppy and DVD images too

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: tstVDShareable.cpp 33567 2010-10-28 15:37:21Z vboxsync $ */
2/** @file
3 * Simple VBox HDD container test utility for shareable images.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <VBox/vd.h>
22#include <VBox/err.h>
23#include <VBox/log.h>
24#include <iprt/asm-amd64-x86.h>
25#include <iprt/dir.h>
26#include <iprt/string.h>
27#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. */
43unsigned g_cErrors = 0;
44
45
46static 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
55static int tstVDMessage(void *pvUser, const char *pszFormat, va_list va)
56{
57 RTPrintf("tstVD: ");
58 RTPrintfV(pszFormat, va);
59 return VINF_SUCCESS;
60}
61
62static int tstVDCreateShareDelete(const char *pszBackend, const char *pszFilename,
63 uint64_t cbSize, unsigned uFlags)
64{
65 int rc;
66 PVBOXHDD pVD = NULL, pVD2 = NULL;
67 VDGEOMETRY PCHS = { 0, 0, 0 };
68 VDGEOMETRY LCHS = { 0, 0, 0 };
69 PVDINTERFACE pVDIfs = NULL;
70 VDINTERFACE VDIError;
71 VDINTERFACEERROR VDIErrorCallbacks;
72
73#define CHECK(str) \
74 do \
75 { \
76 RTPrintf("%s rc=%Rrc\n", str, rc); \
77 if (RT_FAILURE(rc)) \
78 { \
79 VDDestroy(pVD); \
80 return rc; \
81 } \
82 } while (0)
83
84 /* Create error interface. */
85 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
86 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
87 VDIErrorCallbacks.pfnError = tstVDError;
88 VDIErrorCallbacks.pfnMessage = tstVDMessage;
89
90 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks,
91 NULL, &pVDIfs);
92 AssertRC(rc);
93
94 rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
95 CHECK("VDCreate()");
96 rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD2);
97 CHECK("VDCreate() #2");
98
99 rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize,
100 uFlags, "Test image", &PCHS, &LCHS, NULL,
101 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
102 CHECK("VDCreateBase()");
103
104 VDClose(pVD, false);
105
106 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
107 CHECK("VDOpen()");
108 rc = VDOpen(pVD2, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
109 CHECK("VDOpen() #2");
110 if (VDIsReadOnly(pVD2))
111 rc = VERR_VD_IMAGE_READ_ONLY;
112
113 VDClose(pVD2, false);
114 VDClose(pVD, true);
115
116 VDDestroy(pVD);
117 VDDestroy(pVD2);
118#undef CHECK
119 return 0;
120}
121
122int main(int argc, char *argv[])
123{
124 RTR3Init();
125 int rc;
126
127 RTPrintf("tstVD: TESTING...\n");
128
129 /*
130 * Clean up potential leftovers from previous unsuccessful runs.
131 */
132 RTFileDelete("tmpVDCreate.vdi");
133
134 if (!RTDirExists("tmp"))
135 {
136 rc = RTDirCreate("tmp", RTFS_UNIX_IRWXU);
137 if (RT_FAILURE(rc))
138 {
139 RTPrintf("tstVD: Failed to create 'tmp' directory! rc=%Rrc\n", rc);
140 g_cErrors++;
141 }
142 }
143
144#ifdef VDI_TEST
145 rc = tstVDCreateShareDelete("VDI", "tmpVDCreate.vdi", 10 * _1M,
146 VD_IMAGE_FLAGS_FIXED);
147 if (RT_FAILURE(rc))
148 {
149 RTPrintf("tstVD: VDI shareable test failed! rc=%Rrc\n", rc);
150 g_cErrors++;
151 }
152#endif /* VDI_TEST */
153
154 /*
155 * Clean up any leftovers.
156 */
157 RTFileDelete("tmpVDCreate.vdi");
158
159 rc = VDShutdown();
160 if (RT_FAILURE(rc))
161 {
162 RTPrintf("tstVD: unloading backends failed! rc=%Rrc\n", rc);
163 g_cErrors++;
164 }
165 /*
166 * Summary
167 */
168 if (!g_cErrors)
169 RTPrintf("tstVD: SUCCESS\n");
170 else
171 RTPrintf("tstVD: FAILURE - %d errors\n", g_cErrors);
172
173 return !!g_cErrors;
174}
175
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette