示例#1
0
    def init(self, clas='', adder=None, examiner=None):
        """This initialization is separate so that unit tests can be done on this module.
            For this reason we delay any logging until main is called.
            adder and examiner are called in configuration if given to allow user
            a chance to add options and see results of option parsing.
        """
        tempfile.tempdir = os.getcwd()
        configuration.init(clas, adder, examiner)
        self.options = configuration.options
        self.inputFiles = configuration.inputFiles
        self.machine = configuration.machine
        self.batchmachine = configuration.batchmachine

        if configuration.options.nobatch:
            self.batchmachine = None
        self.verbose = configuration.options.verbose or debug()
        log.echo = self.verbose
        self.started = datestamp(long_format=True)
        self.continuationFileName = ''
        self.atsRunPath = os.getcwd()
        for a in configuration.options.filter:
            self.filter(a)
        pat1 = re.compile(r'^([^\'].*)\'$')
        pat2 = re.compile(r'^([^\"].*)\"$')
        for a in configuration.options.glue:
            if pat1.search(a) or pat2.search(a):
                a1 = a
            else:
                a1 = a.strip('"').strip("'")
            exec('AtsTest.glue(%s)' % a1)
        if configuration.options.level:
            self.filter("level<= %s" % configuration.options.level)
示例#2
0
    def finalReport(self):
        "Write the final report."
        log.reset()
        if self.testlist:
            log("""
=========================================================
ATS RESULTS %s""" % datestamp(long_format=True),
                echo=True)
            log('-------------------------------------------------', echo=True)
            self.report()
            log('-------------------------------------------------', echo=True)
        if not configuration.options.skip:
            log("""
ATS SUMMARY %s""" % datestamp(long_format=True), echo=True)
            self.summary(log)
            self._summary2(log)
示例#3
0
 def finalBanner(self):
     "Show final banner."
     log.logging = 1
     log.echo = True
     log("ATS WALL TIME", wallTime())
     log("ATS COLLECTION END", self.collectTimeEnded)
     log('ATS END', datestamp(long_format=True))
     log('ATS MACHINE TYPE', configuration.MACHINE_TYPE)
     if configuration.batchmachine is not None:
         log('ATS BATCH TYPE', configuration.BATCH_TYPE)
     log('ATS OUTPUT DIRECTORY', log.directory)
     if self.continuationFileName:
         log("ATS CONTINUATION FILE", self.continuationFileName, echo=True)
     log('ATS LOG FILE', log.name)
     self.logUsage()
     log('ATS END OF RUN STARTED', self.started)
示例#4
0
    def restart(self):
        "Reinitialize basic data structures."
        self.started = datestamp(long_format=True)
        self.collectTimeEnded = self.started
        self.filters = []
        self.testlist = []
        self.badlist = []
        self.onCollectedRoutines = []
        self.onPrioritizedRoutines = []
        self.onExitRoutines = []
        self.beforeRunRoutines = []
        self.onResultsRoutines = []
        self.continuationFileName = ''
        self.saveResultsName = "atsr.py"
        self.saveXmlResultsName = "atsr.xml"

        AtsTest.restart()
示例#5
0
    def getResults(self):
        """Returns an attribute dictionary containing the state of this
           manager suitable for postprocessing. After forming a potential
           result r, calls any resultsHooks functions (r, manager)
        """
        r = AttributeDict(
            started=self.started,
            options=self.options,
            savedTime=datestamp(long_format=True),
            collectTimeEnded=self.collectTimeEnded,
            badlist=self.badlist,
            filters=self.filters,
            groups={},
            onCollectedRoutines=[f.__name__ for f in self.onCollectedRoutines],
            onPrioritizedRoutines=[
                f.__name__ for f in self.onPrioritizedRoutines
            ],
            onExitRoutines=[f.__name__ for f in self.onExitRoutines],
            onResultsRoutines=[f.__name__ for f in self.onResultsRoutines],
        )
        r.testlist = [t.getResults() for t in self.testlist]

        if not hasattr(self, 'machine'):
            return r  # never initialized, nothing else of interest.

        r.inputFiles = self.inputFiles
        r.verbose = self.verbose
        r.machine = AttributeDict()
        r.batchmachine = None
        for key, value in self.machine.getResults().items():
            r.machine[key] = value
        if self.batchmachine:
            r.batchmachine = AttributeDict()
            for key, value in self.batchmachine.getResults().items():
                r.batchmachine[key] = value
        for hook in self.onResultsRoutines:
            log('   Calling onResults function', hook.__name__, echo=True)
            hook(r, self)
        return r
示例#6
0
    def core(self):
        "This is the 'guts' of ATS."

        if configuration.SYS_TYPE == "toss_3_x86_64":
            if configuration.options.bypassSerialMachineCheck == False:
                log("**********************************************************************************",
                    echo=True)
                log("*** This is a serial machine --- Do not use ATS on more than 1 node here!      ***",
                    echo=True)
                log("***                                                                            ***",
                    echo=True)
                log("*** Use ATS option  --bypassSerialMachineCheck if you promise to run on 1 Node ***",
                    echo=True)
                log("**********************************************************************************",
                    echo=True)
                sys.exit(-1)

        # Phase 1 -- collect the tests
        errorOccurred = False
        try:  # surround with keyboard interrupt, AtsError handlers
            self.collectTests()
        except AtsError:
            log("ATS error while collecting tests.", echo=True)
            log(traceback.format_exc(), echo=True)
            errorOccurred = True
            self.collectTimeEnded = datestamp(long_format=True)

        except KeyboardInterrupt:
            log("Keyboard interrupt while collecting tests, terminating.",
                echo=True)
            errorOccurred = True

        self.collectTimeEnded = datestamp(long_format=True)
        if errorOccurred:
            return

        try:
            for f in self.onCollectedRoutines:
                log("Calling onCollected routine",
                    f.__name__,
                    echo=self.verbose)
                f(self)
        except KeyboardInterrupt:
            log("Keyboard interrupt while collecting tests, terminating.",
                echo=True)
            errorOccurred = True
        except Exception:
            log("Error in user-specified onCollected routine.", echo=True)
            log(traceback.format_exc(), echo=True)
            errorOccured = True
        if errorOccurred:
            return

        # divide into interactive and batch tests
        interactiveTests, batchTests = self.sortTests()
        if len(interactiveTests) + len(batchTests) == 0:
            log("No tests found.", echo=True)
            return

        # We have built up the list of tests.  Run functions added via
        # beforeRun() calls to allow user to do stuff like cleaning up old test
        # results before running or other things.
        self.preprocess()

        # Phase 2 -- dispatch the batch tests

        if self.batchmachine and batchTests:
            if configuration.options.skip:
                log("Skipping execution due to --skip")
            else:
                try:
                    log("Sending %d tests to %s." %
                        (len(batchTests), self.batchmachine.name),
                        echo=True)
                    self.batchmachine.load(batchTests)
                except AtsError:
                    log(traceback.format_exc(), echo=True)
                    log("ATS error.", echo=True)
                    return
                except KeyboardInterrupt:
                    log("Keyboard interrupt while dispatching batch, terminating.",
                        echo=True)
                    return

        # Phase 3 -- run the interactive tests

        dieDieDie = False
        if interactiveTests:
            self.machine.scheduler.prioritize(interactiveTests)
            try:
                log("Total number of interactive tests = ",
                    len(interactiveTests),
                    echo=True)
                log("---------------------------------------------------",
                    echo=True)
                for f in self.onPrioritizedRoutines:
                    log("Calling onPrioritized routine",
                        f.__name__,
                        echo=self.verbose)
                    f(interactiveTests)
            except KeyboardInterrupt:
                log("Keyboard interrupt while prioritizing tests, terminating.",
                    echo=True)
                errorOccurred = True
            except Exception:
                log("Error in prioritizing tests.", echo=True)
                log(traceback.format_exc(), echo=True)
                errorOccured = True
            if errorOccurred:
                return

            try:
                self.run(interactiveTests)
            except AtsError:
                log(traceback.format_exc(), echo=True)
                log("ATS error. Removing running jobs....", echo=True)
                dieDieDie = True

            except KeyboardInterrupt:
                dieDieDie = True
                log("Keyboard interrupt. Removing running jobs....", echo=True)

        if dieDieDie:
            time.sleep(3)
            for test in self.testlist:
                if (test.status is RUNNING):
                    self.machine.kill(test)

        self.machine.quit()  #machine shutdown / cleanup

        # Phase 4 -- Continuation file
        #        for t in interactiveTests:
        #            if t.status not in  (PASSED, EXPECTED, FILTERED):
        #                break
        #        else:
        #            self.continuationFileName = ''
        #            return

        self.continuationFile(interactiveTests)
示例#7
0
    def _source(self, path, introspector, vocabulary):
        "Process source file. Returns true if successful"
        here = os.getcwd()
        t = abspath(path)
        directory, filename = os.path.split(t)
        name, e = os.path.splitext(filename)
        if e:
            namelist = [t]
        else:
            namelist = [t, t + '.ats', t + '.py']
        for t1 in namelist:
            if t1 in AtsManager.alreadysourced:
                log("Already sourced:", t1)
                return
            try:
                f = open(t1)
                break
            except IOError as e:
                pass
        else:
            log("Error opening input file:", t1, echo=True)
            self.badlist.append(t1)
            raise AtsError("Could not open input file %s" % path)
        t = abspath(t1)
        directory, filename = os.path.split(t1)
        name, e = os.path.splitext(filename)
        AtsManager.alreadysourced.append(t1)
        # save to restore after this file is read
        savestuck = dict(AtsTest.stuck)
        savetacked = dict(AtsTest.tacked)
        unstick()  #clear sticky list at the start of a file.
        AtsTest.waitNewSource()

        testenv = dict(testEnvironment)
        testenv.update(vocabulary)
        testenv['SELF'] = t1
        atstext = []
        for line1 in f:
            if not line1: continue
            if line1.startswith('#!'):
                continue
            magic = introspector(line1[:-1])
            if magic is not None:
                atstext.append(magic)
        f.close()
        if atstext:
            log('-> Executing statements in', t1, echo=False)
            log.indent()
            code = '\n'.join(atstext)
            if debug():
                for line in atstext:
                    log(line, echo=False)
            os.chdir(directory)
            try:
                exec(code, testenv)
                if debug():
                    log('Finished ', t1, datestamp())
            except KeyboardInterrupt:
                raise
            except Exception as details:
                self.badlist.append(t1)
                log('Error while processing statements in', t1, ':', echo=True)
                log(details, echo=True)
            log.dedent()
        else:
            log('-> Sourcing', t1, echo=False)
            log.indent()
            os.chdir(directory)
            try:
                exec(compile(open(t1, "rb").read(), t1, 'exec'), testenv)
                if debug(): log('Finished ', t1, datestamp())
                result = 1
            except KeyboardInterrupt:
                raise
            except Exception as details:
                self.badlist.append(t1)
                log('Error in input file', t1, ':', echo=True)
                log(details, echo=True)
                log('------------------------------------------', echo=True)
            log.dedent()
        AtsTest.endGroup()
        unstick()
        stick(**savestuck)
        untack()
        tack(**savetacked)
        AtsTest.waitEndSource()
        os.chdir(here)