1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 | # $Id: tdCpuPae1.py 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
4 |
|
---|
5 | """
|
---|
6 | VirtualBox Validation Kit - Catch PAE not enabled.
|
---|
7 |
|
---|
8 | Test that switching into PAE mode when it isn't enable, check that it produces
|
---|
9 | the right runtime error.
|
---|
10 | """
|
---|
11 |
|
---|
12 | __copyright__ = \
|
---|
13 | """
|
---|
14 | Copyright (C) 2010-2024 Oracle and/or its affiliates.
|
---|
15 |
|
---|
16 | This file is part of VirtualBox base platform packages, as
|
---|
17 | available from https://www.virtualbox.org.
|
---|
18 |
|
---|
19 | This program is free software; you can redistribute it and/or
|
---|
20 | modify it under the terms of the GNU General Public License
|
---|
21 | as published by the Free Software Foundation, in version 3 of the
|
---|
22 | License.
|
---|
23 |
|
---|
24 | This program is distributed in the hope that it will be useful, but
|
---|
25 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
27 | General Public License for more details.
|
---|
28 |
|
---|
29 | You should have received a copy of the GNU General Public License
|
---|
30 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
31 |
|
---|
32 | The contents of this file may alternatively be used under the terms
|
---|
33 | of the Common Development and Distribution License Version 1.0
|
---|
34 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
35 | in the VirtualBox distribution, in which case the provisions of the
|
---|
36 | CDDL are applicable instead of those of the GPL.
|
---|
37 |
|
---|
38 | You may elect to license modified versions of this file under the
|
---|
39 | terms and conditions of either the GPL or the CDDL or both.
|
---|
40 |
|
---|
41 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
42 | """
|
---|
43 | __version__ = "$Revision: 106061 $"
|
---|
44 |
|
---|
45 |
|
---|
46 | # Standard Python imports.
|
---|
47 | import os;
|
---|
48 | import sys;
|
---|
49 |
|
---|
50 | # Only the main script needs to modify the path.
|
---|
51 | try: __file__ # pylint: disable=used-before-assignment
|
---|
52 | except: __file__ = sys.argv[0];
|
---|
53 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
54 | sys.path.append(g_ksValidationKitDir);
|
---|
55 |
|
---|
56 | # Validation Kit imports.
|
---|
57 | from testdriver import reporter;
|
---|
58 | from testdriver import base;
|
---|
59 | from testdriver import vbox;
|
---|
60 |
|
---|
61 |
|
---|
62 | class tdCpuPae1ConsoleCallbacks(vbox.ConsoleEventHandlerBase):
|
---|
63 | """
|
---|
64 | For catching the PAE runtime error.
|
---|
65 | """
|
---|
66 | def __init__(self, dArgs):
|
---|
67 | oTstDrv = dArgs['oTstDrv'];
|
---|
68 | oVBoxMgr = dArgs['oVBoxMgr']; _ = oVBoxMgr;
|
---|
69 |
|
---|
70 | vbox.ConsoleEventHandlerBase.__init__(self, dArgs, 'tdCpuPae1');
|
---|
71 | self.oTstDrv = oTstDrv;
|
---|
72 |
|
---|
73 | def onRuntimeError(self, fFatal, sErrId, sMessage):
|
---|
74 | """ Verify the error. """
|
---|
75 | reporter.log('onRuntimeError: fFatal=%s sErrId="%s" sMessage="%s"' % (fFatal, sErrId, sMessage));
|
---|
76 | if sErrId != 'PAEmode':
|
---|
77 | reporter.testFailure('sErrId=%s, expected PAEmode' % (sErrId,));
|
---|
78 | elif fFatal is not True:
|
---|
79 | reporter.testFailure('fFatal=%s, expected True' % (fFatal,));
|
---|
80 | else:
|
---|
81 | self.oTstDrv.fCallbackSuccess = True;
|
---|
82 | self.oTstDrv.fCallbackFired = True;
|
---|
83 | self.oVBoxMgr.interruptWaitEvents();
|
---|
84 | return None;
|
---|
85 |
|
---|
86 |
|
---|
87 | class tdCpuPae1(vbox.TestDriver):
|
---|
88 | """
|
---|
89 | PAE Test #1.
|
---|
90 | """
|
---|
91 |
|
---|
92 | def __init__(self):
|
---|
93 | vbox.TestDriver.__init__(self);
|
---|
94 | self.asSkipTests = [];
|
---|
95 | self.asVirtModesDef = ['hwvirt', 'hwvirt-np', 'raw',]
|
---|
96 | self.asVirtModes = self.asVirtModesDef
|
---|
97 | self.acCpusDef = [1, 2,]
|
---|
98 | self.acCpus = self.acCpusDef;
|
---|
99 | self.fCallbackFired = False;
|
---|
100 | self.fCallbackSuccess = False;
|
---|
101 |
|
---|
102 | #
|
---|
103 | # Overridden methods.
|
---|
104 | #
|
---|
105 | def showUsage(self):
|
---|
106 | rc = vbox.TestDriver.showUsage(self);
|
---|
107 | reporter.log('');
|
---|
108 | reporter.log('tdCpuPae1 Options:');
|
---|
109 | reporter.log(' --virt-modes <m1[:m2[:]]');
|
---|
110 | reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef)));
|
---|
111 | reporter.log(' --cpu-counts <c1[:c2[:]]');
|
---|
112 | reporter.log(' Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
|
---|
113 | reporter.log(' --quick');
|
---|
114 | reporter.log(' Shorthand for: --virt-modes raw --cpu-counts 1 32');
|
---|
115 | return rc;
|
---|
116 |
|
---|
117 | def parseOption(self, asArgs, iArg):
|
---|
118 | if asArgs[iArg] == '--virt-modes':
|
---|
119 | iArg += 1;
|
---|
120 | if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
|
---|
121 | self.asVirtModes = asArgs[iArg].split(':');
|
---|
122 | for s in self.asVirtModes:
|
---|
123 | if s not in self.asVirtModesDef:
|
---|
124 | raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
|
---|
125 | % (s, ' '.join(self.asVirtModesDef)));
|
---|
126 | elif asArgs[iArg] == '--cpu-counts':
|
---|
127 | iArg += 1;
|
---|
128 | if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
|
---|
129 | self.acCpus = [];
|
---|
130 | for s in asArgs[iArg].split(':'):
|
---|
131 | try: c = int(s);
|
---|
132 | except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
|
---|
133 | if c <= 0: raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
|
---|
134 | self.acCpus.append(c);
|
---|
135 | elif asArgs[iArg] == '--quick':
|
---|
136 | self.asVirtModes = ['raw',];
|
---|
137 | self.acCpus = [1,];
|
---|
138 | else:
|
---|
139 | return vbox.TestDriver.parseOption(self, asArgs, iArg);
|
---|
140 | return iArg + 1;
|
---|
141 |
|
---|
142 | def getResourceSet(self):
|
---|
143 | return [];
|
---|
144 |
|
---|
145 | def actionConfig(self):
|
---|
146 | # Make sure vboxapi has been imported so we can use the constants.
|
---|
147 | if not self.importVBoxApi():
|
---|
148 | return False;
|
---|
149 |
|
---|
150 | #
|
---|
151 | # Configure a VM with the PAE bootsector as floppy image.
|
---|
152 | #
|
---|
153 |
|
---|
154 | oVM = self.createTestVM('tst-bs-pae', 2, sKind = 'Other', fVirtEx = False, fPae = False, \
|
---|
155 | sFloppy = os.path.join(self.sVBoxBootSectors, 'bootsector-pae.img') );
|
---|
156 | if oVM is None:
|
---|
157 | return False;
|
---|
158 | return True;
|
---|
159 |
|
---|
160 | def actionExecute(self):
|
---|
161 | """
|
---|
162 | Execute the testcase.
|
---|
163 | """
|
---|
164 | return self.test1();
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 | #
|
---|
169 | # Test execution helpers.
|
---|
170 | #
|
---|
171 |
|
---|
172 | def test1OneCfg(self, oVM, cCpus, fHwVirt, fNestedPaging):
|
---|
173 | """
|
---|
174 | Runs the specified VM thru test #1.
|
---|
175 |
|
---|
176 | Returns a success indicator on the general test execution. This is not
|
---|
177 | the actual test result.
|
---|
178 | """
|
---|
179 |
|
---|
180 | # Reconfigure the VM
|
---|
181 | fRc = True;
|
---|
182 | oSession = self.openSession(oVM);
|
---|
183 | if oSession is not None:
|
---|
184 | fRc = fRc and oSession.enableVirtExX86(fHwVirt);
|
---|
185 | fRc = fRc and oSession.enableNestedPagingX86(fNestedPaging);
|
---|
186 | fRc = fRc and oSession.setCpuCount(cCpus);
|
---|
187 | fRc = fRc and oSession.setupBootLogo(True, 2500); # Race avoidance fudge.
|
---|
188 | fRc = fRc and oSession.saveSettings();
|
---|
189 | fRc = oSession.close() and fRc and True; # pychecker hack.
|
---|
190 | oSession = None;
|
---|
191 | else:
|
---|
192 | fRc = False;
|
---|
193 |
|
---|
194 | # Zap the state (used by the callback).
|
---|
195 | self.fCallbackFired = False;
|
---|
196 | self.fCallbackSuccess = False;
|
---|
197 |
|
---|
198 | # Start up.
|
---|
199 | if fRc is True:
|
---|
200 | self.logVmInfo(oVM);
|
---|
201 | oSession = self.startVm(oVM)
|
---|
202 | if oSession is not None:
|
---|
203 | # Set up a callback for catching the runtime error. !Races the guest bootup!
|
---|
204 | oConsoleCallbacks = oSession.registerDerivedEventHandler(tdCpuPae1ConsoleCallbacks, {'oTstDrv':self,})
|
---|
205 |
|
---|
206 | fRc = False;
|
---|
207 | if oConsoleCallbacks is not None:
|
---|
208 | # Wait for 30 seconds for something to finish.
|
---|
209 | tsStart = base.timestampMilli();
|
---|
210 | while base.timestampMilli() - tsStart < 30000:
|
---|
211 | oTask = self.waitForTasks(1000);
|
---|
212 | if oTask is not None:
|
---|
213 | break;
|
---|
214 | if self.fCallbackFired:
|
---|
215 | break;
|
---|
216 | if not self.fCallbackFired:
|
---|
217 | reporter.testFailure('the callback did not fire');
|
---|
218 | fRc = self.fCallbackSuccess;
|
---|
219 |
|
---|
220 | # cleanup.
|
---|
221 | oConsoleCallbacks.unregister();
|
---|
222 | self.terminateVmBySession(oSession) #, fRc);
|
---|
223 | else:
|
---|
224 | fRc = False;
|
---|
225 | return fRc;
|
---|
226 |
|
---|
227 |
|
---|
228 | def test1(self):
|
---|
229 | """
|
---|
230 | Executes test #1 - Negative API testing.
|
---|
231 |
|
---|
232 | ASSUMES that the VMs are
|
---|
233 | """
|
---|
234 | reporter.testStart('Test 1');
|
---|
235 | oVM = self.getVmByName('tst-bs-pae');
|
---|
236 |
|
---|
237 | for cCpus in self.acCpus:
|
---|
238 | if cCpus == 1: reporter.testStart('1 cpu');
|
---|
239 | else: reporter.testStart('%u cpus' % (cCpus));
|
---|
240 |
|
---|
241 | for sVirtMode in self.asVirtModes:
|
---|
242 | if sVirtMode == 'raw' and cCpus > 1:
|
---|
243 | continue;
|
---|
244 |
|
---|
245 | hsVirtModeDesc = {};
|
---|
246 | hsVirtModeDesc['raw'] = 'Raw-mode';
|
---|
247 | hsVirtModeDesc['hwvirt'] = 'HwVirt';
|
---|
248 | hsVirtModeDesc['hwvirt-np'] = 'NestedPaging';
|
---|
249 | reporter.testStart(hsVirtModeDesc[sVirtMode]);
|
---|
250 |
|
---|
251 | fHwVirt = sVirtMode != 'raw';
|
---|
252 | fNestedPaging = sVirtMode == 'hwvirt-np';
|
---|
253 | self.test1OneCfg(oVM, cCpus, fHwVirt, fNestedPaging);
|
---|
254 |
|
---|
255 | reporter.testDone();
|
---|
256 | reporter.testDone();
|
---|
257 |
|
---|
258 | return reporter.testDone()[1] == 0;
|
---|
259 |
|
---|
260 |
|
---|
261 |
|
---|
262 | if __name__ == '__main__':
|
---|
263 | sys.exit(tdCpuPae1().main(sys.argv));
|
---|
264 |
|
---|