VirtualBox

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

Last change on this file since 44401 was 41965, checked in by vboxsync, 12 years ago

VMM: ran scm. Mostly svn:keywords changes (adding Revision).

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