VirtualBox

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

Last change on this file since 30714 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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/VBoxHDD.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 int tstVDBackendInfo(void)
89{
90 int rc;
91#define MAX_BACKENDS 100
92 VDBACKENDINFO aVDInfo[MAX_BACKENDS];
93 unsigned cEntries;
94
95#define CHECK(str) \
96 do \
97 { \
98 RTPrintf("%s rc=%Rrc\n", str, rc); \
99 if (RT_FAILURE(rc)) \
100 return rc; \
101 } while (0)
102
103 rc = VDBackendInfo(MAX_BACKENDS, aVDInfo, &cEntries);
104 CHECK("VDBackendInfo()");
105
106 for (unsigned i=0; i < cEntries; i++)
107 {
108 RTPrintf("Backend %u: name=%s capabilities=%#06x extensions=",
109 i, aVDInfo[i].pszBackend, aVDInfo[i].uBackendCaps);
110 if (aVDInfo[i].papszFileExtensions)
111 {
112 const char *const *papsz = aVDInfo[i].papszFileExtensions;
113 while (*papsz != NULL)
114 {
115 if (papsz != aVDInfo[i].papszFileExtensions)
116 RTPrintf(",");
117 RTPrintf("%s", *papsz);
118 papsz++;
119 }
120 if (papsz == aVDInfo[i].papszFileExtensions)
121 RTPrintf("<EMPTY>");
122 }
123 else
124 RTPrintf("<NONE>");
125 RTPrintf(" config=");
126 if (aVDInfo[i].paConfigInfo)
127 {
128 PCVDCONFIGINFO pa = aVDInfo[i].paConfigInfo;
129 while (pa->pszKey != NULL)
130 {
131 if (pa != aVDInfo[i].paConfigInfo)
132 RTPrintf(",");
133 RTPrintf("(key=%s type=", pa->pszKey);
134 switch (pa->enmValueType)
135 {
136 case VDCFGVALUETYPE_INTEGER:
137 RTPrintf("integer");
138 break;
139 case VDCFGVALUETYPE_STRING:
140 RTPrintf("string");
141 break;
142 case VDCFGVALUETYPE_BYTES:
143 RTPrintf("bytes");
144 break;
145 default:
146 RTPrintf("INVALID!");
147 }
148 RTPrintf(" default=");
149 if (pa->pszDefaultValue)
150 RTPrintf("%s", pa->pszDefaultValue);
151 else
152 RTPrintf("<NONE>");
153 RTPrintf(" flags=");
154 if (!pa->uKeyFlags)
155 RTPrintf("none");
156 unsigned cFlags = 0;
157 if (pa->uKeyFlags & VD_CFGKEY_MANDATORY)
158 {
159 if (cFlags)
160 RTPrintf(",");
161 RTPrintf("mandatory");
162 cFlags++;
163 }
164 if (pa->uKeyFlags & VD_CFGKEY_EXPERT)
165 {
166 if (cFlags)
167 RTPrintf(",");
168 RTPrintf("expert");
169 cFlags++;
170 }
171 RTPrintf(")");
172 pa++;
173 }
174 if (pa == aVDInfo[i].paConfigInfo)
175 RTPrintf("<EMPTY>");
176 }
177 else
178 RTPrintf("<NONE>");
179 RTPrintf("\n");
180
181 VDINTERFACE ic;
182 ic.cbSize = sizeof(ic);
183 ic.enmInterface = VDINTERFACETYPE_CONFIG;
184 ic.pCallbacks = &icc;
185 char *pszLocation, *pszName;
186 rc = aVDInfo[i].pfnComposeLocation(&ic, &pszLocation);
187 CHECK("pfnComposeLocation()");
188 if (pszLocation)
189 {
190 RTMemFree(pszLocation);
191 if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
192 {
193 RTPrintf("Non-NULL location returned for file-based backend!\n");
194 return VERR_INTERNAL_ERROR;
195 }
196 }
197 rc = aVDInfo[i].pfnComposeName(&ic, &pszName);
198 CHECK("pfnComposeName()");
199 if (pszName)
200 {
201 RTMemFree(pszName);
202 if (aVDInfo[i].uBackendCaps & VD_CAP_FILE)
203 {
204 RTPrintf("Non-NULL name returned for file-based backend!\n");
205 return VERR_INTERNAL_ERROR;
206 }
207 }
208 }
209
210#undef CHECK
211 return 0;
212}
213
214
215int main(int argc, char *argv[])
216{
217 int rc;
218
219 RTR3Init();
220 RTPrintf("tstVD-2: TESTING...\n");
221
222 rc = tstVDBackendInfo();
223 if (RT_FAILURE(rc))
224 {
225 RTPrintf("tstVD-2: getting backend info test failed! rc=%Rrc\n", rc);
226 g_cErrors++;
227 }
228
229 rc = VDShutdown();
230 if (RT_FAILURE(rc))
231 {
232 RTPrintf("tstVD-2: unloading backends failed! rc=%Rrc\n", rc);
233 g_cErrors++;
234 }
235 /*
236 * Summary
237 */
238 if (!g_cErrors)
239 RTPrintf("tstVD-2: SUCCESS\n");
240 else
241 RTPrintf("tstVD-2: FAILURE - %d errors\n", g_cErrors);
242
243 return !!g_cErrors;
244}
245
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