Skip to content

Commit 70c71f0

Browse files
committed
[Misc] refactor
1 parent 7da80f2 commit 70c71f0

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

src/coverage.ml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,20 @@ module F = Format
33
module L = Logger
44

55
let parse_targets targets_file =
6-
(AUtil.readlines targets_file
6+
AUtil.readlines targets_file
77
|> List.map (fun line ->
88
let chunks = String.split_on_char ':' line in
99
let filename = List.nth chunks 0 |> Filename.basename in
1010
let lineno = List.nth chunks 1 |> int_of_string in
1111
(filename, lineno))
1212
|> List.sort_uniq compare
13-
|> List.hd)
14-
:: []
1513

1614
module BlockTrace = struct
1715
type t = int list
1816

1917
let of_lines lines =
2018
(* SAFETY: if the file is generated, it has at least one line *)
21-
let lines =
22-
lines
23-
|> List.map (fun line ->
24-
match int_of_string_opt line with
25-
| Some n -> n
26-
| None ->
27-
F.eprintf "BlockTrace.of_lines: invalid line %s" line;
28-
exit 1)
29-
in
19+
let lines = lines |> List.map int_of_string in
3020
match lines with
3121
| [] -> []
3222
| _ ->

src/fuzzer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ let evaluate_mutant parent_llm llm importants covset node_tbl distance_map =
3838
match optim_res with
3939
| Error _ -> None
4040
| Ok lines ->
41-
let filter_func =
41+
let in_slice =
4242
match !Config.coverage with
4343
| Config.FuzzingMode.Sliced_cfg ->
4444
fun addr ->
4545
Coverage.sliced_cfg_node_of_addr node_tbl distance_map addr
4646
|> Option.is_some
4747
| _ -> fun _ -> true
4848
in
49-
let trace = lines |> List.map int_of_string |> List.filter filter_func in
49+
let trace = lines |> List.map int_of_string |> List.filter in_slice in
5050
let cov = trace |> AUtil.pairs |> Coverage.EdgeCoverage.of_list in
5151
let new_points = Coverage.EdgeCoverage.diff cov covset in
5252
if Coverage.EdgeCoverage.is_empty new_points then

src/main.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ let main targets_file cfg_dir =
3232
|> List.iter (fun (filename, lineno) ->
3333
F.printf "target: %s:%d@." (Filename.basename filename) lineno);
3434

35+
(* TODO: check *)
36+
let targets = [ List.hd targets ] in
37+
3538
let cfgs =
3639
Sys.readdir cfg_dir
3740
|> Array.to_list

src/oracle.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module Validator = struct
2020

2121
let has_target line = String.starts_with ~prefix:"target " line
2222

23+
let launch_tv src opted =
24+
Unix.open_process_args_in "timeout"
25+
[| "timeout"; "2m"; !Config.alive_tv_bin; src; opted |]
26+
2327
let run src optimized =
2428
if not (Sys.file_exists src && Sys.file_exists optimized) then Errors
2529
else
@@ -33,10 +37,7 @@ module Validator = struct
3337
in
3438
Out_channel.with_open_text optimized (fun instr ->
3539
List.iter (Printf.fprintf instr "%s\n") lines);
36-
let tv_process =
37-
Unix.open_process_args_in "timeout"
38-
[| "timeout"; "2m"; !Config.alive_tv_bin; src; optimized |]
39-
in
40+
let tv_process = launch_tv src optimized in
4041
let text = In_channel.input_all tv_process in
4142
print_endline text;
4243
(*AUtil.log "%s@." text;*)

0 commit comments

Comments
 (0)