~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Devices/Storage/testcase/tstVD-2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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. */
33
 
unsigned g_cErrors = 0;
34
 
 
35
 
static 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
 
 
45
 
static bool tstAreKeysValid(void *pvUser, const char *pszzValid)
46
 
{
47
 
    return true;
48
 
}
49
 
 
50
 
static 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
 
 
58
 
static 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
 
 
67
 
static 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
 
 
80
 
VDINTERFACECONFIG icc = {
81
 
    sizeof(VDINTERFACECONFIG),
82
 
    VDINTERFACETYPE_CONFIG,
83
 
    tstAreKeysValid,
84
 
    tstQuerySize,
85
 
    tstQuery
86
 
};
87
 
 
88
 
static 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
 
 
215
 
int 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