mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-14 11:30:38 +11:00
Add some more allocation tests
This commit is contained in:
parent
b30cc7715c
commit
22189eb809
2 changed files with 47 additions and 1 deletions
agb/src/agb_alloc
|
@ -75,7 +75,7 @@ unsafe impl GlobalAlloc for BlockAllocator {
|
|||
// find a block that this current request fits in
|
||||
let block_layout = Layout::new::<Block>();
|
||||
let (full_layout, offset) = block_layout.extend(layout).unwrap();
|
||||
|
||||
|
||||
{
|
||||
let state = self.state.lock();
|
||||
let mut current_block = state.first_block;
|
||||
|
|
|
@ -25,6 +25,8 @@ mod test {
|
|||
|
||||
use super::*;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[test_case]
|
||||
fn test_box(_gba: &mut crate::Gba) {
|
||||
|
@ -42,4 +44,48 @@ mod test {
|
|||
address
|
||||
);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_vec(_gba: &mut crate::Gba) {
|
||||
let mut v = Vec::with_capacity(5);
|
||||
|
||||
for i in 0..100 {
|
||||
v.push(i);
|
||||
}
|
||||
|
||||
for i in 0..100 {
|
||||
assert_eq!(v[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_creating_and_removing_things(_gba: &mut crate::Gba) {
|
||||
let item = Box::new(1);
|
||||
for i in 0..1_000 {
|
||||
let x = Box::new(i);
|
||||
assert_eq!(*x, i);
|
||||
let address = &*x as *const _ as usize;
|
||||
assert!(
|
||||
address >= EWRAM_START && address < EWRAM_END,
|
||||
"ewram is located between 0x0200_0000 and 0x0204_0000, address was actually found to be {:#010X}",
|
||||
address
|
||||
);
|
||||
}
|
||||
|
||||
assert_eq!(*item, 1);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_adding_to_2_different_vectors(_gba: &mut crate::Gba) {
|
||||
let mut v1 = vec![1, 2, 3];
|
||||
let mut v2 = vec![4, 5, 6];
|
||||
|
||||
for i in 0..100 {
|
||||
v1.push(i + 100);
|
||||
v2.push(i + 1000);
|
||||
}
|
||||
|
||||
assert_eq!(v1[40], 137);
|
||||
assert_eq!(v2[78], 1075);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue