コード例 #1
0
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

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

        sXmlFile = self.prepareResultFile();
        asEnv = [ 'IPRT_TEST_FILE=' + sXmlFile];

        self.logVmInfo(oVM);
        oSession = self.startVm(oVM, sName = oTestVm.sVmName, asEnv = asEnv);
        if oSession is not None:
            self.addTask(oSession);

            cMsTimeout = 15*60*1000;
            if not reporter.isLocal(): ## @todo need to figure a better way of handling timeouts on the testboxes ...
                cMsTimeout = self.adjustTimeoutMs(180 * 60000);

            oRc = self.waitForTasks(cMsTimeout);
            self.removeTask(oSession);
            if oRc == oSession:
                fRc = oSession.assertPoweredOff();
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession));

            reporter.addSubXmlFile(sXmlFile);
            self.terminateVmBySession(oSession);
        return fRc;
コード例 #2
0
ファイル: tdBenchmark1.py プロジェクト: sailfishos/virtualbox
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

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

        sXmlFile = self.prepareResultFile()
        asEnv = ['IPRT_TEST_FILE=' + sXmlFile]

        self.logVmInfo(oVM)
        oSession = self.startVm(oVM, sName=oTestVm.sVmName, asEnv=asEnv)
        if oSession is not None:
            cMsTimeout = 15 * 60 * 1000
            if not reporter.isLocal(
            ):  ## @todo need to figure a better way of handling timeouts on the testboxes ...
                cMsTimeout = self.adjustTimeoutMs(180 * 60000)

            oRc = self.waitForTasks(cMsTimeout)
            if oRc == oSession:
                fRc = oSession.assertPoweredOff()
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession))

            reporter.addSubXmlFile(sXmlFile)
            self.terminateVmBySession(oSession)
        return fRc
コード例 #3
0
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

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

        sXmlFile = self.prepareResultFile()
        asEnv = ['IPRT_TEST_FILE=' + sXmlFile]

        self.logVmInfo(oVM)
        oSession = self.startVm(oVM, sName=oTestVm.sVmName, asEnv=asEnv)
        if oSession is not None:
            self.addTask(oSession)

            oRc = self.waitForTasks(15 * 60 * 1000)
            self.removeTask(oSession)
            if oRc == oSession:
                fRc = oSession.assertPoweredOff()
            else:
                reporter.error('oRc=%s, expected %s' % (oRc, oSession))

            reporter.addSubXmlFile(sXmlFile)
            self.terminateVmBySession(oSession)
        return fRc
