VirtualBox

Ignore:
Timestamp:
Jan 24, 2018 6:28:12 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120486
Message:

tdExoticOrAncient1.py,vbox.py: Got the serial port output parsing going. The dos20 and dos71 test VMs works now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/vbox.py

    r70718 r70731  
    3232
    3333# Standard Python imports.
     34import datetime
    3435import os
    3536import platform
     37import re;
    3638import sys
    3739import threading
    3840import time
    3941import traceback
    40 import datetime
    4142
    4243# Figure out where the validation kit lives and make sure it's in the path.
     
    396397                    s = oFile.readline();
    397398                    oFile.close();
    398                     import re;
    399399                    oMatch = re.search("VBOX_SVN_REV=(\\d+)", s);
    400400                    if oMatch is not None:
     
    36813681    # pylint: enable=R0914,R0913
    36823682
     3683
     3684    #
     3685    # Working with test results via serial port.
     3686    #
     3687
     3688    class TxsMonitorComFile(base.TdTaskBase):
     3689        """
     3690        Class that monitors a COM output file.
     3691        """
     3692
     3693        def __init__(self, sComRawFile, asStopWords = None):
     3694            base.TdTaskBase.__init__(self, utils.getCallerName());
     3695            self.sComRawFile    = sComRawFile;
     3696            self.oStopRegExp    = re.compile('\\b(' + '|'.join(asStopWords if asStopWords else ('PASSED', 'FAILED',)) + ')\\b');
     3697            self.sResult        = None; ##< The result.
     3698            self.cchDisplayed   = 0;    ##< Offset into the file string of what we've already fed to the logger.
     3699
     3700        def toString(self):
     3701            return '<%s sComRawFile=%s oStopRegExp=%s sResult=%s cchDisplayed=%s>' \
     3702                  % (base.TdTaskBase.toString(self), self.sComRawFile, self.oStopRegExp, self.sResult, self.cchDisplayed,);
     3703
     3704        def pollTask(self, fLocked = False):
     3705            """
     3706            Overrides TdTaskBase.pollTask() for the purpose of polling the file.
     3707            """
     3708            if not fLocked:
     3709                self.lockTask();
     3710
     3711            sFile = utils.noxcptReadFile(self.sComRawFile, '', 'rU');
     3712            if len(sFile) > self.cchDisplayed:
     3713                sNew = sFile[self.cchDisplayed:];
     3714                oMatch = self.oStopRegExp.search(sNew);
     3715                if oMatch:
     3716                    # Done! Get result, flush all the output and signal the task.
     3717                    self.sResult = oMatch.group(1);
     3718                    for sLine in sNew.split('\n'):
     3719                        reporter.log('COM OUTPUT: %s' % (sLine,));
     3720                    self.cchDisplayed = len(sFile);
     3721                    self.signalTaskLocked();
     3722                else:
     3723                    # Output whole lines only.
     3724                    offNewline = sFile.find('\n', self.cchDisplayed);
     3725                    while offNewline >= 0:
     3726                        reporter.log('COM OUTPUT: %s' % (sFile[self.cchDisplayed:offNewline]))
     3727                        self.cchDisplayed = offNewline + 1;
     3728                        offNewline = sFile.find('\n', self.cchDisplayed);
     3729
     3730            fRet = self.fSignalled;
     3731            if not fLocked:
     3732                self.unlockTask();
     3733            return fRet;
     3734
     3735        # Our stuff.
     3736        def getResult(self):
     3737            """
     3738            Returns the connected TXS session object on success.
     3739            Returns None on failure or if the task has not yet completed.
     3740            """
     3741            self.oCv.acquire();
     3742            sResult = self.sResult;
     3743            self.oCv.release();
     3744            return sResult;
     3745
     3746        def cancelTask(self):
     3747            """ Cancels the task. """
     3748            self.signalTask();
     3749            return True;
     3750
     3751
     3752    def monitorComRawFile(self, oSession, sComRawFile, cMsTimeout = 15*60000, asStopWords = None):
     3753        """
     3754        Monitors the COM output file for stop words (PASSED and FAILED by default).
     3755
     3756        Returns the stop word.
     3757        Returns None on VM error and timeout.
     3758        """
     3759
     3760        reporter.log2('monitorComRawFile: oSession=%s, cMsTimeout=%s, sComRawFile=%s' % (oSession, cMsTimeout, sComRawFile));
     3761
     3762        oMonitorTask = self.TxsMonitorComFile(sComRawFile, asStopWords);
     3763        self.addTask(oMonitorTask);
     3764
     3765        cMsTimeout = self.adjustTimeoutMs(cMsTimeout);
     3766        oTask = self.waitForTasks(cMsTimeout + 1);
     3767        reporter.log2('monitorComRawFile: waitForTasks returned %s' % (oTask,));
     3768
     3769        if oTask is not oMonitorTask:
     3770            oMonitorTask.cancelTask();
     3771        self.removeTask(oMonitorTask);
     3772
     3773        oMonitorTask.pollTask();
     3774        return oMonitorTask.getResult();
     3775
     3776
     3777    def runVmAndMonitorComRawFile(self, sVmName, sComRawFile, cMsTimeout = 15*60000, asStopWords = None):
     3778        """
     3779        Runs the specified VM and monitors the given COM output file for stop
     3780        words (PASSED and FAILED by default).
     3781
     3782        The caller is assumed to have configured the VM to use the given
     3783        file. The method will take no action to verify this.
     3784
     3785        Returns the stop word.
     3786        Returns None on VM error and timeout.
     3787        """
     3788
     3789        # Start the VM.
     3790        reporter.log('runVmAndMonitorComRawFile: Starting(/preparing) "%s" (timeout %s s)...' % (sVmName, cMsTimeout / 1000));
     3791        reporter.flushall();
     3792        oSession = self.startVmByName(sVmName);
     3793        if oSession is not None:
     3794            # Let it run and then terminate it.
     3795            sRet = self.monitorComRawFile(oSession, sComRawFile, cMsTimeout, asStopWords);
     3796            self.terminateVmBySession(oSession);
     3797        else:
     3798            sRet = None;
     3799        return sRet;
     3800
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette