mirror of
https://github.com/bspeice/qadapt
synced 2025-08-27 09:46:47 -04:00
Strip QADAPT symbols for release-mode builds
This commit is contained in:
@ -3,6 +3,7 @@ extern crate qadapt;
|
||||
|
||||
use qadapt::enter_protected;
|
||||
use qadapt::exit_protected;
|
||||
use qadapt::protection_level;
|
||||
use qadapt::QADAPT;
|
||||
|
||||
#[global_allocator]
|
||||
@ -59,6 +60,11 @@ fn test_vec_push() {
|
||||
let mut v = Vec::new();
|
||||
enter_protected();
|
||||
v.push(0);
|
||||
// We don't make it here in debug mode, but in release mode,
|
||||
// pushing one element doesn't trigger an allocation. Instead,
|
||||
// we use a box to force it onto the heap
|
||||
assert_eq!(protection_level(), 1);
|
||||
let _b = Box::new(v);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -89,7 +95,12 @@ fn test_vec_new() {
|
||||
#[should_panic]
|
||||
fn test_vec_with_one() {
|
||||
enter_protected();
|
||||
let _v: Vec<u8> = Vec::with_capacity(1);
|
||||
let v: Vec<u8> = Vec::with_capacity(1);
|
||||
// We don't make it here in debug mode, but in release mode,
|
||||
// pushing one element doesn't trigger an allocation. Instead,
|
||||
// we use a box to force it onto the heap
|
||||
assert_eq!(protection_level(), 1);
|
||||
let _b = Box::new(v);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -7,64 +7,58 @@ use qadapt::QADAPT;
|
||||
#[global_allocator]
|
||||
static Q: QADAPT = QADAPT;
|
||||
|
||||
#[allocate_panic]
|
||||
fn allocates() {
|
||||
assert_eq!(::qadapt::protection_level(), 1);
|
||||
// Without boxing, release profile can actually optimize out the allocation
|
||||
let mut v = Box::new(Vec::new());
|
||||
v.push(1);
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate() {
|
||||
#[cfg(not(release))]
|
||||
{
|
||||
let _v = 0;
|
||||
}
|
||||
assert_eq!(::qadapt::protection_level(), 1);
|
||||
let _v: Vec<()> = Vec::with_capacity(0);
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_ret() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_implicit_ret() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_arg(b: bool) -> bool {
|
||||
b
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_args(_b: bool, _u: usize, i: i64) -> i64 {
|
||||
i
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn return_result(r: Result<usize, io::Error>) -> Result<Result<usize, io::Error>, ()> {
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_no_allocate() {
|
||||
no_allocate();
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn allocates() {
|
||||
assert_eq!(::qadapt::protection_level(), 1);
|
||||
// Without boxing, release profile can actually optimize out the allocation
|
||||
let mut v = Box::new(Vec::new());
|
||||
v.push(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn macro_allocates() {
|
||||
allocates();
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_ret() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_return() {
|
||||
assert!(no_allocate_ret());
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_implicit_ret() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_implicit_return() {
|
||||
assert!(no_allocate_ret());
|
||||
assert!(no_allocate_implicit_ret());
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_arg(b: bool) -> bool {
|
||||
b
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -73,13 +67,23 @@ fn macro_allocate_arg() {
|
||||
no_allocate_arg(false);
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn no_allocate_args(_b: bool, _u: usize, i: i64) -> i64 {
|
||||
i
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_allocate_args() {
|
||||
no_allocate_args(true, 0, -1);
|
||||
no_allocate_args(false, 4, -90);
|
||||
}
|
||||
|
||||
#[allocate_panic]
|
||||
fn return_result(r: Result<usize, io::Error>) -> Result<Result<usize, io::Error>, ()> {
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_return_result() {
|
||||
return_result(Ok(16)).unwrap().unwrap();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user