From 5d27a7c0b24d1a5092490d3dd34fa02eab858a31 Mon Sep 17 00:00:00 2001 From: lemolatoon <63438515+lemolatoon@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:24:19 +0900 Subject: [PATCH] Fix test of bump allocator --- kernel-lib/src/allocator.rs | 9 +++++---- kernel-lib/src/allocator/bump_allocator.rs | 7 ++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/kernel-lib/src/allocator.rs b/kernel-lib/src/allocator.rs index d9d805d..509081e 100644 --- a/kernel-lib/src/allocator.rs +++ b/kernel-lib/src/allocator.rs @@ -182,8 +182,6 @@ where #[cfg(test)] mod tests { - use std::println; - use super::*; pub fn alloc_huge_times_template( @@ -250,7 +248,10 @@ mod tests { for i in 0..n_times { let mut vec = Vec::::with_capacity_in(i, allocator); let mut vec2 = Vec::::with_capacity_in(i, allocator); - let one = Box::::new_in(core::hint::black_box(1), allocator); + let mut one = Box::::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)); } @@ -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); } } diff --git a/kernel-lib/src/allocator/bump_allocator.rs b/kernel-lib/src/allocator/bump_allocator.rs index e25f83e..b03c296 100644 --- a/kernel-lib/src/allocator/bump_allocator.rs +++ b/kernel-lib/src/allocator/bump_allocator.rs @@ -62,8 +62,6 @@ impl_allocator_for_global_alloc!(crate::mutex::Mutex); #[cfg(test)] mod tests { - use std::println; - use super::*; use crate::allocator::tests::{ alloc_huge_times_template, alloc_huge_times_with_value_template, @@ -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); } }