VirtualBox

Changeset 99518 in vbox


Ignore:
Timestamp:
Apr 24, 2023 9:47:11 AM (20 months ago)
Author:
vboxsync
Message:

Validation Kit/vbox.py: Added txsRunTestStdIn() to provide a simple wrapper method for piping simple string input data to a given guest process.

File:
1 edited

Legend:

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

    r99413 r99518  
    43274327
    43284328    def txsRunTestRedirectStd(self, oTxsSession, sTestName, cMsTimeout, sExecName, asArgs = (), asAddEnv = (), sAsUser = "",
    4329                               oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null'):
     4329                              oStdIn = '/dev/null', oStdOut = '/dev/null', oStdErr = '/dev/null', oTestPipe = '/dev/null',
     4330                              fIgnoreErrors = False):
    43304331        """
    43314332        Executes the specified test task, waiting till it completes or times out,
     
    43464347        fRc = False;
    43474348        if oTxsSession.asyncExecEx(sExecName, asArgs, asAddEnv, oStdIn, oStdOut, oStdErr,
    4348                                    oTestPipe, sAsUser, cMsTimeout = self.adjustTimeoutMs(cMsTimeout)):
     4349                                   oTestPipe, sAsUser, cMsTimeout = self.adjustTimeoutMs(cMsTimeout),
     4350                                   fIgnoreErrors = fIgnoreErrors):
    43494351            self.addTask(oTxsSession);
    43504352
     
    43534355                oTask = self.waitForTasks(cMsTimeout + 1);
    43544356                if oTask is None:
    4355                     reporter.log('txsRunTestRedirectStd: waitForTasks timed out');
     4357                    if fIgnoreErrors:
     4358                        reporter.log('txsRunTestRedirectStd: waitForTasks timed out');
     4359                    else:
     4360                        reporter.error('txsRunTestRedirectStd: waitForTasks timed out');
    43564361                    break;
    43574362                if oTask is oTxsSession:
    43584363                    fRc = True;
    4359                     reporter.log('txsRunTestRedirectStd: isSuccess=%s getResult=%s'
    4360                                  % (oTxsSession.isSuccess(), oTxsSession.getResult()));
     4364                    if  not oTxsSession.isSuccess() \
     4365                    and not fIgnoreErrors:
     4366                        reporter.error('txsRunTestRedirectStd: failed; result is "%s"' % (oTxsSession.getResult()));
     4367                    else:
     4368                        reporter.log('txsRunTestRedirectStd: isSuccess=%s getResult=%s'
     4369                                     % (oTxsSession.isSuccess(), oTxsSession.getResult()));
    43614370                    break;
     4371
    43624372                if not self.handleTask(oTask, 'txsRunTestRedirectStd'):
    43634373                    break;
     
    43714381        reporter.testDone();
    43724382        return fRc;
     4383
     4384    def txsRunTestStdIn(self, oTxsSession, sTestName, cMsTimeout, sExecName, asArgs = (), asAddEnv = (), sAsUser = "",
     4385                        sStdIn = None, fIgnoreErrors = False):
     4386        """
     4387        Executes the specified test task, waiting till it completes or times out.
     4388        Redirecting simple string input into stdin, redirecting text stdout / stderr output to verbose logging.
     4389
     4390        The VM session (if any) must be in the task list.
     4391
     4392        Returns True if we executed the task and nothing abnormal happend.
     4393        Query the process status from the TXS session.
     4394
     4395        Returns False if some unexpected task was signalled or we failed to
     4396        submit the job.
     4397        """
     4398        assert sStdIn is not None;
     4399        # Wrap sStdIn in a file like class.
     4400        class StdInWrapper(object): # pylint: disable=too-few-public-methods
     4401            def __init__(self, sStdIn):
     4402                self.sContent = sStdIn;
     4403                self.off      = 0;
     4404
     4405            def read(self, cbMax):
     4406                cbLeft = len(self.sContent) - self.off;
     4407                if cbLeft == 0:
     4408                    return "";
     4409                if cbLeft <= cbMax:
     4410                    sRet = self.sContent[self.off:(self.off + cbLeft)];
     4411                else:
     4412                    sRet = self.sContent[self.off:(self.off + cbMax)];
     4413                self.off = self.off + len(sRet);
     4414                reporter.log2('Reading from stdin: "%s"' % (sRet,));
     4415                return sRet;
     4416
     4417        return self.txsRunTestRedirectStd(oTxsSession, sTestName, cMsTimeout, sExecName, asArgs, asAddEnv, sAsUser,
     4418                                          oStdIn  = StdInWrapper(sStdIn),
     4419                                          oStdErr = reporter.FileWrapper('stderr'), oStdOut = reporter.FileWrapper('stdout'),
     4420                                          fIgnoreErrors = fIgnoreErrors);
    43734421
    43744422    def txsRunTest2(self, oTxsSession1, oTxsSession2, sTestName, cMsTimeout,
Note: See TracChangeset for help on using the changeset viewer.

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