Ejemplo n.º 1
0
    def __init__(self):
        ReporterBase.__init__(self);
        self.oLogFile   = None;
        self.oXmlFile   = None;
        self.fXmlOk     = True;
        self.iSubXml    = 0;
        self.iOtherFile = 0;
        self.fnGetIsoTimestamp  = utils.getIsoTimestamp;    # Hack to get a timestamp in __del__.
        self.oStdErr            = sys.stderr;               # Hack for __del__ output.

        #
        # Figure the main log directory.
        #
        try:
            import user;
            self.sDefLogDir = os.path.abspath(os.path.join(user.home, "VBoxTestLogs"));
        except:
            self.sDefLogDir = os.path.abspath("VBoxTestLogs");
        try:
            sLogDir = os.path.abspath(os.environ.get('TESTBOX_REPORTER_LOG_DIR', self.sDefLogDir));
            if not os.path.isdir(sLogDir):
                os.makedirs(sLogDir, 0750);
        except:
            sLogDir = self.sDefLogDir;
            if not os.path.isdir(sLogDir):
                os.makedirs(sLogDir, 0750);

        #
        # Make a subdirectory for this test run.
        #
        sTs = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H-%M-%S.log');
        self.sLogDir = sLogDir = os.path.join(sLogDir, '%s-%s' % (sTs, self.sName));
        try:
            os.makedirs(self.sLogDir, 0750);
        except:
            self.sLogDir = '%s-%s' % (self.sLogDir, os.getpid());
            os.makedirs(self.sLogDir, 0750);

        #
        # Open the log file and write a header.
        #
        sLogName = os.path.join(self.sLogDir, 'testsuite.log');
        sTsIso = utils.getIsoTimestamp();
        self.oLogFile = utils.openNoInherit(sLogName, "w");
        self.oLogFile.write(('Created log file at %s.\nRunning: %s' % (sTsIso, sys.argv)).encode('utf-8'));

        #
        # Open the xml log file and write the mandatory introduction.
        #
        # Note! This is done here and not in the base class because the remote
        #       logger doesn't really need this.  It doesn't need the outer
        #       test wrapper either.
        #
        sXmlName = os.path.join(self.sLogDir, 'testsuite.xml');
        self.oXmlFile = utils.openNoInherit(sXmlName, "w");
        self._xmlWrite([ '<?xml version="1.0" encoding="UTF-8" ?>',
                         '<Test timestamp="%s" name="%s">' % (sTsIso, self._xmlEscAttr(self.sName),), ],
                       fIndent = False);
Ejemplo n.º 2
0
def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True):
    """
    Downloads the given file if an URL is given, otherwise assume it's
    something on the build share and copy it from there.

    Raises no exceptions, returns log + success indicator instead.

    Note! This method may use proxies configured on the system and the
          http_proxy, ftp_proxy, no_proxy environment variables.

    @todo Fixed build burn here. Please set default value for fNoProxies
          to appropriate one.
    """
    if fnError is None:
        fnError = fnLog;

    if  sUrlFile.startswith('http://') \
     or sUrlFile.startswith('https://') \
     or sUrlFile.startswith('ftp://'):
        # Download the file.
        fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile));
        try:
            ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
            if fNoProxies:
                oSrc = urllib_urlopen(sUrlFile);
            else:
                oSrc = urllib_urlopen(sUrlFile, proxies = dict());
            oDst = utils.openNoInherit(sDstFile, 'wb');
            oDst.write(oSrc.read());
            oDst.close();
            oSrc.close();
        except Exception, oXcpt:
            fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt));
            return False;
Ejemplo n.º 3
0
def addLogFile(sFilename, sKind, sDescription='', sAltName=None):
    """
    Adds the specified log file to the report if the file exists.

    The sDescription is a free form description of the log file.

    The sKind parameter is for adding some machine parsable hint what kind of
    log file this really is.

    Returns True on success, False on failure (no ENOENT errors are logged).
    """
    sTsPrf = utils.getTimePrefix()
    sCaller = utils.getCallerName()
    fRc = False
    if sAltName is None:
        sAltName = sFilename

    try:
        oSrcFile = utils.openNoInherit(sFilename, 'rb')
    except IOError, oXcpt:
        if oXcpt.errno != errno.ENOENT:
            logXcpt('addLogFile(%s,%s,%s)' % (sFilename, sDescription, sKind))
        else:
            logXcpt('addLogFile(%s,%s,%s) IOError' %
                    (sFilename, sDescription, sKind))
Ejemplo n.º 4
0
def downloadFile(sUrlFile,
                 sDstFile,
                 sLocalPrefix,
                 fnLog,
                 fnError=None,
                 fNoProxies=True):
    """
    Downloads the given file if an URL is given, otherwise assume it's
    something on the build share and copy it from there.

    Raises no exceptions, returns log + success indicator instead.

    Note! This method may use proxies configured on the system and the
          http_proxy, ftp_proxy, no_proxy environment variables.

    """
    if fnError is None:
        fnError = fnLog

    if  sUrlFile.startswith('http://') \
     or sUrlFile.startswith('https://') \
     or sUrlFile.startswith('ftp://'):
        # Download the file.
        fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile))
        try:
            ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
            if not fNoProxies:
                oOpener = urllib_build_opener()
            else:
                oOpener = urllib_build_opener(
                    urllib_ProxyHandler(proxies=dict()))
            oSrc = oOpener.open(sUrlFile)
            oDst = utils.openNoInherit(sDstFile, 'wb')
            oDst.write(oSrc.read())
            oDst.close()
            oSrc.close()
        except Exception as oXcpt:
            fnError('Error downloading "%s" to "%s": %s' %
                    (sUrlFile, sDstFile, oXcpt))
            return False
    else:
        # Assumes file from the build share.
        if sUrlFile.startswith('file:///'):
            sSrcPath = sUrlFile[7:]
        elif sUrlFile.startswith('file://'):
            sSrcPath = sUrlFile[6:]
        elif os.path.isabs(sUrlFile):
            sSrcPath = sUrlFile
        else:
            sSrcPath = os.path.join(sLocalPrefix, sUrlFile)
        fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile))
        try:
            utils.copyFileSimple(sSrcPath, sDstFile)
        except Exception as oXcpt:
            fnError('Error copying "%s" to "%s": %s' %
                    (sSrcPath, sDstFile, oXcpt))
            return False

    return True
