VirtualBox

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

Last change on this file since 98523 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.3 KB
Line 
1/* $Id: tstCFGM.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Testcase for CFGM.
4 */
5
6/*
7 * Copyright (C) 2006-2023 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
47#include <iprt/test.h>
48
49
50static void doGeneralTests(PCFGMNODE pRoot)
51{
52 /* test multilevel node creation */
53 PCFGMNODE pChild = NULL;
54 RTTESTI_CHECK_RC_RETV(CFGMR3InsertNode(pRoot, "First/Second/Third//Final", &pChild), VINF_SUCCESS);
55 RTTESTI_CHECK_RETV(RT_VALID_PTR(pChild));
56 RTTESTI_CHECK(CFGMR3GetChild(pRoot, "First/Second/Third/Final") == pChild);
57
58 /*
59 * Boolean queries.
60 */
61 RTTESTI_CHECK_RC(CFGMR3InsertInteger(pChild, "BoolValue", 1), VINF_SUCCESS);
62 bool f = false;
63 RTTESTI_CHECK_RC(CFGMR3QueryBool(pChild, "BoolValue", &f), VINF_SUCCESS);
64 RTTESTI_CHECK(f == true);
65
66 RTTESTI_CHECK_RC(CFGMR3QueryBool(pRoot, "BoolValue", &f), VERR_CFGM_VALUE_NOT_FOUND);
67 RTTESTI_CHECK_RC(CFGMR3QueryBool(NULL, "BoolValue", &f), VERR_CFGM_NO_PARENT);
68
69 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, true), VINF_SUCCESS);
70 RTTESTI_CHECK(f == true);
71 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, false), VINF_SUCCESS);
72 RTTESTI_CHECK(f == false);
73
74 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, true), VINF_SUCCESS);
75 RTTESTI_CHECK(f == true);
76 RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, false), VINF_SUCCESS);
77 RTTESTI_CHECK(f == false);
78
79}
80
81
82
83static void doTestsOnDefaultValues(PCFGMNODE pRoot)
84{
85 /* integer */
86 uint64_t u64;
87 RTTESTI_CHECK_RC(CFGMR3QueryU64(pRoot, "RamSize", &u64), VINF_SUCCESS);
88
89 size_t cb = 0;
90 RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "RamSize", &cb), VINF_SUCCESS);
91 RTTESTI_CHECK(cb == sizeof(uint64_t));
92
93 /* string */
94 char *pszName = NULL;
95 RTTESTI_CHECK_RC(CFGMR3QueryStringAlloc(pRoot, "Name", &pszName), VINF_SUCCESS);
96 RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "Name", &cb), VINF_SUCCESS);
97 RTTESTI_CHECK(cb == strlen(pszName) + 1);
98 MMR3HeapFree(pszName);
99}
100
101
102static void doInVmmTests(RTTEST hTest)
103{
104 /*
105 * Create empty VM structure and init SSM.
106 */
107 int rc = SUPR3Init(NULL);
108 if (RT_FAILURE(rc))
109 {
110 RTTestSkipped(hTest, "SUPR3Init failed with rc=%Rrc", rc);
111 return;
112 }
113
114 PVM pVM;
115 RTTESTI_CHECK_RC_RETV(SUPR3PageAlloc(RT_ALIGN_Z(sizeof(*pVM), HOST_PAGE_SIZE) >> HOST_PAGE_SHIFT, 0, (void **)&pVM),
116 VINF_SUCCESS);
117
118
119 PUVM pUVM = (PUVM)RTMemPageAllocZ(sizeof(*pUVM));
120 pUVM->u32Magic = UVM_MAGIC;
121 pUVM->pVM = pVM;
122 pVM->pUVM = pUVM;
123
124 /*
125 * Do the testing.
126 */
127 RTTESTI_CHECK_RC_RETV(STAMR3InitUVM(pUVM), VINF_SUCCESS);
128 RTTESTI_CHECK_RC_RETV(MMR3InitUVM(pUVM), VINF_SUCCESS);
129 RTTESTI_CHECK_RC_RETV(CFGMR3Init(pVM, NULL, NULL), VINF_SUCCESS);
130 RTTESTI_CHECK_RETV(CFGMR3GetRoot(pVM) != NULL);
131
132 doTestsOnDefaultValues(CFGMR3GetRoot(pVM));
133 doGeneralTests(CFGMR3GetRoot(pVM));
134
135
136 /* done */
137 RTTESTI_CHECK_RC_RETV(CFGMR3Term(pVM), VINF_SUCCESS);
138 MMR3TermUVM(pUVM);
139 STAMR3TermUVM(pUVM);
140 DBGFR3TermUVM(pUVM);
141 RTMemPageFree(pUVM, sizeof(*pUVM));
142}
143
144
145static void doStandaloneTests(void)
146{
147 RTTestISub("Standalone");
148 PCFGMNODE pRoot;;
149 RTTESTI_CHECK_RETV((pRoot = CFGMR3CreateTree(NULL)) != NULL);
150 doGeneralTests(pRoot);
151 CFGMR3DestroyTree(pRoot);
152}
153
154
155/**
156 * Entry point.
157 */
158extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
159{
160 RT_NOREF3(argc, argv, envp);
161
162 /*
163 * Init runtime.
164 */
165 RTTEST hTest;
166 RTR3InitExeNoArguments(RTR3INIT_FLAGS_TRY_SUPLIB);
167 RTEXITCODE rcExit = RTTestInitAndCreate("tstCFGM", &hTest);
168 if (rcExit != RTEXITCODE_SUCCESS)
169 return rcExit;
170
171 doInVmmTests(hTest);
172 doStandaloneTests();
173
174 return RTTestSummaryAndDestroy(hTest);
175}
176
177
178#if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
179/**
180 * Main entry point.
181 */
182int main(int argc, char **argv, char **envp)
183{
184 return TrustedMain(argc, argv, envp);
185}
186#endif
187
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