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