1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdBenchmark2.py 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Test that runs various benchmarks.
|
---|
7 | """
|
---|
8 |
|
---|
9 | __copyright__ = \
|
---|
10 | """
|
---|
11 | Copyright (C) 2010-2022 Oracle and/or its affiliates.
|
---|
12 |
|
---|
13 | This file is part of VirtualBox base platform packages, as
|
---|
14 | available from https://www.virtualbox.org.
|
---|
15 |
|
---|
16 | This program is free software; you can redistribute it and/or
|
---|
17 | modify it under the terms of the GNU General Public License
|
---|
18 | as published by the Free Software Foundation, in version 3 of the
|
---|
19 | License.
|
---|
20 |
|
---|
21 | This program is distributed in the hope that it will be useful, but
|
---|
22 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
24 | General Public License for more details.
|
---|
25 |
|
---|
26 | You should have received a copy of the GNU General Public License
|
---|
27 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
28 |
|
---|
29 | The contents of this file may alternatively be used under the terms
|
---|
30 | of the Common Development and Distribution License Version 1.0
|
---|
31 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
32 | in the VirtualBox distribution, in which case the provisions of the
|
---|
33 | CDDL are applicable instead of those of the GPL.
|
---|
34 |
|
---|
35 | You may elect to license modified versions of this file under the
|
---|
36 | terms and conditions of either the GPL or the CDDL or both.
|
---|
37 |
|
---|
38 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
39 | """
|
---|
40 | __version__ = "$Revision: 96407 $"
|
---|
41 |
|
---|
42 |
|
---|
43 | # Standard Python imports.
|
---|
44 | import os;
|
---|
45 | import sys;
|
---|
46 |
|
---|
47 | # Only the main script needs to modify the path.
|
---|
48 | try: __file__
|
---|
49 | except: __file__ = sys.argv[0];
|
---|
50 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
51 | sys.path.append(g_ksValidationKitDir);
|
---|
52 |
|
---|
53 | # Validation Kit imports.
|
---|
54 | from testdriver import reporter;
|
---|
55 | from testdriver import vbox;
|
---|
56 | from testdriver import vboxcon;
|
---|
57 | from testdriver import vboxtestvms;
|
---|
58 |
|
---|
59 |
|
---|
60 | class tdBenchmark2(vbox.TestDriver):
|
---|
61 | """
|
---|
62 | Benchmark #2 - Memory.
|
---|
63 | """
|
---|
64 |
|
---|
65 | def __init__(self):
|
---|
66 | vbox.TestDriver.__init__(self);
|
---|
67 | oTestVm = vboxtestvms.BootSectorTestVm(self.oTestVmSet, 'tst-bs-memalloc-1',
|
---|
68 | os.path.join(self.sVBoxBootSectors, 'bs3-memalloc-1.img'));
|
---|
69 | self.oTestVmSet.aoTestVms.append(oTestVm);
|
---|
70 |
|
---|
71 |
|
---|
72 | #
|
---|
73 | # Overridden methods.
|
---|
74 | #
|
---|
75 |
|
---|
76 |
|
---|
77 | def actionConfig(self):
|
---|
78 | self._detectValidationKit();
|
---|
79 | return self.oTestVmSet.actionConfig(self);
|
---|
80 |
|
---|
81 | def actionExecute(self):
|
---|
82 | return self.oTestVmSet.actionExecute(self, self.testOneCfg);
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 | #
|
---|
87 | # Test execution helpers.
|
---|
88 | #
|
---|
89 |
|
---|
90 | def testOneCfg(self, oVM, oTestVm):
|
---|
91 | """
|
---|
92 | Runs the specified VM thru the tests.
|
---|
93 |
|
---|
94 | Returns a success indicator on the general test execution. This is not
|
---|
95 | the actual test result.
|
---|
96 | """
|
---|
97 | fRc = False;
|
---|
98 |
|
---|
99 | #
|
---|
100 | # Determin the RAM configurations we want to test.
|
---|
101 | #
|
---|
102 | cMbMaxGuestRam = self.oVBox.systemProperties.maxGuestRAM;
|
---|
103 | cMbHostAvail = self.oVBox.host.memoryAvailable;
|
---|
104 | cMbHostTotal = self.oVBox.host.memorySize;
|
---|
105 | reporter.log('cMbMaxGuestRam=%s cMbHostAvail=%s cMbHostTotal=%s' % (cMbMaxGuestRam, cMbHostAvail, cMbHostTotal,));
|
---|
106 |
|
---|
107 | cMbHostAvail -= cMbHostAvail // 7; # Rough 14% safety/overhead margin.
|
---|
108 | if cMbMaxGuestRam < cMbHostAvail:
|
---|
109 | # Currently: 2048 GiB, 1536 GiB, 1024 GiB, 512 GiB, 256 GiB, 128 GiB, 64 GiB, 32 GiB
|
---|
110 | acMbRam = [ cMbMaxGuestRam, cMbMaxGuestRam // 4 * 3, cMbMaxGuestRam // 2, cMbMaxGuestRam // 4,
|
---|
111 | cMbMaxGuestRam // 8, cMbMaxGuestRam // 16 ];
|
---|
112 | if acMbRam[-1] > 64*1024:
|
---|
113 | acMbRam.append(64*1024);
|
---|
114 | if acMbRam[-1] > 32*1024:
|
---|
115 | acMbRam.append(32*1024);
|
---|
116 | elif cMbHostAvail > 8*1024:
|
---|
117 | # First entry is available memory rounded down to the nearest 8 GiB
|
---|
118 | cMbHostAvail = cMbHostAvail & ~(8 * 1024 - 1);
|
---|
119 | acMbRam = [ cMbHostAvail, ];
|
---|
120 |
|
---|
121 | # The remaining entries are powers of two below that, up to 6 of these stopping at 16 GiB.
|
---|
122 | cMb = 8*1024;
|
---|
123 | while cMb < cMbHostAvail:
|
---|
124 | cMb *= 2;
|
---|
125 | while len(acMbRam) < 7 and cMb > 16 * 1024:
|
---|
126 | cMb //= 2;
|
---|
127 | acMbRam.append(cMb);
|
---|
128 | elif cMbHostAvail >= 16000 and cMbHostAvail > 7168:
|
---|
129 | # Desperate attempt at getting some darwin testruns too. We've got two
|
---|
130 | # with 16 GiB and they usually end up with just short of 8GiB of free RAM.
|
---|
131 | acMbRam = [7168,];
|
---|
132 | else:
|
---|
133 | reporter.log("Less than 8GB of host RAM available for VMs, skipping test");
|
---|
134 | return None;
|
---|
135 | reporter.log("RAM configurations: %s" % (acMbRam));
|
---|
136 |
|
---|
137 | # Large pages only work with nested paging.
|
---|
138 | afLargePages = [False, ];
|
---|
139 | try:
|
---|
140 | if oVM.getHWVirtExProperty(vboxcon.HWVirtExPropertyType_NestedPaging):
|
---|
141 | afLargePages = [True, False];
|
---|
142 | except:
|
---|
143 | return reporter.errorXcpt("Failed to get HWVirtExPropertyType_NestedPaging");
|
---|
144 |
|
---|
145 | #
|
---|
146 | # Test the RAM configurations.
|
---|
147 | #
|
---|
148 | for fLargePages in afLargePages:
|
---|
149 | sLargePages = 'large pages' if fLargePages is True else 'no large pages';
|
---|
150 | for cMbRam in acMbRam:
|
---|
151 | reporter.testStart('%s MiB, %s' % (cMbRam, sLargePages));
|
---|
152 |
|
---|
153 | # Reconfigure the VM:
|
---|
154 | fRc = False
|
---|
155 | oSession = self.openSession(oVM);
|
---|
156 | if oSession:
|
---|
157 | fRc = oSession.setRamSize(cMbRam);
|
---|
158 | fRc = oSession.setLargePages(fLargePages) and fRc;
|
---|
159 | if fRc:
|
---|
160 | fRc = oSession.saveSettings();
|
---|
161 | if not fRc:
|
---|
162 | oSession.discardSettings(True);
|
---|
163 | oSession.close();
|
---|
164 | if fRc:
|
---|
165 | # Set up the result file
|
---|
166 | sXmlFile = self.prepareResultFile();
|
---|
167 | asEnv = [ 'IPRT_TEST_FILE=' + sXmlFile, ];
|
---|
168 |
|
---|
169 | # Do the test:
|
---|
170 | self.logVmInfo(oVM);
|
---|
171 | oSession = self.startVm(oVM, sName = oTestVm.sVmName, asEnv = asEnv);
|
---|
172 | if oSession is not None:
|
---|
173 | cMsTimeout = 15 * 60000 + cMbRam // 168;
|
---|
174 | if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
|
---|
175 | cMsTimeout = self.adjustTimeoutMs(180 * 60000 + cMbRam // 168);
|
---|
176 |
|
---|
177 | oRc = self.waitForTasks(cMsTimeout);
|
---|
178 | if oRc == oSession:
|
---|
179 | fRc = oSession.assertPoweredOff();
|
---|
180 | else:
|
---|
181 | reporter.error('oRc=%s, expected %s' % (oRc, oSession));
|
---|
182 |
|
---|
183 | reporter.addSubXmlFile(sXmlFile);
|
---|
184 | self.terminateVmBySession(oSession);
|
---|
185 | else:
|
---|
186 | reporter.errorXcpt("Failed to set memory size to %s MiB or setting largePages to %s" % (cMbRam, fLargePages));
|
---|
187 | reporter.testDone();
|
---|
188 |
|
---|
189 | return fRc;
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 | if __name__ == '__main__':
|
---|
194 | sys.exit(tdBenchmark2().main(sys.argv));
|
---|
195 |
|
---|