mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Merge pull request #242 from corwinkuiper/memset-test
a test for agbabi memset
This commit is contained in:
commit
0b1ed3a3dd
|
@ -19,13 +19,13 @@
|
|||
.balign 4
|
||||
|
||||
.section .iwram.__aeabi_memset, "ax", %progbits
|
||||
.global __agbabi_memset
|
||||
__agbabi_memset:
|
||||
.global __aeabi_memclr
|
||||
__aeabi_memclr:
|
||||
mov r2, #0
|
||||
b .LskipShifts
|
||||
|
||||
.global __agbabi_memset
|
||||
__agbabi_memset:
|
||||
.global __aeabi_memset
|
||||
__aeabi_memset:
|
||||
mov r2, r2, lsl #24
|
||||
|
|
|
@ -1,5 +1,113 @@
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
mod memset {
|
||||
use core::slice;
|
||||
|
||||
use crate::Gba;
|
||||
use alloc::vec;
|
||||
|
||||
extern "C" {
|
||||
fn __agbabi_memset(dest: *mut u8, n: usize, v: u8);
|
||||
fn __aeabi_memset4(dest: *mut u32, n: usize, v: u8);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memset_with_different_sizes_and_offsets(_gba: &mut Gba) {
|
||||
let mut values = vec![0u8; 100];
|
||||
|
||||
let stored_value = 0x12;
|
||||
|
||||
for n in 0..80 {
|
||||
for o in 0..10 {
|
||||
values.fill(0xFF);
|
||||
|
||||
unsafe {
|
||||
__agbabi_memset(values.as_mut_ptr().add(o), n, stored_value);
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().take(o) {
|
||||
assert_eq!(v, 0xFF, "underrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().skip(o).take(n) {
|
||||
assert_eq!(
|
||||
v, stored_value,
|
||||
"incorrect value at {i}, offset {o}, size {n}"
|
||||
);
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().skip(o + n) {
|
||||
assert_eq!(v, 0xFF, "overrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memset4_with_different_sizes_and_offsets(_gba: &mut Gba) {
|
||||
let mut values = vec![0u32; 100];
|
||||
|
||||
let stored_value = 0x12;
|
||||
|
||||
for n in 0..80 {
|
||||
for o in 0..10 {
|
||||
values.fill(0xFF);
|
||||
|
||||
unsafe {
|
||||
__aeabi_memset4(values.as_mut_ptr().add(o), n * 4, stored_value);
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().take(o) {
|
||||
assert_eq!(v, 0xFF, "underrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().skip(o).take(n) {
|
||||
assert_eq!(
|
||||
v, 0x12121212,
|
||||
"incorrect value at {i}, offset {o}, size {n}"
|
||||
);
|
||||
}
|
||||
|
||||
for (i, &v) in values.iter().enumerate().skip(o + n) {
|
||||
assert_eq!(v, 0xFF, "overrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_memset4_with_non_word_size_sizes_and_offsets(_gba: &mut Gba) {
|
||||
let mut values = vec![0u32; 100];
|
||||
|
||||
let stored_value = 0x12;
|
||||
|
||||
for n in 0..80 {
|
||||
for o in 0..10 {
|
||||
values.fill(0xFFFFFFFF);
|
||||
|
||||
unsafe {
|
||||
__aeabi_memset4(values.as_mut_ptr().add(o), n, stored_value);
|
||||
}
|
||||
|
||||
let values_bytes: &[u8] =
|
||||
unsafe { slice::from_raw_parts(values.as_ptr().cast(), values.len() * 4) };
|
||||
|
||||
for (i, &v) in values_bytes.iter().enumerate().take(o * 4) {
|
||||
assert_eq!(v, 0xFF, "underrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
|
||||
for (i, &v) in values_bytes.iter().enumerate().skip(o * 4).take(n) {
|
||||
assert_eq!(v, 0x12, "incorrect value at {i}, offset {o}, size {n}");
|
||||
}
|
||||
|
||||
for (i, &v) in values_bytes.iter().enumerate().skip(o * 4 + n) {
|
||||
assert_eq!(v, 0xFF, "overrun at {i}, offset {o}, size {n}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod memcpy {
|
||||
use alloc::vec;
|
||||
|
||||
|
|
Loading…
Reference in a new issue