VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstCFGM.cpp@ 8707

Last change on this file since 8707 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 Id
File size: 4.7 KB
Line 
1/* $Id: tstCFGM.cpp 8155 2008-04-18 15:16:47Z vboxsync $ */
2/** @file
3 * Testcase for CFGM.
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
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/sup.h>
28#include <VBox/cfgm.h>
29#include <VBox/mm.h>
30#include <VBox/vm.h>
31#include <VBox/uvm.h>
32
33#include <VBox/err.h>
34#include <VBox/param.h>
35#include <iprt/initterm.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38
39
40int main()
41{
42 /*
43 * Init runtime.
44 */
45 RTR3Init();
46
47 /*
48 * Create empty VM structure and init SSM.
49 */
50 PVM pVM;
51 int rc = SUPInit(NULL);
52 if (VBOX_SUCCESS(rc))
53 rc = SUPPageAlloc(RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT, (void **)&pVM);
54 if (VBOX_FAILURE(rc))
55 {
56 RTPrintf("Fatal error: SUP Failure! rc=%Vrc\n", rc);
57 return 1;
58 }
59
60 static UVM s_UVM;
61 PUVM pUVM = &s_UVM;
62 pUVM->pVM = pVM;
63 pVM->pUVM = pUVM;
64
65 rc = STAMR3InitUVM(pUVM);
66 if (VBOX_FAILURE(rc))
67 {
68 RTPrintf("FAILURE: STAMR3Init failed. rc=%Vrc\n", rc);
69 return 1;
70 }
71
72 rc = MMR3InitUVM(pUVM);
73 if (VBOX_FAILURE(rc))
74 {
75 RTPrintf("FAILURE: STAMR3Init failed. rc=%Vrc\n", rc);
76 return 1;
77 }
78
79 rc = CFGMR3Init(pVM, NULL, NULL);
80 if (VBOX_FAILURE(rc))
81 {
82 RTPrintf("FAILURE: CFGMR3Init failed. rc=%Vrc\n", rc);
83 return 1;
84 }
85
86 if (!CFGMR3GetRoot(pVM))
87 {
88 RTPrintf("FAILURE: CFGMR3GetRoot failed\n");
89 return 1;
90 }
91
92 /* integer */
93 uint64_t u64;
94 rc = CFGMR3QueryU64(CFGMR3GetRoot(pVM), "RamSize", &u64);
95 if (VBOX_FAILURE(rc))
96 {
97 RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\",) failed. rc=%Vrc\n", rc);
98 return 1;
99 }
100
101 size_t cb;
102 rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "RamSize", &cb);
103 if (VBOX_FAILURE(rc))
104 {
105 RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Vrc\n", rc);
106 return 1;
107 }
108 if (cb != sizeof(uint64_t))
109 {
110 RTPrintf("FAILURE: Incorrect valuesize %d for \"RamSize\" value.\n", cb);
111 return 1;
112 }
113
114 /* string */
115 char *pszName = NULL;
116 rc = CFGMR3QueryStringAlloc(CFGMR3GetRoot(pVM), "Name", &pszName);
117 if (VBOX_FAILURE(rc))
118 {
119 RTPrintf("FAILURE: CFGMR3QueryStringAlloc(,\"Name\" failed. rc=%Vrc\n", rc);
120 return 1;
121 }
122
123 rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "Name", &cb);
124 if (VBOX_FAILURE(rc))
125 {
126 RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Vrc\n", rc);
127 return 1;
128 }
129 if (cb != strlen(pszName) + 1)
130 {
131 RTPrintf("FAILURE: Incorrect valuesize %d for \"Name\" value '%s'.\n", cb, pszName);
132 return 1;
133 }
134 MMR3HeapFree(pszName);
135
136
137 /* test multilevel node creation */
138 PCFGMNODE pChild = NULL;
139 rc = CFGMR3InsertNode(CFGMR3GetRoot(pVM), "First/Second/Third//Final", &pChild);
140 if (VBOX_FAILURE(rc))
141 {
142 RTPrintf("FAILURE: CFGMR3InsertNode(,\"First/Second/Third//Final\" failed. rc=%Vrc\n", rc);
143 return 1;
144 }
145 rc = CFGMR3InsertInteger(pChild, "BoolValue", 1);
146 if (VBOX_FAILURE(rc))
147 {
148 RTPrintf("FAILURE: CFGMR3InsertInteger(,\"BoolValue\", 1) failed. rc=%Vrc\n", rc);
149 return 1;
150 }
151 PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "First/Second/Third/Final");
152 if (pNode != pChild)
153 {
154 RTPrintf("FAILURE: CFGMR3GetChild(,\"First/Second/Third/Final/BoolValue\") failed. pNode=%p expected %p\n", pNode, pChild);
155 return 1;
156 }
157 bool f = false;
158 rc = CFGMR3QueryBool(pNode, "BoolValue", &f);
159 if (VBOX_FAILURE(rc) || !f)
160 {
161 RTPrintf("FAILURE: CFGMR3QueryBool(,\"BoolValue\",) failed. rc=%Vrc f=%d\n", rc, f);
162 return 1;
163 }
164
165
166 /* done */
167 rc = CFGMR3Term(pVM);
168 if (VBOX_FAILURE(rc))
169 {
170 RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\" failed. rc=%Vrc\n", rc);
171 return 1;
172 }
173
174 RTPrintf("tstCFGM: SUCCESS\n");
175 return rc;
176}
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