From 10eeeaf9e78ebda470ea28d62efce06bd7c98eaa Mon Sep 17 00:00:00 2001 From: Corwin Date: Tue, 21 Jun 2022 02:00:29 +0100 Subject: [PATCH] a test for agbabi memset --- agb/src/agbabi/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/agb/src/agbabi/mod.rs b/agb/src/agbabi/mod.rs index 65f74c4f..375268b4 100644 --- a/agb/src/agbabi/mod.rs +++ b/agb/src/agbabi/mod.rs @@ -1,5 +1,42 @@ #[cfg(test)] mod test { + mod memset { + use crate::Gba; + use alloc::vec; + + extern "C" { + fn __aeabi_memset(dest: *mut u8, n: usize, v: u8); + fn __aeabi_memset4(dest: *mut u8, n: usize, v: u8); + } + + #[test_case] + fn test_memset_with_different_sizes(_gba: &mut Gba) { + let mut values = vec![0u8; 100]; + + let v = 0x12; + + for n in 0..80 { + values.fill(0xFF); + + unsafe { + __aeabi_memset4(values.as_mut_ptr().wrapping_offset(10), n, v); + } + + for (i, &v) in values.iter().enumerate().take(10) { + assert_eq!(v, 0xFF, "underrun at {}", i); + } + + for i in 0..n { + assert_eq!(values[10 + i], v, "incorrect value at {}", i + 10); + } + + for (i, &v) in values.iter().enumerate().skip(10 + n) { + assert_eq!(v, 0xFF, "overrun at {}", i); + } + } + } + } + mod memcpy { use alloc::vec;