Ejemplo n.º 5
0
def addSubXmlFile(sFilename):
    """
    Adds a sub-xml result file to the party.
    """
    fRc = False;
    try:
        oSrcFile = utils.openNoInherit(sFilename, 'r');
    except IOError, oXcpt:
        if oXcpt.errno != errno.ENOENT:
            logXcpt('addSubXmlFile(%s)' % (sFilename,));
Ejemplo n.º 6
0
def addSubXmlFile(sFilename):
    """
    Adds a sub-xml result file to the party.
    """
    fRc = False
    try:
        oSrcFile = utils.openNoInherit(sFilename, 'r')
    except IOError, oXcpt:
        if oXcpt.errno != errno.ENOENT:
            logXcpt('addSubXmlFile(%s)' % (sFilename, ))
Ejemplo n.º 7
0
    def _unattendedConfigure(self, oIUnattended, oTestDrv): # type: (Any, vbox.TestDriver) -> bool
        """
        Configures the unattended install object.

        The ISO attribute has been set and detectIsoOS has been done, the rest of the
        setup is done here.

        Returns True on success, False w/ errors logged on failure.
        """

        #
        # Make it install the TXS.
        #
        try:    oIUnattended.installTestExecService = True;
        except: return reporter.errorXcpt();
        try:    oIUnattended.validationKitIsoPath   = oTestDrv.sVBoxValidationKitIso;
        except: return reporter.errorXcpt();
        oTestDrv.processPendingEvents();

        #
        # Install GAs?
        #
        if self.fOptInstallAdditions:
            if (self.fInstVmFlags & self.kfNoGAs) == 0:
                try:    oIUnattended.installGuestAdditions = True;
                except: return reporter.errorXcpt();
                try:    oIUnattended.additionsIsoPath      = oTestDrv.getGuestAdditionsIso();
                except: return reporter.errorXcpt();
                oTestDrv.processPendingEvents();
            else:
                reporter.log("Warning! Ignoring request to install Guest Additions as kfNoGAs is set!");

        #
        # Product key?
        #
        if self.fInstVmFlags & UnattendedVm.kfKeyFile:
            sKeyFile = '';
            sKey     = '';
            try:
                sKeyFile = oIUnattended.isoPath + '.key';
                oFile = utils.openNoInherit(sKeyFile);
                for sLine in oFile:
                    sLine = sLine.strip();
                    if sLine and not sLine.startswith(';') and not sLine.startswith('#') and not sLine.startswith('//'):
                        sKey = sLine;
                        break;
                oFile.close();
            except:
                return reporter.errorXcpt('sKeyFile=%s' % (sKeyFile,));
            if not sKey:
                return reporter.error('No key in keyfile (%s)!' % (sKeyFile,));
            try:    oIUnattended.productKey = sKey;
            except: return reporter.errorXcpt();

        return True;
Ejemplo n.º 8
0
    def addLogFile(self, oSrcFile, sSrcFilename, sAltName, sDescription, sKind, sCaller, sTsPrf):
        # Figure the destination filename.
        iOtherFile = self.iOtherFile;
        self.iOtherFile += 1;
        sDstFilename = os.path.join(self.sLogDir, 'other-%d-%s.log' \
                                    % (iOtherFile, os.path.splitext(os.path.basename(sSrcFilename))[0]));
        self.log(0, 'Other log file: %s - %s (%s)' % (sDstFilename, sDescription, sSrcFilename), sCaller, sTsPrf);

        # Open the destination file and copy over the data.
        fRc = True;
        try:
            oDstFile = utils.openNoInherit(sDstFilename, 'w');
        except Exception, oXcpt:
            self.log(0, 'error opening %s: %s' % (sDstFilename, oXcpt), sCaller, sTsPrf);
Ejemplo n.º 9
0
 def subXmlStart(self, oFileWrapper):
     # Open a new file and just include it from the main XML.
     iSubXml = self.iSubXml;
     self.iSubXml += 1;
     sSubXmlName = os.path.join(self.sLogDir, 'sub-%d.xml' % (iSubXml,));
     try:
         oFileWrapper.oSubXmlFile = utils.openNoInherit(sSubXmlName, "w");
     except:
         errorXcpt('open(%s)' % oFileWrapper.oSubXmlName);
         oFileWrapper.oSubXmlFile = None;
     else:
         self._xmlWrite('<Include timestamp="%s" filename="%s"/>\n'
                 % (utils.getIsoTimestamp(), self._xmlEscAttr(os.path.basename(sSubXmlName))));
     return None;
Ejemplo n.º 10
0
 def subXmlStart(self, oFileWrapper):
     # Open a new file and just include it from the main XML.
     iSubXml = self.iSubXml
     self.iSubXml += 1
     sSubXmlName = os.path.join(self.sLogDir, 'sub-%d.xml' % (iSubXml, ))
     try:
         oFileWrapper.oSubXmlFile = utils.openNoInherit(sSubXmlName, "w")
     except:
         errorXcpt('open(%s)' % oFileWrapper.oSubXmlName)
         oFileWrapper.oSubXmlFile = None
     else:
         self._xmlWrite('<Include timestamp="%s" filename="%s"/>\n' %
                        (utils.getIsoTimestamp(),
                         self._xmlEscAttr(os.path.basename(sSubXmlName))))
     return None
Ejemplo n.º 11
0
    def addLogFile(self, oSrcFile, sSrcFilename, sAltName, sDescription, sKind,
                   sCaller, sTsPrf):
        # Figure the destination filename.
        iOtherFile = self.iOtherFile
        self.iOtherFile += 1
        sDstFilename = os.path.join(self.sLogDir, 'other-%d-%s.log' \
                                    % (iOtherFile, os.path.splitext(os.path.basename(sSrcFilename))[0]))
        self.log(
            0, 'Other log file: %s - %s (%s)' %
            (sDstFilename, sDescription, sSrcFilename), sCaller, sTsPrf)

        # Open the destination file and copy over the data.
        fRc = True
        try:
            oDstFile = utils.openNoInherit(sDstFilename, 'w')
        except Exception, oXcpt:
            self.log(0, 'error opening %s: %s' % (sDstFilename, oXcpt),
                     sCaller, sTsPrf)
