|
| 1 | + (* operate over arrays to avoid needless allocation underway *) |
| 2 | + let interp sut cs = |
| 3 | + let cs_arr = Array.of_list cs in |
| 4 | + let res_arr = Array.map (fun c -> Domain.cpu_relax(); Spec.run c sut) cs_arr in |
| 5 | + List.combine cs (Array.to_list res_arr) |
| 6 | + |
| 7 | + (* Linearizability property based on [Domain] and an Atomic flag *) |
| 8 | + let lin_prop_domain (seq_pref,cmds1,cmds2) = |
| 9 | + let sut = Spec.init () in |
| 10 | + let pref_obs = interp sut seq_pref in |
| 11 | + let wait = Atomic.make true in |
| 12 | + let dom1 = Domain.spawn (fun () -> while Atomic.get wait do Domain.cpu_relax() done; try Ok (interp sut cmds1) with exn -> Error exn) in |
| 13 | + let dom2 = Domain.spawn (fun () -> Atomic.set wait false; try Ok (interp sut cmds2) with exn -> Error exn) in |
| 14 | + let obs1 = Domain.join dom1 in |
| 15 | + let obs2 = Domain.join dom2 in |
| 16 | + let obs1 = match obs1 with Ok v -> v | Error exn -> raise exn in |
| 17 | + let obs2 = match obs2 with Ok v -> v | Error exn -> raise exn in |
| 18 | + let seq_sut = Spec.init () in |
| 19 | + check_seq_cons pref_obs obs1 obs2 seq_sut [] |
| 20 | + || Test.fail_reportf " Results incompatible with sequential execution\n\n%s" |
| 21 | + @@ print_triple_vertical ~fig_indent:5 ~res_width:35 |
| 22 | + (fun (c,r) -> Printf.sprintf "%s : %s" (Spec.show_cmd c) (Spec.show_res r)) |
| 23 | + (pref_obs,obs1,obs2) |
| 24 | + |
| 25 | + | `Domain -> |
| 26 | + let arb_cmd_triple = arb_cmds_par seq_len par_len in |
| 27 | + let rep_count = 50 in |
| 28 | + Test.make ~count ~retries:3 ~name |
| 29 | + arb_cmd_triple (repeat rep_count lin_prop_domain) |
| 30 | + |
| 31 | + | `Domain -> |
| 32 | + let arb_cmd_triple = arb_cmds_par seq_len par_len in |
| 33 | + let rep_count = 50 in |
| 34 | + Test.make_neg ~count ~retries:3 ~name |
| 35 | + arb_cmd_triple (repeat rep_count lin_prop_domain) |
0 commit comments