VirtualBox

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

Last change on this file since 57358 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: tstVDShareable.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * Simple VBox HDD container test utility for shareable images.
4 */
5
6/*
7 * Copyright (C) 2010-2011 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/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/vd.h>
23#include <VBox/err.h>
24#include <VBox/log.h>
25#include <iprt/asm-amd64-x86.h>
26#include <iprt/dir.h>
27#include <iprt/string.h>
28#include <iprt/stream.h>
29#include <iprt/file.h>
30#include <iprt/mem.h>
31#include <iprt/initterm.h>
32#include <iprt/rand.h>
33#include "stdio.h"
34#include "stdlib.h"
35
36#define VHD_TEST
37#define VDI_TEST
38#define VMDK_TEST
39
40
41/*********************************************************************************************************************************
42* Global Variables *
43*********************************************************************************************************************************/
44/** The error count. */
45unsigned g_cErrors = 0;
46
47
48static void tstVDError(void *pvUser, int rc, RT_SRC_POS_DECL,
49 const char *pszFormat, va_list va)
50{
51 g_cErrors++;
52 RTPrintf("tstVD: Error %Rrc at %s:%u (%s): ", rc, RT_SRC_POS_ARGS);
53 RTPrintfV(pszFormat, va);
54 RTPrintf("\n");
55}
56
57static int tstVDMessage(void *pvUser, const char *pszFormat, va_list va)
58{
59 RTPrintf("tstVD: ");
60 RTPrintfV(pszFormat, va);
61 return VINF_SUCCESS;
62}
63
64static int tstVDCreateShareDelete(const char *pszBackend, const char *pszFilename,
65 uint64_t cbSize, unsigned uFlags)
66{
67 int rc;
68 PVBOXHDD pVD = NULL, pVD2 = NULL;
69 VDGEOMETRY PCHS = { 0, 0, 0 };
70 VDGEOMETRY LCHS = { 0, 0, 0 };
71 PVDINTERFACE pVDIfs = NULL;
72 VDINTERFACEERROR VDIfError;
73
74#define CHECK(str) \
75 do \
76 { \
77 RTPrintf("%s rc=%Rrc\n", str, rc); \
78 if (RT_FAILURE(rc)) \
79 { \
80 VDDestroy(pVD); \
81 return rc; \
82 } \
83 } while (0)
84
85 /* Create error interface. */
86 VDIfError.pfnError = tstVDError;
87 VDIfError.pfnMessage = tstVDMessage;
88
89 rc = VDInterfaceAdd(&VDIfError.Core, "tstVD_Error", VDINTERFACETYPE_ERROR,
90 NULL, sizeof(VDINTERFACEERROR), &pVDIfs);
91 AssertRC(rc);
92
93 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD);
94 CHECK("VDCreate()");
95 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD2);
96 CHECK("VDCreate() #2");
97
98 rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize,
99 uFlags, "Test image", &PCHS, &LCHS, NULL,
100 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
101 CHECK("VDCreateBase()");
102
103 VDClose(pVD, false);
104
105 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
106 CHECK("VDOpen()");
107 rc = VDOpen(pVD2, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
108 CHECK("VDOpen() #2");
109 if (VDIsReadOnly(pVD2))
110 rc = VERR_VD_IMAGE_READ_ONLY;
111
112 VDClose(pVD2, false);
113 VDClose(pVD, true);
114
115 VDDestroy(pVD);
116 VDDestroy(pVD2);
117#undef CHECK
118 return 0;
119}
120
121int main(int argc, char *argv[])
122{
123 RTR3InitExe(argc, &argv, 0);
124 int rc;
125
126 RTPrintf("tstVD: TESTING...\n");
127
128 /*
129 * Clean up potential leftovers from previous unsuccessful runs.
130 */
131 RTFileDelete("tmpVDCreate.vdi");
132
133 if (!RTDirExists("tmp"))
134 {
135 rc = RTDirCreate("tmp", RTFS_UNIX_IRWXU, 0);
136 if (RT_FAILURE(rc))
137 {
138 RTPrintf("tstVD: Failed to create 'tmp' directory! rc=%Rrc\n", rc);
139 g_cErrors++;
140 }
141 }
142
143#ifdef VDI_TEST
144 rc = tstVDCreateShareDelete("VDI", "tmpVDCreate.vdi", 10 * _1M,
145 VD_IMAGE_FLAGS_FIXED);
146 if (RT_FAILURE(rc))
147 {
148 RTPrintf("tstVD: VDI shareable test failed! rc=%Rrc\n", rc);
149 g_cErrors++;
150 }
151#endif /* VDI_TEST */
152
153 /*
154 * Clean up any leftovers.
155 */
156 RTFileDelete("tmpVDCreate.vdi");
157
158 rc = VDShutdown();
159 if (RT_FAILURE(rc))
160 {
161 RTPrintf("tstVD: unloading backends failed! rc=%Rrc\n", rc);
162 g_cErrors++;
163 }
164 /*
165 * Summary
166 */
167 if (!g_cErrors)
168 RTPrintf("tstVD: SUCCESS\n");
169 else
170 RTPrintf("tstVD: FAILURE - %d errors\n", g_cErrors);
171
172 return !!g_cErrors;
173}
174
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