summaryrefslogtreecommitdiffstats
path: root/src/VBox/ValidationKit/tests/cpu/tdCpuPae1.py
blob: b0d6c3428da91c5c4d8ae3beb59e93e376326885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# $Id: tdCpuPae1.py $

"""
VirtualBox Validation Kit - Catch PAE not enabled.

Test that switching into PAE mode when it isn't enable, check that it produces
the right runtime error.
"""

__copyright__ = \
"""
Copyright (C) 2010-2023 Oracle and/or its affiliates.

This file is part of VirtualBox base platform packages, as
available from https://www.virtualbox.org.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, in version 3 of the
License.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses>.

The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
in the VirtualBox distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.

You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.

SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
"""
__version__ = "$Revision: 155244 $"


# Standard Python imports.
import os;
import sys;

# Only the main script needs to modify the path.
try:    __file__
except: __file__ = sys.argv[0];
g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
sys.path.append(g_ksValidationKitDir);

# Validation Kit imports.
from testdriver import reporter;
from testdriver import base;
from testdriver import vbox;


class tdCpuPae1ConsoleCallbacks(vbox.ConsoleEventHandlerBase):
    """
    For catching the PAE runtime error.
    """
    def __init__(self, dArgs):
        oTstDrv  = dArgs['oTstDrv'];
        oVBoxMgr = dArgs['oVBoxMgr']; _ = oVBoxMgr;

        vbox.ConsoleEventHandlerBase.__init__(self, dArgs, 'tdCpuPae1');
        self.oTstDrv  = oTstDrv;

    def onRuntimeError(self, fFatal, sErrId, sMessage):
        """ Verify the error. """
        reporter.log('onRuntimeError: fFatal=%s sErrId="%s" sMessage="%s"' % (fFatal, sErrId, sMessage));
        if sErrId != 'PAEmode':
            reporter.testFailure('sErrId=%s, expected PAEmode' % (sErrId,));
        elif fFatal is not True:
            reporter.testFailure('fFatal=%s, expected True' % (fFatal,));
        else:
            self.oTstDrv.fCallbackSuccess = True;
        self.oTstDrv.fCallbackFired = True;
        self.oVBoxMgr.interruptWaitEvents();
        return None;


