Skip to content

Commit

Permalink
Fix tests after minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrm committed Nov 23, 2024
1 parent 29a52e6 commit 4bbccc9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
31 changes: 16 additions & 15 deletions test/ws_deque/qcheck_ws_deque.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ let tests_one_producer =
in
pop_list = List.rev l'));
(* TEST 2 - single producer no stealer :
forall q of size n, forall m > n, poping m times raises Exit (m-n) times. *)
forall q of size n, forall m > n, poping m times raises Empty (m-n) times. *)
QCheck.(
Test.make ~name:"pop_on_empty_deque_raises_exit" ~count:1
Test.make ~name:"pop_on_empty_deque_raises_empty" ~count:1
(pair (list int) small_nat)
(fun (l, m) ->
assume (m > 0);
Expand All @@ -49,7 +49,8 @@ let tests_one_producer =
let deque = deque_of_list l in

for _i = 0 to m - 1 do
try ignore (Ws_deque.pop_exn deque) with Exit -> incr count
try ignore (Ws_deque.pop_exn deque)
with Ws_deque.Empty -> incr count
done;

!count = m - n));
Expand All @@ -63,7 +64,7 @@ let tests_one_producer_one_stealer =
This checks :
- order is preserved (first push = first steal)
- Exit is raised only when the deque is empty *)
- Empty is raised only when the deque is empty *)
QCheck.(
Test.make ~name:"steals_are_in_order"
(pair (list int) small_nat)
Expand All @@ -72,14 +73,14 @@ let tests_one_producer_one_stealer =
let deque = deque_of_list l in

(* Then the stealer domain steals [n] times. The output list
is composed of all stolen value. If an [Exit] is raised,
is composed of all stolen value. If an [Empty] is raised,
it is register as a [None] value in the returned list.*)
let stealer =
Domain.spawn (fun () ->
let steal' deque =
match Ws_deque.steal_exn deque with
| value -> Some value
| exception Exit ->
| exception Ws_deque.Empty ->
Domain.cpu_relax ();
None
in
Expand All @@ -99,7 +100,7 @@ let tests_one_producer_one_stealer =
nfirst expected_stolen)
&&
(* The [n - (List.length l)] last values of [steal_list]
should be [None] (i.e. the [steal] function had raised [Exit]). *)
should be [None] (i.e. the [steal] function had raised [Empty]). *)
let exits = List.filteri (fun i _ -> i >= List.length l) steal_list in
List.for_all (function None -> true | _ -> false) exits));
(* TEST 2 with 1 producer, 1 stealer and parallel execution.
Expand All @@ -108,7 +109,7 @@ let tests_one_producer_one_stealer =
This test checks :
- order is preserved (first push = first steal)
- Exit is raised only when the deque is empty *)
- Empty is raised only when the deque is empty *)
QCheck.(
Test.make ~name:"parallel_pushes_and_steals"
(pair (list small_int) (int_bound 200))
Expand All @@ -119,14 +120,14 @@ let tests_one_producer_one_stealer =

(* The stealer domain steals n times. If a value [v] is stolen,
it is registered as [Some v] in the returned list whereas any
[Exit] raised is registered as a [None].*)
[Empty] raised is registered as a [None].*)
let stealer =
Domain.spawn (fun () ->
Barrier.await barrier;
let steal' deque =
match Ws_deque.steal_exn deque with
| value -> Some value
| exception Exit ->
| exception Ws_deque.Empty ->
Domain.cpu_relax ();
None
in
Expand Down Expand Up @@ -177,21 +178,21 @@ let tests_one_producer_one_stealer =
let pop' deque =
match Ws_deque.pop_exn deque with
| value -> Some value
| exception Exit ->
| exception Ws_deque.Empty ->
Domain.cpu_relax ();
None
in

(* The stealer domain steals [nsteal] times. If a value [v] is stolen,
it is registered as [Some v] in the returned list whereas any [Exit]
it is registered as [Some v] in the returned list whereas any [Empty]
raised, it is registered as a [None].*)
let stealer =
Domain.spawn (fun () ->
Barrier.await barrier;
let steal' deque =
match Ws_deque.steal_exn deque with
| value -> Some value
| exception Exit ->
| exception Ws_deque.Empty ->
Domain.cpu_relax ();
None
in
Expand Down Expand Up @@ -225,7 +226,7 @@ let tests_one_producer_two_stealers =
This test checks :
- order is preserved (first push = first steal)
- no element is stolen by both stealers
- Exit is raised only when the deque is empty *)
- Empty is raised only when the deque is empty *)
QCheck.(
Test.make ~name:"parallel_steals"
(pair (list small_int) (pair small_nat small_nat))
Expand All @@ -244,7 +245,7 @@ let tests_one_producer_two_stealers =
res.(i) <-
(match Ws_deque.steal_exn deque with
| value -> Some value
| exception Exit ->
| exception Ws_deque.Empty ->
Domain.cpu_relax ();
None)
done;
Expand Down
2 changes: 1 addition & 1 deletion test/ws_deque/stm_ws_deque.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Spec = struct
match (c, res) with
| Push _, Res ((Unit, _), _) -> true
| Pop, Res ((Result (Int, Exn), _), res) -> (
match s with [] -> res = Error Exit | j :: _ -> res = Ok j)
match s with [] -> res = Error Ws_deque.Empty | j :: _ -> res = Ok j)
| Steal, Res ((Result (Int, Exn), _), res) -> (
match List.rev s with [] -> Result.is_error res | j :: _ -> res = Ok j)
| _, _ -> false
Expand Down
6 changes: 3 additions & 3 deletions test/ws_deque/test_ws_deque.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Saturn.Work_stealing_deque
let test_empty () =
let q = create () in
match pop_exn q with
| exception Exit -> print_string "test_exit: ok\n"
| exception Empty -> print_string "test_exit: ok\n"
| _ -> assert false

let test_push_and_pop () =
Expand Down Expand Up @@ -65,7 +65,7 @@ let test_concurrent_workload () =
decr n
and pop () =
match pop_exn q with
| exception Exit ->
| exception Empty ->
Domain.cpu_relax ();
false
| x ->
Expand All @@ -90,7 +90,7 @@ let test_concurrent_workload () =
Domain.spawn (fun () ->
let steal () =
match steal_exn q with
| exception Exit -> Domain.cpu_relax ()
| exception Empty -> Domain.cpu_relax ()
| x -> stolen.(i) <- x :: stolen.(i)
in

Expand Down

0 comments on commit 4bbccc9

Please sign in to comment.