From a31efe71566a55122df45f620ea0bee1f856cb54 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Mon, 4 Oct 2021 20:15:34 +0100 Subject: [PATCH] Add test that data_end is in the correct place --- agb/src/agb_alloc/bump_allocator.rs | 35 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/agb/src/agb_alloc/bump_allocator.rs b/agb/src/agb_alloc/bump_allocator.rs index 733e6667..98038629 100644 --- a/agb/src/agb_alloc/bump_allocator.rs +++ b/agb/src/agb_alloc/bump_allocator.rs @@ -3,16 +3,6 @@ use core::ptr::NonNull; use crate::interrupt::Mutex; -fn get_data_end() -> usize { - extern "C" { - static __ewram_data_end: usize; - } - - // TODO: This seems completely wrong, but without the &, rust generates - // a double dereference :/. Maybe a bug in nightly? - (unsafe { &__ewram_data_end }) as *const _ as usize -} - pub(crate) struct BumpAllocator { current_ptr: Mutex>>, } @@ -60,3 +50,28 @@ unsafe impl GlobalAlloc for BumpAllocator { unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} } + +fn get_data_end() -> usize { + extern "C" { + static __ewram_data_end: usize; + } + + // TODO: This seems completely wrong, but without the &, rust generates + // a double dereference :/. Maybe a bug in nightly? + (unsafe { &__ewram_data_end }) as *const _ as usize +} + +#[test_case] +fn should_return_data_end_somewhere_in_ewram(_gba: &mut crate::Gba) { + let data_end = get_data_end(); + + assert!( + 0x0200_0000 <= data_end, + "data end should be bigger than 0x0200_0000, got {}", + data_end + ); + assert!( + 0x0204_0000 > data_end, + "data end should be smaller than 0x0203_0000" + ); +}