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

153 lines
3.8 KiB
Rust

#[cfg(test)]
#[cfg(feature = "hooks")]
mod tests {
use core::ptr::null;
use asan::{expect_panic, hooks::wcscmp::wcscmp, wchar_t};
use widestring::widecstr;
#[test]
fn test_wcscmp_null_s1() {
expect_panic();
let data = [0u16; 10];
unsafe { wcscmp(null(), data.as_ptr() as *const wchar_t) };
unreachable!();
}
#[test]
fn test_wcscmp_null_s2() {
expect_panic();
let data = [0u16; 10];
unsafe { wcscmp(data.as_ptr() as *const wchar_t, null()) };
unreachable!();
}
#[test]
fn test_wcscmp_eq() {
let data = [1u16; 10];
let ret = unsafe {
wcscmp(
data.as_ptr() as *const wchar_t,
data.as_ptr() as *const wchar_t,
)
};
assert_eq!(ret, 0);
}
#[test]
fn test_wcscmp_zero_length_both() {
let data = [0u16; 10];
let ret = unsafe {
wcscmp(
data.as_ptr() as *const wchar_t,
data.as_ptr() as *const wchar_t,
)
};
assert_eq!(ret, 0);
}
#[test]
fn test_wcscmp_zero_length_s1() {
let data1 = [0u16; 10];
let data2 = [1u16; 10];
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret < 0);
}
#[test]
fn test_wcscmp_zero_length_s2() {
let data1 = [1u16; 10];
let data2 = [0u16; 10];
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret > 0);
}
#[test]
fn test_wcscmp_eq_string() {
let data1 = widecstr!("abcdefghij");
let data2 = widecstr!("abcdefghij");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert_eq!(ret, 0);
}
#[test]
fn test_wcscmp_s1_shorter() {
let data1 = widecstr!("abcdefghi");
let data2 = widecstr!("abcdefghij");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret < 0);
}
#[test]
fn test_wcscmp_s1_longer() {
let data1 = widecstr!("abcdefghij");
let data2 = widecstr!("abcdefghi");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret > 0);
}
#[test]
fn test_wcscmp_s1_less_than() {
let data1 = widecstr!("abcdefghii");
let data2 = widecstr!("abcdefghij");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret < 0);
}
#[test]
fn test_wcscmp_s1_greater_than() {
let data1 = widecstr!("abcdefghik");
let data2 = widecstr!("abcdefghij");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret > 0);
}
#[test]
fn test_wcscmp_case_not_ignored() {
let data1 = widecstr!("abcdefghijklmnopqrstuvwxyz");
let data2 = widecstr!("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
let ret = unsafe {
wcscmp(
data1.as_ptr() as *const wchar_t,
data2.as_ptr() as *const wchar_t,
)
};
assert!(ret > 0);
}
}