def validate(self, monitor, snapshot, name, test): join, basename = os.path.join, os.path.basename desired_file = join(self._srcdir, basename(name)) if not os.path.exists(desired_file): return 'no desired test structure' monitor.log.debug('validating structure of test %s' % name) try: desired = parser.load(desired_file) except: return 'desired test structure invalid' # look at the actual state actual = snapshot # check the state of the application if desired.alive != actual.alive: return 'alive: expected %r, received %r' \ % (desired.alive, actual.alive) # sort the desired and actual uids (easier to compare them) key = operator.itemgetter('Uid') sort = lambda x: sorted(x, key = key) desired, actual = sort(desired.state), sort(actual.state) try: # validate children _compare_children(desired, actual) # validate properties based on desired structure self._compare_properties(desired, actual) except AssertionError, e: return 'assertion error: %s' % e
def load_state(monitor, efg_file): cache_file = '%s.cache' % efg_file if os.path.exists(cache_file): try: # reload cache file log.info('loading cache file from %s' % cache_file) return parser.load(cache_file) except Exception, e: log.exception(e)
def main(monitors, cfg): efg_file = cfg.get('general', 'efg_file') state, lock = load_state(monitors[0], efg_file), threading.Lock() config_loc = cfg.get('general', 'configuration') ignored_patterns = [] try: ignored_patterns = parser.load(config_loc) except Exception, e: # Some error happened when reading the configuration file log.exception(e)
def run(self): try: while True: interrupt_point() with self._lock: testfile = self._testcases.pop() left = len(self._testcases) log.info('running %s on monitor %s (%d left)' % (testfile, self._monitor.name, left)) test = parser.load(testfile) name = os.path.split(testfile)[1] logfile = os.path.join( self._out_dir, os.path.splitext(name)[0]) + '.log' stdout = StringIO.StringIO() with self._monitor.open(logfile, stdout): interrupt_point() # Perform each action in the test try: for event in test: event.perform(self._monitor) time.sleep(self._steptime) interrupt_point() # Take final snapshot of the state and save it snapshot = self._monitor.take_snapshot() parser.dump(snapshot, os.path.join( self._out_dir, name)) except Exception, e: log.exception(e) self._results.error( testfile, message = str(e), stdout = stdout.getvalue()) else: # Validate with oracles for oracle in self._oracles: reason = oracle.validate( self._monitor, snapshot, testfile, test) if reason: log.error('test %s failed (oracle %s)' % (testfile, type(oracle))) self._results.failure( testfile, message = '%s\nreason: %s' % (type(oracle), reason), stdout = stdout.getvalue()) break else: self._results.success( testfile, stdout = stdout.getvalue())
def main(argv = None): cfg = guitarlib.initialize(argv) # Load in the efg file efg_file = cfg.get('general', 'efg_file') log.info('loading efg file %s' % efg_file) gr = parser.load(efg_file) try: pkg, class_ = cfg.get('testgenerator', 'plugin').rsplit('.', 1) testgenerator = getattr(__import__(pkg, fromlist=[class_]), class_)() except (ImportError, AttributeError), e: log.exception(e) return 1
def preload(self, cfg): self._srcdir = cfg.get('replayer', 'desired') self._structure = parser.load(cfg.get('replayer', 'structure')) for name, expr in self._structure.iteritems(): self._structure[name] = \ compile(_expr_template % (expr, name), name, 'eval')