| 1 |
open Core |
| 2 |
module Unix = Core_unix |
| 3 |
module Thread = Core_thread |
| 4 |
|
| 5 |
module Tests (Hash : Base.Hash.S with type hash_value = int) = struct |
| 6 |
module Ppx_hash_lib = struct |
| 7 |
module Std = struct |
| 8 |
module Hash = Base.Hash.F (Hash) |
| 9 |
end |
| 10 |
end |
| 11 |
|
| 12 |
module Hash = Ppx_hash_lib.Std.Hash |
| 13 |
open Hash.Builtin |
| 14 |
|
| 15 |
let hash_fold_int s t = |
| 16 |
|
| 17 |
ignore (Unix.nanosleep 0.01); |
| 18 |
hash_fold_int s t |
| 19 |
;; |
| 20 |
|
| 21 |
let run_in_two_threads f1 x1 f2 x2 = |
| 22 |
let res1 = ref None in |
| 23 |
let t = |
| 24 |
Thread.create (fun () -> res1 := Some (f1 x1)) ~on_uncaught_exn:`Print_to_stderr () |
| 25 |
in |
| 26 |
let res2 = f2 x2 in |
| 27 |
Thread.join t; |
| 28 |
let res1 = |
| 29 |
match !res1 with |
| 30 |
| Some x -> x |
| 31 |
| None -> assert false |
| 32 |
in |
| 33 |
res1, res2 |
| 34 |
;; |
| 35 |
|
| 36 |
module T = struct |
| 37 |
let some_list = List.init 10 ~f:Fn.id |
| 38 |
let h () = [%hash: int list] some_list |
| 39 |
let res0 = h () |
| 40 |
let res1, res2 = run_in_two_threads h () h () |
| 41 |
let%test_unit _ = [%test_result: int] res1 ~expect:res0 |
| 42 |
let%test_unit _ = [%test_result: int] res2 ~expect:res0 |
| 43 |
end |
| 44 |
end |
| 45 |
|
| 46 |
module T1 = Tests (Base.Hash) |
| 47 |
module T2 = Tests (Siphash_lib.Siphash) |