示例#1
0
    def _parseClassAndConfigDict(self, node, defaultClass):
        """Parses a dictionary of arbitrary options and a python class out of the specified XML node.

		The node may optionally contain classname and module (if not specified as a separate attribute,
		module will be extracted from the first part of classname); any other attributes will be returned in
		the optionsDict, as will <option name=""></option> child elements.

		@param node: The node, may be None
		@param defaultClass: a string specifying the default fully-qualified class
		@return: a tuple of (pythonclass, propertiesdict)
		"""
        optionsDict = {}
        if node:
            for att in range(node.attributes.length):
                value = self.expandFromEnvironent(
                    node.attributes.item(att).value, None)
                optionsDict[node.attributes.item(
                    att).name] = self.expandFromProperty(value, None)
            for tag in node.getElementsByTagName('property'):
                assert tag.getAttribute('name')
                value = self.expandFromEnvironent(tag.getAttribute("value"),
                                                  tag.getAttribute("default"))
                optionsDict[tag.getAttribute(
                    'name')] = self.expandFromProperty(
                        value, tag.getAttribute("default"))

        classname = optionsDict.pop('classname', defaultClass)
        mod = optionsDict.pop('module', '.'.join(classname.split('.')[:-1]))
        classname = classname.split('.')[-1]
        module = import_module(mod, sys.path)
        cls = getattr(module, classname)
        return cls, optionsDict
示例#2
0
def makeTest(args):
	Project.findAndLoadProject()

	cls = Project.getInstance().makerClassname.split('.')
	module = import_module('.'.join(cls[:-1]), sys.path)
	maker = getattr(module, cls[-1])("make")

	maker.parseArgs(args)
	maker.makeTest()
示例#3
0
def runTest(args):
    try:
        launcher = ConsoleLaunchHelper(os.getcwd(), "run")
        args = launcher.parseArgs(args)
        module = import_module(PROJECT.runnerModule, sys.path)
        runner = getattr(module, PROJECT.runnerClassname)(*args)
        runner.start()

        for cycledict in runner.results.values():
            for outcome in FAILS:
                if cycledict.get(outcome, None): sys.exit(2)
        sys.exit(0)
    except Exception as e:
        sys.stderr.write('\nWARN: %s\n' % e)
        sys.exit(-1)
示例#4
0
def runTest(args):
    try:
        launcher = ConsoleLaunchHelper(os.getcwd(), "run")
        args = launcher.parseArgs(args)

        cls = Project.getInstance().runnerClassname.split('.')
        module = import_module('.'.join(cls[:-1]), sys.path)
        runner = getattr(module, cls[-1])(*args)
        runner.start()

        for cycledict in runner.results.values():
            for outcome in OUTCOMES:
                if outcome.isFailure() and cycledict.get(outcome, None):
                    sys.exit(2)
        sys.exit(0)
    except Exception as e:
        sys.stderr.write('\nPYSYS FATAL ERROR: %s\n' % e)
        if not isinstance(e, UserError): traceback.print_exc()
        sys.exit(10)
示例#5
0
 def classConstructor(*args, **kwargs):
     module = import_module(mod, sys.path)
     cls = getattr(module, classname)
     return cls(*args,
                **kwargs)  # invoke the constructor for this class
示例#6
0
def makeTest(args):
    module = import_module(PROJECT.makerModule, sys.path)
    maker = getattr(module, PROJECT.makerClassname)("make")
    maker.parseArgs(args)
    maker.makeTest()
