Skip to content

Commit

Permalink
Fix test of bump allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Nov 18, 2023
1 parent 25bdbbd commit 5d27a7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 5 additions & 4 deletions kernel-lib/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ where

#[cfg(test)]
mod tests {
use std::println;

use super::*;

pub fn alloc_huge_times_template(
Expand Down Expand Up @@ -250,7 +248,10 @@ mod tests {
for i in 0..n_times {
let mut vec = Vec::<usize, _>::with_capacity_in(i, allocator);
let mut vec2 = Vec::<usize, _>::with_capacity_in(i, allocator);
let one = Box::<usize, _>::new_in(core::hint::black_box(1), allocator);
let mut one = Box::<usize, _>::try_new_uninit_in(allocator).unwrap();
unsafe {
one.as_mut_ptr().write_volatile(1);
}
for j in 0..i {
vec.push(core::hint::black_box(j));
}
Expand All @@ -263,7 +264,7 @@ mod tests {
assert_eq!(val, j);
assert_eq!(vec2[j], j);
}
assert_eq!(*one, 1);
assert_eq!(*unsafe { one.assume_init() }, 1);
}
}

Expand Down
7 changes: 2 additions & 5 deletions kernel-lib/src/allocator/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ impl_allocator_for_global_alloc!(crate::mutex::Mutex<BumpAllocator>);

#[cfg(test)]
mod tests {
use std::println;

use super::*;
use crate::allocator::tests::{
alloc_huge_times_template, alloc_huge_times_with_value_template,
Expand All @@ -82,12 +80,11 @@ mod tests {
#[test]
fn alloc_huge_times_with_value() {
const SIZE: usize = 100 * 1024;
static mut HEAP: &[u8] = &[0u8; SIZE];
static mut HEAP: [u8; SIZE] = [0u8; SIZE];
let allocator = crate::mutex::Mutex::new(BumpAllocator::new());
unsafe {
crate::lock!(allocator).init(HEAP.as_ptr() as usize, HEAP.as_ptr() as usize + SIZE)
};
// TODO: fix this
// alloc_huge_times_with_value_template(&allocator, SIZE / 1024);
alloc_huge_times_with_value_template(&allocator, SIZE / 1024);
}
}

0 comments on commit 5d27a7c

Please sign in to comment.