VirtualBox

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

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

More DECLCALLBACK fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: tstVDShareable.cpp 57415 2015-08-18 10:58:19Z 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 DECLCALLBACK(void) tstVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
49{
50 g_cErrors++;
51 RTPrintf("tstVDShareable: Error %Rrc at %s:%u (%s): ", rc, RT_SRC_POS_ARGS);
52 RTPrintfV(pszFormat, va);
53 RTPrintf("\n");
54}
55
56static DECLCALLBACK(int) tstVDMessage(void *pvUser, const char *pszFormat, va_list va)
57{
58 RTPrintf("tstVDShareable: ");
59 RTPrintfV(pszFormat, va);
60 return VINF_SUCCESS;
61}
62
63static int tstVDCreateShareDelete(const char *pszBackend, const char *pszFilename,
64 uint64_t cbSize, unsigned uFlags)
65{
66 int rc;
67 PVBOXHDD pVD = NULL, pVD2 = NULL;
68 VDGEOMETRY PCHS = { 0, 0, 0 };
69 VDGEOMETRY LCHS = { 0, 0, 0 };
70 PVDINTERFACE pVDIfs = NULL;
71 VDINTERFACEERROR VDIfError;
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 VDIfError.pfnError = tstVDError;
86 VDIfError.pfnMessage = tstVDMessage;
87
88 rc = VDInterfaceAdd(&VDIfError.Core, "tstVD_Error", VDINTERFACETYPE_ERROR,
89 NULL, sizeof(VDINTERFACEERROR), &pVDIfs);
90 AssertRC(rc);
91
92 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD);
93 CHECK("VDCreate()");
94 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD2);
95 CHECK("VDCreate() #2");
96
97 rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize,
98 uFlags, "Test image", &PCHS, &LCHS, NULL,
99 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
100 CHECK("VDCreateBase()");
101
102 VDClose(pVD, false);
103
104 rc = VDOpen(pVD, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
105 CHECK("VDOpen()");
106 rc = VDOpen(pVD2, pszBackend, pszFilename, VD_OPEN_FLAGS_SHAREABLE, NULL);
107 CHECK("VDOpen() #2");
108 if (VDIsReadOnly(pVD2))
109 rc = VERR_VD_IMAGE_READ_ONLY;
110
111 VDClose(pVD2, false);
112 VDClose(pVD, true);
113
114 VDDestroy(pVD);
115 VDDestroy(pVD2);
116#undef CHECK
117 return 0;
118}
119
120int main(int argc, char *argv[])
121{
122 RTR3InitExe(argc, &argv, 0);
123 int rc;
124
125 RTPrintf("tstVDShareable: TESTING...\n");
126
127 /*
128 * Clean up potential leftovers from previous unsuccessful runs.
129 */
130 RTFileDelete("tmpVDCreate.vdi");
131
132 if (!RTDirExists("tmp"))
133 {
134 rc = RTDirCreate("tmp", RTFS_UNIX_IRWXU, 0);
135 if (RT_FAILURE(rc))
136 {
137 RTPrintf("tstVDShareable: Failed to create 'tmp' directory! rc=%Rrc\n", rc);
138 g_cErrors++;
139 }
140 }
141
142#ifdef VDI_TEST
143 rc = tstVDCreateShareDelete("VDI", "tmpVDCreate.vdi", 10 * _1M,
144 VD_IMAGE_FLAGS_FIXED);
145 if (RT_FAILURE(rc))
146 {
147 RTPrintf("tstVDShareable: VDI shareable test failed! rc=%Rrc\n", rc);
148 g_cErrors++;
149 }
150#endif /* VDI_TEST */
151
152 /*
153 * Clean up any leftovers.
154 */
155 RTFileDelete("tmpVDCreate.vdi");
156
157 rc = VDShutdown();
158 if (RT_FAILURE(rc))
159 {
160 RTPrintf("tstVDShareable: unloading backends failed! rc=%Rrc\n", rc);
161 g_cErrors++;
162 }
163 /*
164 * Summary
165 */
166 if (!g_cErrors)
167 RTPrintf("tstVDShareable: SUCCESS\n");
168 else
169 RTPrintf("tstVDShareable: FAILURE - %d errors\n", g_cErrors);
170
171 return !!g_cErrors;
172}
173
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