Beispiel #1
0
    def _executeSubDriver(self, asActions, fMaySkip=True, fPreloadASan=True):
        """
        Execute the sub testdriver with the specified action.
        """
        asArgs = list(self._asSubDriver)
        asArgs.append('--no-wipe-clean')
        asArgs.extend(asActions)

        asASanLibs = []
        if fPreloadASan:
            asASanLibs = self._findASanLibsForASanBuild()
        if asASanLibs:
            os.environ['LD_PRELOAD'] = ':'.join(asASanLibs)
            os.environ['LSAN_OPTIONS'] = 'detect_leaks=0'
            # We don't want python leaks. vbox.py disables this.

            # Because of https://github.com/google/sanitizers/issues/856 we must try use setarch to disable
            # address space randomization.

            reporter.log('LD_PRELOAD...')
            if utils.getHostArch() == 'amd64':
                sSetArch = utils.whichProgram('setarch')
                reporter.log('sSetArch=%s' % (sSetArch, ))
                if sSetArch:
                    asArgs = [sSetArch, 'x86_64', '-R', sys.executable
                              ] + asArgs
                    reporter.log('asArgs=%s' % (asArgs, ))

            rc = self._executeSync(asArgs, fMaySkip=fMaySkip)

            del os.environ['LSAN_OPTIONS']
            del os.environ['LD_PRELOAD']
            return rc

        return self._executeSync(asArgs, fMaySkip=fMaySkip)
    def _getHelperOutput(self, sCmd):
        """
        Invokes TestBoxHelper to obtain information hard to access from python.
        """
        if self._sTestBoxHelper is None:
            if not utils.isRunningFromCheckout():
                # See VBoxTestBoxScript.zip for layout.
                self._sTestBoxHelper = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch(), \
                                                    'TestBoxHelper');
            else: # Only for in-tree testing, so don't bother be too accurate right now.
                sType = os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug'));
                self._sTestBoxHelper = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', \
                                                    utils.getHostOsDotArch(), sType, 'testboxscript', \
                                                    utils.getHostOs(), utils.getHostArch(), \
                                                    'TestBoxHelper');
            if utils.getHostOs() in ['win', 'os2']:
                self._sTestBoxHelper += '.exe';

        return utils.processOutputChecked([self._sTestBoxHelper, sCmd]).strip();
    def _getHelperOutput(self, sCmd):
        """
        Invokes TestBoxHelper to obtain information hard to access from python.
        """
        if self._sTestBoxHelper is None:
            if not utils.isRunningFromCheckout():
                # See VBoxTestBoxScript.zip for layout.
                self._sTestBoxHelper = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch(), \
                                                    'TestBoxHelper');
            else: # Only for in-tree testing, so don't bother be too accurate right now.
                sType = os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug'));
                self._sTestBoxHelper = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', \
                                                    utils.getHostOsDotArch(), sType, 'testboxscript', \
                                                    utils.getHostOs(), utils.getHostArch(), \
                                                    'TestBoxHelper');
            if utils.getHostOs() in ['win', 'os2']:
                self._sTestBoxHelper += '.exe';

        return utils.processOutputChecked([self._sTestBoxHelper, sCmd]).strip();
Beispiel #4
0
def checkProcessHeap():
    """
    Calls HeapValidate(GetProcessHeap(), 0, NULL);
    """

    # Get the process heap.
    try:
        hHeap = ctypes.windll.kernel32.GetProcessHeap()
    except:
        reporter.logXcpt()
        return False

    # Check it.
    try:
        fIsOkay = ctypes.windll.kernel32.HeapValidate(hHeap, 0, None)
    except:
        reporter.logXcpt()
        return False

    if fIsOkay == 0:
        reporter.log('HeapValidate failed!')

        # Try trigger a dump using c:\utils\procdump64.exe.
        from common import utils

        iPid = os.getpid()
        asArgs = [
            'e:\\utils\\procdump64.exe', '-ma',
            '%s' % (iPid, ),
            'c:\\CrashDumps\\python.exe-%u-heap.dmp' % (iPid, )
        ]
        if utils.getHostArch() != 'amd64':
            asArgs[0] = 'c:\\utils\\procdump.exe'
        reporter.log('Trying to dump this process using: %s' % (asArgs, ))
        utils.processCall(asArgs)

        # Generate a crash exception.
        ctypes.windll.msvcrt.strcpy(None, None, 1024)

    return True
