Skip to content

Commit e1dfec4

Browse files
authored
Merge pull request diffblue#151 from diffblue/bugfix/evalautor
Bugfixes in the Evalautor of our benchmarks
2 parents 7d96d8b + 541581f commit e1dfec4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

benchmarks/evaluator.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
import os
44
import json
5-
import urllib
65
import zipfile
76
import shutil
87
import fnmatch
@@ -11,6 +10,15 @@
1110
def __get_my_dir(): return os.path.dirname(os.path.realpath(__file__))
1211

1312

13+
def _download_file(url, dst_pathname):
14+
if (sys.version_info > (3, 0)):
15+
import urllib.request
16+
urllib.request.urlretrieve(url, dst_pathname)
17+
else:
18+
import urllib
19+
urllib.URLopener().retrieve(url, dst_pathname)
20+
21+
1422
def __benchmark_installer_libraries():
1523
try:
1624
libraries_root_dir = os.path.join(__get_my_dir(), "LIBRARIES")
@@ -23,8 +31,8 @@ def __benchmark_installer_libraries():
2331
if not os.path.exists(tomcat_dir):
2432
os.makedirs(temp_dir)
2533
downloaded_zip_pathname = os.path.join(temp_dir, "__tomcat9__.zip")
26-
urllib.URLopener().retrieve(
27-
"http://mirror.vorboss.net/apache/tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.zip",
34+
_download_file(
35+
"http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M21/bin/apache-tomcat-9.0.0.M21.zip",
2836
downloaded_zip_pathname
2937
)
3038
with zipfile.ZipFile(downloaded_zip_pathname, 'r') as zip_file:
@@ -49,10 +57,10 @@ def search_for_rt_jar(start_dir):
4957
if not java_rt_file:
5058
os.makedirs(temp_dir)
5159
downloaded_deb_pathname = os.path.join(temp_dir, "__openjdk8__.deb")
52-
urllib.URLopener().retrieve(
60+
_download_file(
5361
"http://ftp.uk.debian.org/debian/pool/main/o/openjdk-8/openjdk-8-jre-headless_8u121-b13-1~bpo8+1_amd64.deb",
5462
downloaded_deb_pathname
55-
)
63+
)
5664
old_cwd = os.getcwd()
5765
os.chdir(temp_dir)
5866
os.system("ar -x " + downloaded_deb_pathname)
@@ -70,7 +78,7 @@ def search_for_rt_jar(start_dir):
7078
shutil.rmtree(temp_dir)
7179
return None # no error
7280
except:
73-
print "In '__benchmark_installer_libraries()': Unexpected error:", sys.exc_info()[0]
81+
print("In '__benchmark_installer_libraries()': Unexpected error:", sys.exc_info()[0])
7482

7583

7684
def __benchmark_installer_TRAINING_diffblue(record):
@@ -123,7 +131,7 @@ def __evaluate_benchmark(record):
123131
return "Cannot find the installer function '" + record["installer"] + "'."
124132
error_message = eval(record["installer"])(record)
125133
if error_message:
126-
return error_messages # failed!
134+
return error_message # failed!
127135

128136
# Now we can run the security-scanner on the installed benchmark
129137
command = (
@@ -142,7 +150,7 @@ def __evaluate_benchmark(record):
142150
os.path.join(__get_my_dir(), record["results-dir"], "search_for_error_traces", "error_traces.json")
143151
if not os.path.exists(error_traces_pathname):
144152
return "The results file '" + error_traces_pathname + "' does not exist."
145-
with open(error_traces_pathname,"rb") as ifile:
153+
with open(error_traces_pathname,"r") as ifile:
146154
error_traces = json.load(ifile)
147155
return __compare_computed_and_expected_results(error_traces,record)
148156

@@ -188,7 +196,7 @@ def __main():
188196
return 1 # failure (for Travis)
189197

190198
for benchmark_pathname in sorted(benchmarks):
191-
with open(benchmark_pathname, "rb") as ifile:
199+
with open(benchmark_pathname, "r") as ifile:
192200
benchmark = json.load(ifile)
193201

194202
error_message = __benchmark_installer_libraries()
@@ -201,7 +209,11 @@ def __main():
201209
return 1 # failure (for Travis)
202210
print("PASSED:\"" + benchmark["sources-dir"] + "\"")
203211
return 0 # success (for Travis)
212+
except Exception as e:
213+
print("ERROR: " + str(e))
214+
return 1 # failure (for Travis)
204215
except:
216+
print("ERROR: Unknown exception was raised.")
205217
return 1 # failure (for Travis)
206218

207219

0 commit comments

Comments
 (0)