Skip to content

Commit

Permalink
revise tests for the talc-based allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Jul 27, 2023
1 parent a3a144e commit 8f1c64c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/mm/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ mod tests {
use super::*;

#[test]
fn empty() {
let mut allocator = GlobalAllocator::empty();
fn basic() {
const SIZE: usize = 0x1000;
static mut ARENA: [u8; SIZE] = [0; SIZE];

let mut allocator = LockedAllocator::empty();
unsafe {
allocator.init(ARENA.as_mut_ptr(), SIZE);
}

let layout = Layout::from_size_align(1, 1).unwrap();
// we have 4 kbyte static memory
assert!(allocator.allocate(layout.clone()).is_ok());
assert!(unsafe { !allocator.alloc(layout.clone()).is_null() });

let layout = Layout::from_size_align(0x1000, mem::align_of::<usize>());
let addr = allocator.allocate(layout.unwrap());
assert!(addr.is_err());
let layout = Layout::from_size_align(0x1000, mem::align_of::<usize>()).unwrap();
let addr = unsafe { allocator.alloc(layout) };
assert!(addr.is_null());
}
}

0 comments on commit 8f1c64c

Please sign in to comment.