コード例 #4
0
    def _executeTestCase(self, sName, sFullPath, sTestCaseSubDir, oDevNull): # pylint: disable=R0914
        """
        Executes a test case.
        """

        fSkipped = False;

        #
        # If hardening is enabled, some test cases and their dependencies
        # needs to be copied to and execute from the sVBoxInstallRoot
        # directory in order to work. They also have to be executed as
        # root, i.e. via sudo.
        #
        fHardened       = False;
        asFilesToRemove = []; # Stuff to clean up.
        asDirsToRemove  = []; # Ditto.
        if    sName in self.kasHardened \
          and self.sUnitTestsPathBase != self.sVBoxInstallRoot:

            sDstDir = os.path.join(self.sVBoxInstallRoot, sTestCaseSubDir);
            if not os.path.exists(sDstDir):
                self._hardenedMkDir(sDstDir);
                asDirsToRemove.append(sDstDir);

            sDst = os.path.join(sDstDir, os.path.basename(sFullPath));
            self._hardenedCopyFile(sFullPath, sDst, 0755);
            asFilesToRemove.append(sDst);

            # Copy any associated .dll/.so/.dylib.
            for sSuff in [ '.dll', '.so', '.dylib' ]:
                sSrc = os.path.splitext(sFullPath)[0] + sSuff;
                if os.path.exists(sSrc):
                    sDst = os.path.join(sDstDir, os.path.basename(sSrc));
                    self._hardenedCopyFile(sSrc, sDst, 0644);
                    asFilesToRemove.append(sDst);

            # Copy any associated .r0, .rc and .gc modules.
            offDriver = sFullPath.rfind('Driver')
            if offDriver > 0:
                for sSuff in [ '.r0', 'RC.rc', 'RC.gc' ]:
                    sSrc = sFullPath[:offDriver] + sSuff;
                    if os.path.exists(sSrc):
                        sDst = os.path.join(sDstDir, os.path.basename(sSrc));
                        self._hardenedCopyFile(sSrc, sDst, 0644);
                        asFilesToRemove.append(sDst);

            sFullPath = os.path.join(sDstDir, os.path.basename(sFullPath));
            fHardened = True;

        #
        # Set up arguments and environment.
        #
        asArgs = [sFullPath,]
        if sName in self.kdArguments:
            asArgs.extend(self.kdArguments[sName]);

        os.environ['IPRT_TEST_OMIT_TOP_TEST'] = '1';
        os.environ['IPRT_TEST_FILE'] = sXmlFile = os.path.join(self.sScratchPath, 'result.xml');
        if os.path.exists(sXmlFile):
            try:    os.unlink(sXmlFile);
            except: self._hardenedDeleteFile(sXmlFile);

        #
        # Execute the test case.
        #
        # Windows is confusing output.  Trying a few things to get rid of this.
        # First, flush both stderr and stdout before running the child.  Second,
        # assign the child stderr to stdout.  If this doesn't help, we'll have
        # to capture the child output.
        #
        reporter.log('*** Executing %s%s...' % (asArgs, ' [hardened]' if fHardened else ''));
        try:    sys.stdout.flush();
        except: pass;
        try:    sys.stderr.flush();
        except: pass;
        if not self.fDryRun:
            try:
                if fHardened:
                    oChild = utils.sudoProcessPopen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
                else:
                    oChild = subprocess.Popen(      asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
            except:
                if sName in [ 'tstAsmStructsRC',    # 32-bit, may fail to start on 64-bit linux. Just ignore.
                              ]:
                    reporter.logXcpt();
                    fSkipped = True;
                else:
                    reporter.errorXcpt();
                iRc    = 1023;
                oChild = None;

            if oChild is not None:
                self.pidFileAdd(oChild.pid, fSudo = fHardened);
                iRc = oChild.wait();
                self.pidFileRemove(oChild.pid);
        else:
            iRc = 0;

        #
        # Clean up
        #
        for sPath in asFilesToRemove:
            self._hardenedDeleteFile(sPath);
        for sPath in asDirsToRemove:
            self._hardenedRemoveDir(sPath);

        #
        # Report.
        #
        if os.path.exists(sXmlFile):
            reporter.addSubXmlFile(sXmlFile);
            if fHardened:
                self._hardenedDeleteFile(sXmlFile);
            else:
                os.unlink(sXmlFile);

        if iRc == 0:
            reporter.log('*** %s: exit code %d' % (sFullPath, iRc));
            self.cPassed += 1

        elif iRc == 4: # RTEXITCODE_SKIPPED
            reporter.log('*** %s: exit code %d (RTEXITCODE_SKIPPED)' % (sFullPath, iRc));
            fSkipped = True;
            self.cSkipped += 1;

        elif fSkipped:
            reporter.log('*** %s: exit code %d (Skipped)' % (sFullPath, iRc));
            self.cSkipped += 1;

        else:
            sName = self.kdExitCodeNames.get(iRc, '');
            if iRc in self.kdExitCodeNamesWin and utils.getHostOs() == 'win':
                sName = self.kdExitCodeNamesWin[iRc];
            if sName != '':
                sName = ' (%s)' % (sName);

            if iRc != 1:
                reporter.testFailure('Exit status: %d%s' % (iRc, sName));
                reporter.log(  '!*! %s: exit code %d%s' % (sFullPath, iRc, sName));
            else:
                reporter.error('!*! %s: exit code %d%s' % (sFullPath, iRc, sName));
            self.cFailed += 1

        return fSkipped;
コード例 #5
0
    def _executeTestCase(self, sName, sFullPath, sTestCaseSubDir, oDevNull):  # pylint: disable=R0914
        """
        Executes a test case.
        """

        fSkipped = False

        #
        # If hardening is enabled, some test cases and their dependencies
        # needs to be copied to and execute from the sVBoxInstallRoot
        # directory in order to work. They also have to be executed as
        # root, i.e. via sudo.
        #
        fHardened = False
        asFilesToRemove = []
        # Stuff to clean up.
        asDirsToRemove = []
        # Ditto.
        if    sName in self.kasHardened \
          and self.sUnitTestsPathBase != self.sVBoxInstallRoot:

            sDstDir = os.path.join(self.sVBoxInstallRoot, sTestCaseSubDir)
            if not os.path.exists(sDstDir):
                self._hardenedMkDir(sDstDir)
                asDirsToRemove.append(sDstDir)

            sDst = os.path.join(sDstDir, os.path.basename(sFullPath))
            self._hardenedCopyFile(sFullPath, sDst, 0o755)
            asFilesToRemove.append(sDst)

            # Copy any associated .dll/.so/.dylib.
            for sSuff in ['.dll', '.so', '.dylib']:
                sSrc = os.path.splitext(sFullPath)[0] + sSuff
                if os.path.exists(sSrc):
                    sDst = os.path.join(sDstDir, os.path.basename(sSrc))
                    self._hardenedCopyFile(sSrc, sDst, 0o644)
                    asFilesToRemove.append(sDst)

            # Copy any associated .r0, .rc and .gc modules.
            offDriver = sFullPath.rfind('Driver')
            if offDriver > 0:
                for sSuff in ['.r0', 'RC.rc', 'RC.gc']:
                    sSrc = sFullPath[:offDriver] + sSuff
                    if os.path.exists(sSrc):
                        sDst = os.path.join(sDstDir, os.path.basename(sSrc))
                        self._hardenedCopyFile(sSrc, sDst, 0o644)
                        asFilesToRemove.append(sDst)

            sFullPath = os.path.join(sDstDir, os.path.basename(sFullPath))
            fHardened = True

        #
        # Set up arguments and environment.
        #
        asArgs = [
            sFullPath,
        ]
        if sName in self.kdArguments:
            asArgs.extend(self.kdArguments[sName])

        os.environ['IPRT_TEST_OMIT_TOP_TEST'] = '1'
        os.environ['IPRT_TEST_FILE'] = sXmlFile = os.path.join(
            self.sScratchPath, 'result.xml')
        if os.path.exists(sXmlFile):
            try:
                os.unlink(sXmlFile)
            except:
                self._hardenedDeleteFile(sXmlFile)

        #
        # Execute the test case.
        #
        # Windows is confusing output.  Trying a few things to get rid of this.
        # First, flush both stderr and stdout before running the child.  Second,
        # assign the child stderr to stdout.  If this doesn't help, we'll have
        # to capture the child output.
        #
        reporter.log('*** Executing %s%s...' %
                     (asArgs, ' [hardened]' if fHardened else ''))
        try:
            sys.stdout.flush()
        except:
            pass
        try:
            sys.stderr.flush()
        except:
            pass
        if not self.fDryRun:
            try:
                if fHardened:
                    oChild = utils.sudoProcessPopen(asArgs,
                                                    stdin=oDevNull,
                                                    stdout=sys.stdout,
                                                    stderr=sys.stdout)
                else:
                    oChild = utils.processPopenSafe(asArgs,
                                                    stdin=oDevNull,
                                                    stdout=sys.stdout,
                                                    stderr=sys.stdout)
            except:
                if sName in [
                        'tstAsmStructsRC',  # 32-bit, may fail to start on 64-bit linux. Just ignore.
                ]:
                    reporter.logXcpt()
                    fSkipped = True
                else:
                    reporter.errorXcpt()
                iRc = 1023
                oChild = None

            if oChild is not None:
                self.pidFileAdd(oChild.pid, sName, fSudo=fHardened)
                iRc = oChild.wait()
                self.pidFileRemove(oChild.pid)
        else:
            iRc = 0

        #
        # Clean up
        #
        for sPath in asFilesToRemove:
            self._hardenedDeleteFile(sPath)
        for sPath in asDirsToRemove:
            self._hardenedRemoveDir(sPath)

        #
        # Report.
        #
        if os.path.exists(sXmlFile):
            reporter.addSubXmlFile(sXmlFile)
            if fHardened:
                self._hardenedDeleteFile(sXmlFile)
            else:
                os.unlink(sXmlFile)

        if iRc == 0:
            reporter.log('*** %s: exit code %d' % (sFullPath, iRc))
            self.cPassed += 1

        elif iRc == 4:  # RTEXITCODE_SKIPPED
            reporter.log('*** %s: exit code %d (RTEXITCODE_SKIPPED)' %
                         (sFullPath, iRc))
            fSkipped = True
            self.cSkipped += 1

        elif fSkipped:
            reporter.log('*** %s: exit code %d (Skipped)' % (sFullPath, iRc))
            self.cSkipped += 1

        else:
            sName = self.kdExitCodeNames.get(iRc, '')
            if iRc in self.kdExitCodeNamesWin and utils.getHostOs() == 'win':
                sName = self.kdExitCodeNamesWin[iRc]
            if sName != '':
                sName = ' (%s)' % (sName)

            if iRc != 1:
                reporter.testFailure('Exit status: %d%s' % (iRc, sName))
                reporter.log('!*! %s: exit code %d%s' %
                             (sFullPath, iRc, sName))
            else:
                reporter.error('!*! %s: exit code %d%s' %
                               (sFullPath, iRc, sName))
            self.cFailed += 1

        return fSkipped
コード例 #6
0
ファイル: tdUnitTest1.py プロジェクト: rickysarraf/virtualbox
    def _executeTestCase(self, sName, sFullPath, sTestCaseSubDir, oDevNull):  # pylint: disable=R0914
        """
        Executes a test case.
        """

        fSkipped = False

        #
        # If hardening is enabled, some test cases and their dependencies
        # needs to be copied to and execute from the sVBoxInstallRoot
        # directory in order to work. They also have to be executed as
        # root, i.e. via sudo.
        #
        fHardened = False
        asFilesToRemove = []
        # Stuff to clean up.
        asDirsToRemove = []
        # Ditto.
        if sName in self.kasHardened and self.sUnitTestsPathBase != self.sVBoxInstallRoot:

            sDstDir = os.path.join(self.sVBoxInstallRoot, sTestCaseSubDir)
            if not os.path.exists(sDstDir):
                self._hardenedMkDir(sDstDir)
                asDirsToRemove.append(sDstDir)

            sDst = os.path.join(sDstDir, os.path.basename(sFullPath))
            self._hardenedCopyFile(sFullPath, sDst, 0755)
            asFilesToRemove.append(sDst)

            # Copy any associated .dll/.so/.dylib.
            for sSuff in [".dll", ".so", ".dylib"]:
                sSrc = os.path.splitext(sFullPath)[0] + sSuff
                if os.path.exists(sSrc):
                    sDst = os.path.join(sDstDir, os.path.basename(sSrc))
                    self._hardenedCopyFile(sSrc, sDst, 0644)
                    asFilesToRemove.append(sDst)

            # Copy any associated .r0, .rc and .gc modules.
            offDriver = sFullPath.rfind("Driver")
            if offDriver > 0:
                for sSuff in [".r0", "RC.rc", "RC.gc"]:
                    sSrc = sFullPath[:offDriver] + sSuff
                    if os.path.exists(sSrc):
                        sDst = os.path.join(sDstDir, os.path.basename(sSrc))
                        self._hardenedCopyFile(sSrc, sDst, 0644)
                        asFilesToRemove.append(sDst)

            sFullPath = os.path.join(sDstDir, os.path.basename(sFullPath))
            fHardened = True

        #
        # Set up arguments and environment.
        #
        asArgs = [sFullPath]
        if sName in self.kdArguments:
            asArgs.extend(self.kdArguments[sName])

        os.environ["IPRT_TEST_OMIT_TOP_TEST"] = "1"
        os.environ["IPRT_TEST_FILE"] = sXmlFile = os.path.join(self.sScratchPath, "result.xml")
        if os.path.exists(sXmlFile):
            try:
                os.unlink(sXmlFile)
            except:
                self._hardenedDeleteFile(sXmlFile)

        #
        # Execute the test case.
        #
        # Windows is confusing output.  Trying a few things to get rid of this.
        # First, flush both stderr and stdout before running the child.  Second,
        # assign the child stderr to stdout.  If this doesn't help, we'll have
        # to capture the child output.
        #
        reporter.log("*** Executing %s%s..." % (asArgs, " [hardened]" if fHardened else ""))
        try:
            sys.stdout.flush()
        except:
            pass
        try:
            sys.stderr.flush()
        except:
            pass
        if not self.fDryRun:
            try:
                if fHardened:
                    oChild = utils.sudoProcessPopen(asArgs, stdin=oDevNull, stdout=sys.stdout, stderr=sys.stdout)
                else:
                    oChild = subprocess.Popen(asArgs, stdin=oDevNull, stdout=sys.stdout, stderr=sys.stdout)
            except:
                if sName in ["tstAsmStructsRC"]:  # 32-bit, may fail to start on 64-bit linux. Just ignore.
                    reporter.logXcpt()
                    fSkipped = True
                else:
                    reporter.errorXcpt()
                iRc = 1023
                oChild = None

            if oChild is not None:
                self.pidFileAdd(oChild.pid, fSudo=fHardened)
                iRc = oChild.wait()
                self.pidFileRemove(oChild.pid)
        else:
            iRc = 0

        #
        # Clean up
        #
        for sPath in asFilesToRemove:
            self._hardenedDeleteFile(sPath)
        for sPath in asDirsToRemove:
            self._hardenedRemoveDir(sPath)

        #
        # Report.
        #
        if os.path.exists(sXmlFile):
            reporter.addSubXmlFile(sXmlFile)
            if fHardened:
                self._hardenedDeleteFile(sXmlFile)
            else:
                os.unlink(sXmlFile)

        if iRc == 0:
            reporter.log("*** %s: exit code %d" % (sFullPath, iRc))
            self.cPassed += 1

        elif iRc == 4:  # RTEXITCODE_SKIPPED
            reporter.log("*** %s: exit code %d (RTEXITCODE_SKIPPED)" % (sFullPath, iRc))
            fSkipped = True
            self.cSkipped += 1

        elif fSkipped:
            reporter.log("*** %s: exit code %d (Skipped)" % (sFullPath, iRc))
            self.cSkipped += 1

        else:
            sName = self.kdExitCodeNames.get(iRc, "")
            if iRc in self.kdExitCodeNamesWin and utils.getHostOs() == "win":
                sName = self.kdExitCodeNamesWin[iRc]
            if sName != "":
                sName = " (%s)" % (sName)

            if iRc != 1:
                reporter.testFailure("Exit status: %d%s" % (iRc, sName))
                reporter.log("!*! %s: exit code %d%s" % (sFullPath, iRc, sName))
            else:
                reporter.error("!*! %s: exit code %d%s" % (sFullPath, iRc, sName))
            self.cFailed += 1

        return fSkipped
コード例 #7
0
ファイル: tdBenchmark2.py プロジェクト: Ratio2/vbox
    def testOneCfg(self, oVM, oTestVm):
        """
        Runs the specified VM thru the tests.

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

        #
        # Determin the RAM configurations we want to test.
        #
        cMbMaxGuestRam = self.oVBox.systemProperties.maxGuestRAM
        cMbHostAvail = self.oVBox.host.memoryAvailable
        cMbHostTotal = self.oVBox.host.memorySize
        reporter.log('cMbMaxGuestRam=%s cMbHostAvail=%s cMbHostTotal=%s' % (
            cMbMaxGuestRam,
            cMbHostAvail,
            cMbHostTotal,
        ))

        cMbHostAvail -= cMbHostAvail // 7
        # Rough 14% safety/overhead margin.
        if cMbMaxGuestRam < cMbHostAvail:
            # Currently: 2048 GiB, 1536 GiB, 1024 GiB, 512 GiB, 256 GiB, 128 GiB, 64 GiB, 32 GiB
            acMbRam = [
                cMbMaxGuestRam, cMbMaxGuestRam // 4 * 3, cMbMaxGuestRam // 2,
                cMbMaxGuestRam // 4, cMbMaxGuestRam // 8, cMbMaxGuestRam // 16
            ]
            if acMbRam[-1] > 64 * 1024:
                acMbRam.append(64 * 1024)
            if acMbRam[-1] > 32 * 1024:
                acMbRam.append(32 * 1024)
        elif cMbHostAvail > 8 * 1024:
            # First entry is available memory rounded down to the nearest 8 GiB
            cMbHostAvail = cMbHostAvail & ~(8 * 1024 - 1)
            acMbRam = [
                cMbHostAvail,
            ]

            # The remaining entries are powers of two below that, up to 6 of these stopping at 16 GiB.
            cMb = 8 * 1024
            while cMb < cMbHostAvail:
                cMb *= 2
            while len(acMbRam) < 7 and cMb > 16 * 1024:
                cMb //= 2
                acMbRam.append(cMb)
        elif cMbHostAvail >= 16000 and cMbHostAvail > 7168:
            # Desperate attempt at getting some darwin testruns too.  We've got two
            # with 16 GiB and they usually end up with just short of 8GiB of free RAM.
            acMbRam = [
                7168,
            ]
        else:
            reporter.log(
                "Less than 8GB of host RAM available for VMs, skipping test")
            return None
        reporter.log("RAM configurations: %s" % (acMbRam))

        # Large pages only work with nested paging.
        afLargePages = [
            False,
        ]
        try:
            if oVM.getHWVirtExProperty(
                    vboxcon.HWVirtExPropertyType_NestedPaging):
                afLargePages = [True, False]
        except:
            return reporter.errorXcpt(
                "Failed to get HWVirtExPropertyType_NestedPaging")

        #
        # Test the RAM configurations.
        #
        for fLargePages in afLargePages:
            sLargePages = 'large pages' if fLargePages is True else 'no large pages'
            for cMbRam in acMbRam:
                reporter.testStart('%s MiB, %s' % (cMbRam, sLargePages))

                # Reconfigure the VM:
                fRc = False
                oSession = self.openSession(oVM)
                if oSession:
                    fRc = oSession.setRamSize(cMbRam)
                    fRc = oSession.setLargePages(fLargePages) and fRc
                    if fRc:
                        fRc = oSession.saveSettings()
                    if not fRc:
                        oSession.discardSettings(True)
                    oSession.close()
                if fRc:
                    # Set up the result file
                    sXmlFile = self.prepareResultFile()
                    asEnv = [
                        'IPRT_TEST_FILE=' + sXmlFile,
                    ]

                    # Do the test:
                    self.logVmInfo(oVM)
                    oSession = self.startVm(oVM,
                                            sName=oTestVm.sVmName,
                                            asEnv=asEnv)
                    if oSession is not None:
                        cMsTimeout = 15 * 60000 + cMbRam // 168
                        if not reporter.isLocal(
                        ):  ## @todo need to figure a better way of handling timeouts on the testboxes ...
                            cMsTimeout = self.adjustTimeoutMs(180 * 60000 +
                                                              cMbRam // 168)

                        oRc = self.waitForTasks(cMsTimeout)
                        if oRc == oSession:
                            fRc = oSession.assertPoweredOff()
                        else:
                            reporter.error('oRc=%s, expected %s' %
                                           (oRc, oSession))

                        reporter.addSubXmlFile(sXmlFile)
                        self.terminateVmBySession(oSession)
                else:
                    reporter.errorXcpt(
                        "Failed to set memory size to %s MiB or setting largePages to %s"
                        % (cMbRam, fLargePages))
                reporter.testDone()

        return fRc