VirtualBox

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

Last change on this file since 108843 was 108631, checked in by vboxsync, 7 weeks ago

VMM/testcase/tstCFGM.cpp: Make it work for hosts where we don't know the host page size when building, bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.3 KB
Line 
1/* $Id: tstCFGM.cpp 108631 2025-03-20 11:17:11Z vboxsync $ */
2/** @file
3 * Testcase for CFGM.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29
30/*********************************************************************************************************************************
31* Header Files *
32*********************************************************************************************************************************/
33#include <VBox/sup.h>
34#include <VBox/vmm/cfgm.h>
35#include <VBox/vmm/dbgf.h>
36#include <VBox/vmm/mm.h>
37#include <VBox/vmm/vm.h>
38#include <VBox/vmm/uvm.h>
39
40#include <VBox/err.h>
41#include <VBox/param.h>
42#include <iprt/initterm.h>
43#include <iprt/stream.h>
44#include <iprt/mem.h>
45#include <iprt/string.h>
46#include <iprt/system.h>
47
48#include <iprt/test.h>
49
50
51static void doGeneralTests(PCFGMNODE pRoot)
52{
53 /* test multilevel node creation */
54 PCFGMNODE pChild = NULL;
55 RTTESTI_CHECK_RC_RETV(CFGMR3InsertNode(pRoot, "First/Second/Third//Final", &pChild), VINF_SUCCESS);
56 RTTESTI_CHECK_RETV(RT_VALID_PTR(pChild));
57 RTTESTI_CHECK(CFGMR3GetChild(pRoot, "First/Second/Third/Final") == pChild);
58
59 /*
60 * Boolean queries.
61 */
62 RTTESTI_CHECK_RC(CFGMR3InsertInteger(pChild, "BoolValue", 1), VINF_SUCCESS);
63 bool f = false;
64 RTTESTI_CHECK_RC(CFGMR3QueryBool(pChild, "BoolValue", &f), VINF_SUCCESS);
65 RTTESTI_CHECK(f == true);
66
67 RTTESTI_CHECK_RC(CFGMR3QueryBool(pRoot, "BoolValue", &f), VERR_CFGM_VALUE_NOT_FOUND);
68 RTTESTI_CHECK_RC(CFGMR3QueryBool(NULL, "BoolValue", &f), VERR_CFGM_NO_PARENT);
69
70 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, true), VINF_SUCCESS);
71 RTTESTI_CHECK(f == true);
72 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, false), VINF_SUCCESS);
73 RTTESTI_CHECK(f == false);
74
75 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, true), VINF_SUCCESS);
76 RTTESTI_CHECK(f == true);
77 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, false), VINF_SUCCESS);
78 RTTESTI_CHECK(f == false);
79
80}
81
82
83
84static void doTestsOnDefaultValues(PCFGMNODE pRoot)
85{
86 /* integer */
87 uint64_t u64;
88 RTTESTI_CHECK_RC(CFGMR3QueryU64(pRoot, "RamSize", &u64), VINF_SUCCESS);
89
90 size_t cb = 0;
91 RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "RamSize", &cb), VINF_SUCCESS);
92 RTTESTI_CHECK(cb == sizeof(uint64_t));
93
94 /* string */
95 char *pszName = NULL;
96 RTTESTI_CHECK_RC(CFGMR3QueryStringAlloc(pRoot, "Name", &pszName), VINF_SUCCESS);
97 RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "Name", &cb), VINF_SUCCESS);
98 RTTESTI_CHECK(cb == strlen(pszName) + 1);
99 MMR3HeapFree(pszName);
100}
101
102
103static void doInVmmTests(RTTEST hTest)
104{
105 /*
106 * Create empty VM structure and init SSM.
107 */
108 int rc = SUPR3Init(NULL);
109 if (RT_FAILURE(rc))
110 {
111 RTTestSkipped(hTest, "SUPR3Init failed with rc=%Rrc", rc);
112 return;
113 }
114
115 PVM pVM;
116 RTTESTI_CHECK_RC_RETV(SUPR3PageAlloc(RT_ALIGN_Z(sizeof(*pVM), RTSystemGetPageSize()) >> RTSystemGetPageShift(), 0, (void **)&pVM),
117 VINF_SUCCESS);
118
119
120 PUVM pUVM = (PUVM)RTMemPageAllocZ(sizeof(*pUVM));
121 pUVM->u32Magic = UVM_MAGIC;
122 pUVM->pVM = pVM;
123 pVM->pUVM = pUVM;
124
125 /*
126 * Do the testing.
127 */
128 RTTESTI_CHECK_RC_RETV(STAMR3InitUVM(pUVM), VINF_SUCCESS);
129 RTTESTI_CHECK_RC_RETV(MMR3InitUVM(pUVM), VINF_SUCCESS);
130 RTTESTI_CHECK_RC_RETV(CFGMR3Init(pVM, NULL, NULL), VINF_SUCCESS);
131 RTTESTI_CHECK_RETV(CFGMR3GetRoot(pVM) != NULL);
132
133 doTestsOnDefaultValues(CFGMR3GetRoot(pVM));
134 doGeneralTests(CFGMR3GetRoot(pVM));
135
136
137 /* done */
138 RTTESTI_CHECK_RC_RETV(CFGMR3Term(pVM), VINF_SUCCESS);
139 MMR3TermUVM(pUVM);
140 STAMR3TermUVM(pUVM);
141 DBGFR3TermUVM(pUVM);
142 RTMemPageFree(pUVM, sizeof(*pUVM));
143}
144
145
146static void doStandaloneTests(void)
147{
148 RTTestISub("Standalone");
149 PCFGMNODE pRoot;;
150 RTTESTI_CHECK_RETV((pRoot = CFGMR3CreateTree(NULL)) != NULL);
151 doGeneralTests(pRoot);
152 CFGMR3DestroyTree(pRoot);
153}
154
155
156/**
157 * Entry point.
158 */
159extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
160{
161 RT_NOREF3(argc, argv, envp);
162
163 /*
164 * Init runtime.
165 */
166 RTTEST hTest;
167 RTR3InitExeNoArguments(RTR3INIT_FLAGS_TRY_SUPLIB);
168 RTEXITCODE rcExit = RTTestInitAndCreate("tstCFGM", &hTest);
169 if (rcExit != RTEXITCODE_SUCCESS)
170 return rcExit;
171
172 doInVmmTests(hTest);
173 doStandaloneTests();
174
175 return RTTestSummaryAndDestroy(hTest);
176}
177
178
179#if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
180/**
181 * Main entry point.
182 */
183int main(int argc, char **argv, char **envp)
184{
185 return TrustedMain(argc, argv, envp);
186}
187#endif
188
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette