Ejemplo n.º 1
0
	def handle_error(self, ex, val, tb):
		if self._debug:
			import debugger
			debugger.post_mortem(ex, val, tb)
		else:
			import traceback
			traceback.print_exception(ex, val, tb)
Ejemplo n.º 2
0
	def _lambda(*iargs, **ikwargs):
		try:
			return meth(*iargs, **ikwargs)
		except:
			ex, val, tb = sys.exc_info()
			import debugger
			debugger.post_mortem(ex, val, tb)
Ejemplo n.º 3
0
	def _finalize(self, rv):
		try:
			self.finalize()
		except:
			ex, val, tb = sys.exc_info()
			self.diagnostic("%s (%s)" % (ex, val))
			if self._debug:
				debugger.post_mortem(ex, val, tb)
			rv = self.abort("Test finalize failed!")
		return rv
Ejemplo n.º 4
0
def shell_hook(type, value, tb):
    if type in (NameError, SyntaxError):
        do_shell(value)
    elif type in (IndentationError,):
        sys.__excepthook__(type, value, tb)
    else:
        print
        if __debug__:
            debugger.post_mortem(tb, type, value)
        else:
            import traceback
            traceback.print_exception(type, value, tb)
Ejemplo n.º 5
0
def shell_hook(type, value, tb):
    if type in (NameError, SyntaxError):
        do_shell(value)
    elif type in (IndentationError, ):
        sys.__excepthook__(type, value, tb)
    else:
        print
        if __debug__:
            debugger.post_mortem(tb, type, value)
        else:
            import traceback
            traceback.print_exception(type, value, tb)
Ejemplo n.º 6
0
	def mainloop(self, debug=False):
		try:
			self.parser.interact()
		except KeyboardInterrupt:
			self.syslog.message("EXITING", "User interrupt")
			return
		except:
			exc, val, tb = sys.exc_info()
			self.syslog.message("EXCEPTION", "internal error: %s(%s)" % (exc, val))
			if debug:
				import debugger
				debugger.post_mortem(exc, val, tb)
		else:
			self.syslog.message("EXITING", "User exited")
Ejemplo n.º 7
0
	def _initialize(self, args, kwargs):
		self.report.add_heading("Test suite: %s" % self.__class__.__name__, 1)
		# initialize the suite
		try:
			rv = self.initialize(*args, **kwargs)
		except KeyboardInterrupt:
			self.info("Suite aborted by user in initialize().")
			raise TestSuiteAbort
		except:
			ex, val, tb = sys.exc_info()
			if self._debug:
				ex, val, tb = sys.exc_info()
				debugger.post_mortem(ex, val, tb)
			self.info("Suite failed to initialize: %s (%s)" % (ex, val))
			raise TestSuiteAbort, val
Ejemplo n.º 8
0
    def __call__(self, *args, **kw):
        cf = self.config
        if os.path.isfile(self.configfile):
            pass
        else:  #try another path
            alternate_conf_file = os.path.join(cf.conf_dir, "%s.conf" % (self.test_name))
            if os.path.isfile(alternate_conf_file):
                self.configfile = alternate_conf_file

        if os.path.isfile(self.configfile):
            print "CONF file is: %s" % self.configfile
            cf.mergefile(self.configfile)
            try:
                cf.config_ID = os.path.basename(cf.config_ID.split()[1])
            except AttributeError:
                cf.config_ID = None
            except IndexError:
                cf.config_ID = "<undefined>"
                print >>sys.stderr, 'Make sure your config file is type "ktext" in Perforce.'
        else:
            cf.config_ID = None
        # this heading displays the test name just as a PREREQUISITES entry needs.
        self._ui.add_heading(repr_test(self.test_name, args, kw), 2)
        self._report.add_heading(repr_test(self.test_name, args, kw), 2)
        if cf.config_ID:
            self.info("Configuration ID: %s" % (cf.config_ID,))
        self.starttime = timelib.now()
        self.info("STARTTIME: %s" % self.timestamp(self.starttime))
        rv = None # in case of exception
        rv = self._initialize(rv)
        if rv is not None: # an exception happened
            return rv
        # test elapsed time does not include initializer time.
        teststarttime = timelib.now()
        # run test_method
        testloops = int(cf.get("testloops", 1))
        try:
            for l in xrange(testloops):
                rv = apply(self.test_method, args, kw)
        except KeyboardInterrupt:
            if self._debug:
                ex, val, tb = sys.exc_info()
                debugger.post_mortem(ex, val, tb)
            rv = self.abort("%s: aborted by user." % self.test_name)
            self._finalize(rv)
            raise
        except TestFailError, errval:
            rv = self.failed("Caught Fail exception: %s" % (errval,))
Ejemplo n.º 9
0
    def _finalize(self):
		# finalize the suite
		try:
			self.finalize()
		except KeyboardInterrupt:
			if self._nested:
				raise TestSuiteAbort, "Suite '%s' aborted by user in finalize()." % (self.suite_name,)
			else:
				self.info("Suite aborted by user in finalize().")
		except:
			ex, val, tb = sys.exc_info()
			if self._debug:
				debugger.post_mortem(ex, val, tb)
			self.info("Suite failed to finalize: %s (%s)" % (ex, val))
			if self._nested:
				raise TestSuiteAbort, "subordinate suite '%s' failed to finalize." % (self.test_name,)
		self._report_summary()
Ejemplo n.º 10
0
	def __call__(self, *args, **kw):
		# this heading displays the test name just as a PREREQUISITES entry needs.
		self._report.add_heading(repr_test(self.test_name, args, kw), 2)
		self.starttime = timelib.now()
		self.info("STARTTIME: %s" % (timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(self.starttime)),))
		rv = None # in case of exception
		rv = self._initialize(rv)
		if rv is not None: # an exception happened
			return rv
		# test elapsed time does not include initializer time.
		teststarttime = timelib.now()
		# run test_method
		try:
			rv = apply(self.test_method, args, kw)
		except KeyboardInterrupt:
			if self._debug:
				ex, val, tb = sys.exc_info()
				debugger.post_mortem(ex, val, tb)
			rv = self.abort("%s: aborted by user." % self.test_name)
			self._finalize(rv)
			raise
		except TestFailError, errval:
			rv = self.failed("Caught Fail exception: %s" % (errval,))
Ejemplo n.º 11
0
            except OSError, errno:
                if errno[0] == EEXIST:
                    pass
                else:
                    raise

            os.chmod(cf.resultsdir, 0777)
            # firstly, run the module-level initialize function.
            if hasattr(mod, "initialize") and callable(mod.initialize):
                if cf.flags.DEBUG:
                    try:
                        mod.initialize(cf)
                    except:
                        ex, val, tb = sys.exc_info()
                        import debugger
                        debugger.post_mortem(ex, val, tb)
                else:
                    mod.initialize(cf)

            rpt = cf.get_report()
            cf.reportfilenames = rpt.filenames # Report file's names. save for future use.
            rpt.initialize()
            rpt.logfile(cf.logfilename)
            rpt.add_title("Test Results for module %r." % (mod.__name__, ))
            rpt.add_message("ARGUMENTS", " ".join(cf.arguments))
            # get the build version
            version_file = os.path.join(os.environ["STRATATEST_HOME"], 'etc',
                    'VERSION')
            self.rpt = rpt # new report object.
            try:
                vf = open(version_file)
Ejemplo n.º 12
0
	def run_module(self, mod):
		"""run_module(module)
	Runs the module. The parameter should be a module object, but if it is a
	string then a module object with that name will be imported. 
	"""
		cf = self._config
		if type(mod) is str:
			mod = self.get_module(mod)
		if mod:
			try:
				cf.module_ID = mod._ID
			except AttributeError:
				cf.module_ID = "<unknown>"
			cf.reportbasename = mod.__name__.replace(".", "_")
			cf.logbasename = "%s.log" % (cf.reportbasename,)
			# merge any test-module specific config files.
			testconf = os.path.join(os.path.dirname(mod.__file__) , "%s.conf" % (mod.__name__.split(".")[-1],))
			cf.mergefile(testconf)
			# resultsdir is where you would place any resulting data files.
			starttime = timelib.now()
			cf.resultsdir = os.path.join(
					cf.get("resultsdirbase", os.environ["HOME"]),
					"%s-%s" % (cf.reportbasename, timelib.strftime("%Y%m%d%H%M", timelib.localtime(starttime)))
			)
			# make collection dir 
			try:
				os.mkdir(cf.resultsdir)
			except OSError, errno:
				if errno[0] == EEXIST:
					pass
				else:
					raise
			# firstly, run the module-level initialize function.
			if hasattr(mod, "initialize") and callable(mod.initialize):
				if cf.flags.DEBUG:
					try:
						mod.initialize(cf)
					except:
						ex, val, tb = sys.exc_info()
						import debugger
						debugger.post_mortem(ex, val, tb)
				else:
					mod.initialize(cf)

			rpt = cf.get_report()
			cf.reportfilenames = rpt.filenames # Report file's names. save for future use.
			rpt.initialize()
			rpt.logfile(cf.logfilename)
			rpt.add_title("Test Results for module %r." % (mod.__name__, ))
			rpt.add_message("ARGUMENTS", " ".join(cf.arguments))
			note = self.get_note()
			if note:
				rpt.add_message("NOTE", note)
				self._config.comment = note
			else:
				self._config.comment = "<none>"
			self._reporturl(rpt)
			rpt.add_message("MODULESTART", timelib.strftime("%a, %d %b %Y %H:%M:%S %Z", timelib.localtime(starttime)))
			mod.run(cf) # run the test!
			rpt.add_message("MODULEEND", timelib.localtimestamp())
			rpt.finalize()
			# force close of report and logfile between modules
			cf.logfile.flush()
			del cf.report ; del cf.logfile 

			# lastly, run the module-level finalize function.
			if hasattr(mod, "finalize") and callable(mod.finalize):
				if cf.flags.DEBUG:
					try:
						mod.finalize(cf)
					except:
						ex, val, tb = sys.exc_info()
						import debugger
						debugger.post_mortem(ex, val, tb)
				else:
					mod.finalize(cf)
