コード例 #1
0
    def test_age_avg(self):
        ANSWER_FILE_PATH = 'aux_files/age-avg-answers.json'
        SQLITE_PATH = 'C:/Users/linha/Desktop/ws/py-scripts-examples/age-avg/.noworkflow/db.sqlite'
        CURSOR = sqlite3.connect(SQLITE_PATH).cursor()
        creator = ExecTreeCreator(CURSOR)
        navs = [SingleStepping, TopDown, HeaviestFirst, DivideAndQuery]
        results = []
        for nav in navs:
            exec_tree = None
            exec_tree = creator.create_exec_tree()
            nav_instance = nav(exec_tree, True, ANSWER_FILE_PATH)
            nav_instance.navigate()
            vis = Visualization(exec_tree)
            vis.generate_exec_tree()
            results.append(str(vis.graph))

        SS_FILE = 'debugprov/tests/test_files/age-avg-ss.gv'
        TD_FILE = 'debugprov/tests/test_files/age-avg-td.gv'
        HF_FILE = 'debugprov/tests/test_files/age-avg-hf.gv'
        DQ_FILE = 'debugprov/tests/test_files/age-avg-dq.gv'

        result_files = [SS_FILE, TD_FILE, HF_FILE, DQ_FILE]
        idx = 0
        for idx, val in enumerate(result_files):
            with open(val, 'r') as myfile:
                content = myfile.read()
                self.assertEquals(content, results[idx])
コード例 #2
0
def process_mutant(mutant_dir):
    os.chdir(mutant_dir)
    print(os.getcwd())
    FAULTY_LINE = discover_changed_lines(mutant_dir + ".diff")
    now2_sqlite_path = os.getcwd() + '/.noworkflow/db.sqlite'
    cursor = sqlite3.connect(now2_sqlite_path).cursor()
    exec_tree = ExecTreeCreator(cursor).create_exec_tree()
    exec_tree.root_node.validity = Validity.INVALID
    faulty_code_component_id = get_faulty_cc_id(FAULTY_LINE, cursor)
    search_result = exec_tree.search_by_ccid(faulty_code_component_id)

    if len(search_result) != 1:
        raise Exception(
            "More than one node in ET associated with faulty code_component_id. CC id: "
            + str(faulty_code_component_id))

    buggy_node = search_result.pop()
    invalidate_node_and_parents(buggy_node)
    node_with_wrong_data = get_node_with_wrong_data(mutant_dir, cursor)
    ansfile = open('oracle.json', 'w')
    ansfile.write(json.dumps(format_answers(exec_tree, node_with_wrong_data)))
    ansfile.close()
    print('saving oracle.json file: ' + os.getcwd() + '/oracle.json')
    vis = Visualization(exec_tree)
    vis.generate_exec_tree()
    vis.graph.render(filename='exec_tree', format='pdf')
    os.chdir('..')
コード例 #3
0
 def _interactive_evaluation(self, node: Node) -> Node:
     self.exec_tree.node_under_evaluation = node
     vis = Visualization(self.exec_tree)
     vis.view_exec_tree(str(id(node)))
     answer = ConsoleEvaluation.evaluate_node(node)
     if answer:
         # The YES answer prunes the subtree rooted at N
         self.recursive_validate(node)
     else:
         # The NO answer prunes all the nodes of the ET,
         # exept the subtree rooted at N
         node.validity = Validity.INVALID
         self.recursive_validate(self.exec_tree.root_node,node)
     self.exec_tree.node_under_evaluation = None
     return node
