FRET-LibAFL/libafl_qemu/librasan/asan/tests/hooks_aligned_alloc.rs
WorksButNotTested 728b1216bb
Librasan (#3023)
* Fixes to main

* Add librasan

* Party like it's 2024

* Fix snapshot module to work with guest asan

* Fix guest_asan module

* Fixes to runner

* Fix linking issues using a REL

* Fix qemu_launcher

* Change modify_mapping to a method

* Fix gasan_test

* Remove debug from Justfile

* Optimize release build of librasan

* Set ulimit for qasan and gasan tests

* Tidy up symbol renaming

* Add missing symbols for PPC

* Change to support rustix 1.0.0

* Canonicalize the CUSTOM_ASAN_PATH

* Review changes

* Restructure backends

* release_max_level_info

* More review changes

* Clippy fixes

* Changes to reduce the burden on the CI

* Fix macos clippy

---------

Co-authored-by: Your Name <you@example.com>
2025-03-10 17:27:55 +01:00

47 lines
1.1 KiB
Rust

#[cfg(test)]
#[cfg(feature = "hooks")]
mod tests {
use core::{ptr::null_mut, slice::from_raw_parts_mut};
use asan::{expect_panic, hooks::aligned_alloc::aligned_alloc};
#[test]
fn aligned_alloc_zero_size() {
let ret = unsafe { aligned_alloc(8, 0) };
assert_eq!(ret, null_mut());
}
#[test]
fn aligned_alloc_size_not_multiple() {
expect_panic();
unsafe { aligned_alloc(9, 8) };
unreachable!();
}
#[test]
fn aligned_alloc_power_of_two() {
let addr = unsafe { aligned_alloc(8, 8) };
assert_ne!(addr, null_mut());
assert_eq!(addr as usize & 7, 0);
}
#[test]
fn aligned_alloc_not_power_of_two() {
expect_panic();
unsafe { aligned_alloc(7, 24) };
unreachable!();
}
#[test]
fn aligned_alloc_buff() {
let ret = unsafe { aligned_alloc(32, 8) };
assert_ne!(ret, null_mut());
assert!(ret as usize & 0x1f == 0);
unsafe {
from_raw_parts_mut(ret as *mut u8, 8)
.iter_mut()
.for_each(|x| *x = 0)
};
}
}