Ejemplo n.º 13
0
	def _initialize(self, args, kwargs):
		self.report.add_heading("Test suite: %s" % self.__class__.__name__, 1)
		self.verify_testbed()
		if self._testbed_needed:
        	self.report.add_message("TESTBED", self.config.testbed.name)
		# initialize the suite
		try:
			rv = self.initialize(*args, **kwargs)
		except KeyboardInterrupt:
			self.info("Suite aborted by user in initialize().")
			raise TestSuiteAbort
		except:
			ex, val, tb = sys.exc_info()
			if self._debug:
				ex, val, tb = sys.exc_info()
				debugger.post_mortem(ex, val, tb)
			self.error("Suite failed to initialize: %s (%s)" % (ex, val))
			raise TestSuiteAbort, val
		# run all the tests

	# verify any prerequisites are met at run time. Note that this
	# currently only checks this particular suite.
	def check_prerequisites(self, currententry, upto):
		for prereq in currententry.prerequisites():
			for entry in self._tests[:upto]:
				if entry.match_prerequisite(prereq):
					if entry.result == PASSED:
						continue
					else:
						self.report.add_heading(repr(currententry), 2)
						self.info("WARNING: prerequisite of %s did not pass." % (currententry,))
						self.info("%s: %s" % (prereq, entry.result))
						currententry.abort()
						return False
		return True # no prerequisite

	def get_testbeds(self):
		"""Get a list of available testbeds that will work will all tests in
		the suite. Generally, this is called before the suite is run.  """
		tblist = []
		tbneeded = False
		for entry in self._tests:
			if entry.inst.ITEST is None:
				continue
			tbneeded = True
			tbs = entry.inst.get_testbeds()
			if tbs:
				tblist.extend(tbs)
		tblist = removedups(tblist)
		# prune testbeds that wont work for some tests
		for entry in self._tests:
			for tb in tblist[:]:
				if not entry.inst.testbed_will_work(tb):
					tblist.remove(tb)
					break
		self._testbed_needed = tbneeded
		return tblist

	def verify_testbed(self):
		if not self.testbed_needed:
			return True
		tbr = self.config.testbed
		if tbr is None:
			for entry in self._tests:
				if entry.inst.ITEST is not None:
					raise TestSuiteAbort, "No testbed specified or found."
			return True # no testbed needed
		for entry in self._tests:
			if not entry.inst.testbed_will_work(tbr._testbed):
				reason = entry.inst.why_testbed_wont_work(tbr._testbed)
				raise TestSuiteAbort, "Cannot use testbed %s: %s" % (tbr._testbed.name, reason)
	
	def _get_tbneeded(self):
		if self._testbed_needed is None:
			self.get_testbeds()
		return self._testbed_needed
	def _del_tbneeded(self):
		self._testbed_needed = None
	testbed_needed = property(_get_tbneeded, None, _del_tbneeded, "Is a testbed needed for this suite?")

	def run_tests(self):
        self.config.rv_dict = {}
		for i, entry in enumerate(self._tests):
			if not self.check_prerequisites(entry, i):
				continue
			try:
				self.config.logfile.note("%s: %r" % (timelib.localtimestamp(), entry))
                rv = entry()
			except KeyboardInterrupt:
				self.info("Test suite aborted by user.")
				if self._nested:
					raise TestSuiteAbort, "aborted by user"
				else:
					break
			except TestSuiteAbort, err:
				self.info("Suite aborted by test %s (%s)." % (entry.name(), err))
				rv = ABORT