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