def checkProcessHeap():
    """
    Calls HeapValidate(GetProcessHeap(), 0, NULL);
    """

    # Get the process heap.
    try:
        hHeap = ctypes.windll.kernel32.GetProcessHeap();
    except:
        reporter.logXcpt();
        return False;

    # Check it.
    try:
        fIsOkay = ctypes.windll.kernel32.HeapValidate(hHeap, 0, None);
    except:
        reporter.logXcpt();
        return False;

    if fIsOkay == 0:
        reporter.log('HeapValidate failed!');

        # Try trigger a dump using c:\utils\procdump64.exe.
        from common import utils;

        iPid = os.getpid();
        asArgs = [ 'e:\\utils\\procdump64.exe', '-ma', '%s' % (iPid,), 'c:\\CrashDumps\\python.exe-%u-heap.dmp' % (iPid,)];
        if utils.getHostArch() != 'amd64':
            asArgs[0] = 'c:\\utils\\procdump.exe'
        reporter.log('Trying to dump this process using: %s' % (asArgs,));
        utils.processCall(asArgs);

        # Generate a crash exception.
        ctypes.windll.msvcrt.strcpy(None, None, 1024);

    return True;
    def __init__(self, oOptions):
        """
        Initialize internals
        """
        self._oOptions        = oOptions;
        self._sTestBoxHelper  = None;

        # Signed-on state
        self._cSignOnAttempts = 0;
        self._fSignedOn       = False;
        self._fNeedReSignOn   = False;
        self._fFirstSignOn    = True;
        self._idTestBox       = None;
        self._sTestBoxName    = '';
        self._sTestBoxUuid    = self.ksNullUuid; # convenience, assigned below.

        # Command processor.
        self._oCommand = TestBoxCommand(self);

        #
        # Scratch dir setup.  Use /var/tmp instead of /tmp because we may need
        # many many GBs for some test scenarios and /tmp can be backed by swap
        # or be a fast+small disk of some kind, while /var/tmp is normally
        # larger, if slower.  /var/tmp is generally not cleaned up on reboot,
        # /tmp often is, this would break host panic / triple-fault detection.
        #
        if self._oOptions.sScratchRoot is None:
            if utils.getHostOs() in ('win', 'os2', 'haiku', 'dos'):
                # We need *lots* of space, so avoid /tmp as it may be a memory
                # file system backed by the swap file, or worse.
                self._oOptions.sScratchRoot = tempfile.gettempdir();
            else:
                self._oOptions.sScratchRoot = '/var/tmp';
            sSubDir = 'testbox';
            try:
                sSubDir = '%s-%u' % (sSubDir, os.getuid()); # pylint: disable=E1101
            except:
                pass;
            self._oOptions.sScratchRoot = os.path.join(self._oOptions.sScratchRoot, sSubDir);

        self._sScratchSpill   = os.path.join(self._oOptions.sScratchRoot, 'scratch');
        self._sScratchScripts = os.path.join(self._oOptions.sScratchRoot, 'scripts');
        self._sScratchState   = os.path.join(self._oOptions.sScratchRoot, 'state');   # persistant storage.

        for sDir in [self._oOptions.sScratchRoot, self._sScratchSpill, self._sScratchScripts, self._sScratchState]:
            if not os.path.isdir(sDir):
                os.makedirs(sDir, 0700);

        # We count consecutive reinitScratch failures and will reboot the
        # testbox after a while in the hope that it will correct the issue.
        self._cReinitScratchErrors = 0;

        #
        # Mount builds and test resources if requested.
        #
        self.mountShares();

        #
        # Sign-on parameters: Packed into list of records of format:
        # { <Parameter ID>: { <Current value>, <Check function> } }
        #
        self._ddSignOnParams = \
        {
            constants.tbreq.ALL_PARAM_TESTBOX_UUID:        { self.VALUE: self._getHostSystemUuid(),    self.FN: None },
            constants.tbreq.SIGNON_PARAM_OS:               { self.VALUE: utils.getHostOs(),            self.FN: None },
            constants.tbreq.SIGNON_PARAM_OS_VERSION:       { self.VALUE: utils.getHostOsVersion(),     self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_ARCH:         { self.VALUE: utils.getHostArch(),          self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_VENDOR:       { self.VALUE: self._getHostCpuVendor(),     self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_NAME:         { self.VALUE: self._getHostCpuName(),       self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_REVISION:     { self.VALUE: self._getHostCpuRevision(),   self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_HW_VIRT:      { self.VALUE: self._hasHostHwVirt(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_NESTED_PAGING:{ self.VALUE: self._hasHostNestedPaging(),  self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_64_BIT_GUEST: { self.VALUE: self._can64BitGuest(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_IOMMU:        { self.VALUE: self._hasHostIoMmu(),         self.FN: None },
            #constants.tbreq.SIGNON_PARAM_WITH_RAW_MODE:    { self.VALUE: self._withRawModeSupport(),   self.FN: None },
            constants.tbreq.SIGNON_PARAM_SCRIPT_REV:       { self.VALUE: self._getScriptRev(),         self.FN: None },
            constants.tbreq.SIGNON_PARAM_REPORT:           { self.VALUE: self._getHostReport(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_PYTHON_VERSION:   { self.VALUE: self._getPythonHexVersion(),  self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_COUNT:        { self.VALUE: None,     self.FN: multiprocessing.cpu_count },
            constants.tbreq.SIGNON_PARAM_MEM_SIZE:         { self.VALUE: None,     self.FN: self._getHostMemSize },
            constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE:     { self.VALUE: None,     self.FN: self._getFreeScratchSpace },
        }
        for sItem in self._ddSignOnParams:
            if self._ddSignOnParams[sItem][self.FN] is not None:
                self._ddSignOnParams[sItem][self.VALUE] = self._ddSignOnParams[sItem][self.FN]()

        testboxcommons.log('Starting Test Box script (%s)' % __version__)
        testboxcommons.log('Test Manager URL: %s' % self._oOptions.sTestManagerUrl,)
        testboxcommons.log('Scratch root path: %s' % self._oOptions.sScratchRoot,)
        for sItem in self._ddSignOnParams:
            testboxcommons.log('Sign-On value %18s: %s' % (sItem, self._ddSignOnParams[sItem][self.VALUE]));

        #
        # The System UUID is the primary identification of the machine, so
        # refuse to cooperate if it's NULL.
        #
        self._sTestBoxUuid = self.getSignOnParam(constants.tbreq.ALL_PARAM_TESTBOX_UUID);
        if self._sTestBoxUuid == self.ksNullUuid:
            raise TestBoxScriptException('Couldn\'t determine the System UUID, please use --system-uuid to specify it.');

        #
        # Export environment variables, clearing any we don't know yet.
        #
        for sEnvVar in self._oOptions.asEnvVars:
            iEqual = sEnvVar.find('=');
            if iEqual == -1:    # No '=', remove it.
                if sEnvVar in os.environ:
                    del os.environ[sEnvVar];
            elif iEqual > 0:    # Set it.
                os.environ[sEnvVar[:iEqual]] = sEnvVar[iEqual+1:];
            else:               # Starts with '=', bad user.
                raise TestBoxScriptException('Invalid -E argument: "%s"' % (sEnvVar,));

        os.environ['TESTBOX_PATH_BUILDS']       = self._oOptions.sBuildsPath;
        os.environ['TESTBOX_PATH_RESOURCES']    = self._oOptions.sTestRsrcPath;
        os.environ['TESTBOX_PATH_SCRATCH']      = self._sScratchSpill;
        os.environ['TESTBOX_PATH_SCRIPTS']      = self._sScratchScripts;
        os.environ['TESTBOX_PATH_UPLOAD']       = self._sScratchSpill; ## @todo drop the UPLOAD dir?
        os.environ['TESTBOX_HAS_HW_VIRT']       = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_HW_VIRT);
        os.environ['TESTBOX_HAS_NESTED_PAGING'] = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_NESTED_PAGING);
        os.environ['TESTBOX_HAS_IOMMU']         = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_IOMMU);
        os.environ['TESTBOX_SCRIPT_REV']        = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_SCRIPT_REV);
        os.environ['TESTBOX_CPU_COUNT']         = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_CPU_COUNT);
        os.environ['TESTBOX_MEM_SIZE']          = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_MEM_SIZE);
        os.environ['TESTBOX_SCRATCH_SIZE']      = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE);
        #TODO: os.environ['TESTBOX_WITH_RAW_MODE']     = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_WITH_RAW_MODE);
        os.environ['TESTBOX_WITH_RAW_MODE']     = self._withRawModeSupport();
        os.environ['TESTBOX_MANAGER_URL']       = self._oOptions.sTestManagerUrl;
        os.environ['TESTBOX_UUID']              = self._sTestBoxUuid;
        os.environ['TESTBOX_REPORTER']          = 'remote';
        os.environ['TESTBOX_NAME']              = '';
        os.environ['TESTBOX_ID']                = '';
        os.environ['TESTBOX_TEST_SET_ID']       = '';
        os.environ['TESTBOX_TIMEOUT']           = '0';
        os.environ['TESTBOX_TIMEOUT_ABS']       = '0';

        if utils.getHostOs() is 'win':
            os.environ['COMSPEC']            = os.path.join(os.environ['SystemRoot'], 'System32', 'cmd.exe');
Beispiel #7
0
 def postRequestRaw(self, sAction, dParams):
     """
     Posts a request to the test manager and gets the response.  The dParams
     argument is a dictionary of unencoded key-value pairs (will be
     modified).
     Raises exception on failure.
     """
     dHeader = \
     {
         'Content-Type':     'application/x-www-form-urlencoded; charset=utf-8',
         'User-Agent':       'TestBoxScript/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch()),
         'Accept':           'text/plain,application/x-www-form-urlencoded',
         'Accept-Encoding':  'identity',
         'Cache-Control':    'max-age=0',
         'Connection':       'keep-alive',
     }
     sServerPath = '/%s/testboxdisp.py' % (
         self._oParsedUrl.path.strip('/'), )
     # pylint: disable=no-member
     dParams[constants.tbreq.ALL_PARAM_ACTION] = sAction
     sBody = urllib_urlencode(dParams)
     ##testboxcommons.log2('sServerPath=%s' % (sServerPath,));
     try:
         self._oConn.request('POST', sServerPath, sBody, dHeader)
         oResponse = self._oConn.getresponse()
         oResponse2 = TestBoxResponse(oResponse)
     except:
         testboxcommons.log2Xcpt()
         raise
     return oResponse2
    def __init__(self, oOptions):
        """
        Initialize internals
        """
        self._oOptions        = oOptions;
        self._sTestBoxHelper  = None;

        # Signed-on state
        self._cSignOnAttempts = 0;
        self._fSignedOn       = False;
        self._fNeedReSignOn   = False;
        self._fFirstSignOn    = True;
        self._idTestBox       = None;
        self._sTestBoxName    = '';
        self._sTestBoxUuid    = self.ksNullUuid; # convenience, assigned below.

        # Command processor.
        self._oCommand = TestBoxCommand(self);

        #
        # Scratch dir setup.  Use /var/tmp instead of /tmp because we may need
        # many many GBs for some test scenarios and /tmp can be backed by swap
        # or be a fast+small disk of some kind, while /var/tmp is normally
        # larger, if slower.  /var/tmp is generally not cleaned up on reboot,
        # /tmp often is, this would break host panic / triple-fault detection.
        #
        if self._oOptions.sScratchRoot is None:
            if utils.getHostOs() in ('win', 'os2', 'haiku', 'dos'):
                # We need *lots* of space, so avoid /tmp as it may be a memory
                # file system backed by the swap file, or worse.
                self._oOptions.sScratchRoot = tempfile.gettempdir();
            else:
                self._oOptions.sScratchRoot = '/var/tmp';
            sSubDir = 'testbox';
            try:
                sSubDir = '%s-%u' % (sSubDir, os.getuid()); # pylint: disable=E1101
            except:
                pass;
            self._oOptions.sScratchRoot = os.path.join(self._oOptions.sScratchRoot, sSubDir);

        self._sScratchSpill   = os.path.join(self._oOptions.sScratchRoot, 'scratch');
        self._sScratchScripts = os.path.join(self._oOptions.sScratchRoot, 'scripts');
        self._sScratchState   = os.path.join(self._oOptions.sScratchRoot, 'state');   # persistant storage.

        for sDir in [self._oOptions.sScratchRoot, self._sScratchSpill, self._sScratchScripts, self._sScratchState]:
            if not os.path.isdir(sDir):
                os.makedirs(sDir, 0700);

        # We count consecutive reinitScratch failures and will reboot the
        # testbox after a while in the hope that it will correct the issue.
        self._cReinitScratchErrors = 0;

        #
        # Mount builds and test resources if requested.
        #
        self.mountShares();

        #
        # Sign-on parameters: Packed into list of records of format:
        # { <Parameter ID>: { <Current value>, <Check function> } }
        #
        self._ddSignOnParams = \
        {
            constants.tbreq.ALL_PARAM_TESTBOX_UUID:        { self.VALUE: self._getHostSystemUuid(),    self.FN: None },
            constants.tbreq.SIGNON_PARAM_OS:               { self.VALUE: utils.getHostOs(),            self.FN: None },
            constants.tbreq.SIGNON_PARAM_OS_VERSION:       { self.VALUE: utils.getHostOsVersion(),     self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_ARCH:         { self.VALUE: utils.getHostArch(),          self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_VENDOR:       { self.VALUE: self._getHostCpuVendor(),     self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_NAME:         { self.VALUE: self._getHostCpuName(),       self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_REVISION:     { self.VALUE: self._getHostCpuRevision(),   self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_HW_VIRT:      { self.VALUE: self._hasHostHwVirt(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_NESTED_PAGING:{ self.VALUE: self._hasHostNestedPaging(),  self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_64_BIT_GUEST: { self.VALUE: self._can64BitGuest(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_HAS_IOMMU:        { self.VALUE: self._hasHostIoMmu(),         self.FN: None },
            #constants.tbreq.SIGNON_PARAM_WITH_RAW_MODE:    { self.VALUE: self._withRawModeSupport(),   self.FN: None },
            constants.tbreq.SIGNON_PARAM_SCRIPT_REV:       { self.VALUE: self._getScriptRev(),         self.FN: None },
            constants.tbreq.SIGNON_PARAM_REPORT:           { self.VALUE: self._getHostReport(),        self.FN: None },
            constants.tbreq.SIGNON_PARAM_PYTHON_VERSION:   { self.VALUE: self._getPythonHexVersion(),  self.FN: None },
            constants.tbreq.SIGNON_PARAM_CPU_COUNT:        { self.VALUE: None,     self.FN: multiprocessing.cpu_count },
            constants.tbreq.SIGNON_PARAM_MEM_SIZE:         { self.VALUE: None,     self.FN: self._getHostMemSize },
            constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE:     { self.VALUE: None,     self.FN: self._getFreeScratchSpace },
        }
        for sItem in self._ddSignOnParams:
            if self._ddSignOnParams[sItem][self.FN] is not None:
                self._ddSignOnParams[sItem][self.VALUE] = self._ddSignOnParams[sItem][self.FN]()

        testboxcommons.log('Starting Test Box script (%s)' % (self._getScriptRev(),));
        testboxcommons.log('Test Manager URL: %s' % self._oOptions.sTestManagerUrl,)
        testboxcommons.log('Scratch root path: %s' % self._oOptions.sScratchRoot,)
        for sItem in self._ddSignOnParams:
            testboxcommons.log('Sign-On value %18s: %s' % (sItem, self._ddSignOnParams[sItem][self.VALUE]));

        #
        # The System UUID is the primary identification of the machine, so
        # refuse to cooperate if it's NULL.
        #
        self._sTestBoxUuid = self.getSignOnParam(constants.tbreq.ALL_PARAM_TESTBOX_UUID);
        if self._sTestBoxUuid == self.ksNullUuid:
            raise TestBoxScriptException('Couldn\'t determine the System UUID, please use --system-uuid to specify it.');

        #
        # Export environment variables, clearing any we don't know yet.
        #
        for sEnvVar in self._oOptions.asEnvVars:
            iEqual = sEnvVar.find('=');
            if iEqual == -1:    # No '=', remove it.
                if sEnvVar in os.environ:
                    del os.environ[sEnvVar];
            elif iEqual > 0:    # Set it.
                os.environ[sEnvVar[:iEqual]] = sEnvVar[iEqual+1:];
            else:               # Starts with '=', bad user.
                raise TestBoxScriptException('Invalid -E argument: "%s"' % (sEnvVar,));

        os.environ['TESTBOX_PATH_BUILDS']       = self._oOptions.sBuildsPath;
        os.environ['TESTBOX_PATH_RESOURCES']    = self._oOptions.sTestRsrcPath;
        os.environ['TESTBOX_PATH_SCRATCH']      = self._sScratchSpill;
        os.environ['TESTBOX_PATH_SCRIPTS']      = self._sScratchScripts;
        os.environ['TESTBOX_PATH_UPLOAD']       = self._sScratchSpill; ## @todo drop the UPLOAD dir?
        os.environ['TESTBOX_HAS_HW_VIRT']       = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_HW_VIRT);
        os.environ['TESTBOX_HAS_NESTED_PAGING'] = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_NESTED_PAGING);
        os.environ['TESTBOX_HAS_IOMMU']         = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_HAS_IOMMU);
        os.environ['TESTBOX_SCRIPT_REV']        = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_SCRIPT_REV);
        os.environ['TESTBOX_CPU_COUNT']         = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_CPU_COUNT);
        os.environ['TESTBOX_MEM_SIZE']          = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_MEM_SIZE);
        os.environ['TESTBOX_SCRATCH_SIZE']      = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_SCRATCH_SIZE);
        #TODO: os.environ['TESTBOX_WITH_RAW_MODE']     = self.getSignOnParam(constants.tbreq.SIGNON_PARAM_WITH_RAW_MODE);
        os.environ['TESTBOX_WITH_RAW_MODE']     = str(self._withRawModeSupport());
        os.environ['TESTBOX_MANAGER_URL']       = self._oOptions.sTestManagerUrl;
        os.environ['TESTBOX_UUID']              = self._sTestBoxUuid;
        os.environ['TESTBOX_REPORTER']          = 'remote';
        os.environ['TESTBOX_NAME']              = '';
        os.environ['TESTBOX_ID']                = '';
        os.environ['TESTBOX_TEST_SET_ID']       = '';
        os.environ['TESTBOX_TIMEOUT']           = '0';
        os.environ['TESTBOX_TIMEOUT_ABS']       = '0';

        if utils.getHostOs() == 'win':
            os.environ['COMSPEC']            = os.path.join(os.environ['SystemRoot'], 'System32', 'cmd.exe');
    def _detectPaths(self):
        """
        Internal worker for actionVerify and actionExecute that detects paths.

        This sets sVBoxInstallRoot and sUnitTestsPathBase and returns True/False.
        """

        #
        # We need a VBox install (/ build) to test.
        #
        if False:
            if not self.importVBoxApi():
                reporter.error('Unabled to import the VBox Python API.')
                return False
        else:
            self._detectBuild();
            if self.oBuild is None:
                reporter.error('Unabled to detect the VBox build.');
                return False;

        #
        # Where are the files installed?
        # Solaris requires special handling because of it's multi arch subdirs.
        #
        self.sVBoxInstallRoot = self.oBuild.sInstallPath
        if not self.oBuild.isDevBuild() and utils.getHostOs() == 'solaris':
            sArchDir = utils.getHostArch();
            if sArchDir == 'x86': sArchDir = 'i386';
            self.sVBoxInstallRoot = os.path.join(self.sVBoxInstallRoot, sArchDir);

        # Add the installation root to the PATH on windows so we can get DLLs from it.
        if utils.getHostOs() == 'win':
            sPathName = 'PATH';
            if not sPathName in os.environ:
                sPathName = 'Path';
            sPath = os.environ.get(sPathName, '.');
            if len(sPath) > 0 and sPath[-1] != ';':
                sPath += ';';
            os.environ[sPathName] = sPath + self.sVBoxInstallRoot + ';';

        #
        # The unittests are generally not installed, so look for them.
        #
        sBinOrDist = 'dist' if utils.getHostOs() in [ 'darwin', ] else 'bin';
        asCandidates = [
            self.oBuild.sInstallPath,
            os.path.join(self.sScratchPath, sBinOrDist + '.' + utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist, utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist),
        ];
        if utils.getHostOs() == 'darwin':
            for i in range(1, len(asCandidates)):
                asCandidates[i] = os.path.join(asCandidates[i], 'VirtualBox.app', 'Contents', 'MacOS');

        for sCandidat in asCandidates:
            if os.path.exists(os.path.join(sCandidat, 'testcase', 'tstVMStructSize' + self.sExeSuff)):
                self.sUnitTestsPathBase = sCandidat;
                return True;

        reporter.error('Unable to find unit test dir. Candidates: %s' % (asCandidates,))
        return False;
Beispiel #10
0
    def __init__(self):
        ReporterBase.__init__(self);
        self.sTestManagerUrl    = os.environ.get('TESTBOX_MANAGER_URL');
        self.sTestBoxUuid       = os.environ.get('TESTBOX_UUID');
        self.idTestBox          = int(os.environ.get('TESTBOX_ID'));
        self.idTestSet          = int(os.environ.get('TESTBOX_TEST_SET_ID'));
        self._asXml             = [];
        self._secTsXmlFlush     = utils.timestampSecond();
        self._secTsXmlLast      = self._secTsXmlFlush;
        self._fXmlFlushing      = False;
        self.oOutput            = sys.stdout; # Hack for __del__ output.
        self.fFlushEachLine     = True;
        self.fDebugXml          = 'TESTDRIVER_REPORTER_DEBUG_XML' in os.environ;

        # Prepare the TM connecting.
        import urlparse;
        import httplib;
        import urllib;
        from common import constants;

        self._fnUrlEncode       = urllib.urlencode;
        self._fnUrlParseQs      = urlparse.parse_qs;
        self._oParsedTmUrl      = urlparse.urlparse(self.sTestManagerUrl);

        if     sys.version_info[0] >= 3 \
           or (sys.version_info[0] == 2 and sys.version_info[1] >= 6):
            if self._oParsedTmUrl.scheme == 'https': # pylint: disable=E1101
                self._fnTmConnect = lambda: httplib.HTTPSConnection(self._oParsedTmUrl.hostname,
                                                                    timeout = self.kcSecTestManagerRequestTimeout);
            else:
                self._fnTmConnect = lambda: httplib.HTTPConnection( self._oParsedTmUrl.hostname,
                                                                    timeout = self.kcSecTestManagerRequestTimeout);
        else:
            if self._oParsedTmUrl.scheme == 'https': # pylint: disable=E1101
                self._fnTmConnect = lambda: httplib.HTTPSConnection(self._oParsedTmUrl.hostname);
            else:
                self._fnTmConnect = lambda: httplib.HTTPConnection( self._oParsedTmUrl.hostname);
        self._dHttpHeader = \
        {
            'Content-Type':     'application/x-www-form-urlencoded; charset=utf-8',
            'User-Agent':       'TestDriverReporter/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch(),),
            'Accept':           'text/plain,application/x-www-form-urlencoded',
            'Accept-Encoding':  'identity',
            'Cache-Control':    'max-age=0',
            #'Connection':       'keep-alive',
        };

        dParams = {
            constants.tbreq.ALL_PARAM_TESTBOX_UUID:     self.sTestBoxUuid,
            constants.tbreq.ALL_PARAM_TESTBOX_ID:       self.idTestBox,
            constants.tbreq.RESULT_PARAM_TEST_SET_ID:   self.idTestSet,
        };
        self._sTmServerPath = '/%s/testboxdisp.py?%s' \
                            % ( self._oParsedTmUrl.path.strip('/'), # pylint: disable=E1101
                                urllib.urlencode(dParams), );
Beispiel #11
0
    def _detectPaths(self):
        """
        Internal worker for actionVerify and actionExecute that detects paths.

        This sets sVBoxInstallRoot and sUnitTestsPathBase and returns True/False.
        """

        #
        # We need a VBox install (/ build) to test.
        #
        if False is True:
            if not self.importVBoxApi():
                reporter.error('Unabled to import the VBox Python API.')
                return False
        else:
            self._detectBuild()
            if self.oBuild is None:
                reporter.error('Unabled to detect the VBox build.')
                return False

        #
        # Where are the files installed?
        # Solaris requires special handling because of it's multi arch subdirs.
        #
        self.sVBoxInstallRoot = self.oBuild.sInstallPath
        if not self.oBuild.isDevBuild() and utils.getHostOs() == 'solaris':
            sArchDir = utils.getHostArch()
            if sArchDir == 'x86': sArchDir = 'i386'
            self.sVBoxInstallRoot = os.path.join(self.sVBoxInstallRoot,
                                                 sArchDir)

        # Add the installation root to the PATH on windows so we can get DLLs from it.
        if utils.getHostOs() == 'win':
            sPathName = 'PATH'
            if not sPathName in os.environ:
                sPathName = 'Path'
            sPath = os.environ.get(sPathName, '.')
            if sPath and sPath[-1] != ';':
                sPath += ';'
            os.environ[sPathName] = sPath + self.sVBoxInstallRoot + ';'

        #
        # The unittests are generally not installed, so look for them.
        #
        sBinOrDist = 'dist' if utils.getHostOs() in [
            'darwin',
        ] else 'bin'
        asCandidates = [
            self.oBuild.sInstallPath,
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(),
                         self.oBuild.sType, sBinOrDist),
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(),
                         'release', sBinOrDist),
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(), 'debug',
                         sBinOrDist),
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(), 'strict',
                         sBinOrDist),
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(), 'dbgopt',
                         sBinOrDist),
            os.path.join(self.sScratchPath, utils.getHostOsDotArch(),
                         'profile', sBinOrDist),
            os.path.join(self.sScratchPath,
                         sBinOrDist + '.' + utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist, utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist),
        ]
        if utils.getHostOs() == 'darwin':
            for i in range(1, len(asCandidates)):
                asCandidates[i] = os.path.join(asCandidates[i],
                                               'VirtualBox.app', 'Contents',
                                               'MacOS')

        for sCandidat in asCandidates:
            if os.path.exists(
                    os.path.join(sCandidat, 'testcase',
                                 'tstVMStructSize' + self.sExeSuff)):
                self.sUnitTestsPathBase = sCandidat
                return True

        reporter.error('Unable to find unit test dir. Candidates: %s' %
                       (asCandidates, ))
        return False
Beispiel #12
0
 def postRequestRaw(self, sAction, dParams):
     """
     Posts a request to the test manager and gets the response.  The dParams
     argument is a dictionary of unencoded key-value pairs (will be
     modified).
     Raises exception on failure.
     """
     dHeader = \
     {
         'Content-Type':     'application/x-www-form-urlencoded; charset=utf-8',
         'User-Agent':       'TestBoxScript/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch()),
         'Accept':           'text/plain,application/x-www-form-urlencoded',
         'Accept-Encoding':  'identity',
         'Cache-Control':    'max-age=0',
         'Connection':       'keep-alive',
     };
     sServerPath = '/%s/testboxdisp.py' % (self._oParsedUrl.path.strip('/'),); # pylint: disable=E1101
     dParams[constants.tbreq.ALL_PARAM_ACTION] = sAction;
     sBody = urllib.urlencode(dParams);
     ##testboxcommons.log2('sServerPath=%s' % (sServerPath,));
     try:
         self._oConn.request('POST', sServerPath, sBody, dHeader);
         oResponse = self._oConn.getresponse();
         oResponse2 = TestBoxResponse(oResponse);
     except:
         testboxcommons.log2Xcpt();
         raise
     return oResponse2;
Beispiel #13
0
    def __init__(self):
        ReporterBase.__init__(self)
        self.sTestManagerUrl = os.environ.get('TESTBOX_MANAGER_URL')
        self.sTestBoxUuid = os.environ.get('TESTBOX_UUID')
        self.idTestBox = int(os.environ.get('TESTBOX_ID'))
        self.idTestSet = int(os.environ.get('TESTBOX_TEST_SET_ID'))
        self._asXml = []
        self._secTsXmlFlush = utils.timestampSecond()
        self._secTsXmlLast = self._secTsXmlFlush
        self._fXmlFlushing = False
        self.oOutput = sys.stdout
        # Hack for __del__ output.
        self.fFlushEachLine = True
        self.fDebugXml = 'TESTDRIVER_REPORTER_DEBUG_XML' in os.environ

        # Prepare the TM connecting.
        import urlparse
        import httplib
        import urllib
        from common import constants

        self._fnUrlEncode = urllib.urlencode
        self._fnUrlParseQs = urlparse.parse_qs
        self._oParsedTmUrl = urlparse.urlparse(self.sTestManagerUrl)
        if     sys.version_info[0] >= 3 \
           or (sys.version_info[0] == 2 and sys.version_info[1] >= 6):
            if self._oParsedTmUrl.scheme == 'https':  # pylint: disable=E1101
                self._fnTmConnect = lambda: httplib.HTTPSConnection(
                    self._oParsedTmUrl.hostname,
                    timeout=self.kcSecTestManagerRequestTimeout)
            else:
                self._fnTmConnect = lambda: httplib.HTTPConnection(
                    self._oParsedTmUrl.hostname,
                    timeout=self.kcSecTestManagerRequestTimeout)
        else:
            if self._oParsedTmUrl.scheme == 'https':  # pylint: disable=E1101
                self._fnTmConnect = lambda: httplib.HTTPSConnection(
                    self._oParsedTmUrl.hostname)
            else:
                self._fnTmConnect = lambda: httplib.HTTPConnection(
                    self._oParsedTmUrl.hostname)
        self._dHttpHeader = \
        {
            'Content-Type':     'application/x-www-form-urlencoded; charset=utf-8',
            'User-Agent':       'TestDriverReporter/%s.0 (%s, %s)' % (__version__, utils.getHostOs(), utils.getHostArch(),),
            'Accept':           'text/plain,application/x-www-form-urlencoded',
            'Accept-Encoding':  'identity',
            'Cache-Control':    'max-age=0',
            #'Connection':       'keep-alive',
        }

        dParams = {
            constants.tbreq.ALL_PARAM_TESTBOX_UUID: self.sTestBoxUuid,
            constants.tbreq.ALL_PARAM_TESTBOX_ID: self.idTestBox,
            constants.tbreq.RESULT_PARAM_TEST_SET_ID: self.idTestSet,
        }
        self._sTmServerPath = '/%s/testboxdisp.py?%s' \
                            % ( self._oParsedTmUrl.path.strip('/'), # pylint: disable=E1101
                                urllib.urlencode(dParams), )
Beispiel #14
0
    def _detectPaths(self):
        """
        Internal worker for actionVerify and actionExecute that detects paths.

        This sets sVBoxInstallRoot and sUnitTestsPathBase and returns True/False.
        """

        #
        # We need a VBox install (/ build) to test.
        #
        if False:
            if not self.importVBoxApi():
                reporter.error("Unabled to import the VBox Python API.")
                return False
        else:
            self._detectBuild()
            if self.oBuild is None:
                reporter.error("Unabled to detect the VBox build.")
                return False

        #
        # Where are the files installed?
        # Solaris requires special handling because of it's multi arch subdirs.
        #
        self.sVBoxInstallRoot = self.oBuild.sInstallPath
        if not self.oBuild.isDevBuild() and utils.getHostOs() == "solaris":
            sArchDir = utils.getHostArch()
            if sArchDir == "x86":
                sArchDir = "i386"
            self.sVBoxInstallRoot = os.path.join(self.sVBoxInstallRoot, sArchDir)

        # Add the installation root to the PATH on windows so we can get DLLs from it.
        if utils.getHostOs() == "win":
            sPathName = "PATH"
            if not sPathName in os.environ:
                sPathName = "Path"
            sPath = os.environ.get(sPathName, ".")
            if len(sPath) > 0 and sPath[-1] != ";":
                sPath += ";"
            os.environ[sPathName] = sPath + self.sVBoxInstallRoot + ";"

        #
        # The unittests are generally not installed, so look for them.
        #
        sBinOrDist = "dist" if utils.getHostOs() in ["darwin"] else "bin"
        asCandidates = [
            self.oBuild.sInstallPath,
            os.path.join(self.sScratchPath, sBinOrDist + "." + utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist, utils.getHostArch()),
            os.path.join(self.sScratchPath, sBinOrDist),
        ]
        if utils.getHostOs() == "darwin":
            for i in range(1, len(asCandidates)):
                asCandidates[i] = os.path.join(asCandidates[i], "VirtualBox.app", "Contents", "MacOS")

        for sCandidat in asCandidates:
            if os.path.exists(os.path.join(sCandidat, "testcase", "tstVMStructSize" + self.sExeSuff)):
                self.sUnitTestsPathBase = sCandidat
                return True

        reporter.error("Unable to find unit test dir. Candidates: %s" % (asCandidates,))
        return False