@@ -205,7 +205,7 @@ let var_name i =
205205 let c = Char. chr (i + 96 ) in
206206 Printf. sprintf " %c" c
207207
208- let print_execution_sequence () =
208+ let print_execution_sequence chan =
209209 let highest_proc =
210210 List. fold_left
211211 (fun highest (curr_proc , _ , _ ) ->
@@ -216,11 +216,12 @@ let print_execution_sequence () =
216216 let bar =
217217 List. init ((highest_proc * 20 ) + 20 ) (fun _ -> " -" ) |> String. concat " "
218218 in
219- Printf. printf " \n sequence %d\n " ! num_interleavings;
220- Printf. printf " %s\n " bar;
221- List. init (highest_proc + 1 ) (fun proc -> Printf. printf " P%d\t\t\t " proc)
219+ Printf. fprintf chan " \n sequence %d\n " ! num_interleavings;
220+ Printf. fprintf chan " %s\n " bar;
221+ List. init (highest_proc + 1 ) (fun proc ->
222+ Printf. fprintf chan " P%d\t\t\t " proc)
222223 |> ignore;
223- Printf. printf " \n %s\n " bar;
224+ Printf. fprintf chan " \n %s\n " bar;
224225
225226 List. iter
226227 (fun s ->
@@ -230,13 +231,14 @@ let print_execution_sequence () =
230231 let tabs =
231232 List. init last_run_proc (fun _ -> " \t\t\t " ) |> String. concat " "
232233 in
233- Printf. printf " %s%s %s\n " tabs
234+ Printf. fprintf chan " %s%s %s\n " tabs
234235 (atomic_op_str last_run_op)
235236 last_run_ptr)
236237 ! schedule_for_checks;
237- Printf. printf " %s\n %!" bar
238+ Printf. fprintf chan " %s\n %!" bar
238239
239- let print_max_exec_seq = ref false
240+ let interleavings_chan = (ref None : out_channel option ref )
241+ let record_traces_flag = ref false
240242
241243let do_run init_func init_schedule =
242244 init_func () ;
@@ -254,8 +256,15 @@ let do_run init_func init_schedule =
254256 | [] ->
255257 if ! finished_processes == num_processes then (
256258 tracing := false ;
259+
257260 num_interleavings := ! num_interleavings + 1 ;
258- if ! print_max_exec_seq then print_execution_sequence () ;
261+ if ! record_traces_flag then
262+ Trace_tracker. add_trace ! schedule_for_checks;
263+
264+ (match ! interleavings_chan with
265+ | None -> ()
266+ | Some chan -> print_execution_sequence chan);
267+
259268 ! final_func () ;
260269 tracing := true )
261270 | (process_id_to_run , next_op , next_ptr ) :: schedule ->
@@ -274,7 +283,7 @@ let do_run init_func init_schedule =
274283 finished_processes := 0 ;
275284 tracing := false ;
276285 num_states := ! num_states + 1 ;
277- if ! num_states mod 1000 == 0 then Printf. printf " run: %d\n %!" ! num_states;
286+ (* if !num_states mod 1000 == 0 then Printf.printf "run: %d\n%!" !num_states; *)
278287 let procs =
279288 CCVector. mapi
280289 (fun i p -> { proc_id = i; op = p.next_op; obj_ptr = p.next_repr })
@@ -347,7 +356,7 @@ let check f =
347356 tracing := false ;
348357 if not (f () ) then (
349358 Printf. printf " Found assertion violation at run %d:\n " ! num_interleavings;
350- print_execution_sequence () ;
359+ print_execution_sequence stdout ;
351360 assert false );
352361 tracing := tracing_at_start
353362
@@ -357,15 +366,34 @@ let reset_state () =
357366 num_states := 0 ;
358367 num_interleavings := 0 ;
359368 schedule_for_checks := [] ;
369+ Trace_tracker. clear_traces () ;
360370 CCVector. clear processes
361371
362- let trace ?(print_interleavings = false ) func =
363- print_max_exec_seq := print_interleavings;
372+ let dscheck_trace_file_env = Sys. getenv_opt " dscheck_trace_file"
373+
374+ let dpor func =
364375 reset_state () ;
365376 let empty_state = do_run func [ (0 , Start , None ) ] :: [] in
366377 let empty_clock = IntMap. empty in
367378 let empty_last_access = IntMap. empty in
368- explore func empty_state empty_clock empty_last_access;
369- if print_interleavings then
370- Printf. printf " \n explored %d maximal interleavings and %d states\n "
371- ! num_interleavings ! num_states
379+ explore func empty_state empty_clock empty_last_access
380+
381+ let trace ?interleavings ?(record_traces = false ) func =
382+ record_traces_flag := record_traces || Option. is_some dscheck_trace_file_env;
383+ interleavings_chan := interleavings;
384+
385+ dpor func;
386+
387+ (* print reports *)
388+ (match ! interleavings_chan with
389+ | None -> ()
390+ | Some chan ->
391+ Printf. fprintf chan " \n explored %d maximal interleavings and %d states\n "
392+ ! num_interleavings ! num_states);
393+
394+ match dscheck_trace_file_env with
395+ | None -> ()
396+ | Some path ->
397+ let chan = open_out path in
398+ Trace_tracker. print_traces chan;
399+ close_out chan
0 commit comments