コード例 #4
0
def generate_exec_trees(scripts):
    for script_path in scripts:
        print(script_path)
        directory = script_path.split('/')[0]
        os.chdir(script_path)
        os.chdir(config.mutants_with_wrong_result)
        for mutant_dir in os.listdir():
            os.chdir(mutant_dir)
            now2_sqlite_path = os.getcwd() + '/.noworkflow/db.sqlite'
            cursor = sqlite3.connect(now2_sqlite_path).cursor()
            exec_tree = ExecTreeCreator(cursor).create_exec_tree()
            vis = Visualization(exec_tree)
            vis.generate_exec_tree()
            vis.graph.render(filename='exec_tree', format='pdf')
            print('Rendering: ' + os.getcwd() + '/exec_tree.pdf')
            os.chdir('..')
        os.chdir('../..')
コード例 #5
0
    def run(self):
        self.db_path = self.DEFAULT_SQLITE_PATH
        try:
            cursor = sqlite3.connect(self.db_path).cursor()
            creator = ExecTreeCreator(cursor)
        except:
            raise Exception('Error reading database!')
            import sys
            sys.exit()
        exec_tree = creator.create_exec_tree()
        self.select_nav_strategy()
        nav = self.choosen_nav_strategy(exec_tree)
        if self.ask_use_prov():
            prov = ProvenanceEnhancement(exec_tree, cursor)
            strategy = self.ask_use_wrong_data()
            if strategy == 1:
                # Slice Criterion: last print
                wrong_data_id = prov.get_last_print_evid()
                prov.enhance(wrong_data_id)
            elif strategy == 2:
                # Slice criterion: Wrong output (informed by user)
                wrong_data = self.ask_wrong_data()
                wrong_data_id = prov.get_wrong_data_evid(wrong_data)
                prov.enhance(wrong_data_id)
            elif strategy == 3:
                # Slice criterion: Node in tree (informed by user)
                tmp_vis = Visualization(exec_tree)
                tmp_vis.view_exec_tree('tmp_tree')
                print("Tell me which ID ")
                ev_id = int(prompt('> '))
                prov.enhance(ev_id)

        result_tree = nav.navigate()
        file_name = self.ask_output_file_name()
        vis = Visualization(result_tree)
        vis.view_exec_tree(file_name)
コード例 #6
0
# In[7]:

wrong_data = prov.ask_wrong_data()

# In[8]:

wrong_data

# In[9]:

prov.enhance(wrong_data)

# In[ ]:

len(exec_tree.dependencies)

# In[ ]:

vis = Visualization(prov.exec_tree)

# In[ ]:

vis.view_exec_tree('exec_tree_p3')

# In[ ]:

######################################################################################################################

# In[ ]:
コード例 #7
0
    creator = ExecTreeCreator(CURSOR)

    #################################
    # FIRST EXPERIMENT
    # COMPARING NAVIGATION STRATEGIES WITHOUT PROVENANCE
    navs = [SingleStepping, TopDown, HeaviestFirst, DivideAndQuery]
    if RUN_1ST_EXPERIMENT:
        for nav in navs:
            exec_tree = None
            exec_tree = creator.create_exec_tree()
            nav_instance = nav(exec_tree, True, ANSWER_FILE_PATH)
            nav_instance.navigate()
            print(nav_instance.__class__.__name__ + " experiment finished: " +
                  str(nav_instance.sequence_num) + " steps.")
            if GENERATE_TREES:
                vis = Visualization(exec_tree)
                vis.view_exec_tree(str(id(exec_tree)))

    #################################
    # SECOND EXPERIMENT
    # COMPARING NAVIGATION STRATEGIES WITH PROVENANCE PRUNE, BUT WITHOUT ASKING WHICH OUTPUT DATA IS WRONG
    navs = [SingleStepping, TopDown, HeaviestFirst, DivideAndQuery]
    if RUN_2ND_EXPERIMENT:
        for nav in navs:
            exec_tree = None
            exec_tree = creator.create_exec_tree()
            prov = ProvenanceEnhancement(exec_tree, CURSOR)
            prov.enhance_all()
            nav_instance = nav(exec_tree, True, ANSWER_FILE_PATH)
            nav_instance.provenance_prune()
            nav_instance.navigate()