示例#7
0
    def __init__(self, record, purge, cycle, mode, threads, outsubdir,
                 descriptors, xargs):
        """Create an instance of the BaseRunner class.
		
		@param record: Indicates if the test results should be recorded 
		@param purge: Indicates if the output subdirectory should be purged on C{PASSED} result
		@param cycle: The number of times to execute the set of requested testcases
		@param mode: The user defined mode to run the testcases in
		@param threads: The number of worker threads to execute the requested testcases
		@param outsubdir: The name of the output subdirectory
		@param descriptors: List of XML descriptor containers detailing the set of testcases to be run
		@param xargs: The dictionary of additional arguments to be set as data attributes to the class
		
		"""
        ProcessUser.__init__(self)

        self.record = record
        self.purge = purge
        self.cycle = cycle
        self.mode = mode
        self.threads = threads
        self.outsubdir = outsubdir
        self.descriptors = descriptors
        self.xargs = xargs
        self.validateOnly = False
        self.setKeywordArgs(xargs)

        if self.threads == 0:
            self.threads = N_CPUS

        self.writers = []
        summarywriters = []
        progresswriters = []
        for classname, module, filename, properties in PROJECT.writers:
            module = import_module(module, sys.path)
            writer = getattr(module, classname)(filename)
            for key in list(properties.keys()):
                setattr(writer, key, properties[key])

            if isinstance(writer, BaseSummaryResultsWriter):
                summarywriters.append(writer)
            elif isinstance(writer, BaseProgressResultsWriter):
                progresswriters.append(writer)
            elif self.record:  # assume everything else is a record result writer (for compatibility reasons)
                self.writers.append(writer)

        # summary writers are always enabled regardless of record mode.
        # allow user to provide their own summary writer in the config, or if not, supply our own
        if summarywriters:
            self.writers.extend(summarywriters)
        else:
            self.writers.append(ConsoleSummaryResultsWriter())

        if xargs.get('__progressWritersEnabled', False):
            if progresswriters:
                self.writers.extend(progresswriters)
            else:
                self.writers.append(ConsoleProgressResultsWriter())

        # duration and results used to be used for printing summary info, now (in 1.3.0) replaced by
        # more extensible ConsoleSummaryResultsWriter implementation. Keeping these around for
        # a bit to allow overlap before removal
        self.duration = 0  # no longer needed
        self.results = {}
        self.__remainingTests = self.cycle * len(self.descriptors)

        self.performanceReporters = PROJECT._createPerformanceReporters(
            self.outsubdir)
