1 | /* $Id: tstCFGM.cpp 86361 2020-09-30 18:59:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Testcase for CFGM.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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 |
|
---|
40 | static 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 |
|
---|
73 | static 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 |
|
---|
92 | static 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), PAGE_SIZE) >> PAGE_SHIFT, (void **)&pVM), VINF_SUCCESS);
|
---|
106 |
|
---|
107 |
|
---|
108 | PUVM pUVM = (PUVM)RTMemPageAllocZ(sizeof(*pUVM));
|
---|
109 | pUVM->u32Magic = UVM_MAGIC;
|
---|
110 | pUVM->pVM = pVM;
|
---|
111 | pVM->pUVM = pUVM;
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * Do the testing.
|
---|
115 | */
|
---|
116 | RTTESTI_CHECK_RC_RETV(STAMR3InitUVM(pUVM), VINF_SUCCESS);
|
---|
117 | RTTESTI_CHECK_RC_RETV(MMR3InitUVM(pUVM), VINF_SUCCESS);
|
---|
118 | RTTESTI_CHECK_RC_RETV(CFGMR3Init(pVM, NULL, NULL), VINF_SUCCESS);
|
---|
119 | RTTESTI_CHECK_RETV(CFGMR3GetRoot(pVM) != NULL);
|
---|
120 |
|
---|
121 | doTestsOnDefaultValues(CFGMR3GetRoot(pVM));
|
---|
122 | doGeneralTests(CFGMR3GetRoot(pVM));
|
---|
123 |
|
---|
124 |
|
---|
125 | /* done */
|
---|
126 | RTTESTI_CHECK_RC_RETV(CFGMR3Term(pVM), VINF_SUCCESS);
|
---|
127 | MMR3TermUVM(pUVM);
|
---|
128 | STAMR3TermUVM(pUVM);
|
---|
129 | DBGFR3TermUVM(pUVM);
|
---|
130 | RTMemPageFree(pUVM, sizeof(*pUVM));
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | static void doStandaloneTests(void)
|
---|
135 | {
|
---|
136 | RTTestISub("Standalone");
|
---|
137 | PCFGMNODE pRoot;;
|
---|
138 | RTTESTI_CHECK_RETV((pRoot = CFGMR3CreateTree(NULL)) != NULL);
|
---|
139 | doGeneralTests(pRoot);
|
---|
140 | CFGMR3DestroyTree(pRoot);
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Entry point.
|
---|
146 | */
|
---|
147 | extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
|
---|
148 | {
|
---|
149 | RT_NOREF3(argc, argv, envp);
|
---|
150 |
|
---|
151 | /*
|
---|
152 | * Init runtime.
|
---|
153 | */
|
---|
154 | RTTEST hTest;
|
---|
155 | RTR3InitExeNoArguments(RTR3INIT_FLAGS_SUPLIB);
|
---|
156 | RTEXITCODE rcExit = RTTestInitAndCreate("tstCFGM", &hTest);
|
---|
157 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
158 | return rcExit;
|
---|
159 |
|
---|
160 | doInVmmTests(hTest);
|
---|
161 | doStandaloneTests();
|
---|
162 |
|
---|
163 | return RTTestSummaryAndDestroy(hTest);
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | #if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
|
---|
168 | /**
|
---|
169 | * Main entry point.
|
---|
170 | */
|
---|
171 | int main(int argc, char **argv, char **envp)
|
---|
172 | {
|
---|
173 | return TrustedMain(argc, argv, envp);
|
---|
174 | }
|
---|
175 | #endif
|
---|
176 |
|
---|