Skip to content

Commit 485a174

Browse files
committed
Add option to use models library to run.py
1 parent d218a41 commit 485a174

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

security-scanner/mkbench.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def install_class_file(pathname,output_dir,class_temp_dir):
126126
shutil.copyfile(pathname,class_pathname)
127127

128128
prof["duration"] = time.time() - prof_start_time
129+
prof["count"] = 1
129130
return prof
130131

131132

@@ -187,55 +188,58 @@ def install_war_file(pathname,output_dir,temp_dir,class_temp_dir):
187188
return prof
188189

189190

190-
def build_classes_configuration(app_binary_dir,output_dir,temp_dir):
191+
def build_classes_configuration(app_binary_dirs, output_dir, temp_dir):
191192
prof = {}
192193
prof_start_time = time.time()
193194

194195
prof["unpack"] = {"duration": 0.0}
195196
prof["collect"] = {"duration": 0.0}
197+
prof["install"] = { "count": 0, "duration": 0.0, "fullname": { "duration": 0.0 } }
198+
199+
def add_prof_install(arg1, arg2):
200+
return {
201+
"count": arg1["count"] + arg2["count"],
202+
"duration": arg1["duration"] + arg2["duration"],
203+
"fullname": {"duration": arg1["fullname"]["duration"] + arg2["fullname"]["duration"]}
204+
}
196205

197206
class_temp_dir = os.path.join(temp_dir, "FULLNAME")
198207

199-
files = []
200-
prof["collect"] = collect_java_files(app_binary_dir,"class",files)
208+
for app_binary_dir in app_binary_dirs:
201209

202-
prof["install"] = { "count": len(files), "duration": 0.0, "fullname": { "duration": 0.0 } }
210+
files = []
211+
prof_collect = collect_java_files(app_binary_dir,"class",files)
212+
prof["collect"]["duration"] += prof_collect["duration"]
203213

204-
for fname in files:
205-
prof_install = install_class_file(fname,output_dir,class_temp_dir)
214+
for fname in files:
215+
prof_install = install_class_file(fname,output_dir,class_temp_dir)
216+
prof["install"] = add_prof_install(prof["install"], prof_install)
206217

207-
prof["install"]["duration"] += prof_install["duration"]
208-
prof["install"]["fullname"]["duration"] += prof_install["fullname"]["duration"]
218+
temp_dir_counter = 0
209219

210-
temp_dir_counter = 0
220+
files = []
221+
prof_collect = collect_java_files(app_binary_dir,"jar",files)
222+
prof["collect"]["duration"] += prof_collect["duration"]
211223

212-
files = []
213-
prof_collect = collect_java_files(app_binary_dir,"jar",files)
214-
prof["collect"]["duration"] += prof_collect["duration"]
224+
for fname in files:
225+
prof_install = install_jar_file(fname,output_dir,_make_temp_unpack_dir(os.path.join(temp_dir,"JAR"),fname,temp_dir_counter),class_temp_dir)
226+
temp_dir_counter += 1
215227

216-
for fname in files:
217-
prof_install = install_jar_file(fname,output_dir,_make_temp_unpack_dir(os.path.join(temp_dir,"JAR"),fname,temp_dir_counter),class_temp_dir)
218-
temp_dir_counter += 1
228+
prof["unpack"]["duration"] += prof_install["unpack"]["duration"]
229+
prof["collect"]["duration"] += prof_install["collect"]["duration"]
230+
prof["install"] = add_prof_install(prof["install"], prof_install["install"])
219231

220-
prof["unpack"]["duration"] += prof_install["unpack"]["duration"]
221-
prof["collect"]["duration"] += prof_install["collect"]["duration"]
222-
prof["install"]["count"] += prof_install["install"]["count"]
223-
prof["install"]["duration"] += prof_install["install"]["duration"]
224-
prof["install"]["fullname"]["duration"] += prof_install["install"]["fullname"]["duration"]
225-
226-
files = []
227-
prof_collect = collect_java_files(app_binary_dir, "war", files)
228-
prof["collect"]["duration"] += prof_collect["duration"]
232+
files = []
233+
prof_collect = collect_java_files(app_binary_dir, "war", files)
234+
prof["collect"]["duration"] += prof_collect["duration"]
229235

230-
for fname in files:
231-
prof_install = install_war_file(fname,output_dir,_make_temp_unpack_dir(os.path.join(temp_dir,"WAR"),fname,temp_dir_counter),class_temp_dir)
232-
temp_dir_counter += 1
236+
for fname in files:
237+
prof_install = install_war_file(fname,output_dir,_make_temp_unpack_dir(os.path.join(temp_dir,"WAR"),fname,temp_dir_counter),class_temp_dir)
238+
temp_dir_counter += 1
233239

234-
prof["unpack"]["duration"] += prof_install["unpack"]["duration"]
235-
prof["collect"]["duration"] += prof_install["collect"]["duration"]
236-
prof["install"]["count"] += prof_install["install"]["count"]
237-
prof["install"]["duration"] += prof_install["install"]["duration"]
238-
prof["install"]["fullname"]["duration"] += prof_install["install"]["fullname"]["duration"]
240+
prof["unpack"]["duration"] += prof_install["unpack"]["duration"]
241+
prof["collect"]["duration"] += prof_install["collect"]["duration"]
242+
prof["install"] = add_prof_install(prof["install"], prof_install["install"])
239243

240244
prof["duration"] = time.time() - prof_start_time
241245
return prof

security-scanner/run.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __parse_cmd_line():
5757
parser.add_argument("--verbosity", type=int, default=9,
5858
help="It specifies how many debugging messages will be printed to the standard output stream "
5959
"during the analysis.")
60+
parser.add_argument("--use-models-library", action="store_true", help="Add the Diffblue models library to the application JAR")
6061
parser.add_argument("--data-flow-insensitive-instrumentation", action="store_true",
6162
help="If specified, then the tool 'security-analyser' will use the data-flow insensitive "
6263
"instrumentation of the checked properties into the output GOTO programs. In that case"
@@ -82,8 +83,15 @@ def evaluate(cmdline):
8283

8384
print("Collecting Java CLASS files to analyse:")
8485

86+
input_search_dirs = [cmdline.install_dir]
87+
if cmdline.use_models_library:
88+
input_search_dirs.append(os.path.join(__get_my_dir(), "../benchmarks/LIBRARIES/models/model/target/classes"))
89+
if not os.path.exists(input_search_dirs[-1]):
90+
repo_root = os.path.realpath(os.path.join(__get_my_dir(), ".."))
91+
raise Exception("Models library not found at %s; consider running 'make' in %s" % (input_search_dirs[-1], repo_root))
92+
8593
prof["install_classes"] = mkbench.build_classes_configuration(
86-
cmdline.install_dir,
94+
input_search_dirs,
8795
os.path.abspath(os.path.join(cmdline.temp_dir,"BIN","CLASSES")),
8896
os.path.abspath(os.path.join(cmdline.temp_dir,"BIN","UNPACK"))
8997
)

0 commit comments

Comments
 (0)