Skip to content

Commit 78bddb7

Browse files
committed
Extension of the Python driver script w.r.t. calling of the slicer.
Once the slicer is functional, it can be enabled by uncommenting 2 lines in the script. The code was tested with the functional slicer in Lucas'es local branch (There is PR to CBMC repo; not merged yet).
1 parent a853b6a commit 78bddb7

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

security-scanner/analyser.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,46 @@ def run_program_slicing(
109109
timeout,
110110
verbosity
111111
):
112-
prof = {}
112+
prof = { "calling_goto_instrument": [] }
113113
prof_start_time = time.time()
114114

115-
# TODO: once the slicer in "goto-instrument" tool is available, then provide proper implementation here!
116-
# Until then we assume the slicing removes nothing from the instrumented program.
117-
shutil.copyfile(json_cfg_fname, os.path.join(os.path.dirname(json_cfg_fname),"sliced_goto_programs.json"))
115+
with open(json_cfg_fname) as data_file:
116+
cfgs = json.load(data_file)
117+
118+
result = []
119+
for cfg in cfgs:
120+
src_plain_fname = os.path.splitext(os.path.basename(cfg["goto_binary_file"]))[0]
121+
src_idx_name = int(src_plain_fname[src_plain_fname.rfind("_")+1:])
122+
dst_goto_program_fname = os.path.join(results_dir, "sliced_goto_program_" + str(src_idx_name) + ".gbf")
123+
124+
old_cwd = os.getcwd()
125+
os.chdir(results_dir)
126+
command = (
127+
get_goto_instrument_pathname() + " " +
128+
"--full-slice " +
129+
"--verbosity " + str(1) + " " +
130+
cfg["goto_binary_file"] + " " +
131+
"-o " + dst_goto_program_fname
132+
)
133+
prof_calling_goto_instrument_start_time = time.time()
134+
print("Invoking 'goto-instrument' ...")
135+
if verbosity >= 9:
136+
print("CWD: " + results_dir)
137+
print("CMD: " + command)
138+
# TODO: Uncomment the next line when the slicer is functional!
139+
# os.system(command)
140+
prof["calling_goto_instrument"].append({
141+
"gbf_idx": src_idx_name,
142+
"duration": time.time() - prof_calling_goto_instrument_start_time
143+
})
144+
os.chdir(old_cwd)
145+
146+
result.append(cfg.copy())
147+
# TODO: Uncomment the next line when the slicer is functional!
148+
# result[-1]["goto_binary_file"] = dst_goto_program_fname
149+
150+
with open(os.path.join(results_dir, "sliced_goto_programs.json"), "w") as results_json:
151+
results_json.write(json.dumps(result, sort_keys=False, indent=4))
118152

119153
prof["duration"] = time.time() - prof_start_time
120154
return prof

0 commit comments

Comments
 (0)