vile / scheme / bounded_rest_allocation_test.v
23 lines · 21 sloc · 904 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3import arena
4
5fn test_bounded_rest_spines_allocate_only_their_pair_cells() {
6 mut instance := new_bounded(Options{}, arena.ChunkLimits{ max_live_bytes: 8 * 1024 * 1024 })!
7 defer { instance.close() or { panic(err) } }
8 instance.run(fn (mut vm VM) !Value {
9 for count in [0, 1, 3, 4, 65] {
10 items := []Value{len: count, init: integer(42)}
11 // Start on a whole-pair boundary so unrelated cursor padding is
12 // excluded from the allocation contract being measured.
13 unsafe { arena.current_allocator().calloc(int(sizeof(Pair))) }
14 before, _ := v_arena_stats(v_arena_current())
15 value := vm.owner.bounded_files.argument_list(items)!
16 after, _ := v_arena_stats(v_arena_current())
17 assert after - before == count * int(sizeof(Pair))
18 assert value.list_length()! == count
19 if count > 0 { assert value.pair_pointer().car.as_integer()! == 42 }
20 }
21 return unspecified()
22 })!
23}
24