Skip to content

Commit

Permalink
Add zero_alloc test
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinans committed Dec 23, 2024
1 parent e87c92b commit ea2267a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/alloc/dune
Original file line number Diff line number Diff line change
@@ -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)))
27 changes: 27 additions & 0 deletions tests/alloc/test.ml
Original file line number Diff line number Diff line change
@@ -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 ()
3 changes: 3 additions & 0 deletions tests/alloc/test.out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Allocations:
0
0

0 comments on commit ea2267a

Please sign in to comment.