def mixed_passes(go, prev_hash, post_hash, refined_expansion_set, refined_target_set, old_refined_target_set, new_refined_target_set, old_cp, new_cp, old_junit_torun, new_junit_torun): if config.class_level_expansion: impact_set = refined_target_set | refined_expansion_set else: impact_set = refined_target_set # checkout old commit, then checkout new tests os.sys_call("git checkout " + prev_hash) new_test_path = mvn.path_from_mvn_call("testSourceDirectory") os.sys_call(" ".join(["git", "checkout", post_hash, new_test_path])) # # may need to check whether it is compilable, return code? # os.sys_call("mvn clean test-compile") one_inv_pass(go, new_cp, new_junit_torun, prev_hash + "_" + post_hash, impact_set, analysis_only=True) git.clear_temp_checkout(prev_hash) # checkout old commit, then checkout new src os.sys_call("git checkout " + prev_hash) new_src_path = mvn.path_from_mvn_call("sourceDirectory") os.sys_call(" ".join(["git", "checkout", post_hash, new_src_path])) # # may need to check whether it is compilable, return code? # os.sys_call("mvn clean test-compile") one_inv_pass(go, new_cp, old_junit_torun, post_hash + "_" + prev_hash, impact_set, analysis_only=True) git.clear_temp_checkout(prev_hash)
def checkout_build(proj_dir, commit_hash): os.sys_call("git checkout " + commit_hash) os.sys_call("mvn clean") bin_path = mvn.path_from_mvn_call("outputDirectory") src_rel_path = mvn.path_from_mvn_call("sourceDirectory") if src_rel_path.startswith(proj_dir): src_rel_path = src_rel_path[len(proj_dir):] else: raise ValueError("proj_dir is not a prefix of src path") print "current src path (relative): " + src_rel_path + "\n" test_src_rel_path = mvn.path_from_mvn_call("testSourceDirectory") if test_src_rel_path.startswith(proj_dir): test_src_rel_path = test_src_rel_path[len(proj_dir):] else: raise ValueError("proj_dir is not a prefix of test src path") print "current test src path (relative): " + test_src_rel_path + "\n" os.sys_call("mvn test-compile") return bin_path, src_rel_path, test_src_rel_path
def mixed_passes(go, refined_target_set, prev_hash, post_hash, old_cp, new_cp, old_junit_torun, new_junit_torun): # checkout old commit, then checkout new tests os.sys_call("git checkout " + prev_hash) new_test_path = mvn.path_from_mvn_call("testSourceDirectory") os.sys_call(" ".join(["git", "checkout", post_hash, new_test_path])) # # may need to check whether it is compilable, return code? # os.sys_call("mvn clean test-compile") one_inv_pass(go, new_cp, new_junit_torun, prev_hash + "_" + post_hash, refined_target_set, analysis_only=True) git.clear_temp_checkout(prev_hash) # checkout old commit, then checkout new src os.sys_call("git checkout " + prev_hash) new_src_path = mvn.path_from_mvn_call("sourceDirectory") os.sys_call(" ".join(["git", "checkout", post_hash, new_src_path])) # # may need to check whether it is compilable, return code? # os.sys_call("mvn clean test-compile") one_inv_pass(go, new_cp, old_junit_torun, post_hash + "_" + prev_hash, refined_target_set, analysis_only=True) git.clear_temp_checkout(prev_hash)
def one_info_pass( junit_path, sys_classpath, agent_path, cust_mvn_repo, dyng_go, go, this_hash, target_set, changed_methods, changed_tests, inner_dataflow_methods, outer_dataflow_methods, ): os.sys_call("git checkout " + this_hash) os.sys_call("mvn clean") bin_path = mvn.path_from_mvn_call("outputDirectory") test_bin_path = mvn.path_from_mvn_call("testOutputDirectory") cp = mvn.full_classpath(junit_path, sys_classpath, bin_path, test_bin_path) if SHOW_DEBUG_INFO: print "\n===full classpath===\n" + cp + "\n" print "\ncopying all code to specific directory ...\n" all_code_dirs = [ mvn.path_from_mvn_call("sourceDirectory"), # mvn.path_from_mvn_call("scriptSourceDirectory"), mvn.path_from_mvn_call("testSourceDirectory"), ] getty_code_store = go + "_getty_allcode_" + this_hash + "_/" print "copy to " + getty_code_store + "\n" makedirs(getty_code_store) for adir in all_code_dirs: os.sys_call(" ".join(["cp -r", adir + "/*", getty_code_store]), ignore_bad_exit=True) if config.use_special_junit_for_dyn: info_junit_path = os.rreplace(junit_path, config.default_junit_version, config.special_junit_version, 1) infocp = mvn.full_classpath(info_junit_path, sys_classpath, bin_path, test_bin_path) else: infocp = cp java_cmd = " ".join( [ "java", "-cp", infocp, # "-Xms"+config.min_heap, "-Xmx" + config.max_heap, "-XX:+UseConcMarkSweepGC", # "-XX:-UseGCOverheadLimit", "-XX:-UseSplitVerifier", # FIXME: JDK 8- only! ] ) # os.sys_call("mvn test -DskipTests", ignore_bad_exit=True) os.sys_call("mvn test-compile") junit_torun = mvn.junit_torun_str(cust_mvn_repo) if SHOW_DEBUG_INFO: print "\n===junit torun===\n" + junit_torun + "\n" #### dynamic run one round for all information prefixes = daikon.common_prefixes(target_set) common_package = "" if len(prefixes) == 1: last_period_index = prefixes[0].rindex(".") if last_period_index > 0: # the common package should be at least one period away from the rest common_package = prefixes[0][:last_period_index] prefix_regexes = [] for p in prefixes: prefix_regexes.append(p + "*") instrument_regex = "|".join(prefix_regexes) if SHOW_DEBUG_INFO: print "\n===instrumentation pattern===\n" + instrument_regex + "\n" # run tests with instrumentation run_instrumented_tests = " ".join( [java_cmd, "-javaagent:" + agent_path + '="' + instrument_regex + '"', junit_torun] ) if SHOW_DEBUG_INFO: print "\n=== Instrumented testing command to run: \n" + run_instrumented_tests if not path.exists(dyng_go): makedirs(dyng_go) os.sys_call(run_instrumented_tests, ignore_bad_exit=True) os.merge_dyn_files(dyng_go, go, "_getty_dyncg_-hash-_.ex", this_hash) os.merge_dyn_files(dyng_go, go, "_getty_dynfg_-hash-_.ex", this_hash) caller_of, callee_of = agency.caller_callee(go, this_hash) pred_of, succ_of = agency.pred_succ(go, this_hash) # add test methods into target set test_set = agency.get_test_set_dyn(target_set, callee_of, junit_torun) # set target set here refined_target_set = agency.refine_targets( target_set, test_set, caller_of, callee_of, pred_of, succ_of, changed_methods, changed_tests, inner_dataflow_methods, outer_dataflow_methods, ) profiler.log_csv( ["method_count", "test_count", "refined_target_count"], [[len(target_set), len(test_set), len(refined_target_set)]], go + "_getty_y_method_count_" + this_hash + "_.profile.readable", ) git.clear_temp_checkout(this_hash) return common_package, test_set, refined_target_set, cp, junit_torun
def one_info_pass( junit_path, sys_classpath, agent_path, cust_mvn_repo, dyng_go, go, this_hash, target_set, changed_methods, changed_tests, inner_dataflow_methods, outer_dataflow_methods): os.sys_call("git checkout " + this_hash) os.sys_call("mvn clean") bin_path = mvn.path_from_mvn_call("outputDirectory") test_bin_path = mvn.path_from_mvn_call("testOutputDirectory") cp = mvn.full_classpath(junit_path, sys_classpath, bin_path, test_bin_path) if SHOW_DEBUG_INFO: print "\n===full classpath===\n" + cp + "\n" print "\ncopying all code to specific directory ...\n" all_code_dirs = [mvn.path_from_mvn_call("sourceDirectory"), # mvn.path_from_mvn_call("scriptSourceDirectory"), mvn.path_from_mvn_call("testSourceDirectory")] getty_code_store = go + '_getty_allcode_' + this_hash + '_/' print 'copy to ' + getty_code_store + '\n' makedirs(getty_code_store) for adir in all_code_dirs: os.sys_call(" ".join(["cp -r", adir + "/*", getty_code_store]), ignore_bad_exit=True) if config.use_special_junit_for_dyn: info_junit_path = os.rreplace(junit_path, config.default_junit_version, config.special_junit_version, 1) infocp = mvn.full_classpath(info_junit_path, sys_classpath, bin_path, test_bin_path) else: infocp = cp java_cmd = " ".join(["java", "-cp", infocp, # "-Xms"+config.min_heap, "-Xmx"+config.max_heap, "-XX:+UseConcMarkSweepGC", # "-XX:-UseGCOverheadLimit", "-XX:-UseSplitVerifier", # FIXME: JDK 8- only! ]) # os.sys_call("mvn test -DskipTests", ignore_bad_exit=True) os.sys_call("mvn test-compile") junit_torun = mvn.junit_torun_str(cust_mvn_repo) if SHOW_DEBUG_INFO: print "\n===junit torun===\n" + junit_torun + "\n" #### dynamic run one round for all information prefixes = daikon.common_prefixes(target_set) common_package = '' if len(prefixes) == 1: last_period_index = prefixes[0].rindex('.') if last_period_index > 0: # the common package should be at least one period away from the rest common_package = prefixes[0][:last_period_index] prefix_regexes = [] for p in prefixes: prefix_regexes.append(p + "*") instrument_regex = "|".join(prefix_regexes) if SHOW_DEBUG_INFO: print "\n===instrumentation pattern===\n" + instrument_regex + "\n" # run tests with instrumentation run_instrumented_tests = \ " ".join([java_cmd, "-ea", "-javaagent:" + agent_path + "=\"" + instrument_regex + "\"", junit_torun]) if SHOW_DEBUG_INFO: print "\n=== Instrumented testing command to run: \n" + run_instrumented_tests if not path.exists(dyng_go): makedirs(dyng_go) full_info_exfile = go + "_getty_binary_info_" + this_hash + "_.ex" os.sys_call(run_instrumented_tests + " > " + full_info_exfile + ("" if config.show_stack_trace_info else " 2> /dev/null"), ignore_bad_exit=True) full_method_info_map = {} ext_start_index = len(config.method_info_line_prefix) with open(full_info_exfile, 'r') as f: contents = f.read().split("\n") for line in contents: line = line.strip() if line.startswith(config.method_info_line_prefix): rawdata = line[ext_start_index:] k, v = rawdata.split(" : ") full_method_info_map[k.strip()] = v.strip() os.merge_dyn_files(dyng_go, go, "_getty_dyncg_-hash-_.ex", this_hash) os.merge_dyn_files(dyng_go, go, "_getty_dynfg_-hash-_.ex", this_hash) caller_of, callee_of = agency.caller_callee(go, this_hash) pred_of, succ_of = agency.pred_succ(go, this_hash) # add test methods into target set test_set = agency.get_test_set_dyn(target_set, callee_of, junit_torun) # reset target set here refined_target_set, changed_methods, changed_tests = \ agency.refine_targets(full_method_info_map, target_set, test_set, caller_of, callee_of, pred_of, succ_of, changed_methods, changed_tests, inner_dataflow_methods, outer_dataflow_methods) profiler.log_csv(["method_count", "test_count", "refined_target_count"], [[len(target_set), len(test_set), len(refined_target_set)]], go + "_getty_y_method_count_" + this_hash + "_.profile.readable") git.clear_temp_checkout(this_hash) return common_package, test_set, refined_target_set, changed_methods, changed_tests, \ cp, junit_torun, full_method_info_map