Skip to content

Commit

Permalink
arena tests
Browse files Browse the repository at this point in the history
Signed-off-by: Graham MacDonald <[email protected]>
  • Loading branch information
gmacd committed Jun 11, 2024
1 parent 24e5f94 commit 4858483
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions port/src/boundarytag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,18 +734,32 @@ mod tests {
// To do this we run through each case (comments from the `free` function)

// Prev and next both non-free
// Change curr_tag to free
let a1 = arena.alloc(4096);
assert_eq!(arena.free_tags.len(), 99);
let a2 = arena.alloc(4096);
assert_eq!(arena.free_tags.len(), 98);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 2, 4096 * 19).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 2, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 3, 4096 * 18).unwrap()),
],
);
arena.free(a1);
assert_eq!(arena.free_tags.len(), 98);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 2, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 3, 4096 * 18).unwrap()),
],
);

// Prev and next both free
arena.free(a2);
assert_eq!(arena.free_tags.len(), 100);
assert_tags_eq(
&arena,
Expand All @@ -755,36 +769,54 @@ mod tests {
],
);

// Prev non-free, next free
// Change next tag start to merge with curr_tag, release curr_tag
// Prev free, next non-free
let a1 = arena.alloc(4096);
let _ = arena.alloc(4096);
assert_eq!(arena.free_tags.len(), 98);
let a2 = arena.alloc(4096);
let a3 = arena.alloc(4096);
arena.free(a1);
assert_eq!(arena.free_tags.len(), 97);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 2, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 3, 4096 * 18).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 3, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 4, 4096 * 17).unwrap()),
],
);
arena.free(a1);
arena.free(a2);
assert_eq!(arena.free_tags.len(), 98);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 2, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 3, 4096 * 18).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096, 4096 * 2).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096 * 3, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 4, 4096 * 17).unwrap()),
],
);

// Prev free, next non-free
// Change prev tag size to merge with curr_tag, release curr_tag

// Prev and next both free
// Change prev size to merge with both curr_tag and next, release curr_tag
// Prev non-free, next free
arena.free(a3);
let a1 = arena.alloc(4096);
assert_eq!(arena.free_tags.len(), 99);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Allocated, Boundary::new(4096, 4096).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096 * 2, 4096 * 19).unwrap()),
],
);
arena.free(a1);
assert_eq!(arena.free_tags.len(), 100);
assert_tags_eq(
&arena,
&[
Tag::new(TagType::Span, Boundary::new(4096, 4096 * 20).unwrap()),
Tag::new(TagType::Free, Boundary::new(4096, 4096 * 20).unwrap()),
],
);
}
}

0 comments on commit 4858483

Please sign in to comment.