def generate_data(project_name, check_trace=True): if not project_name in settings.projects: return git_url, jira_url = settings.projects.get(project_name) if check_trace: out_path = os.path.join(settings.DATA_DIR, project_name) else: out_path = os.path.join(settings.NON_TRACE_DIR, project_name) if os.path.exists(out_path): return set_up(git_url, jira_url) extractor = JiraExtractor(repo_dir=repo.working_dir, jira_url=jira_url, branch_inspected=branch_inspected, issue_key=None, query=None, commit=None) commits = [] for candidate in extractor.extract_possible_bugs(check_trace=check_trace): hexsha = repo.commit(candidate.fix_commit).hexsha commits.append(hexsha) with open(out_path, "wb") as f: json.dump(commits, f) return commits
def execute(git_url, jira_url, specific_commit, check_trace=True): bug_data_set = [] extractor = JiraExtractor(repo_dir=repo.working_dir, jira_url=jira_url, branch_inspected=branch_inspected, commit=specific_commit) for candidate in extractor.extract_possible_bugs(check_trace=check_trace): try: bugs = extract_bugs(candidate, check_trace) bug_data_handler.add_bugs(bugs) except mvn_bug.BugError as e: logging.info('BUG ERROR ' + e.msg + '\n' + traceback.format_exc()) except TestObjects.TestParserException as e: logging.info('TEST PARSER ERROR ' + e.msg + '\n' + traceback.format_exc()) except git.exc.GitCommandError as e: logging.info('SHOULD NOT HAPPEN GIT ' + str(e) + '\n' + traceback.format_exc()) logging.info('Resetting repos') reset_repos(git_url, jira_url, specific_commit) except Exception as e: if 'IOError: [Errno 22]' in e.message: logging.info('SHOULD NOT HAPPEN EXCEPTION ' + str(e) + '\n' + traceback.format_exc()) logging.info('Resetting repos') reset_repos(git_url, jira_url, specific_commit) else: logging.info('SHOULD NOT HAPPEN EXCEPTION ' + str(e) + '\n' + traceback.format_exc())
def test_extract_bugs_delta_testcases_that_passed_in_parrent(self): print('test_extract_bugs_pick_up_failures') Main.set_up(['', 'https://github.com/rotba/MavenProj']) issue = jira.issue('TIKA-19') possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') proj_name = 'MavenProj' exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [ 'sub_mod_1', 'src', 'test', 'java', 'p_1', 'AmitTest.java#AmitTest#None_deltaPassedTest()' ], settings.ProjFiles(proj_name).repo) commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == 'd03e45c84ad903435fae8f1814a56569906663eb' ][0] module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1' Main.repo.git.reset('--hard') Main.repo.git.checkout(commit.hexsha) tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) res = Main.extract_bugs( issue, commit, tests_paths, possible_bugs_extractor.get_changed_components(commit)) for bug in res: if not bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.DELTA \ and bug.desctiption == Main.mvn_bug.invalid_passed_desc: return self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
def extract_bugs_auto_generated_test_basic_project(self): def is_bp_test_cases(test_case): return test_case.valid and test_case.type == Main.mvn_bug.Bug_type.GEN Main.branch_inspected = 'origin/test_extract_bugs_5' Main.set_up(['', 'https://github.com/rotba/MavenProj']) Main.USE_CACHED_STATE = False issue = jira.issue('TIKA-19') possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == '23270ce01dbf36cd0cf2ccc9438dce641822abb8' ][0] module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1' Main.repo.git.reset('--hard') Main.repo.git.checkout(commit.hexsha, '-f') tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) Main.GENERATE_TESTS = True Main.TESTS_GEN_SEED = 3333333 res = Main.extract_bugs( issue, commit, tests_paths, possible_bugs_extractor.get_changed_components(commit)) num_of_success_bugs = reduce( lambda acc, curr: acc + int(is_bp_test_cases(curr)), res, 0) Main.repo.git.add('--all') Main.repo.git.checkout('HEAD', '-f') print(colored("The number of BP-test-cases generated is:", 'blue')) print(colored(num_of_success_bugs, 'blue'))
def test_extract_bugs_pick_up_failures(self): print('test_extract_bugs_pick_up_failures') Main.set_up(['', 'https://github.com/rotba/MavenProj']) issue = jira.issue('TIKA-19') possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') proj_name = 'MavenProj' exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [ 'sub_mod_1', 'src', 'test', 'java', 'p_1', 'AmitTest.java#AmitTest#None_RTerrorTest()' ], settings.ProjFiles(proj_name).repo) commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == '1d3c81c1f7a4722408264cc5279df7abb22a3c04' ][0] module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1' Main.repo.git.reset('--hard') Main.repo.git.checkout(commit.hexsha) tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) res = Main.extract_bugs( issue, commit, tests_paths, possible_bugs_extractor.get_changed_components(commit)) for bug in res: if not bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.REGRESSION \ and bug.desctiption.startswith(Main.mvn_bug.invalid_rt_error_desc): return self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
def test_extract_bugs_2(self): Main.set_up(['', 'https://github.com/rotba/MavenProj']) possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') issue = jira.issue('TIKA-19') proj_name = 'MavenProj' exp_testcase_id = reduce(lambda acc, curr: os.path.join(acc, curr), [ 'sub_mod_1', 'src', 'test', 'java', 'p_1', 'AmitTest.java#AmitTest#None_fooTest()' ], settings.ProjFiles(proj_name).repo) commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == '19f6c78889f9e929bc964d420315a043b62c7967' ][0] module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1' Main.repo.git.reset('--hard') Main.repo.git.checkout(commit.hexsha) tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) res = Main.extract_bugs( issue, commit, tests_paths, possible_bugs_extractor.get_changed_components(commit)) for bug in res: if bug.valid and bug.bugged_testcase.id == exp_testcase_id and bug.type == Main.mvn_bug.Bug_type.DELTA: return self.fail('Did not extracted the bug of testcase -' + exp_testcase_id)
def test_extract_bugs_auto_generated_test_basic_project(self): Main.branch_inspected = 'origin/test_extract_bugs_5' Main.set_up(['', 'https://github.com/rotba/MavenProj']) Main.USE_CACHED_STATE = False issue = jira.issue('TIKA-19') possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') exp_testcase_id = [ os.getcwd() + r'\tested_project\MavenProj\sub_mod_1\.evosuite\best-tests_ignore_ignore\p_1\Amit_ESTest.java#Amit_ESTest#None_test4()', os.getcwd() + r'\tested_project\MavenProj\sub_mod_1\.evosuite\best-tests_ignore_ignore\p_1\Amit_ESTest.java#Amit_ESTest#None_test04()', os.getcwd() + r'\tested_project\MavenProj\sub_mod_1\.evosuite\best-tests_ignore_ignore\p_1\Amit_ESTest.java#Amit_ESTest#None_test01()', os.getcwd() + r'\tested_project\MavenProj\sub_mod_1\.evosuite\best-tests_ignore_ignore\p_1\Amit_ESTest.java#Amit_ESTest#None_test00()', os.getcwd() + r'\tested_project\MavenProj\sub_mod_1\.evosuite\best-tests_ignore_ignore\p_1\Amit_ESTest.java#Amit_ESTest#None_test0()' ] commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == '23270ce01dbf36cd0cf2ccc9438dce641822abb8' ][0] module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1' Main.repo.git.reset('--hard') Main.repo.git.checkout(commit.hexsha, '-f') tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) Main.GENERATE_TESTS = True res = Main.extract_bugs( issue, commit, tests_paths, possible_bugs_extractor.get_changed_components(commit)) success = False num_of_success_bugs = 0 for bug in res: if bug.valid and bug.type == Main.mvn_bug.Bug_type.GEN: num_of_success_bugs += 1 Main.repo.git.add('--all') Main.repo.git.checkout('HEAD', '-f') if not 0 < num_of_success_bugs <= 3: self.fail('Did not extracted the bug of testcase -' + str(exp_testcase_id))
def test_issue_and_commit(self): if os.path.exists(os.path.join(os.getcwd(), 'results')): time.sleep(5) shutil.rmtree(os.path.join(os.getcwd(), 'results'), ignore_errors=True) Main.USE_CACHE = False Main.GENERATE_DATA = True Main.GENERATE_TESTS = True Main.USE_CACHED_STATE = False Main.TESTS_GEN_STRATEGY = Main.TestGenerationStrategy.CMD github = 'https://github.com/apache/commons-math' issue_tracker = 'http:\issues.apache.org\jira\projects\MATH' Main.set_up(['', github]) i = 0 for issue_key, commit_h in zip(['MATH-255', 'MATH-258'], [ '22d13e12320f2d878880eba50a5bcdc48aa63cc3', '9f0ea4e9c43295713c1fc422a1b40b15e902d665' ]): extractor = JiraExtractor(repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url=issue_tracker, issue_key=issue_key) Main.mvn_repo.clean() # try: # if i ==0: # Main.reset_repos(['', github]) # i+=1 # continue # Main.repo.git.add('.') # except git.exc.GitCommandError as e: # Main.reset_repos(['', github]) # continue Main.repo.git.checkout(commit_h, '-f') k = extractor.extract_possible_bugs() bug = filter(lambda x: commit_h in x.fix_commit, extractor.extract_possible_bugs())[0] bug_commit = Main.repo.commit(bug.fix_commit) Main.USE_CACHED_STATE = not Main.USE_CACHED_STATE bugs = Main.extract_bugs(bug.issue, bug_commit, bug.tests, bug.diffed_components) x = 1
def test_check_out_and_get_tests_from_commit(self): Main.set_up(['', 'https://github.com/rotba/MavenProj']) possible_bugs_extractor = JiraExtractor( repo_dir=Main.repo.working_dir, branch_inspected=Main.branch_inspected, jira_url='') commit = [ c for c in list(Main.repo.iter_commits(Main.branch_inspected)) if c.hexsha == '52e80f56a2f2877ff2261889b1dc180c51b72f6b' ][0] tests_paths = possible_bugs_extractor.get_tests_paths_from_commit( commit) tests = list( map(lambda t_path: Main.TestObjects.TestClass(t_path), tests_paths)) self.assertEqual( len(tests), 1, 'Only one test should be associated with 52e80f56a2f2877ff2261889b1dc180c51b72f6b' ) self.assertTrue( 'NaimTest' in tests[0].mvn_name, '\'NaimTest\' should be associated with 52e80f56a2f2877ff2261889b1dc180c51b72f6b' )