Merge pull request #113 from gwilymk/add-test-for-rust-bug

Add test that data_end is in the correct place
This commit is contained in:
Gwilym Kuiper 2021-10-04 20:38:54 +01:00 committed by GitHub
commit 94309a2518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,16 +3,6 @@ use core::ptr::NonNull;
use crate::interrupt::Mutex; 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 { pub(crate) struct BumpAllocator {
current_ptr: Mutex<Option<NonNull<u8>>>, current_ptr: Mutex<Option<NonNull<u8>>>,
} }
@ -60,3 +50,28 @@ unsafe impl GlobalAlloc for BumpAllocator {
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} 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"
);
}