VirtualBox

source: vbox/trunk/src/VBox/Storage/testcase/tstVD-2.cpp@ 33746

Last change on this file since 33746 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: 7.1 KB
Line 
1/** @file
2 *
3 * Simple VBox HDD container test utility. Only fast tests.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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#include <VBox/err.h>
19#include <VBox/vd.h>
20#include <iprt/string.h>
21#include <iprt/stream.h>
22#include <iprt/file.h>
23#include <iprt/mem.h>
24#include <iprt/initterm.h>
25#include <iprt/rand.h>
26#include "stdio.h"
27#include "stdlib.h"
28
29/*******************************************************************************
30* Global Variables *
31*******************************************************************************/
32/** The error count. */
33unsigned g_cErrors = 0;
34
35static struct KeyValuePair {
36 const char *key;
37 const char *value;
38} aCfgNode[] = {
39 { "TargetName", "test" },
40 { "LUN", "1" },
41 { "TargetAddress", "address" },
42 { NULL, NULL }
43};
44
45static bool tstAreKeysValid(void *pvUser, const char *pszzValid)
46{
47 return true;
48}
49
50static const char *tstGetValueByKey(const char *pszKey)
51{
52 for (int i = 0; aCfgNode[i].key; i++)
53 if (!strcmp(aCfgNode[i].key, pszKey))
54 return aCfgNode[i].value;
55 return NULL;
56}
57
58static int tstQuerySize(void *pvUser, const char *pszName, size_t *pcbValue)
59{
60 const char *pszValue = tstGetValueByKey(pszName);
61 if (!pszValue)
62 return VERR_CFGM_VALUE_NOT_FOUND;
63 *pcbValue = strlen(pszValue) + 1;
64 return VINF_SUCCESS;
65}
66
67static int tstQuery(void *pvUser, const char *pszName, char *pszValue, size_t cchValue)
68{
69 const char *pszTmp = tstGetValueByKey(pszName);
70 if (!pszValue)
71 return VERR_CFGM_VALUE_NOT_FOUND;
72 size_t cchTmp = strlen(pszTmp) + 1;
73 if (cchValue < cchTmp)
74 return VERR_CFGM_NOT_ENOUGH_SPACE;
75 memcpy(pszValue, pszTmp, cchTmp);
76 return VINF_SUCCESS;
77}
78
79
80VDINTERFACECONFIG icc = {
81 sizeof(VDINTERFACECONFIG),
82 VDINTERFACETYPE_CONFIG,
83 tstAreKeysValid,
84 tstQuerySize,
85 tstQuery
86};
87
88static const char *tstVDDeviceType(VDTYPE enmType)
89{
90 switch (enmType)
91 {
92 case VDTYPE_HDD:
93 return "HardDisk";
94 case VDTYPE_DVD:
95 return "DVD";
96 case VDTYPE_FLOPPY:
97 return "Floppy";
98 default:
99 return "Unknown";
100 }
101}
102
103static int tstVDBackendInfo(void)
104{
105 int rc;
106#define MAX_BACKENDS 100
107 VDBACKENDINFO aVDInfo[MAX_BACKENDS];
108 unsigned cEntries;
109
110#define CHECK(str) \
111 do \
112 { \
113 RTPrintf("%s rc=%Rrc\n", str, rc); \
114 if (RT_FAILURE(rc)) \
115 return rc; \
116 } while (0)
117
118 rc = VDBackendInfo(MAX_BACKENDS, aVDInfo, &cEntries);
119 CHECK("VDBackendInfo()");
120
121 for (unsigned i=0; i < cEntries; i++)
122 {
123 RTPrintf("Backend %u: name=%s capabilities=%#06x extensions=",
124 i, aVDInfo[i].pszBackend, aVDInfo[i].uBackendCaps);
125 if (aVDInfo[i].paFileExtensions)
126 {
127 PCVDFILEEXTENSION pa = aVDInfo[i].paFileExtensions;
128 while (pa->pszExtension != NULL)
129 {
130 if (pa != aVDInfo[i].paFileExtensions)
131 RTPrintf(",");
132 RTPrintf("%s (%s)", pa->pszExtension, tstVDDeviceType(pa->enmType));
133 pa++;
134 }
135 if (pa == aVDInfo[i].paFileExtensions)
136 RTPrintf("<EMPTY>");
137 }
138 else
139 RTPrintf("<NONE>");
140 RTPrintf(" config=");
141 if (aVDInfo[i].paConfigInfo)
142 {
143 PCVDCONFIGINFO pa = aVDInfo[i].paConfigInfo;
144 while (pa->pszKey != NULL)
145 {
146 if (pa != aVDInfo[i].paConfigInfo)
147 RTPrintf(",");
148 RTPrintf("(key=%s type=", pa->pszKey);
149 switch (pa->enmValueType)
150 {
151 case VDCFGVALUETYPE_INTEGER:
152 RTPrintf("integer");
153 break;
154 case VDCFGVALUETYPE_STRING:
155 RTPrintf("string");
156 break;
157 case VDCFGVALUETYPE_BYTES:
158 RTPrintf("bytes");
159 break;
160 default:
161 RTPrintf("INVALID!");
162 }
163 RTPrintf(" default=");
164 if (pa->pszDefaultValue)
165 RTPrintf("%s", pa->pszDefaultValue);
166 else
167 RTPrintf("<NONE>");
168 RTPrintf(" flags=");
169 if (!pa->uKeyFlags)
170 RTPrintf("none");
171 unsigned cFlags = 0;
172 if (pa->uKeyFlags & VD_CFGKEY_MANDATORY)
173 {
174 if (cFlags)
175 RTPrintf(",");
176 RTPrintf("mandatory");
177 cFlags++;
178 }
179 if (pa->uKeyFlags & VD_CFGKEY_EXPERT)
180 {
181 if (cFlags)
182 RTPrintf(",");
183 RTPrintf("expert");
184 cFlags++;
185 }
186 RTPrintf(")");
187 pa++;
188 }
189 if (pa == aVDInfo[i].paConfigInfo)
190 RTPrintf("<EMPTY>");
191 }
192 else
193 RTPrintf("<NONE>");
194 RTPrintf("\n");
195
196 VDINTERFACE ic;
197 ic.cbSize = sizeof(ic);
198 ic.enmInterface = VDINTERFACETYPE_CONFIG;
199 ic.pCallbacks = &icc;
200 char *pszLocation, *pszName;
201 rc = aVDInfo[i].pfnComposeLocation(&ic, &pszLocation);
202 CHECK("pfnComposeLocation()");
203 if (pszLocation)
204 {
205 RTMemFree(pszLocation);
206 if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
207 {
208 RTPrintf("Non-NULL location returned for file-based backend!\n");
209 return VERR_INTERNAL_ERROR;
210 }
211 }
212 rc = aVDInfo[i].pfnComposeName(&ic, &pszName);
213 CHECK("pfnComposeName()");
214 if (pszName)
215 {
216 RTMemFree(pszName);
217 if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
218 {
219 RTPrintf("Non-NULL name returned for file-based backend!\n");
220 return VERR_INTERNAL_ERROR;
221 }
222 }
223 }
224
225#undef CHECK
226 return 0;
227}
228
229
230int main(int argc, char *argv[])
231{
232 int rc;
233
234 RTR3Init();
235 RTPrintf("tstVD-2: TESTING...\n");
236
237 rc = tstVDBackendInfo();
238 if (RT_FAILURE(rc))
239 {
240 RTPrintf("tstVD-2: getting backend info test failed! rc=%Rrc\n", rc);
241 g_cErrors++;
242 }
243
244 rc = VDShutdown();
245 if (RT_FAILURE(rc))
246 {
247 RTPrintf("tstVD-2: unloading backends failed! rc=%Rrc\n", rc);
248 g_cErrors++;
249 }
250 /*
251 * Summary
252 */
253 if (!g_cErrors)
254 RTPrintf("tstVD-2: SUCCESS\n");
255 else
256 RTPrintf("tstVD-2: FAILURE - %d errors\n", g_cErrors);
257
258 return !!g_cErrors;
259}
260
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