Source file test_alloc.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
open! Base
open! Import

let%expect_test "result doesn't allocate" =
  (match
     Expect_test_helpers_core.require_no_allocation_local (fun () -> exclave_
       Parallel.For_scheduler.Result.try_with (fun () -> 1))
   with
   | Ok n -> assert (n = 1)
   | _ -> assert false);
  [%expect {| |}]
;;

let%expect_test "capsule doesn't allocate" =
  (match
     Expect_test_helpers_core.require_no_allocation_local (fun () -> exclave_
       Parallel.For_scheduler.Result.Capsule.try_with (fun () -> 1))
   with
   | Ok (n, _) -> assert (Capsule.Data.project n = 1)
   | _ -> assert false);
  [%expect {| |}]
;;

let%expect_test ("sequential scheduler doesn't allocate" [@tags "fast-flambda"]) =
  Expect_test_helpers_core.require_no_allocation_local (fun () ->
    let #(x, y) = Parallel.fork_join2 Parallel.sequential (fun _ -> 1) (fun _ -> 1) in
    assert (x + y = 2));
  [%expect {| |}]
;;

let%expect_test ("fork_join doesn't allocate" [@tags "fast-flambda"]) =
  Expect_test_helpers_core.require_no_allocation_local ~cr:CR_someday (fun () ->
    let [ x; y; z ] =
      Parallel.fork_join Parallel.sequential [ (fun _ -> 1); (fun _ -> 1); (fun _ -> 1) ]
    in
    assert (x + y + z = 3));
  [%expect
    {|
    ("allocation exceeded limit" (allocation_limit (Minor_words 0)))
    |}]
;;