Exemple #1
0
 def _parse_entry(self, line):
     m = re_entry.match(line)
     if m:
         log.debug("key-value '%s'='%s' added to section %s" %
                   (m.group(1), m.group(2), self._name))
         self._current_section[m.group(1)] = m.group(2)
     return m is not None
Exemple #2
0
    def _match(self, x, visited):
        def compare(a, b):
            if self.conflict_cache.has_key(a):
                # use the cache if possible
                for cache in self.conflict_cache[a]:
                    if cache == b:
                        return True

            if a == b:
                return True
            else:
                common = Levenshtein.ratio(a, b)
                comparison = common > 0.7
                if comparison:
                    # cache the match
                    if self.conflict_cache.has_key(a):
                        self.conflict_cache[a].append(b)
                    else:
                        self.conflict_cache[a] = [b]

        for v in visited:
            if len(v.path) == len(x.path) and v.event == x.event:
                if all((compare(a, b) for a, b in zip(x.path, v.path))):
                    log.debug('resolving %s as %s' % (x, v))
                    return v
Exemple #3
0
    def _parse_section(self, line):
        m = re_section.match(line)

        if m:
            self._push_changes()
            self._name = m.group(1)
            log.debug('parsing section %s' % self._name)
        return m is not None
Exemple #4
0
def main(monitors, cfg):
    # ant_glob for testcases
    testpattern = cfg.get('replayer', 'testcase')
    testcases = util.ant_glob(testpattern)

    log.info('collected %d test cases' % len(testcases))
    log.debug(`testcases`)

    assert len(monitors) > 0, 'No monitors available'

    # Load oracles
    oracles = []
    oracle_names = cfg.get('replayer', 'oracles')
    if len(oracle_names.strip()) != 0:
        for pkg, class_ in (s.strip().rsplit('.', 1)
                                for s in oracle_names.split(',')):
            try:
                oracle = getattr(__import__(pkg,fromlist=[class_]), class_)()
                oracle.add_options(cfg)
                oracles.append(oracle)
                log.info('loaded oracle %r' % oracle)
            except (ImportError, AttributeError):
                log.warn('could not load oracle %s.%s' % (pkg, class_))

    lock = threading.Lock()
    steptime = float(cfg.get('general', 'steptime'))
    out_dir = cfg.get('replayer', 'state_dir')
    if not os.path.exists(out_dir):
        log.debug('creating folder %s' % os.path.abspath(out_dir))
        os.makedirs(out_dir)
    results = Results()
    replayers = [ Replayer(monitor = m,
                           config = cfg,
                           oracles = oracles,
                           testcases = testcases,
                           lock = lock,
                           steptime = steptime,
                           out_dir = out_dir,
                           results = results)
                  for m in monitors ]

    for replayer in replayers:
        replayer.start()

    while any(( replayer.is_alive() for replayer in replayers )):
        time.sleep(steptime)

    results_file = cfg.get('replayer', 'results')
    with open(results_file, 'w') as f:
        f.write( results.xmlreport().toprettyxml(indent = '  ') )

    return 0 if not interrupt else 1
Exemple #5
0
    def disconnect(self, current = None):
        """
        Kills the application. First calls the proxy version
        (so it can do any desired clean up) then it sends sigkill
        in case the process didn't clean itself up properly.

        @note: Due to the nature of this call, the process that kills
        itself <b>must</b> return from the disconnect function call.

        The proxy to this process becomes invalid after this call.
        """
	if self.alive():
		self._impl.disconnect()
		#os.kill(self.pid, signal.sigkill)
		#os.wait()
		process = subprocess.Popen('kill -9 '+ str(self.pid), stderr=subprocess.PIPE, shell=True)

        # destroy all components connected to this process
        for identity in self._connections:
            current.adapter.remove(identity)

        # Remove this object from the Ice runtime
        current.adapter.remove(current.id)

        # run a post script (if one exists)
        if self._post_command:
            cmd = shlex.split(self._post_command)
            log.debug('running post command %r' % cmd)
            process = subprocess.Popen(cmd, stdout = subprocess.PIPE,
                                       stderr = subprocess.PIPE)
            log.debug('return code: %d' % process.wait())
            stdout, stderr = process.communicate()
            log.debug('stdout: %s' % stdout)
            log.debug('stderr: %s' % stderr)
