cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVMM Guest OS boot tests.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2010-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard Python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Only the main script needs to modify the path.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncg_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync VMM Unit Tests Set.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync - Create VM that corresponds to Guest OS pre-installed on selected HDD
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync - Start VM and wait for TXS server connection (which is started after Guest successfully booted)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # VM parameters required to run HDD image.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Format: { HDD image filename: (sKind, HDD controller type) }
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 't-win80.vdi': ( 'Windows 8 (64 bit)', ksSataController ),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # List of platforms which are able to suspend and resume host automatically.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # In order to add new platform, self._SuspendResume() should be adapted.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize child class instance.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sHddPathBase = os.path.join(self.sResourcePath, '4.2', 'nat', 'win80')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # TODO: that should be moved to some common place
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Overridden methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Extend usage info
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Extend standard options set
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--boot-hdd" option requires an argument')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--cpus" option requires an argument')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--suspend-time" option requires an argument')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--shutdown-iters" option requires an argument')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return vbox.TestDriver.parseOption(self, asArgs, iArg)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a set of file and/or directory names relative to
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync TESTBOX_PATH_RESOURCES.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return [os.path.join(self.sHddPathBase, sRsrc) for sRsrc in self.kaoVmParams];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Get VM params specific to HDD image
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sKind, sController = self.kaoVmParams[self.sHddName]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Create VM itself
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eNic0AttachType = vboxcon.NetworkAttachmentType_NAT
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sHddPath = os.path.join(self.sHddPathBase, self.sHddName)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.createTestVM(sVmName, 1, sKind=sKind, cCpus=self.cCpus,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eNic0AttachType=eNic0AttachType, sDvdImage = self.sVBoxValidationKitIso)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert oVM is not None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Attach an HDD
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = oSession.attachHd(sHddPath, sController, fImmutable=True)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable HW virt
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable I/O APIC
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and oSession.enableIoApic(self.fEnableIOAPIC)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable Nested Paging
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and oSession.enableNestedPaging(self.fEnableNestedPaging)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Enable PAE
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if (sNicTraceFile is not None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and oSession.setNicTraceEnabled(True, sNicTraceFile)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Remote desktop
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Configure pre-conditions.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Save time: do not start VM if there is no way to suspend host
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if (self.fSuspendHost is True and sys.platform not in self.kasSuspendAllowedPlatforms):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Platform [%s] is not in the list of supported platforms' % sys.platform)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Error: unknown HDD image specified: %s' % self.sHddName)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Put host into sleep and automatically resume it after specified timeout.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = os.system("/usr/bin/pmset relative wake %d" % self.cSecSuspendTime)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait for host to wake up
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while ((time.time() - tsStart) < self.cSecSuspendTime):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Idle loop until user press CTRL+C
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('[LOCAL CATCH]: waiting for keyboard interrupt')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('[LOCAL CATCH]: keyboard interrupt occurred')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Execute the testcase itself.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #self.logVmInfo(self.oVM)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oExtraSession, oExtraTxsSession = self.startVmAndConnectToTxsViaTcp(self.sExtraVmName,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oExtraSession is None or oExtraTxsSession is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(self.sVmName,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oSession is not None and oTxsSession is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait until guest reported success
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Guest started. Connection to TXS service established.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and self.txsDisconnect(oSession, oTxsSession)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Put host to sleep and resume it automatically after %d seconds.' % self.cSecSuspendTime)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and self._SuspendResume(self.cSecSuspendTime)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (fRc, oTxsSession) = self.txsDoConnectViaTcp(oSession, 2 * 60 * 10000)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = fRc and oTxsSession.syncShutdown(cMsTimeout=(4 * 60 * 1000))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Shutdown request issued successfully.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.waitOnDirectSessionClose(self.oVM, self.kcMsVmShutdownLimit)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('Shutdown %s.' % ('success' if fRc is True else 'failed'))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Do not terminate failing VM in order to catch it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.error('Guest did not start (iteration %d of %d)' % (cIter, self.cShutdownIters))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Stop if fail
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Local catch at the end.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log("Test completed. Waiting for user to press CTRL+C.")