VirtualBox

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

Last change on this file since 64468 was 62776, checked in by vboxsync, 8 years ago

VMM: warnings.

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