def downloadFile(sUrlFile, sDstFile, sLocalPrefix, fnLog, fnError = None, fNoProxies=True):
    """
    Downloads the given file if an URL is given, otherwise assume it's
    something on the build share and copy it from there.

    Raises no exceptions, returns log + success indicator instead.

    Note! This method may use proxies configured on the system and the
          http_proxy, ftp_proxy, no_proxy environment variables.

    """
    if fnError is None:
        fnError = fnLog;

    if  sUrlFile.startswith('http://') \
     or sUrlFile.startswith('https://') \
     or sUrlFile.startswith('ftp://'):
        # Download the file.
        fnLog('Downloading "%s" to "%s"...' % (sUrlFile, sDstFile));
        try:
            ## @todo We get 404.html content instead of exceptions here, which is confusing and should be addressed.
            if not fNoProxies:
                oOpener = urllib_build_opener();
            else:
                oOpener = urllib_build_opener(urllib_ProxyHandler(proxies = dict()));
            oSrc = oOpener.open(sUrlFile);
            oDst = utils.openNoInherit(sDstFile, 'wb');
            oDst.write(oSrc.read());
            oDst.close();
            oSrc.close();
        except Exception as oXcpt:
            fnError('Error downloading "%s" to "%s": %s' % (sUrlFile, sDstFile, oXcpt));
            return False;
    else:
        # Assumes file from the build share.
        sSrcPath = os.path.join(sLocalPrefix, sUrlFile);
        fnLog('Copying "%s" to "%s"...' % (sSrcPath, sDstFile));
        try:
            utils.copyFileSimple(sSrcPath, sDstFile);
        except Exception as oXcpt:
            fnError('Error copying "%s" to "%s": %s' % (sSrcPath, sDstFile, oXcpt));
            return False;

    return True;
Ejemplo n.º 13
0
 def _generateAutoResponseOnSolaris(self):
     """
     Generates an autoresponse file on solaris, returning the name.
     None is return on failure.
     """
     sPath = os.path.join(self.sScratchPath, 'SolarisAutoResponse')
     oFile = utils.openNoInherit(sPath, 'wt')
     oFile.write('basedir=default\n'
                 'runlevel=nocheck\n'
                 'conflict=quit\n'
                 'setuid=nocheck\n'
                 'action=nocheck\n'
                 'partial=quit\n'
                 'instance=unique\n'
                 'idepend=quit\n'
                 'rdepend=quit\n'
                 'space=quit\n'
                 'mail=\n')
     oFile.close()
     return sPath
 def _generateAutoResponseOnSolaris(self):
     """
     Generates an autoresponse file on solaris, returning the name.
     None is return on failure.
     """
     sPath = os.path.join(self.sScratchPath, 'SolarisAutoResponse');
     oFile = utils.openNoInherit(sPath, 'wt');
     oFile.write('basedir=default\n'
                 'runlevel=nocheck\n'
                 'conflict=quit\n'
                 'setuid=nocheck\n'
                 'action=nocheck\n'
                 'partial=quit\n'
                 'instance=unique\n'
                 'idepend=quit\n'
                 'rdepend=quit\n'
                 'space=quit\n'
                 'mail=\n');
     oFile.close();
     return sPath;
Ejemplo n.º 15
0
def addLogFile(sFilename, sKind, sDescription = '', sAltName = None):
    """
    Adds the specified log file to the report if the file exists.

    The sDescription is a free form description of the log file.

    The sKind parameter is for adding some machine parsable hint what kind of
    log file this really is.

    Returns True on success, False on failure (no ENOENT errors are logged).
    """
    sTsPrf  = utils.getTimePrefix();
    sCaller = utils.getCallerName();
    fRc     = False;
    if sAltName is None:
        sAltName = sFilename;

    try:
        oSrcFile = utils.openNoInherit(sFilename, 'rb');
    except IOError, oXcpt:
        if oXcpt.errno != errno.ENOENT:
            logXcpt('addLogFile(%s,%s,%s)' % (sFilename, sDescription, sKind));
        else:
            logXcpt('addLogFile(%s,%s,%s) IOError' % (sFilename, sDescription, sKind));
Ejemplo n.º 16
0
 def _generateWithoutKextsChoicesXmlOnDarwin(self):
     """
     Generates the choices XML when kernel drivers are disabled.
     None is returned on failure.
     """
     sPath = os.path.join(self.sScratchPath, 'DarwinChoices.xml')
     oFile = utils.openNoInherit(sPath, 'wt')
     oFile.write(
         '<?xml version="1.0" encoding="UTF-8"?>\n'
         '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
         '<plist version="1.0">\n'
         '<array>\n'
         '    <dict>\n'
         '        <key>attributeSetting</key>\n'
         '        <integer>0</integer>\n'
         '        <key>choiceAttribute</key>\n'
         '        <string>selected</string>\n'
         '        <key>choiceIdentifier</key>\n'
         '        <string>choiceVBoxKEXTs</string>\n'
         '    </dict>\n'
         '</array>\n'
         '</plist>\n')
     oFile.close()
     return sPath
