Skip to content

Commit 4be4164

Browse files
committed
expose trace options
1 parent 8cf65e8 commit 4be4164

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/tracedAtomic.ml

+22-19
Original file line numberDiff line numberDiff line change
@@ -506,30 +506,33 @@ let check f =
506506

507507
let error_count = ref 0
508508

509-
let rec explore_all func trie =
509+
let explore_one func trie =
510510
let empty_schedule = [{ proc_id = [] ; op = Start ; obj_ptr = None }] in
511511
setup_run func empty_schedule trie ;
512512
let empty_state = do_run empty_schedule :: [] in
513513
let empty_last_access = IdMap.empty, IdMap.empty in
514-
let has_error, trie =
515-
explore func 1 empty_state trie empty_schedule empty_last_access
516-
in
517-
match T.min_depth trie with
518-
| None ->
519-
assert (T.nb_todos trie = 0) ;
520-
T.graphviz ~filename:"/tmp/dscheck.dot" trie ;
521-
trie
522-
| _ when has_error ->
523-
error_count := !error_count + 1 ;
524-
T.graphviz ~filename:"/tmp/dscheck.dot" trie ;
525-
if !error_count >= 5
526-
then trie
527-
else explore_all func trie
528-
| Some _ -> explore_all func trie
529-
530-
let trace func =
514+
explore func 1 empty_state trie empty_schedule empty_last_access
515+
516+
let rec explore_all ~count ~errors func trie =
517+
if !error_count >= errors
518+
|| !num_runs >= count
519+
|| T.nb_todos trie = 0
520+
then trie (* graphviz_output ?graphviz trie *)
521+
else begin
522+
let has_error, trie = explore_one func trie in
523+
if has_error then error_count := !error_count + 1 ;
524+
explore_all ~count ~errors func trie
525+
end
526+
527+
let graphviz_output ?graphviz trie =
528+
match graphviz with
529+
| None -> ()
530+
| Some filename -> T.graphviz ~filename trie
531+
532+
let trace ?(count = max_int) ?(errors = 1) ?graphviz func =
531533
print_header () ;
532534
num_runs := 0 ;
533-
let _ = explore_all func T.todo in
535+
let trie = explore_all ~count ~errors func T.todo in
536+
graphviz_output ?graphviz trie ;
534537
Format.printf "@.Found %#i errors after %#i runs.@." !error_count !num_runs ;
535538
()

src/tracedAtomic.mli

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ val incr : int t -> unit
4646
val decr : int t -> unit
4747
(** [decr r] atomically decrements the value of [r] by [1]. *)
4848

49-
val trace : (unit -> unit) -> unit
50-
(** start the simulation trace *)
49+
val trace : ?count:int -> ?errors:int -> ?graphviz:string -> (unit -> unit) -> unit
50+
(** [trace fn] starts the simulation trace on the function [fn].
51+
52+
- [?count] is the max number of traces to test (defaults to infinity)
53+
- [?errors] is the max number of errors to find (defaults to 1)
54+
- [?graphviz] is a filename to use for outputting a dot file (defaults to no output)
55+
*)
5156

5257
val spawn : (unit -> unit) -> unit
5358
(** spawn [f] as a new 'thread' *)
@@ -59,4 +64,4 @@ val final : (unit -> unit) -> unit
5964
(** run [f] after all processes complete *)
6065

6166
val every : (unit -> unit) -> unit
62-
(** run [f] between every possible interleaving *)
67+
(** run [f] between every possible interleaving *)

0 commit comments

Comments
 (0)