VirtualBox

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

Last change on this file since 94409 was 93554, checked in by vboxsync, 3 years ago

VMM: Changed PAGE_SIZE -> GUEST_PAGE_SIZE / HOST_PAGE_SIZE, PAGE_SHIFT -> GUEST_PAGE_SHIFT / HOST_PAGE_SHIFT, and PAGE_OFFSET_MASK -> GUEST_PAGE_OFFSET_MASK / HOST_PAGE_OFFSET_MASK. Also removed most usage of ASMMemIsZeroPage and ASMMemZeroPage since the host and guest page size doesn't need to be the same any more. Some work left to do in the page pool code. bugref:9898

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