Exemplo n.º 1
0
def is_fts(file_path):
    """Check if the given file_path refers to an dot file containing an FTS.
    Return True on success, False otherwise"""
    with open(file_path, 'r') as source:
        try:
            load_dot(source)
            return True
        except:
            return False
Exemplo n.º 2
0
def full_analysis_worker(fts_file, out_file, queue, event):
    atexit.unregister(fm.final_delete)
    dead = []
    false = []
    hidden = []
    with open(fts_file, 'r') as fts_source:
        fts = load_dot(fts_source)
    with open(out_file, 'w') as sys.stdout:
        event.set()
        z3_analyse_full(fts)
        fts.report()
        sys.stdout.flush()
    for transition in fts._set_dead:
        dead.append({
            'src': transition._in._id,
            'dst': transition._out._id,
            'label': str(transition._label),
            'constraint': str(transition._constraint)
        })
    for transition in fts._set_false_optional:
        false.append({
            'src': transition._in._id,
            'dst': transition._out._id,
            'label': str(transition._label),
            'constraint': str(transition._constraint)
        })
    for state in fts._set_hidden_deadlock:
        hidden.append(state._id)
    queue.put(
        {'ambiguities': {
            'dead': dead,
            'false': false,
            'hidden': hidden
        }})
Exemplo n.º 3
0
 def load_model(self, path):
     try:
         file = open(path, "r")
         self.__fts = analyser.load_dot(file)
     except Exception as e:
         raise Exception('Invalid FTS file')
     finally:
         file.close()
Exemplo n.º 4
0
def main(source, target):
    with open(source, 'r') as fts_source:
        fts = analyser.load_dot(fts_source)
    fts_source.close()
    analyser.z3_analyse_full(fts)
    dis = Disambiguator.from_file(source)
    dis.remove_transitions(fts._set_dead)
    dis.set_true_list(fts._set_false_optional)
    dis.solve_hidden_deadlocks(fts._set_hidden_deadlock)
    with open(target, 'w') as out:
        out.write(dis.get_graph())
def hdead_analysis_worker(fts_file, out_file, queue):
    hidden = []
    fts_source = open(fts_file, 'r')
    sys.stdout = open(out_file, 'w')
    fts = load_dot(fts_source)
    z3_analyse_hdead(fts)
    for state in fts._set_hidden_deadlock:
        hidden.append(state._id)
    queue.put({'ambiguities':{'dead':[], 'false':[], 'hidden': hidden}})
    fts.report()
    sys.stdout.close()
    fts_source.close()
Exemplo n.º 6
0
def hdead_analysis_worker(fts_file, out_file, queue, event):
    atexit.unregister(fm.final_delete)
    hidden = []
    with open(fts_file, 'r') as fts_source:
        fts = load_dot(fts_source)
    with open(out_file, 'w') as sys.stdout:
        event.set()
        z3_analyse_hdead(fts)
        fts.report()
        sys.stdout.flush()
    for state in fts._set_hidden_deadlock:
        hidden.append(state._id)
    queue.put({'ambiguities': {'dead': [], 'false': [], 'hidden': hidden}})
Exemplo n.º 7
0
 def test_disambiguate(self, tmp_path):
     import os
     import src.internals.analyser as analyser
     dot = os.listdir(os.path.join('tests', 'dot'))
     for source in dot:
         dead = []
         false = []
         hidden = []
         with open(os.path.join('tests', 'dot', source), 'r') as fts_source:
             fts = analyser.load_dot(fts_source)
         fts_source.close()
         analyser.z3_analyse_full(fts)
         dis = Disambiguator.from_file(os.path.join('tests', 'dot', source))
         dis.remove_transitions(fts._set_dead)
         dis.set_true_list(fts._set_false_optional)
         dis.solve_hidden_deadlocks(fts._set_hidden_deadlock)
         with open(os.path.join(tmp_path, "fixed-" + source), 'w') as out:
             out.write(dis.get_graph())
         with open(os.path.join(tmp_path, "fixed-" + source), 'r') as fixed:
             fts = analyser.load_dot(fixed)
         analyser.z3_analyse_full(fts)
         assert not (fts._set_dead or fts._set_false_optional
                     or fts._set_hidden_deadlock)
Exemplo n.º 8
0
 def vendingnew(self, tmp_path):
     import src.internals.analyser as analyser
     from src.internals.disambiguator import Disambiguator
     with open(os.path.join('tests', 'dot', 'vendingnew.dot'),
               'r') as fts_source:
         fts = analyser.load_dot(fts_source)
     fts_source.close()
     analyser.z3_analyse_full(fts)
     dis = Disambiguator.from_file(
         os.path.join('tests', 'dot', 'vendingnew.dot'))
     dis.remove_transitions(fts._set_dead)
     dis.set_true_list(fts._set_false_optional)
     dis.solve_hidden_deadlocks(fts._set_hidden_deadlock)
     with open(os.path.join(tmp_path, "fixed-vendingnew.dot"), 'w') as out:
         out.write(dis.get_graph())
     return os.path.join(tmp_path, 'fixed-vendingnew.dot')
Exemplo n.º 9
0
 def fixed_dot(self, tmp_path):
     import src.internals.analyser as analyser
     from src.internals.disambiguator import Disambiguator
     dots = []
     dot = os.listdir(os.path.join('tests', 'dot'))
     for source in dot:
         with open(os.path.join('tests', 'dot', source), 'r') as fts_source:
             fts = analyser.load_dot(fts_source)
         fts_source.close()
         analyser.z3_analyse_full(fts)
         dis = Disambiguator.from_file(os.path.join('tests', 'dot', source))
         dis.remove_transitions(fts._set_dead)
         dis.set_true_list(fts._set_false_optional)
         dis.solve_hidden_deadlocks(fts._set_hidden_deadlock)
         dots.append(os.path.join(tmp_path, "fixed-" + source))
         with open(os.path.join(tmp_path, "fixed-" + source), 'w') as out:
             out.write(dis.get_graph())
     return dots
def full_analysis_worker(fts_file, out_file, queue):
    dead = [] 
    false = [] 
    hidden = []
    fts_source = open(fts_file, 'r')
    sys.stdout = open(out_file, 'w')
    fts = load_dot(fts_source)
    z3_analyse_full(fts)
    for transition in fts._set_dead:
        dead.append({'src':transition._in._id, 'dst':transition._out._id,
            'label':str(transition._label), 'constraint':str(transition._constraint)})
    for transition in fts._set_false_optional:
        false.append({'src':transition._in._id, 'dst':transition._out._id,
            'label':str(transition._label), 'constraint':str(transition._constraint)})
    for state in fts._set_hidden_deadlock:
        hidden.append(state._id)
    queue.put({'ambiguities':{'dead': dead, 'false': false, 'hidden': hidden}})
    fts.report()
    sys.stdout.close()
    fts_source.close()
Exemplo n.º 11
0
 def load_model(self, path):
     try:
         self.__fts = analyser.load_dot(open(path,"r"))
     except Exception as e:
         raise Exception('Invalid FTS file')