示例#8
0
    def __call__(self, *args, **kwargs):
        """Over-ridden call builtin to allow the class instance to be called directly.
		
		Invoked by thread pool when using multiple worker threads.

		"""
        exc_info = []
        self.testStart = time.time()
        try:
            # stdout - set this up right at the very beginning to ensure we can see the log output in case any later step fails
            self.testFileHandlerStdout = ThreadedStreamHandler(StringIO())
            self.testFileHandlerStdout.setFormatter(PROJECT.formatters.stdout)
            self.testFileHandlerStdout.setLevel(stdoutHandler.level)
            log.addHandler(self.testFileHandlerStdout)

            # set the output subdirectory and purge contents
            if os.path.isabs(self.runner.outsubdir):
                self.outsubdir = os.path.join(self.runner.outsubdir,
                                              self.descriptor.id)
            else:
                self.outsubdir = os.path.join(self.descriptor.output,
                                              self.runner.outsubdir)

            mkdir(self.outsubdir)

            if self.cycle == 0 and not self.runner.validateOnly:
                self.purgeDirectory(self.outsubdir)

            if self.runner.cycle > 1:
                self.outsubdir = os.path.join(self.outsubdir,
                                              'cycle%d' % (self.cycle + 1))
                mkdir(self.outsubdir)

            # run.log handler
            self.testFileHandlerRunLog = ThreadedFileHandler(
                os.path.join(self.outsubdir, 'run.log'))
            self.testFileHandlerRunLog.setFormatter(PROJECT.formatters.runlog)
            self.testFileHandlerRunLog.setLevel(logging.INFO)
            if stdoutHandler.level == logging.DEBUG:
                self.testFileHandlerRunLog.setLevel(logging.DEBUG)
            log.addHandler(self.testFileHandlerRunLog)

            log.info(62 * "=")
            title = textwrap.wrap(
                self.descriptor.title.replace('\n', '').strip(), 56)
            log.info("Id   : %s",
                     self.descriptor.id,
                     extra=BaseLogFormatter.tag(LOG_TEST_DETAILS, 0))
            if len(title) > 0:
                log.info("Title: %s",
                         str(title[0]),
                         extra=BaseLogFormatter.tag(LOG_TEST_DETAILS, 0))
            for l in title[1:]:
                log.info("       %s",
                         str(l),
                         extra=BaseLogFormatter.tag(LOG_TEST_DETAILS, 0))
            if self.runner.cycle > 1:
                log.info("Cycle: %s",
                         str(self.cycle + 1),
                         extra=BaseLogFormatter.tag(LOG_TEST_DETAILS, 0))
            log.info(62 * "=")
        except KeyboardInterrupt:
            self.kbrdInt = True

        except Exception:
            exc_info.append(sys.exc_info())

        # import the test class
        with global_lock:
            try:
                module = import_module(
                    os.path.basename(self.descriptor.module),
                    [os.path.dirname(self.descriptor.module)], True)
                self.testObj = getattr(module, self.descriptor.classname)(
                    self.descriptor, self.outsubdir, self.runner)

            except KeyboardInterrupt:
                self.kbrdInt = True

            except Exception:
                exc_info.append(sys.exc_info())
                self.testObj = BaseTest(self.descriptor, self.outsubdir,
                                        self.runner)

        for writer in self.runner.writers:
            try:
                if hasattr(writer, 'processTestStarting'):
                    writer.processTestStarting(testObj=self.testObj,
                                               cycle=self.cycle)
            except Exception:
                log.warn("caught %s calling processTestStarting on %s: %s",
                         sys.exc_info()[0],
                         writer.__class__.__name__,
                         sys.exc_info()[1],
                         exc_info=1)

        # execute the test if we can
        try:
            if self.descriptor.state != 'runnable':
                self.testObj.addOutcome(SKIPPED,
                                        'Not runnable',
                                        abortOnError=False)

            elif self.runner.mode and self.runner.mode not in self.descriptor.modes:
                self.testObj.addOutcome(SKIPPED,
                                        "Unable to run test in %s mode" %
                                        self.runner.mode,
                                        abortOnError=False)

            elif len(exc_info) > 0:
                self.testObj.addOutcome(BLOCKED,
                                        'Failed to set up test: %s' %
                                        exc_info[0][1],
                                        abortOnError=False)
                for info in exc_info:
                    log.warn("caught %s while setting up test %s: %s",
                             info[0],
                             self.descriptor.id,
                             info[1],
                             exc_info=info)

            elif self.kbrdInt:
                log.warn("test interrupt from keyboard")
                self.testObj.addOutcome(BLOCKED,
                                        'Test interrupt from keyboard',
                                        abortOnError=False)

            else:
                try:
                    if not self.runner.validateOnly:
                        self.testObj.setup()
                        self.testObj.execute()
                    self.testObj.validate()
                except AbortExecution as e:
                    del self.testObj.outcome[:]
                    self.testObj.addOutcome(e.outcome,
                                            e.value,
                                            abortOnError=False,
                                            callRecord=e.callRecord)
                    log.warn('Aborted test due to abortOnError set to true')

                if self.detectCore(self.outsubdir):
                    self.testObj.addOutcome(
                        DUMPEDCORE,
                        'Core detected in output subdirectory',
                        abortOnError=False)

        except KeyboardInterrupt:
            self.kbrdInt = True
            self.testObj.addOutcome(BLOCKED,
                                    'Test interrupt from keyboard',
                                    abortOnError=False)

        except Exception:
            log.warn("caught %s while running test: %s",
                     sys.exc_info()[0],
                     sys.exc_info()[1],
                     exc_info=1)
            self.testObj.addOutcome(BLOCKED,
                                    '%s (%s)' %
                                    (sys.exc_info()[1], sys.exc_info()[0]),
                                    abortOnError=False)

        # call the cleanup method to tear down the test
        try:
            self.testObj.cleanup()

        except KeyboardInterrupt:
            self.kbrdInt = True
            self.testObj.addOutcome(BLOCKED,
                                    'Test interrupt from keyboard',
                                    abortOnError=False)

        # print summary and close file handles
        try:
            self.testTime = math.floor(100 *
                                       (time.time() - self.testStart)) / 100.0
            log.info("")
            log.info("Test duration: %s", ('%.2f secs' % self.testTime),
                     extra=BaseLogFormatter.tag(LOG_DEBUG, 0))
            log.info("Test final outcome:  %s",
                     LOOKUP[self.testObj.getOutcome()],
                     extra=BaseLogFormatter.tag(
                         LOOKUP[self.testObj.getOutcome()].lower(), 0))
            if self.testObj.getOutcomeReason(
            ) and self.testObj.getOutcome() != PASSED:
                log.info("Test failure reason: %s",
                         self.testObj.getOutcomeReason(),
                         extra=BaseLogFormatter.tag(LOG_TEST_OUTCOMES, 0))
            log.info("")

            self.testFileHandlerRunLog.close()
            log.removeHandler(self.testFileHandlerRunLog)
            log.removeHandler(self.testFileHandlerStdout)
        except Exception:
            pass

        # return a reference to self
        return self