From ea2267ae176d6c621ff9d513f124dc85b6accff7 Mon Sep 17 00:00:00 2001 From: edwinans Date: Mon, 23 Dec 2024 16:00:21 +0100 Subject: [PATCH] Add zero_alloc test --- tests/alloc/dune | 17 +++++++++++++++++ tests/alloc/test.ml | 27 +++++++++++++++++++++++++++ tests/alloc/test.out.expected | 3 +++ 3 files changed, 47 insertions(+) create mode 100644 tests/alloc/dune create mode 100644 tests/alloc/test.ml create mode 100644 tests/alloc/test.out.expected diff --git a/tests/alloc/dune b/tests/alloc/dune new file mode 100644 index 0000000..cb59b75 --- /dev/null +++ b/tests/alloc/dune @@ -0,0 +1,17 @@ +(executable + (name test) + (modes native) + (libraries landmark)) + +(rule + (ignore-stderr + (with-stdout-to + test.out + (run ./test.exe)))) + +(rule + (alias runtest) + (enabled_if + (>= %{ocaml_version} "4.04")) + (action + (diff test.out.expected test.out))) diff --git a/tests/alloc/test.ml b/tests/alloc/test.ml new file mode 100644 index 0000000..2781280 --- /dev/null +++ b/tests/alloc/test.ml @@ -0,0 +1,27 @@ +module L = Landmark + +let name = "zero_alloc" +let zero_alloc = L.register name + +let () = + L.start_profiling + ~profiling_options:{L.default_options with allocated_bytes = true} (); + L.enter zero_alloc; + L.exit zero_alloc + +let check_allocated_bytes () = + let open Landmark.Graph in + + let graph = L.export () in + let node = + root graph + |> children graph + |> List.filter (fun n -> n.name = name) + |> List.hd + in + Printf.printf "Allocations:\n%d\n%d\n" + (node.allocated_bytes) + (node.allocated_bytes_major) + +let () = + check_allocated_bytes () diff --git a/tests/alloc/test.out.expected b/tests/alloc/test.out.expected new file mode 100644 index 0000000..934999a --- /dev/null +++ b/tests/alloc/test.out.expected @@ -0,0 +1,3 @@ +Allocations: +0 +0