-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create trace tracker, add two tests with conditionals and dump traces for all tests
- Loading branch information
1 parent
ba085b9
commit 0a2a617
Showing
17 changed files
with
23,655 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set -eux pipefail | ||
|
||
dscheck_trace_file="tests/traces/ms_queue" dune exec tests/test_michael_scott_queue.exe | ||
dscheck_trace_file="tests/traces/naive_counter" dune exec tests/test_naive_counter.exe | ||
dscheck_trace_file="tests/traces/list" dune exec tests/test_list.exe | ||
dscheck_trace_file="tests/traces/conditional1" dune exec tests/test_conditional1.exe | ||
dscheck_trace_file="tests/traces/conditional2" dune exec tests/test_conditional2.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
module Op = struct | ||
type t = { proc : int; variable : int; step : int } | ||
|
||
let is_dependent t1 t2 = t1.variable == t2.variable | ||
|
||
let compare_proc_step t1 t2 = | ||
let c1 = Int.compare t1.proc t2.proc in | ||
if c1 <> 0 then c1 else Int.compare t1.step t2.step | ||
|
||
let to_str t = Printf.sprintf "(%d,%c)" t.proc (Char.chr (t.variable + 96)) | ||
end | ||
|
||
module Trace = struct | ||
module Key = struct | ||
type t = (Op.t * Op.t option) list | ||
|
||
let compare t1 t2 = | ||
List.compare | ||
(fun (op1, dep1) (op2, dep2) -> | ||
let c1 = Op.compare_proc_step op1 op2 in | ||
if c1 <> 0 then c1 else Option.compare Op.compare_proc_step dep1 dep2) | ||
t1 t2 | ||
end | ||
|
||
type t = Op.t List.t | ||
|
||
let of_schedule_for_checks schedule_for_checks : t = | ||
let steps = Hashtbl.create 10 in | ||
List.map | ||
(fun (proc, _, variable) -> | ||
Option.map | ||
(fun variable : Op.t -> | ||
(match Hashtbl.find_opt steps proc with | ||
| None -> Hashtbl.add steps proc 1 | ||
| Some v -> | ||
Hashtbl.remove steps proc; | ||
Hashtbl.add steps proc (v + 1)); | ||
|
||
let step = Hashtbl.find steps proc in | ||
|
||
{ proc; variable; step }) | ||
variable) | ||
schedule_for_checks | ||
|> List.filter_map Fun.id | ||
|
||
let to_string t = List.map Op.to_str t |> String.concat "," | ||
|
||
let tag_with_deps (t : t) : Key.t = | ||
let next_dep op t = List.find_opt (Op.is_dependent op) t in | ||
let rec f t = | ||
match t with | ||
| [] -> [] | ||
| hd :: [] -> [ (hd, None) ] | ||
| hd :: tl -> (hd, next_dep hd tl) :: f tl | ||
in | ||
let tagged = f t in | ||
List.sort (fun (op1, _) (op2, _) -> Op.compare_proc_step op1 op2) tagged | ||
|
||
let deps_to_str (key : Key.t) : string = | ||
List.map | ||
(fun (op, dep) -> | ||
Op.to_str op ^ "-" | ||
^ (Option.map Op.to_str dep |> Option.value ~default:"none")) | ||
key | ||
|> String.concat "," | ||
end | ||
|
||
module TraceMap = Map.Make (Trace.Key) | ||
|
||
type t = Trace.t TraceMap.t | ||
|
||
let traces = ref TraceMap.empty | ||
|
||
let add_trace trace = | ||
let trace = Trace.of_schedule_for_checks trace in | ||
let key = Trace.tag_with_deps trace in | ||
traces := | ||
TraceMap.update key | ||
(function Some v -> Some v | None -> Some trace) | ||
!traces | ||
|
||
let print traces channel = | ||
Printf.fprintf channel "----\n"; | ||
TraceMap.iter | ||
(fun _ trace -> Printf.fprintf channel "%s\n" (Trace.to_string trace)) | ||
traces; | ||
Printf.fprintf channel "----\n"; | ||
flush channel | ||
|
||
let print_traces chan = print !traces chan | ||
let clear_traces () = traces := TraceMap.empty | ||
let get_traces () = !traces | ||
|
||
let get_deps_str traces = | ||
TraceMap.to_seq traces |> List.of_seq | ||
|> List.map (fun (_, value) -> value) | ||
|> List.map Trace.tag_with_deps | ||
|> List.map Trace.deps_to_str |> String.concat "\n" | ||
|
||
let equal t1 t2 = | ||
TraceMap.compare | ||
(fun _ _ -> | ||
0 | ||
(* any values under the same key are known to be equivalent, even if the exact sequence is not identical *)) | ||
t1 t2 | ||
== 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type t | ||
|
||
val add_trace : (int * 'a * int option) list -> unit | ||
val clear_traces : unit -> unit | ||
val get_traces : unit -> t | ||
val print_traces : out_channel -> unit | ||
val print : t -> out_channel -> unit | ||
val equal : t -> t -> bool | ||
val get_deps_str : t -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
sequence 1 | ||
---------------------------------------- | ||
P0 P1 | ||
---------------------------------------- | ||
start | ||
fetch_and_add a | ||
start | ||
fetch_and_add a | ||
fetch_and_add b | ||
---------------------------------------- | ||
|
||
sequence 2 | ||
---------------------------------------- | ||
P0 P1 | ||
---------------------------------------- | ||
start | ||
start | ||
fetch_and_add a | ||
fetch_and_add a | ||
fetch_and_add b | ||
---------------------------------------- | ||
|
||
sequence 3 | ||
---------------------------------------- | ||
P0 P1 | ||
---------------------------------------- | ||
start | ||
start | ||
fetch_and_add a | ||
fetch_and_add a | ||
fetch_and_add b | ||
---------------------------------------- | ||
|
||
explored 3 maximal interleavings and 12 states | ||
---- | ||
(1,a),(0,a),(1,b) | ||
(0,a),(1,a),(1,b) | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Atomic = Dscheck.TracedAtomic | ||
|
||
let test () = | ||
let b = Atomic.make 0 in | ||
let c = Atomic.make 0 in | ||
let ok = Atomic.make false in | ||
let seen_b = ref (-1) in | ||
|
||
Atomic.spawn (fun () -> Atomic.set b 1); | ||
Atomic.spawn (fun () -> | ||
Atomic.set c 1; | ||
Atomic.set b 2); | ||
Atomic.spawn (fun () -> | ||
if Atomic.get c = 0 then ( | ||
seen_b := Atomic.get b; | ||
if !seen_b = 0 then Atomic.set ok true)) | ||
|
||
(* Atomic.final (fun () -> | ||
Format.printf "seen_b=%i b=%i c=%i ok=%b@." (!seen_b) (Atomic.get b) (Atomic.get c) | ||
(Atomic.get ok)) *) | ||
|
||
let () = Atomic.trace test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Atomic = Dscheck.TracedAtomic | ||
|
||
let test () = | ||
let x = Atomic.make 0 in | ||
let y = Atomic.make 0 in | ||
let z = Atomic.make 0 in | ||
|
||
let tmp = ref (-1) in | ||
Atomic.spawn (fun () -> tmp := Atomic.get x); | ||
Atomic.spawn (fun () -> Atomic.set y 1); | ||
|
||
Atomic.spawn (fun () -> | ||
let m = Atomic.get y in | ||
if m = 0 then Atomic.set z 1); | ||
|
||
Atomic.spawn (fun () -> | ||
let n = Atomic.get z in | ||
let l = Atomic.get y in | ||
if n = 1 then if l = 0 then Atomic.set x 1) | ||
|
||
(* | ||
Atomic.final (fun () -> | ||
Format.printf "tmp=%d x=%d y=%d z=%d\n%!" !tmp (Atomic.get x) | ||
(Atomic.get y) (Atomic.get z)) *) | ||
|
||
let () = Atomic.trace test |
Oops, something went wrong.