Skip to content

Commit edd802c

Browse files
committed
automated tracer
1 parent 266a520 commit edd802c

File tree

7 files changed

+117
-6
lines changed

7 files changed

+117
-6
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ automation/bin
1313
automation/include
1414
automation/lib
1515
automation/pyvenv.cfg
16-
automation/pip-selfcheck.json
16+
automation/pip-selfcheck.json
17+
utils/JUnitRunner/
18+
automation/javaslicer/

automation/automate.py

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
import sys
33
import shutil
44
import subprocess
5+
import collections
56

67
project_id = sys.argv[1]
78
defect_id = sys.argv[2]
9+
cwd=os.path.dirname(os.path.abspath(__file__))
810
java6_home = "/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
911
java8_home = "/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home"
1012
JAVA_HOME="JAVA_HOME"
@@ -20,6 +22,8 @@
2022
if os.environ.get("D4J_HOME") is None or os.environ.get("GZOLTAR_JAR") is None or os.environ.get("SLOC_HOME"):
2123
sys.exit('Error! Please set D4J_HOME, GZOLTAR_JAR and SLOC_HOME')
2224

25+
d4j_dir=os.environ.get("D4J_HOME")
26+
2327
if shutil.which("defects4j") is None:
2428
sys.exit("Please add defects4j to the PATH variable")
2529

@@ -68,15 +72,99 @@
6872

6973
os.environ[JAVA_HOME]=java6_home
7074
os.chdir(defect_dir)
75+
print("Running " + compile_command)
7176
os.system(compile_command)
77+
print("Running " + package_command)
7278
os.system(package_command)
7379

80+
target_dir = os.path.join(defect_dir,"target")
7481

75-
# os.chdir(os.path.join(defect_dir,"target"))
76-
82+
os.chdir(target_dir)
7783
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)))
80168

81169
#Project name
82170
#bug ID

automation/javaslicer

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b046ed3b70f5c4d304d642565908f9b78a27e157

automation/src/InvokeTests.class

-1.21 KB
Binary file not shown.

automation/src/InvokeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void main(String[] args) {
4040
}
4141
String command = args[1];
4242

43-
List<String> validCommands = new ArrayList<>();
43+
List<String> validCommands = new ArrayList<String>();
4444
validCommands.add("runTestCase");
4545
validCommands.add("runTestFile");
4646
validCommands.add("getTestCases");

utils/JUnitRunner/.classpath

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
@@ -22,5 +23,22 @@
2223
<attribute name="maven.pomderived" value="true"/>
2324
</attributes>
2425
</classpathentry>
26+
<classpathentry kind="src" path="target/generated-sources/annotations">
27+
<attributes>
28+
<attribute name="optional" value="true"/>
29+
<attribute name="maven.pomderived" value="true"/>
30+
<attribute name="ignore_optional_problems" value="true"/>
31+
<attribute name="m2e-apt" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35+
<attributes>
36+
<attribute name="optional" value="true"/>
37+
<attribute name="maven.pomderived" value="true"/>
38+
<attribute name="ignore_optional_problems" value="true"/>
39+
<attribute name="m2e-apt" value="true"/>
40+
<attribute name="test" value="true"/>
41+
</attributes>
42+
</classpathentry>
2543
<classpathentry kind="output" path="target/classes"/>
2644
</classpath>

utils/JUnitRunner/.settings/org.eclipse.jdt.core.prefs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
33
org.eclipse.jdt.core.compiler.compliance=1.7
44
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
6+
org.eclipse.jdt.core.compiler.release=disabled
57
org.eclipse.jdt.core.compiler.source=1.7

0 commit comments

Comments
 (0)