Example #1
0
 def save_cache(self, state):
     # Do not overwrite the old file (yet)
     with lock:
         parser.dump(state, self._cache_backup)
         # Atomic operation (sort of)
         # (just in case the interpreter hard crashes)
         os.rename(self._cache_backup, cache_file)
Example #2
0
    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())
Example #3
0
            except Exception, e:
                self._monitor.log.exception(e)
                # interrupt other tasks
                interrupt_ripper()

    tasks = [Task(m) for m in monitors]

    for t in tasks:
        t.start()

    while any(( task.is_alive() for task in tasks )):
        time.sleep(steptime)

    if not interrupt:
        # Dump gui file to disk only if it wasn't interrupted
        parser.dump(state.efg, efg_file)

        log.info('total events: %d' % len(state.efg.nodes()))
        log.info('visited: %d' % len(state.visited))
        log.info('skipped: %d' % len(state.skipped))
        log.info('failures: %d' % len(state.failures))

        # Dump cache file if skipped is empty and we are finished
        #if len(state.skipped) == 0 and len(state.queue) == 0:
        #    os.remove(cache_file)
    else:
        parser.dump(state, '%s.cache' % efg_file)

    return 0 if not interrupt else 1

if __name__ == '__main__':
Example #4
0
    testgenerator.add_options(cfg)

    max = float(cfg.get('testgenerator', 'max'))
    progress = util.ProgressBar(max)
    counter = util.counter(max, progress.update)
    start_nodes = [x for x in gr if 'start_node' in gr.node_attributes(x)]
    tests = testgenerator.generate(gr, start_nodes, cfg, counter)

    # Write each one of these tests to a separate test file
    print 'writing test files to disk'
    progress = util.ProgressBar(len(tests))
    output_dir = cfg.get('testgenerator', 'folder')
    if not os.path.exists(output_dir):
        log.debug('creating folder %s' % os.path.abspath(output_dir))
        os.makedirs(output_dir)

    format = cfg.get('testgenerator', 'format')
    for i, t in enumerate(tests):
        name = 't_%s.%s' % ('_'.join(['e%u' % hash(m) for m in t]), format)
        file_ = os.path.join(output_dir, name)
        progress.update(i+1)
        log.debug('writing test case %s' % file_)
        parser.dump(t, file_)
    print
    log.info('%d test cases total' % len(tests))

    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv))