|
2 | 2 | import sys
|
3 | 3 | import shutil
|
4 | 4 | import subprocess
|
| 5 | +import collections |
5 | 6 |
|
6 | 7 | project_id = sys.argv[1]
|
7 | 8 | defect_id = sys.argv[2]
|
| 9 | +cwd=os.path.dirname(os.path.abspath(__file__)) |
8 | 10 | java6_home = "/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
|
9 | 11 | java8_home = "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home"
|
10 | 12 | JAVA_HOME="JAVA_HOME"
|
|
20 | 22 | if os.environ.get("D4J_HOME") is None or os.environ.get("GZOLTAR_JAR") is None or os.environ.get("SLOC_HOME"):
|
21 | 23 | sys.exit('Error! Please set D4J_HOME, GZOLTAR_JAR and SLOC_HOME')
|
22 | 24 |
|
| 25 | +d4j_dir=os.environ.get("D4J_HOME") |
| 26 | + |
23 | 27 | if shutil.which("defects4j") is None:
|
24 | 28 | sys.exit("Please add defects4j to the PATH variable")
|
25 | 29 |
|
|
68 | 72 |
|
69 | 73 | os.environ[JAVA_HOME]=java6_home
|
70 | 74 | os.chdir(defect_dir)
|
| 75 | +print("Running " + compile_command) |
71 | 76 | os.system(compile_command)
|
| 77 | +print("Running " + package_command) |
72 | 78 | os.system(package_command)
|
73 | 79 |
|
| 80 | +target_dir = os.path.join(defect_dir,"target") |
74 | 81 |
|
75 |
| -# os.chdir(os.path.join(defect_dir,"target")) |
76 |
| - |
| 82 | +os.chdir(target_dir) |
77 | 83 | junit_get_command = "wget https://github.com/downloads/junit-team/junit/junit-4.10.jar"
|
78 |
| - |
79 |
| -# os.system(junit_get_command) |
| 84 | +print("Running " + junit_get_command) |
| 85 | +os.system(junit_get_command) |
| 86 | + |
| 87 | +# os.environ[JAVA_HOME]=java8_home |
| 88 | + |
| 89 | +junit_path = os.path.join(target_dir,"junit-4.10.jar") |
| 90 | +class_path=[".",target_dir,os.path.join(target_dir,"test-classes"),os.path.join(target_dir,"commons-lang-3.0-SNAPSHOT.jar"),junit_path] |
| 91 | + |
| 92 | + |
| 93 | +os.chdir(os.path.join(cwd,"src")) |
| 94 | +compile_invoke_command = "javac -cp "+ ":".join(class_path) + " InvokeTests.java" |
| 95 | +print("Running " + compile_invoke_command) |
| 96 | +os.system(compile_invoke_command) |
| 97 | + |
| 98 | + |
| 99 | +relevant_tests_list=None |
| 100 | +relevant_test_file=os.path.join(d4j_dir,"framework","projects",project_id,"relevant_tests",defect_id) |
| 101 | +with open(relevant_test_file) as f: |
| 102 | + relevant_tests_list=f.read().splitlines() |
| 103 | + |
| 104 | +test_class_method_map = collections.OrderedDict() |
| 105 | + |
| 106 | +for testclass in relevant_tests_list: |
| 107 | + list_test_command="java -cp "+ ":".join(class_path) + " InvokeTests "+project_dir + " getTestCases " + testclass |
| 108 | + print("Running " + list_test_command) |
| 109 | + tests_list = subprocess.run(list_test_command,stdout=subprocess.PIPE,shell=True) |
| 110 | + tests_list = tests_list.stdout.decode("utf-8") |
| 111 | + tests_list = tests_list.splitlines() |
| 112 | + test_class_method_map[testclass] = tests_list |
| 113 | + |
| 114 | + |
| 115 | +os.environ[JAVA_HOME]=java8_home |
| 116 | +os.chdir(cwd) |
| 117 | +if not os.path.exists("./javaslicer"): |
| 118 | + os.system("git clone https://github.com/hammacher/javaslicer") |
| 119 | + os.chdir("./javaslicer") |
| 120 | + os.system("bash assemble.sh") |
| 121 | + |
| 122 | +tracer_dir = os.path.join(cwd,"javaslicer","assembly") |
| 123 | + |
| 124 | +#os.system("cp "+os.path.join(cwd,"javaslicer","assembly","*.jar")+" "+target_dir ) |
| 125 | + |
| 126 | +os.chdir(os.path.join(cwd,"src")) |
| 127 | +os.makedirs(os.path.join(target_dir,"traces")) |
| 128 | +count=0 |
| 129 | +for testclass in test_class_method_map: |
| 130 | + for testname in test_class_method_map[testclass]: |
| 131 | + tracer_command="java -cp "+ ":".join(class_path) + " -javaagent:"+ \ |
| 132 | + os.path.join(tracer_dir,"tracer.jar")+"=tracefile:"+ \ |
| 133 | + os.path.join(target_dir,"traces","trace."+testclass+"#"+testname)+ \ |
| 134 | + " InvokeTests "+project_dir+" runTestCase " + testclass + " " + testname |
| 135 | + print("Running "+tracer_command) |
| 136 | + os.system(tracer_command) |
| 137 | + |
| 138 | + traceReader_command="java -jar "+os.path.join(tracer_dir,"traceReader.jar")+" "+ \ |
| 139 | + os.path.join(target_dir,"traces","trace."+testclass+"#"+testname) + " > " \ |
| 140 | + + os.path.join(target_dir,"traces","trace."+testclass+"#"+testname+".output") |
| 141 | + print("Running "+traceReader_command) |
| 142 | + os.system(traceReader_command) |
| 143 | + |
| 144 | + count+=1 |
| 145 | + if count==3: |
| 146 | + break |
| 147 | + break |
| 148 | + |
| 149 | +gzoltars_dir=os.path.join(root_directory,"gzoltars",project_id,defect_id) |
| 150 | + |
| 151 | +relevant_class="" |
| 152 | + |
| 153 | +with open(os.path.join(gzoltars_dir,"spectra")) as f: |
| 154 | + relevant_class=f.read().splitlines()[0].split("#")[0] |
| 155 | + |
| 156 | +grep_relevant_command="grep -rl "+relevant_class+" "+os.path.join(target_dir,"traces") |
| 157 | +print("Running "+grep_relevant_command) |
| 158 | +grep_tests_list = subprocess.run(grep_relevant_command,stdout=subprocess.PIPE,shell=True) |
| 159 | +grep_tests_list = grep_tests_list.stdout.decode("utf-8") |
| 160 | +grep_tests_list = grep_tests_list.splitlines() |
| 161 | + |
| 162 | +print(grep_tests_list) |
| 163 | +for i in range(len(grep_tests_list)): |
| 164 | + grep_tests_list[i] = grep_tests_list[i].split("#") |
| 165 | + grep_tests_list[i][1]=grep_tests_list[i][1][:-7] |
| 166 | + |
| 167 | +print("Count of grep result: "+str(len(grep_tests_list))) |
80 | 168 |
|
81 | 169 | #Project name
|
82 | 170 | #bug ID
|
|
0 commit comments