Check sizes 0..80 in size with 0..10 offset for memset

This commit is contained in:
Gwilym Kuiper 2022-06-22 22:00:26 +01:00
parent 10eeeaf9e7
commit cb5763ed53
2 changed files with 22 additions and 17 deletions

View file

@ -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

View file

@ -5,33 +5,38 @@ mod test {
use alloc::vec;
extern "C" {
fn __aeabi_memset(dest: *mut u8, n: usize, v: u8);
fn __agbabi_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) {
fn test_memset_with_different_sizes_and_offsets(_gba: &mut Gba) {
let mut values = vec![0u8; 100];
let v = 0x12;
let stored_value = 0x12;
for n in 0..80 {
for o in 0..10 {
values.fill(0xFF);
unsafe {
__aeabi_memset4(values.as_mut_ptr().wrapping_offset(10), n, v);
__agbabi_memset(values.as_mut_ptr().add(o), n, stored_value);
}
for (i, &v) in values.iter().enumerate().take(10) {
assert_eq!(v, 0xFF, "underrun at {}", i);
for (i, &v) in values.iter().enumerate().take(o) {
assert_eq!(v, 0xFF, "underrun at {i}, offset {o}, size {n}");
}
for i in 0..n {
assert_eq!(values[10 + i], v, "incorrect value at {}", i + 10);
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(10 + n) {
assert_eq!(v, 0xFF, "overrun at {}", i);
for (i, &v) in values.iter().enumerate().skip(o + n) {
assert_eq!(v, 0xFF, "overrun at {i}, offset {o}, size {n}");
}
}
}
}