コード例 #8
0
    def run(self):
        os.chdir(MUTANTS_WRONG_RESULT_DIR)
        for directory in os.listdir():
            if os.path.isfile("{}/{}".format(directory,ORACLE_FILENAME)):
                timestamp = datetime.now().strftime('%Y_%m_%d %H-%M-%S.%f')
                print(timestamp)
                print("Subject: "+directory)
                logging.info("Subject: "+directory)
                self.subjects.append(directory)
                self.timestamps.append(timestamp)
                self.cwds.append(os.getcwd())
                NOW2_SQLITE_PATH = "{}/{}".format(directory,SQLITE_DB_PATH)
                ANSWER_FILE_PATH = "{}/{}".format(directory,ORACLE_FILENAME)
                CURSOR = sqlite3.connect(NOW2_SQLITE_PATH).cursor()
                creator = ExecTreeCreator(CURSOR)

                #################################
                # FIRST EXPERIMENT
                # COMPARING NAVIGATION STRATEGIES WITHOUT PROVENANCE
                if self.run_1st_experiment:
                    original_exec_tree = creator.create_exec_tree() 
                    ##################
                    # Single Stepping
                    ##################
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        single_stepping = SingleStepping(exec_tree, True, ANSWER_FILE_PATH)          
                        single_stepping.navigate()
                        print("SingleStepping experiment finished: " +
                                str(single_stepping.sequence_num)+" steps.")
                        logging.info("SingleStepping experiment finished: " +
                                        str(single_stepping.sequence_num)+" steps.")
                        if self.generate_trees:
                                vis = Visualization(exec_tree)
                                vis.view_exec_tree(str(id(exec_tree)))
                        self.expected_buggy_node.append(max(single_stepping.invalid_nodes))
                        self.single_stepping["single_stepping_results"].append(single_stepping.sequence_num)
                        self.single_stepping["single_stepping_fallback"].append(single_stepping.fallback)
                        if single_stepping.exec_tree.buggy_node is not None:
                            self.single_stepping["single_stepping_buggy_node_returned"].append(single_stepping.exec_tree.buggy_node.ev_id)
                        else:
                            self.single_stepping["single_stepping_buggy_node_returned"].append(None)
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()
                    ############
                    # Top Down #
                    ############
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        top_down = TopDown(exec_tree, True, ANSWER_FILE_PATH)          
                        top_down.navigate()
                        print("TopDown experiment finished: " +
                                str(top_down.sequence_num)+" steps.")
                        logging.info("TopDown experiment finished: " +
                                        str(top_down.sequence_num)+" steps.")
                        if self.generate_trees:
                                vis = Visualization(exec_tree)
                                vis.view_exec_tree(str(id(exec_tree)))
                        self.top_down["top_down_results"].append(top_down.sequence_num)
                        self.top_down["top_down_fallback"].append(top_down.fallback)
                        if top_down.exec_tree.buggy_node is not None:
                            self.top_down["top_down_buggy_node_returned"].append(top_down.exec_tree.buggy_node.ev_id)
                        else:
                            self.single_stepping["top_down_buggy_node_returned"].append(None)
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()
                    
                    ###########
                    # Heaviest First
                    ###########
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        heaviest_first = HeaviestFirst(exec_tree, True, ANSWER_FILE_PATH)          
                        heaviest_first.navigate()
                        print("HeaviestFirst experiment finished: " +
                                str(heaviest_first.sequence_num)+" steps.")
                        logging.info("HeaviestFirst experiment finished: " +
                                        str(heaviest_first.sequence_num)+" steps.")
                        if self.generate_trees:
                                vis = Visualization(exec_tree)
                                vis.view_exec_tree(str(id(exec_tree)))
                        self.heaviest_first["heaviest_first_results"].append(heaviest_first.sequence_num)
                        self.heaviest_first["heaviest_first_fallback"].append(heaviest_first.fallback)
                        if heaviest_first.exec_tree.buggy_node is not None:
                            self.heaviest_first["heaviest_first_buggy_node_returned"].append(heaviest_first.exec_tree.buggy_node.ev_id)
                        else:
                            self.heaviest_first["heaviest_first_buggy_node_returned"].append(None)                 
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()

                    ###########
                    # Divide and Query
                    ###########
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        divide_and_query = DivideAndQuery(exec_tree, True, ANSWER_FILE_PATH)          
                        divide_and_query.navigate()
                        print("DivideAndQuery experiment finished: " +
                                str(divide_and_query.sequence_num)+" steps.")
                        logging.info("DivideAndQuery experiment finished: " +
                                        str(divide_and_query.sequence_num)+" steps.")
                        if self.generate_trees:
                                vis = Visualization(exec_tree)
                                vis.view_exec_tree(str(id(exec_tree)))
                        self.divide_and_query["divide_and_query_results"].append(divide_and_query.sequence_num)
                        self.divide_and_query["divide_and_query_fallback"].append(divide_and_query.fallback)
                        if divide_and_query.exec_tree.buggy_node is not None:
                            self.divide_and_query["divide_and_query_buggy_node_returned"].append(divide_and_query.exec_tree.buggy_node.ev_id)
                        else:
                            self.divide_and_query["divide_and_query_buggy_node_returned"].append(None)
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()



                #################################
                # SECOND EXPERIMENT
                # COMPARING NAVIGATION STRATEGIES WITH PROVENANCE PRUNE, BUT WITHOUT ASKING WHICH OUTPUT DATA IS WRONG
                #navs = [SingleStepping, TopDown, HeaviestFirst, DivideAndQuery]
                #if RUN_2ND_EXPERIMENT:
                #    for nav in navs:
                #        exec_tree = None
                #        exec_tree = creator.create_exec_tree()
                #        prov = ProvenanceEnhancement(exec_tree, CURSOR)
                #        prov.enhance_all()
                #        nav_instance = nav(exec_tree, True, ANSWER_FILE_PATH)
                #        nav_instance.provenance_prune()
                #        nav_instance.navigate()
                #        print(nav_instance.__class__.__name__+" experiment finished: " +
                #            str(nav_instance.sequence_num)+" steps.")
                #        if GENERATE_TREES:
                #            vis = Visualization(exec_tree)
                #            vis.view_exec_tree(str(id(exec_tree)))

                #################################
                # THIRD EXPERIMENT
                # COMPARING NAVIGATION STRATEGIES WITH PROVENANCE PRUNE, ASKING WHICH OUTPUT DATA IS WRONG
                if self.run_3rd_experiment:
                    original_exec_tree = creator.create_exec_tree() 
                    ##################
                    # Single Stepping
                    ##################
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        single_stepping = SingleStepping(exec_tree, True, ANSWER_FILE_PATH)
                        prov = ProvenanceEnhancement(exec_tree, CURSOR)
                        wrong_node_ev = single_stepping.wrong_node_id
                        prov.enhance(wrong_node_ev)
                        single_stepping.navigate()
                        print("SingleStepping PROV experiment finished: " +
                                str(single_stepping.sequence_num)+" steps.")
                        logging.info("SingleStepping experiment finished: " +
                                        str(single_stepping.sequence_num)+" steps.")

                        self.single_stepping["single_stepping_prov_results"].append(single_stepping.sequence_num)
                        self.single_stepping["single_stepping_prov_fallback"].append(single_stepping.fallback)
                        if single_stepping.exec_tree.buggy_node is not None:
                            self.single_stepping["single_stepping_prov_buggy_node_returned"].append(single_stepping.exec_tree.buggy_node.ev_id)
                        else:
                            self.single_stepping["single_stepping_prov_buggy_node_returned"].append(None)
                        if self.generate_trees:
                            vis = Visualization(exec_tree)
                            vis.view_exec_tree(str(id(exec_tree)))
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()


                    ##################
                    # Top Down
                    ##################
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        top_down = TopDown(exec_tree, True, ANSWER_FILE_PATH)
                        prov = ProvenanceEnhancement(exec_tree, CURSOR)
                        wrong_node_ev = top_down.wrong_node_id
                        prov.enhance(wrong_node_ev)
                        top_down.navigate()
                        print("TopDown PROV experiment finished: " +
                                str(top_down.sequence_num)+" steps.")
                        logging.info("TopDown experiment finished: " +
                                        str(top_down.sequence_num)+" steps.")
                        if self.generate_trees:
                            vis = Visualization(exec_tree)
                            vis.view_exec_tree(str(id(exec_tree)))
                        self.top_down["top_down_prov_results"].append(top_down.sequence_num)
                        self.top_down["top_down_prov_fallback"].append(top_down.fallback)
                        if top_down.exec_tree.buggy_node is not None:
                            self.top_down["top_down_prov_buggy_node_returned"].append(top_down.exec_tree.buggy_node.ev_id)
                        else:
                            self.top_down["top_down_prov_buggy_node_returned"].append(None)
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()

                    ##################
                    # Heaviest First
                    ##################
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        heaviest_first = HeaviestFirst(exec_tree, True, ANSWER_FILE_PATH)
                        prov = ProvenanceEnhancement(exec_tree, CURSOR)
                        wrong_node_ev = heaviest_first.wrong_node_id
                        prov.enhance(wrong_node_ev)
                        heaviest_first.navigate()
                        print("HeaviestFirst PROV experiment finished: " +
                                str(heaviest_first.sequence_num)+" steps.")
                        logging.info("HeaviestFirst experiment finished: " +
                                        str(heaviest_first.sequence_num)+" steps.")
                        self.heaviest_first["heaviest_first_prov_results"].append(heaviest_first.sequence_num)
                        self.heaviest_first["heaviest_first_prov_fallback"].append(heaviest_first.fallback)
                        if heaviest_first.exec_tree.buggy_node is not None:
                            self.heaviest_first["heaviest_first_prov_buggy_node_returned"].append(heaviest_first.exec_tree.buggy_node.ev_id)
                        else:
                            self.heaviest_first["heaviest_first_prov_buggy_node_returned"].append(None)
                        if self.generate_trees:
                            vis = Visualization(exec_tree)
                            vis.view_exec_tree(str(id(exec_tree)))
                    except Exception as e:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()

                    ##################
                    # Divide and Query
                    ##################
                    exec_tree = copy.deepcopy(original_exec_tree)
                    try:
                        divide_and_query = DivideAndQuery(exec_tree, True, ANSWER_FILE_PATH)
                        prov = ProvenanceEnhancement(exec_tree, CURSOR)
                        wrong_node_ev = divide_and_query.wrong_node_id
                        prov.enhance(wrong_node_ev)
                        divide_and_query.navigate()
                        print("DivideAndQuery PROV experiment finished: " +
                                str(divide_and_query.sequence_num)+" steps.")
                        logging.info("DivideAndQuery experiment finished: " +
                                        str(divide_and_query.sequence_num)+" steps.")
                        if self.generate_trees:
                            vis = Visualization(exec_tree)
                            vis.view_exec_tree(str(id(exec_tree)))
                        self.divide_and_query["divide_and_query_prov_results"].append(divide_and_query.sequence_num)
                        self.divide_and_query["divide_and_query_prov_fallback"].append(divide_and_query.fallback)
                        if divide_and_query.exec_tree.buggy_node is not None:
                            self.divide_and_query["divide_and_query_prov_buggy_node_returned"].append(divide_and_query.exec_tree.buggy_node.ev_id)
                        else:
                            self.divide_and_query["divide_and_query_prov_buggy_node_returned"].append(None)
                    except:
                        print("Exception: {}".format(e))
                        logging.info("Exception: {}".format(e))
                        sys.exit()
        os.chdir('..')