Ejemplo n.º 17
0
def main(asArgs): # pylint: disable=C0111,R0914,R0915
    cMsTimeout      = long(30*1000);
    sAddress        = 'localhost';
    uPort           = None;
    fReversedSetup  = False;
    fReboot         = False;
    fStdTests       = True;

    i = 1;
    while i < len(asArgs):
        if asArgs[i] == '--hostname':
            sAddress = asArgs[i + 1];
            i = i + 2;
        elif asArgs[i] == '--port':
            uPort = int(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reversed-setup':
            fReversedSetup = True;
            i = i + 1;
        elif asArgs[i] == '--timeout':
            cMsTimeout = long(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reboot':
            fReboot   = True;
            fStdTests = False;
            i = i + 1;
        elif asArgs[i] == '--help':
            print 'tst-txsclient.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>] [--reboot] [--reversed-setup]'
            return 0;
        else:
            print 'Unknown argument: %s' % (asArgs[i]);
            return 2;

    if uPort is None:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, fReversedSetup = fReversedSetup);
    else:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, uPort = uPort, fReversedSetup = fReversedSetup);
    if oSession is None:
        print 'openTcpSession failed';
        return 1;

    fDone = oSession.waitForTask(30*1000);
    print 'connect: waitForTask -> %s, result %s' % (fDone, oSession.getResult());
    if fDone is True and oSession.isSuccess():
        if fStdTests:
            # Get the UUID of the remote instance.
            sUuid = oSession.syncUuid();
            if sUuid is not False:
                print '%s: UUID = %s' % (boolRes(True), sUuid);
            else:
                print '%s: UUID' % (boolRes(False),);

            # Create and remove a directory on the scratch area.
            rc = oSession.syncMkDir('${SCRATCH}/testdir1');
            print '%s: MKDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncIsDir('${SCRATCH}/testdir1');
            print '%s: ISDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncRmDir('${SCRATCH}/testdir1');
            print '%s: RMDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc);

            # Create a two-level subdir.
            rc = oSession.syncMkDirPath('${SCRATCH}/testdir2/subdir1');
            print '%s: MKDRPATH(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncIsDir('${SCRATCH}/testdir2');
            print '%s: ISDIR(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc);
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/');
            print '%s: ISDIR(${SCRATCH}/testdir2/) -> %s' % (boolRes(rc), rc);
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/subdir1');
            print '%s: ISDIR(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncRmTree('${SCRATCH}/testdir2');
            print '%s: RMTREE(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc);

            # Check out a simple file.
            rc = oSession.syncUploadString('howdy', '${SCRATCH}/howdyfile');
            print '%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncUploadString('howdy-replaced', '${SCRATCH}/howdyfile');
            print '%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc);

            rc = oSession.syncDownloadString('${SCRATCH}/howdyfile');
            print '%s: GET FILE(${SCRATCH}/howdyfile) -> "%s" expected "howdy-replaced"' % (stringRes(rc, 'howdy-replaced'), rc);

            rc = oSession.syncIsFile('${SCRATCH}/howdyfile');
            print '%s: ISFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc);
            rc = oSession.syncIsDir('${SCRATCH}/howdyfile');
            print '%s: ISDIR(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc);
            rc = oSession.syncIsSymlink('${SCRATCH}/howdyfile');
            print '%s: ISSYMLNK(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc);

            rc = oSession.syncRmFile('${SCRATCH}/howdyfile');
            print '%s: RMFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc);

            # Unicode filename (may or may not work, LANG/LC_TYPE dependent on some hosts).
            rc = oSession.syncUploadString('howdy', u'${SCRATCH}/Schröder');
            print (u'%s: PUT FILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace');

            rc = oSession.syncIsFile(u'${SCRATCH}/Schröder');
            print (u'%s: ISFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace');

            rc = oSession.syncRmFile(u'${SCRATCH}/Schröder');
            print (u'%s: RMFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace');

            # Finally, some file uploading and downloading with unicode filenames.
            strUpFile  = 'tst-txsclient-upload.bin';
            strDwnFile = 'tst-txsclient-download.bin';
            try:
                abRandFile = os.urandom(257897);
            except:
                print 'INFO: no urandom... falling back on a simple string.'
                abRandFile = 'asdflkjasdlfkjasdlfkjq023942relwjgkna9epr865u2nm345;hndafgoukhasre5kb2453km';
                for i in range(1, 64):
                    abRandFile += abRandFile;
            try:
                oLocalFile = utils.openNoInherit(strUpFile, 'w+b');
                oLocalFile.write(abRandFile);
                oLocalFile.close();
                rc = True;
            except:
                rc = False;
                print('%s: creating file (%s) to upload failed....' % (boolRes(rc), strUpFile));

            if rc is True:
                rc = oSession.syncUploadFile(strUpFile, '${SCRATCH}/tst-txsclient-uploaded.bin')
                print('%s: PUT FILE(%s, ${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), strUpFile, rc));

                rc = oSession.syncDownloadFile('${SCRATCH}/tst-txsclient-uploaded.bin', strDwnFile)
                print('%s: GET FILE(${SCRATCH}/tst-txsclient-uploaded.bin, tst-txsclient-downloaded.txt) -> %s'
                      % (boolRes(rc), rc));

                try:
                    oLocalFile = utils.openNoInherit(strDwnFile, "rb");
                    abDwnFile = oLocalFile.read();
                    oLocalFile.close();
                    if abRandFile == abDwnFile:
                        print '%s: downloaded file matches the uploaded file' % (boolRes(True),);
                    else:
                        print '%s: downloaded file does not match the uploaded file' % (boolRes(False),);
                        print 'abRandFile=%s' % (abRandFile,);
                        print 'abDwnFile =%s' % (abRandFile,);
                except:
                    print '%s: reading downloaded file (%s) failed....' % (boolRes(False), strDwnFile);

                rc = oSession.syncRmFile(u'${SCRATCH}/tst-txsclient-uploaded.bin');
                print '%s: RMFILE(${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), rc);

            try:    os.remove(strUpFile);
            except: pass;
            try:    os.remove(strDwnFile);
            except: pass;

            # Execute some simple thing, if available.
            # Intentionally skip this test if file is not available due to
            # another inserted CD-ROM (e.g. not TestSuite.iso).
            sProg = '${CDROM}/${OS/ARCH}/NetPerf${EXESUFF}';
            rc = oSession.syncIsFile(sProg, 30 * 1000, True);
            if rc is True:
                rc = oSession.syncExecEx(sProg, (sProg, '--help'));
                print '%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc);

                rc = oSession.syncExecEx(sProg, (sProg, 'there', 'is no such', 'parameter'), \
                                         oStdOut='${SCRATCH}/stdout', \
                                         oStdErr='${SCRATCH}/stderr');
                print('%s: EXEC(%s there is not such parameter > ${SCRATCH}/stdout 2> ${SCRATCH}/stderr) -> %s'
                      % (boolRes(rc, False), sProg, rc));

                rc = oSession.syncDownloadString('${SCRATCH}/stdout');
                print 'INFO:   GET FILE(${SCRATCH}/stdout) -> "%s"' % (rc);
                rc = oSession.syncDownloadString('${SCRATCH}/stderr');
                print 'INFO:   GET FILE(${SCRATCH}/stderr) -> "%s"' % (rc);

                print 'TESTING: syncExec...'
                rc = oSession.syncExec(sProg, (sProg, '--version'));
                print '%s: EXEC(%s --version) -> %s' % (boolRes(rc), sProg, rc);

                print 'TESTING: syncExec...'
                rc = oSession.syncExec(sProg, (sProg, '--help'));
                print '%s: EXEC(%s --help) -> %s' % (boolRes(rc), sProg, rc);

                #print 'TESTING: syncExec sleep 30...'
                #rc = oSession.syncExec('/usr/bin/sleep', ('/usr/bin/sleep', '30'));
                #print '%s: EXEC(/bin/sleep 30) -> %s' % (boolRes(rc), rc);
            else:
                print 'SKIP:   Execution of %s skipped, does not exist on CD-ROM' % (sProg,);

            # Execute a non-existing file on CD-ROM.
            sProg = '${CDROM}/${OS/ARCH}/NonExisting${EXESUFF}';
            rc = oSession.syncExecEx(sProg, (sProg,), oStdIn = '/dev/null', oStdOut = '/dev/null', \
                                     oStdErr = '/dev/null', oTestPipe = '/dev/null', \
                                     sAsUser = '', cMsTimeout = 3600000, fIgnoreErrors = True);
            if rc is None:
                rc = True;
            else:
                reporter.error('Unexpected value \"%s\" while executing non-existent file "%s"' % (rc, sProg));
            print '%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc);

            # Done
            rc = oSession.syncDisconnect();
            print '%s: disconnect() -> %s' % (boolRes(rc), rc);

        elif fReboot:
            print 'TESTING: syncReboot...'
            rc = oSession.syncReboot();
            print '%s: REBOOT() -> %s' % (boolRes(rc), rc);

    if g_cFailures != 0:
        print 'tst-txsclient.py: %u out of %u test failed' % (g_cFailures, g_cTests);
        return 1;
    print 'tst-txsclient.py: all %u tests passed!' % (g_cTests);
    return 0;
Ejemplo n.º 18
0
    def __init__(self):
        ReporterBase.__init__(self)
        self.oLogFile = None
        self.oXmlFile = None
        self.fXmlOk = True
        self.iSubXml = 0
        self.iOtherFile = 0
        self.fnGetIsoTimestamp = utils.getIsoTimestamp
        # Hack to get a timestamp in __del__.
        self.oStdErr = sys.stderr
        # Hack for __del__ output.

        #
        # Figure the main log directory.
        #
        try:
            import user
            self.sDefLogDir = os.path.abspath(
                os.path.join(user.home, "VBoxTestLogs"))
        except:
            self.sDefLogDir = os.path.abspath("VBoxTestLogs")
        try:
            sLogDir = os.path.abspath(
                os.environ.get('TESTBOX_REPORTER_LOG_DIR', self.sDefLogDir))
            if not os.path.isdir(sLogDir):
                os.makedirs(sLogDir, 0750)
        except:
            sLogDir = self.sDefLogDir
            if not os.path.isdir(sLogDir):
                os.makedirs(sLogDir, 0750)

        #
        # Make a subdirectory for this test run.
        #
        sTs = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H-%M-%S.log')
        self.sLogDir = sLogDir = os.path.join(sLogDir,
                                              '%s-%s' % (sTs, self.sName))
        try:
            os.makedirs(self.sLogDir, 0750)
        except:
            self.sLogDir = '%s-%s' % (self.sLogDir, os.getpid())
            os.makedirs(self.sLogDir, 0750)

        #
        # Open the log file and write a header.
        #
        sLogName = os.path.join(self.sLogDir, 'testsuite.log')
        sTsIso = utils.getIsoTimestamp()
        self.oLogFile = utils.openNoInherit(sLogName, "w")
        self.oLogFile.write(('Created log file at %s.\nRunning: %s' %
                             (sTsIso, sys.argv)).encode('utf-8'))

        #
        # Open the xml log file and write the mandatory introduction.
        #
        # Note! This is done here and not in the base class because the remote
        #       logger doesn't really need this.  It doesn't need the outer
        #       test wrapper either.
        #
        sXmlName = os.path.join(self.sLogDir, 'testsuite.xml')
        self.oXmlFile = utils.openNoInherit(sXmlName, "w")
        self._xmlWrite([
            '<?xml version="1.0" encoding="UTF-8" ?>',
            '<Test timestamp="%s" name="%s">' % (
                sTsIso,
                self._xmlEscAttr(self.sName),
            ),
        ],
                       fIndent=False)
Ejemplo n.º 19
0
def main(asArgs):  # pylint: disable=C0111,R0914,R0915
    cMsTimeout = 30 * 1000
    sAddress = "localhost"
    uPort = None
    fReversedSetup = False
    fReboot = False
    fStdTests = True

    i = 1
    while i < len(asArgs):
        if asArgs[i] == "--hostname":
            sAddress = asArgs[i + 1]
            i = i + 2
        elif asArgs[i] == "--port":
            uPort = int(asArgs[i + 1])
            i = i + 2
        elif asArgs[i] == "--reversed-setup":
            fReversedSetup = True
            i = i + 1
        elif asArgs[i] == "--timeout":
            cMsTimeout = long(asArgs[i + 1])
            i = i + 2
        elif asArgs[i] == "--reboot":
            fReboot = True
            fStdTests = False
            i = i + 1
        elif asArgs[i] == "--help":
            print "tst-txsclient.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>] [--reboot] [--reversed-setup]"
            return 0
        else:
            print "Unknown argument: %s" % (asArgs[i])
            return 2

    if uPort is None:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, fReversedSetup=fReversedSetup)
    else:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, uPort=uPort, fReversedSetup=fReversedSetup)
    if oSession is None:
        print "openTcpSession failed"
        return 1

    fDone = oSession.waitForTask(30 * 1000)
    print "connect: waitForTask -> %s, result %s" % (fDone, oSession.getResult())
    if fDone is True and oSession.isSuccess():
        if fStdTests:
            # Get the UUID of the remote instance.
            sUuid = oSession.syncUuid()
            if sUuid is not False:
                print "%s: UUID = %s" % (boolRes(True), sUuid)
            else:
                print "%s: UUID" % (boolRes(False),)

            # Create and remove a directory on the scratch area.
            rc = oSession.syncMkDir("${SCRATCH}/testdir1")
            print "%s: MKDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncIsDir("${SCRATCH}/testdir1")
            print "%s: ISDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncRmDir("${SCRATCH}/testdir1")
            print "%s: RMDIR(${SCRATCH}/testdir1) -> %s" % (boolRes(rc), rc)

            # Create a two-level subdir.
            rc = oSession.syncMkDirPath("${SCRATCH}/testdir2/subdir1")
            print "%s: MKDRPATH(${SCRATCH}/testdir2/subdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncIsDir("${SCRATCH}/testdir2")
            print "%s: ISDIR(${SCRATCH}/testdir2) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/testdir2/")
            print "%s: ISDIR(${SCRATCH}/testdir2/) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/testdir2/subdir1")
            print "%s: ISDIR(${SCRATCH}/testdir2/subdir1) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncRmTree("${SCRATCH}/testdir2")
            print "%s: RMTREE(${SCRATCH}/testdir2) -> %s" % (boolRes(rc), rc)

            # Check out a simple file.
            rc = oSession.syncUploadString("howdy", "${SCRATCH}/howdyfile")
            print "%s: PUT FILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncUploadString("howdy-replaced", "${SCRATCH}/howdyfile")
            print "%s: PUT FILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            rc = oSession.syncDownloadString("${SCRATCH}/howdyfile")
            print '%s: GET FILE(${SCRATCH}/howdyfile) -> "%s" expected "howdy-replaced"' % (
                stringRes(rc, "howdy-replaced"),
                rc,
            )

            rc = oSession.syncIsFile("${SCRATCH}/howdyfile")
            print "%s: ISFILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)
            rc = oSession.syncIsDir("${SCRATCH}/howdyfile")
            print "%s: ISDIR(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc, False), rc)
            rc = oSession.syncIsSymlink("${SCRATCH}/howdyfile")
            print "%s: ISSYMLNK(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc, False), rc)

            rc = oSession.syncRmFile("${SCRATCH}/howdyfile")
            print "%s: RMFILE(${SCRATCH}/howdyfile) -> %s" % (boolRes(rc), rc)

            # Unicode filename (may or may not work, LANG/LC_TYPE dependent on some hosts).
            rc = oSession.syncUploadString("howdy", u"${SCRATCH}/Schröder")
            print (u"%s: PUT FILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            rc = oSession.syncIsFile(u"${SCRATCH}/Schröder")
            print (u"%s: ISFILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            rc = oSession.syncRmFile(u"${SCRATCH}/Schröder")
            print (u"%s: RMFILE(${SCRATCH}/Schröder) -> %s" % (boolRes(rc), rc)).encode("ascii", "replace")

            # Finally, some file uploading and downloading with unicode filenames.
            strUpFile = "tst-txsclient-upload.bin"
            strDwnFile = "tst-txsclient-download.bin"
            try:
                abRandFile = os.urandom(257897)
            except:
                print "INFO: no urandom... falling back on a simple string."
                abRandFile = "asdflkjasdlfkjasdlfkjq023942relwjgkna9epr865u2nm345;hndafgoukhasre5kb2453km"
                for i in range(1, 64):
                    abRandFile += abRandFile
            try:
                oLocalFile = utils.openNoInherit(strUpFile, "w+b")
                oLocalFile.write(abRandFile)
                oLocalFile.close()
                rc = True
            except:
                rc = False
                print ("%s: creating file (%s) to upload failed...." % (boolRes(rc), strUpFile))

            if rc is True:
                rc = oSession.syncUploadFile(strUpFile, "${SCRATCH}/tst-txsclient-uploaded.bin")
                print ("%s: PUT FILE(%s, ${SCRATCH}/tst-txsclient-uploaded.bin) -> %s" % (boolRes(rc), strUpFile, rc))

                rc = oSession.syncDownloadFile("${SCRATCH}/tst-txsclient-uploaded.bin", strDwnFile)
                print (
                    "%s: GET FILE(${SCRATCH}/tst-txsclient-uploaded.bin, tst-txsclient-downloaded.txt) -> %s"
                    % (boolRes(rc), rc)
                )

                try:
                    oLocalFile = utils.openNoInherit(strDwnFile, "rb")
                    abDwnFile = oLocalFile.read()
                    oLocalFile.close()
                    if abRandFile == abDwnFile:
                        print "%s: downloaded file matches the uploaded file" % (boolRes(True),)
                    else:
                        print "%s: downloaded file does not match the uploaded file" % (boolRes(False),)
                        print "abRandFile=%s" % (abRandFile,)
                        print "abDwnFile =%s" % (abRandFile,)
                except:
                    print "%s: reading downloaded file (%s) failed...." % (boolRes(False), strDwnFile)

                rc = oSession.syncRmFile(u"${SCRATCH}/tst-txsclient-uploaded.bin")
                print "%s: RMFILE(${SCRATCH}/tst-txsclient-uploaded.bin) -> %s" % (boolRes(rc), rc)

            try:
                os.remove(strUpFile)
            except:
                pass
            try:
                os.remove(strDwnFile)
            except:
                pass

            # Execute some simple thing, if available.
            # Intentionally skip this test if file is not available due to
            # another inserted CD-ROM (e.g. not TestSuite.iso).
            sProg = "${CDROM}/${OS/ARCH}/NetPerf${EXESUFF}"
            rc = oSession.syncIsFile(sProg, 30 * 1000, True)
            if rc is True:
                rc = oSession.syncExecEx(sProg, (sProg, "--help"))
                print "%s: EXEC(%s ${SCRATCH}) -> %s" % (boolRes(rc), sProg, rc)

                rc = oSession.syncExecEx(
                    sProg,
                    (sProg, "there", "is no such", "parameter"),
                    oStdOut="${SCRATCH}/stdout",
                    oStdErr="${SCRATCH}/stderr",
                )
                print (
                    "%s: EXEC(%s there is not such parameter > ${SCRATCH}/stdout 2> ${SCRATCH}/stderr) -> %s"
                    % (boolRes(rc, False), sProg, rc)
                )

                rc = oSession.syncDownloadString("${SCRATCH}/stdout")
                print 'INFO:   GET FILE(${SCRATCH}/stdout) -> "%s"' % (rc)
                rc = oSession.syncDownloadString("${SCRATCH}/stderr")
                print 'INFO:   GET FILE(${SCRATCH}/stderr) -> "%s"' % (rc)

                print "TESTING: syncExec..."
                rc = oSession.syncExec(sProg, (sProg, "--version"))
                print "%s: EXEC(%s --version) -> %s" % (boolRes(rc), sProg, rc)

                print "TESTING: syncExec..."
                rc = oSession.syncExec(sProg, (sProg, "--help"))
                print "%s: EXEC(%s --help) -> %s" % (boolRes(rc), sProg, rc)

                # print 'TESTING: syncExec sleep 30...'
                # rc = oSession.syncExec('/usr/bin/sleep', ('/usr/bin/sleep', '30'));
                # print '%s: EXEC(/bin/sleep 30) -> %s' % (boolRes(rc), rc);
            else:
                print "SKIP:   Execution of %s skipped, does not exist on CD-ROM" % (sProg,)

            # Execute a non-existing file on CD-ROM.
            sProg = "${CDROM}/${OS/ARCH}/NonExisting${EXESUFF}"
            rc = oSession.syncExecEx(
                sProg,
                (sProg,),
                oStdIn="/dev/null",
                oStdOut="/dev/null",
                oStdErr="/dev/null",
                oTestPipe="/dev/null",
                sAsUser="",
                cMsTimeout=3600000,
                fIgnoreErrors=True,
            )
            if rc is None:
                rc = True
            else:
                reporter.error('Unexpected value "%s" while executing non-existent file "%s"' % (rc, sProg))
            print "%s: EXEC(%s ${SCRATCH}) -> %s" % (boolRes(rc), sProg, rc)

            # Done
            rc = oSession.syncDisconnect()
            print "%s: disconnect() -> %s" % (boolRes(rc), rc)

        elif fReboot:
            print "TESTING: syncReboot..."
            rc = oSession.syncReboot()
            print "%s: REBOOT() -> %s" % (boolRes(rc), rc)

    if g_cFailures != 0:
        print "tst-txsclient.py: %u out of %u test failed" % (g_cFailures, g_cTests)
        return 1
    print "tst-txsclient.py: all %u tests passed!" % (g_cTests)
    return 0
def main(asArgs): # pylint: disable=C0111,R0914,R0915
    cMsTimeout      = long(30*1000);
    sAddress        = 'localhost';
    uPort           = None;
    fReversedSetup  = False;
    fReboot         = False;
    fShutdown       = False;
    fStdTests       = True;

    i = 1;
    while i < len(asArgs):
        if asArgs[i] == '--hostname':
            sAddress = asArgs[i + 1];
            i = i + 2;
        elif asArgs[i] == '--port':
            uPort = int(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reversed-setup':
            fReversedSetup = True;
            i = i + 1;
        elif asArgs[i] == '--timeout':
            cMsTimeout = long(asArgs[i + 1]);
            i = i + 2;
        elif asArgs[i] == '--reboot':
            fReboot   = True;
            fShutdown = False;
            fStdTests = False;
            i = i + 1;
        elif asArgs[i] == '--shutdown':
            fShutdown = True;
            fReboot   = False;
            fStdTests = False;
            i = i + 1;
        elif asArgs[i] == '--help':
            print('tst-txsclient.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>] '
                  '[--reboot|--shutdown] [--reversed-setup]');
            return 0;
        else:
            print('Unknown argument: %s' % (asArgs[i]));
            return 2;

    if uPort is None:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, fReversedSetup = fReversedSetup);
    else:
        oSession = txsclient.openTcpSession(cMsTimeout, sAddress, uPort = uPort, fReversedSetup = fReversedSetup);
    if oSession is None:
        print('openTcpSession failed');
        return 1;

    fDone = oSession.waitForTask(30*1000);
    print('connect: waitForTask -> %s, result %s' % (fDone, oSession.getResult()));
    if fDone is True and oSession.isSuccess():
        if fStdTests:
            # Get the UUID of the remote instance.
            sUuid = oSession.syncUuid();
            if sUuid is not False:
                print('%s: UUID = %s' % (boolRes(True), sUuid));
            else:
                print('%s: UUID' % (boolRes(False),));

            # Create and remove a directory on the scratch area.
            rc = oSession.syncMkDir('${SCRATCH}/testdir1');
            print('%s: MKDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncIsDir('${SCRATCH}/testdir1');
            print('%s: ISDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncRmDir('${SCRATCH}/testdir1');
            print('%s: RMDIR(${SCRATCH}/testdir1) -> %s' % (boolRes(rc), rc));

            # Create a two-level subdir.
            rc = oSession.syncMkDirPath('${SCRATCH}/testdir2/subdir1');
            print('%s: MKDRPATH(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncIsDir('${SCRATCH}/testdir2');
            print('%s: ISDIR(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/');
            print('%s: ISDIR(${SCRATCH}/testdir2/) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/testdir2/subdir1');
            print('%s: ISDIR(${SCRATCH}/testdir2/subdir1) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncRmTree('${SCRATCH}/testdir2');
            print('%s: RMTREE(${SCRATCH}/testdir2) -> %s' % (boolRes(rc), rc));

            # Check out a simple file.
            rc = oSession.syncUploadString('howdy', '${SCRATCH}/howdyfile');
            print('%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncUploadString('howdy-replaced', '${SCRATCH}/howdyfile');
            print('%s: PUT FILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            rc = oSession.syncDownloadString('${SCRATCH}/howdyfile');
            print('%s: GET FILE(${SCRATCH}/howdyfile) -> "%s" expected "howdy-replaced"' % (stringRes(rc, 'howdy-replaced'), rc));

            rc = oSession.syncIsFile('${SCRATCH}/howdyfile');
            print('%s: ISFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));
            rc = oSession.syncIsDir('${SCRATCH}/howdyfile');
            print('%s: ISDIR(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc));
            rc = oSession.syncIsSymlink('${SCRATCH}/howdyfile');
            print('%s: ISSYMLNK(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc, False), rc));

            rc = oSession.syncRmFile('${SCRATCH}/howdyfile');
            print('%s: RMFILE(${SCRATCH}/howdyfile) -> %s' % (boolRes(rc), rc));

            # Unicode filename (may or may not work, LANG/LC_TYPE dependent on some hosts).
            rc = oSession.syncUploadString('howdy', u'${SCRATCH}/Schröder');
            print((u'%s: PUT FILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            rc = oSession.syncIsFile(u'${SCRATCH}/Schröder');
            print((u'%s: ISFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            rc = oSession.syncRmFile(u'${SCRATCH}/Schröder');
            print((u'%s: RMFILE(${SCRATCH}/Schröder) -> %s' % (boolRes(rc), rc)).encode('ascii', 'replace'));

            # Finally, some file uploading and downloading with unicode filenames.
            strUpFile  = 'tst-txsclient-upload.bin';
            strDwnFile = 'tst-txsclient-download.bin';
            try:
                abRandFile = os.urandom(257897);
            except:
                print('INFO: no urandom... falling back on a simple string.');
                abRandFile = 'asdflkjasdlfkjasdlfkjq023942relwjgkna9epr865u2nm345;hndafgoukhasre5kb2453km';
                for i in range(1, 64):
                    abRandFile += abRandFile;
            try:
                oLocalFile = utils.openNoInherit(strUpFile, 'w+b');
                oLocalFile.write(abRandFile);
                oLocalFile.close();
                rc = True;
            except:
                rc = False;
                print('%s: creating file (%s) to upload failed....' % (boolRes(rc), strUpFile));

            if rc is True:
                rc = oSession.syncUploadFile(strUpFile, '${SCRATCH}/tst-txsclient-uploaded.bin')
                print('%s: PUT FILE(%s, ${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), strUpFile, rc));

                rc = oSession.syncDownloadFile('${SCRATCH}/tst-txsclient-uploaded.bin', strDwnFile)
                print('%s: GET FILE(${SCRATCH}/tst-txsclient-uploaded.bin, tst-txsclient-downloaded.txt) -> %s'
                      % (boolRes(rc), rc));

                try:
                    oLocalFile = utils.openNoInherit(strDwnFile, "rb");
                    abDwnFile = oLocalFile.read();
                    oLocalFile.close();
                    if abRandFile == abDwnFile:
                        print('%s: downloaded file matches the uploaded file' % (boolRes(True),));
                    else:
                        print('%s: downloaded file does not match the uploaded file' % (boolRes(False),));
                        print('abRandFile=%s' % (abRandFile,));
                        print('abDwnFile =%s' % (abRandFile,));
                except:
                    print('%s: reading downloaded file (%s) failed....' % (boolRes(False), strDwnFile));

                rc = oSession.syncRmFile(u'${SCRATCH}/tst-txsclient-uploaded.bin');
                print('%s: RMFILE(${SCRATCH}/tst-txsclient-uploaded.bin) -> %s' % (boolRes(rc), rc));

            try:    os.remove(strUpFile);
            except: pass;
            try:    os.remove(strDwnFile);
            except: pass;

            # Execute some simple thing, if available.
            # Intentionally skip this test if file is not available due to
            # another inserted CD-ROM (e.g. not TestSuite.iso).
            sProg = '${CDROM}/${OS/ARCH}/NetPerf${EXESUFF}';
            rc = oSession.syncIsFile(sProg, 30 * 1000, True);
            if rc is True:
                rc = oSession.syncExecEx(sProg, (sProg, '--help'));
                print('%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc));

                rc = oSession.syncExecEx(sProg, (sProg, 'there', 'is no such', 'parameter'), \
                                         oStdOut='${SCRATCH}/stdout', \
                                         oStdErr='${SCRATCH}/stderr');
                print('%s: EXEC(%s there is not such parameter > ${SCRATCH}/stdout 2> ${SCRATCH}/stderr) -> %s'
                      % (boolRes(rc, False), sProg, rc));

                rc = oSession.syncDownloadString('${SCRATCH}/stdout');
                print('INFO:   GET FILE(${SCRATCH}/stdout) -> "%s"' % (rc));
                rc = oSession.syncDownloadString('${SCRATCH}/stderr');
                print('INFO:   GET FILE(${SCRATCH}/stderr) -> "%s"' % (rc));

                print('TESTING: syncExec...');
                rc = oSession.syncExec(sProg, (sProg, '--version'));
                print('%s: EXEC(%s --version) -> %s' % (boolRes(rc), sProg, rc));

                print('TESTING: syncExec...');
                rc = oSession.syncExec(sProg, (sProg, '--help'));
                print('%s: EXEC(%s --help) -> %s' % (boolRes(rc), sProg, rc));

                #print('TESTING: syncExec sleep 30...'
                #rc = oSession.syncExec('/usr/bin/sleep', ('/usr/bin/sleep', '30')));
                #print('%s: EXEC(/bin/sleep 30) -> %s' % (boolRes(rc), rc));
            else:
                print('SKIP:   Execution of %s skipped, does not exist on CD-ROM' % (sProg,));

            # Execute a non-existing file on CD-ROM.
            sProg = '${CDROM}/${OS/ARCH}/NonExisting${EXESUFF}';
            rc = oSession.syncExecEx(sProg, (sProg,), oStdIn = '/dev/null', oStdOut = '/dev/null', \
                                     oStdErr = '/dev/null', oTestPipe = '/dev/null', \
                                     sAsUser = '', cMsTimeout = 3600000, fIgnoreErrors = True);
            if rc is None:
                rc = True;
            else:
                reporter.error('Unexpected value \"%s\" while executing non-existent file "%s"' % (rc, sProg));
            print('%s: EXEC(%s ${SCRATCH}) -> %s' % (boolRes(rc), sProg, rc));

            # Done
            rc = oSession.syncDisconnect();
            print('%s: disconnect() -> %s' % (boolRes(rc), rc));

        elif fReboot:
            print('TESTING: syncReboot...');
            rc = oSession.syncReboot();
            print('%s: REBOOT() -> %s' % (boolRes(rc), rc));
        elif fShutdown:
            print('TESTING: syncShutdown...');
            rc = oSession.syncShutdown();
            print('%s: SHUTDOWN() -> %s' % (boolRes(rc), rc));


    if g_cFailures != 0:
        print('tst-txsclient.py: %u out of %u test failed' % (g_cFailures, g_cTests));
        return 1;
    print('tst-txsclient.py: all %u tests passed!' % (g_cTests));
    return 0;