class tdCpuPae1(vbox.TestDriver):
    """
    PAE Test #1.
    """

    def __init__(self):
        vbox.TestDriver.__init__(self);
        self.asSkipTests        = [];
        self.asVirtModesDef     = ['hwvirt', 'hwvirt-np', 'raw',]
        self.asVirtModes        = self.asVirtModesDef
        self.acCpusDef          = [1, 2,]
        self.acCpus             = self.acCpusDef;
        self.fCallbackFired     = False;
        self.fCallbackSuccess   = False;

    #
    # Overridden methods.
    #
    def showUsage(self):
        rc = vbox.TestDriver.showUsage(self);
        reporter.log('');
        reporter.log('tdCpuPae1 Options:');
        reporter.log('  --virt-modes   <m1[:m2[:]]');
        reporter.log('      Default: %s' % (':'.join(self.asVirtModesDef)));
        reporter.log('  --cpu-counts   <c1[:c2[:]]');
        reporter.log('      Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
        reporter.log('  --quick');
        reporter.log('      Shorthand for: --virt-modes raw --cpu-counts 1 32');
        return rc;

    def parseOption(self, asArgs, iArg):
        if asArgs[iArg] == '--virt-modes':
            iArg += 1;
            if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
            self.asVirtModes = asArgs[iArg].split(':');
            for s in self.asVirtModes:
                if s not in self.asVirtModesDef:
                    raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
                        % (s, ' '.join(self.asVirtModesDef)));
        elif asArgs[iArg] == '--cpu-counts':
            iArg += 1;
            if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
            self.acCpus = [];
            for s in asArgs[iArg].split(':'):
                try: c = int(s);
                except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
                if c <= 0:  raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
                self.acCpus.append(c);
        elif asArgs[iArg] == '--quick':
            self.asVirtModes        = ['raw',];
            self.acCpus             = [1,];
        else:
            return vbox.TestDriver.parseOption(self, asArgs, iArg);
        return iArg + 1;

    def getResourceSet(self):
        return [];

    def actionConfig(self):
        # Make sure vboxapi has been imported so we can use the constants.
        if not self.importVBoxApi():
            return False;

        #
        # Configure a VM with the PAE bootsector as floppy image.
        #

        oVM = self.createTestVM('tst-bs-pae', 2, sKind = 'Other', fVirtEx = False, fPae = False, \
                                sFloppy = os.path.join(self.sVBoxBootSectors, 'bootsector-pae.img') );
        if oVM is None:
            return False;
        return True;

    def actionExecute(self):
        """
        Execute the testcase.
        """
        return self.test1();



    #
    # Test execution helpers.
    #

    def test1OneCfg(self, oVM, cCpus, fHwVirt, fNestedPaging):
        """
        Runs the specified VM thru test #1.

        Returns a success indicator on the general test execution. This is not
        the actual test result.
        """

        # Reconfigure the VM
        fRc = True;
        oSession = self.openSession(oVM);
        if oSession is not None:
            fRc = fRc and oSession.enableVirtEx(fHwVirt);
            fRc = fRc and oSession.enableNestedPaging(fNestedPaging);
            fRc = fRc and oSession.setCpuCount(cCpus);
            fRc = fRc and oSession.setupBootLogo(True, 2500); # Race avoidance fudge.
            fRc = fRc and oSession.saveSettings();
            fRc = oSession.close() and fRc and True; # pychecker hack.
            oSession = None;
        else:
            fRc = False;

        # Zap the state (used by the callback).
        self.fCallbackFired = False;
        self.fCallbackSuccess = False;

        # Start up.
        if fRc is True:
            self.logVmInfo(oVM);
            oSession = self.startVm(oVM)
            if oSession is not None:
                # Set up a callback for catching the runtime error. !Races the guest bootup!
                oConsoleCallbacks = oSession.registerDerivedEventHandler(tdCpuPae1ConsoleCallbacks, {'oTstDrv':self,})

                fRc = False;
                if oConsoleCallbacks is not None:
                    # Wait for 30 seconds for something to finish.
                    tsStart = base.timestampMilli();
                    while base.timestampMilli() - tsStart < 30000:
                        oTask = self.waitForTasks(1000);
                        if oTask is not None:
                            break;
                        if self.fCallbackFired:
                            break;
                    if not self.fCallbackFired:
                        reporter.testFailure('the callback did not fire');
                    fRc = self.fCallbackSuccess;

                    # cleanup.
                    oConsoleCallbacks.unregister();
                self.terminateVmBySession(oSession) #, fRc);
            else:
                fRc = False;
        return fRc;


    def test1(self):
        """
        Executes test #1 - Negative API testing.

        ASSUMES that the VMs are
        """
        reporter.testStart('Test 1');
        oVM = self.getVmByName('tst-bs-pae');

        for cCpus in self.acCpus:
            if cCpus == 1:  reporter.testStart('1 cpu');
            else:           reporter.testStart('%u cpus' % (cCpus));

            for sVirtMode in self.asVirtModes:
                if sVirtMode == 'raw' and cCpus > 1:
                    continue;

                hsVirtModeDesc = {};
                hsVirtModeDesc['raw']       = 'Raw-mode';
                hsVirtModeDesc['hwvirt']    = 'HwVirt';
                hsVirtModeDesc['hwvirt-np'] = 'NestedPaging';
                reporter.testStart(hsVirtModeDesc[sVirtMode]);

                fHwVirt       = sVirtMode != 'raw';
                fNestedPaging = sVirtMode == 'hwvirt-np';
                self.test1OneCfg(oVM, cCpus, fHwVirt, fNestedPaging);

                reporter.testDone();
            reporter.testDone();

        return reporter.testDone()[1] == 0;



if __name__ == '__main__':
    sys.exit(tdCpuPae1().main(sys.argv));