def solve_hdd():
    pm = ProcessManager.get_instance()
    if not sessions.check_session():
        return {"text": "No ambiguities data available execute a full analysis first"}, 400
    if not session['ambiguities']:
        queue = pm.get_queue(session['id'])
        if not queue:
            return {"text": "No ambiguities data available execute a full analysis first"}, 400
        else: 
            session['ambiguities'] = queue.get()
    payload = {}
    file_path = session['model']
    if os.path.isfile(file_path):
        dis = Disambiguator.from_file(file_path)
        dis.remove_transitions(session['ambiguities']['dead'])
        dis.solve_hidden_deadlocks(session['ambiguities']['hidden'])
        pm.delete_queue(session['id'])
        graph = graphviz.Graph(dis.get_graph())
        payload['mts'] = graph.get_mts()
        payload['text'] = "Removed hidden deadlocks and dead transitions"
        payload['graph'] = graph.get_graph()
        payload['edges'], payload['nodes'] = graph.get_graph_number()
        graph.draw_graph(session['graph'])
        return payload, 200
    return {"text": 'File not found'}, 400
Esempio n. 2
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())
Esempio n. 3
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')
Esempio n. 4
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
Esempio n. 5
0
def get_output():
    pm = ProcessManager.get_instance()
    if not sessions.check_session():
        sessions.delete_output_file()
        return {"text": '\nSession timed-out'}, 404
    elif not 'id' in session or not pm.process_exists(session['id']):
        sessions.delete_output_file()
        return {"text": ''}, 404
    else:
        if pm.is_alive(session['id']):
            with open(session['output']) as out:
                out.seek(session['position'])
                result = out.read(4096)
                session['position'] = out.tell()
            return {"text": result}, 206
        else:
            with open(session['output']) as out:
                out.seek(session['position'])
                result = out.read()
            os.remove(session['output'])
            queue = pm.get_queue(session['id'])
            payload = {}
            payload['text'] = result
            graph = graphviz.Graph.from_file(session['model'])
            payload['edges'], payload['nodes'] = graph.get_graph_number()
            payload['mts'] = graph.get_mts()
            if (queue):
                tmp = queue.get()['ambiguities']
                session['ambiguities'] = tmp
                payload['ambiguities'] = tmp
                ProcessManager.get_instance().delete_queue(session['id'])
                try:
                    dis = Disambiguator.from_file(session['model'])
                    dis.highlight_ambiguities(tmp['dead'], tmp['false'],
                                              tmp['hidden'])
                    payload['graph'] = dis.get_graph()
                    graphviz.Graph(dis.get_graph()).draw_graph(
                        session['graph'])
                    return payload, 200
                except:
                    return payload, 200
            return payload, 200
Esempio n. 6
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)
Esempio n. 7
0
 def test_wrong_data_type(self):
     import os
     with pytest.raises(Exception, match=r"Invalid data"):
         with open(os.path.join('src', 'templates', 'main.html')) as source:
             Disambiguator(source.read())
Esempio n. 8
0
 def graph(self):
     import os
     dis = Disambiguator.from_file(
         os.path.join('tests', 'dot', 'ambiguous.dot'))
     return dis
Esempio n. 9
0
 def test_wrong_file_type(self):
     import os
     with pytest.raises(Exception, match=r"Wrong file format"):
         Disambiguator.from_file(
             os.path.join('src', 'static', 'js', 'script.js'))
Esempio n. 10
0
 def test_file_not_found(self):
     with pytest.raises(FileNotFoundError):
         Disambiguator.from_file('nothing')
Esempio n. 11
0
 def disambiguated_graph(self):
     import os
     dis = Disambiguator.from_file(
         os.path.join('tests', 'dot', 'test_fts_disambiguato.dot'))
     return dis