Skip to content

Commit 93e9624

Browse files
committed
Code completed, but there is some straneg behavior with wiretap which I am analysing with Christian
1 parent 545a7c6 commit 93e9624

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

bytecode-analyser/bytecode-analyzer.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
FILE_EXTENSIONS = ['.class']
3434

3535

36-
# TODO: Add logging to system calls
37-
3836
def run_main(root_path, file_path):
3937
# Example: 'java -cp .:lava-master/build/: com.golaszewski.lava.evaluate.REPL'
4038
cmd_main = 'java -cp .:%s: %s'
@@ -57,9 +55,12 @@ def run_main(root_path, file_path):
5755

5856

5957
# Finds reachable methods from main
60-
def reachable_methods_from_main(root_path, file_path, jar_paths):
58+
# TODO check with christian the strange behavior of wiretap
59+
def reachable_methods_from_main(root_path, file_path, jar_paths, pid):
60+
temp_folder = pid + '-wiretap'
61+
6162
# Example: 'java -cp .:lava-master/build/: -javaagent:wiretap.jar -Dwiretap.recorder=ReachableMethods com.golaszewski.lava.evaluate.REPL'
62-
cmd_wiretap = 'java -cp .:%s:%s: -javaagent:wiretap.jar -Dwiretap.recorder=ReachableMethods %s'
63+
cmd_wiretap = 'java -cp .:%s:%s: -javaagent:wiretap.jar -Dwiretap.outfolder=\"' + temp_folder + '\" -Dwiretap.recorder=ReachableMethods %s'
6364

6465
cmd_path = root_path[:root_path.find('/build/') + 7]
6566
class_path = os.path.join(root_path, file_path)
@@ -75,9 +76,13 @@ def reachable_methods_from_main(root_path, file_path, jar_paths):
7576
o = ex.output
7677
output = o.decode('utf-8')
7778

78-
# TODO look at wiretap output for number of reached methods, and return the value
79-
print(output)
80-
return 0
79+
print(cmd+'\n'+output)
80+
81+
total_reachable_methods = 0
82+
with open(os.path.join(temp_folder, 'reachable.txt'), 'r') as reachable:
83+
total_reachable_methods = len(reachable.readlines())
84+
shutil.rmtree(temp_folder)
85+
return total_reachable_methods
8186

8287

8388
# Returns True if all tests passed, False otherwise
@@ -147,7 +152,7 @@ def process(list_projs):
147152
proj_counter = 0
148153

149154
with open(OUTPUT_FILE % pid, 'w') as output_file:
150-
output_file.write('proj_name,n_class_files,reachable_mains,with_junit,passed_junit\n')
155+
output_file.write('proj_name,n_class_files,reachable_mains,reachable_methods,with_junit,passed_junit\n')
151156

152157
for full_proj_folder in list_projs:
153158
# print(full_proj_folder)
@@ -162,7 +167,7 @@ def process(list_projs):
162167

163168
# These counts are class files/per project
164169
reachable_mains = 0
165-
reachable_methds = 0 # Per class file with main() found
170+
reachable_methods = 0 # Per class file with main() found
166171
with_junit = 0
167172
passed_junit = 0
168173
n_class_files = 0
@@ -182,9 +187,9 @@ def process(list_projs):
182187
if main_methods:
183188
# print('Has main:', full_filename)
184189
reachable_mains += 1
185-
res = reachable_methods_from_main(root, filename, jar_paths)
190+
res = reachable_methods_from_main(root, filename, jar_paths, str(pid))
186191
# res = run_main(root, filename)
187-
reachable_methds += res
192+
reachable_methods += res
188193

189194
# Search for junit and run the respective class files
190195
try:
@@ -193,7 +198,7 @@ def process(list_projs):
193198
# print('Has junit:', full_filename)
194199

195200
with_junit += 1
196-
res = all_junit_tests(root, filename, jar_paths)
201+
# res = all_junit_tests(root, filename, jar_paths)
197202

198203
if res:
199204
# print('All tests OK!')
@@ -204,7 +209,7 @@ def process(list_projs):
204209
shutil.rmtree(str(pid))
205210

206211
result = full_proj_folder + ',' + str(n_class_files) + ',' + str(reachable_mains) + ',' + str(
207-
with_junit) + ',' + str(passed_junit)
212+
reachable_methods) + ',' + str(with_junit) + ',' + str(passed_junit)
208213

209214
if (proj_counter % 10) == 0:
210215
print('-----------------------------------------')

0 commit comments

Comments
 (0)