VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/testcase/tstVDI.cpp@ 9074

Last change on this file since 9074 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/** @file
2 *
3 * Simple VBox HDD container test utility.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include <VBox/err.h>
23#include <VBox/VBoxHDD.h>
24#include <iprt/runtime.h>
25#include <iprt/string.h>
26#include <iprt/stream.h>
27#include <iprt/mem.h>
28
29
30int dotest(const char *pszBaseFilename, const char *pszDiffFilename)
31{
32 PVDIDISK pVdi = VDIDiskCreate();
33
34#define CHECK(str) \
35 do \
36 { \
37 RTPrintf("%s rc=%Vrc\n", str, rc); \
38 if (VBOX_FAILURE(rc)) \
39 { \
40 VDIDiskCloseAllImages(pVdi); \
41 return rc; \
42 } \
43 } while (0)
44
45
46 int rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
47 RTPrintf("openImage() rc=%Vrc\n", rc);
48 if (VBOX_FAILURE(rc))
49 {
50 rc = VDICreateBaseImage(pszBaseFilename, VDI_IMAGE_TYPE_NORMAL,
51#ifdef _MSC_VER
52 (1000 * 1024 * 1024UI64),
53#else
54 (1000 * 1024 * 1024ULL),
55#endif
56 "Test image", NULL, NULL);
57 CHECK("createImage()");
58
59 rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
60 CHECK("openImage()");
61 }
62
63 void *pvBuf = RTMemAlloc(1*1124*1024);
64
65 memset(pvBuf, 0x33, 1*1124*1024);
66 rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 1024*1024);
67 CHECK("write()");
68
69 memset(pvBuf, 0x46, 1*1124*1024);
70 rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 1024);
71 CHECK("write()");
72
73 memset(pvBuf, 0x51, 1*1124*1024);
74 rc = VDIDiskWrite(pVdi, 40*1024*1024 + 594040, pvBuf, 1024);
75 CHECK("write()");
76
77 rc = VDIDiskCreateOpenDifferenceImage(pVdi, pszDiffFilename, "Test diff image", NULL, NULL);
78 CHECK("create undo");
79// rc = VHDDOpenSecondImage(pVdi, "undoimg.vdi");
80// RTPrintf("open undo rc=%Vrc\n", rc);
81
82 memset(pvBuf, '_', 1*1124*1024);
83 rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 512);
84 CHECK("write()");
85
86 rc = VDIDiskWrite(pVdi, 22*1024*1024 + 594040, pvBuf, 78263);
87 CHECK("write()");
88 rc = VDIDiskWrite(pVdi, 13*1024*1024 + 594040, pvBuf, 782630);
89 CHECK("write()");
90 rc = VDIDiskWrite(pVdi, 44*1024*1024 + 594040, pvBuf, 67899);
91 CHECK("write()");
92
93 RTPrintf("committing..\n");
94 VDIDiskDumpImages(pVdi);
95 rc = VDIDiskCommitLastDiff(pVdi, NULL, NULL);
96 CHECK("commit last diff");
97 VDIDiskCloseAllImages(pVdi);
98#undef CHECK
99 return 0;
100}
101
102
103int main()
104{
105 RTR3Init();
106
107 RTFileDelete("tmpVdiBase.vdi");
108 RTFileDelete("tmpVdiDiff.vdi");
109
110 int rc = dotest("tmpVdiBase.vdi", "tmpVdiDiff.vdi");
111 if (!rc)
112 RTPrintf("tstVDI: SUCCESS\n");
113 else
114 RTPrintf("tstVDI: FAILURE\n");
115
116 RTFileDelete("tmpVdiBase.vdi");
117 RTFileDelete("tmpVdiDiff.vdi");
118 return !!rc;
119}
120
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