From 4bbccc974ffc5716cbb2f10a1a817934405ad0ee Mon Sep 17 00:00:00 2001 From: Carine Morel Date: Sat, 23 Nov 2024 17:51:22 +0100 Subject: [PATCH] Fix tests after minor changes. --- test/ws_deque/qcheck_ws_deque.ml | 31 ++++++++++++++++--------------- test/ws_deque/stm_ws_deque.ml | 2 +- test/ws_deque/test_ws_deque.ml | 6 +++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/test/ws_deque/qcheck_ws_deque.ml b/test/ws_deque/qcheck_ws_deque.ml index b90a34a9..299b2c90 100644 --- a/test/ws_deque/qcheck_ws_deque.ml +++ b/test/ws_deque/qcheck_ws_deque.ml @@ -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); @@ -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)); @@ -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) @@ -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 @@ -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. @@ -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)) @@ -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 @@ -177,13 +178,13 @@ 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 () -> @@ -191,7 +192,7 @@ let tests_one_producer_one_stealer = let steal' deque = match Ws_deque.steal_exn deque with | value -> Some value - | exception Exit -> + | exception Ws_deque.Empty -> Domain.cpu_relax (); None in @@ -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)) @@ -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; diff --git a/test/ws_deque/stm_ws_deque.ml b/test/ws_deque/stm_ws_deque.ml index 5d023833..c2090ddc 100644 --- a/test/ws_deque/stm_ws_deque.ml +++ b/test/ws_deque/stm_ws_deque.ml @@ -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 diff --git a/test/ws_deque/test_ws_deque.ml b/test/ws_deque/test_ws_deque.ml index fbe5f018..1173a448 100644 --- a/test/ws_deque/test_ws_deque.ml +++ b/test/ws_deque/test_ws_deque.ml @@ -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 () = @@ -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 -> @@ -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