Exemple #6
0
    def connect(self, cfg, current = None):
        # pre-run script
        if cfg.has_key('pre_command'):
            cmd = shlex.split(cfg['pre_command'])
            log.debug('running pre command %r' % cmd)
            process = subprocess.Popen(cmd, stdout = subprocess.PIPE,
                                       stderr = subprocess.PIPE)
            log.debug('return code: %d' % process.wait())
            stdout, stderr = process.communicate()
            log.debug('stdout: %s' % stdout)
            log.debug('stderr: %s' % stderr)

        with self._lock:
            port = self._pids.pop(0)

        cmd, env = self._connect_impl(cfg, port)
        env.update(os.environ)
        log.info('launching command %r' % cmd)
        process = subprocess.Popen(cmd, env = env)
        log.info('starting process %d at port %d' % (process.pid, port))

        with self._lock:
            self._active.append((port, process))

        post_command = None
        if cfg.has_key('post_command'):
            post_command = cfg['post_command']
        process = ProcessI(self._adapter, process, port, post_command)
        return guitarlib.ProcessPrx.uncheckedCast(
            self._adapter.addWithUUID(process))
Exemple #7
0
def load(stream_list = None):
    """
    Loads the specified files/streams into a new config parser
    with all the default values.

    The list of files can be files, streams, or strings. If a file
    or stream, they will be read directly. If a string, then it will
    be loaded as a file first and then processed.

    If the type of files is not an iterable type or is a string,
    then only the single file/stream will be loaded.

    @type stream_list: C{list}, C{str}, or C{file}
    @returns: The L{guitarlib.config.ConfigParser} gotten from loading
    the given streams.
    @rtype: L{guitarlib.config.ConfigParser}
    """

    defaults = { 'general' : {
            'gui_file' : 'gui_file.pckl',
            'efg_file' : 'efg_file.pckl',
            'hosts' : 'localhost',
            'steptime' : '2',
            'configuration' : 'configuration.yml' },
                'structure' : {
            'graph' : 'False',
            'image_file' : 'structure.png' },
                'testgenerator' : {
            'format' : 'pckl',
            'folder' : 'TC',
            'plugin' : 'guitarlib.generator.SequenceLength',
            'max' : 'infinity' },
                'replayer' : {
            'testcase' : 'TC/**',
            'state_dir' : 'state_files',
            'oracles' : '',
            'results' : 'replayer-results.xml' },
                'hosts' : {
            'localhost' : 'default -p 10000 -h localhost'
            }
                }

    parser = ConfigParser(defaults)

    # None value defaults to 'guitar.cfg'
    if stream_list is None:
        stream_list = ('guitar.cfg',)
    # Determine if this is a single file
    if isinstance(stream_list, (str, file)):
        stream_list = (stream_list,)

    for stream in stream_list:
        if isinstance(stream, str) and os.path.exists(stream):
            log.debug('parsing %s for config values' % stream)
            with guitarlib.util.open(stream) as f:
                parser.load(f)
        elif not isinstance(stream, str):
            log.debug('parsing stream %r for config values' % stream)
            parser.load(stream)
        else:
            log.debug('no such file: %s' % stream)
    return parser
Exemple #8
0
        return 1

    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__':
Exemple #9
0
        # Convert all available hosts to proxies
        def proxy(name):
            """Tries to convert a host into a proxy"""
            try:
                return guitarlib.ApplicationPrx.checkedCast(
                    self.communicator().stringToProxy(
                        'Application:%s' % potential_hosts[name]))
            except Exception, e:
                log.warn('monitor %s is invalid' % name)
                log.exception(e)
                return None

        server = {}
        if cfg.has_option('general', 'server'):
            section = cfg.get('general', 'server')
            log.debug('loading server configuration from section %s' % section)
            server = cfg.get_section(section)
        retrieveProxy = lambda name, prx: Monitor(prx, server, name)
        valid = lambda name: potential_hosts.has_key(name)

        # Filter out all invalid host names and find their proxies
        monitors = [(name, proxy(name))
                    for name in requested_hosts if valid(name)]
        # Filter out invalid proxies and create the monitors for valid ones
        monitors = [Monitor(prx, server, name)
                    for name, prx in monitors if prx]

        if len(monitors) == 0:
            raise Exception('no monitors available')

        log.info('%d machine(s) available' % len(monitors))