2018-09-21 22:34:42 -04:00
|
|
|
extern crate qadapt;
|
|
|
|
|
|
|
|
use qadapt::QADAPT;
|
|
|
|
use std::alloc::alloc;
|
|
|
|
use std::alloc::Layout;
|
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
static A: QADAPT = QADAPT::INIT;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alloc_nonnull() {
|
|
|
|
unsafe {
|
|
|
|
assert!(!alloc(Layout::new::<u32>()).is_null())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Empty;
|
|
|
|
|
|
|
|
struct NonEmpty {
|
|
|
|
_x: i32,
|
|
|
|
_y: i32
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allocation_flag() {
|
2018-09-23 12:37:07 -04:00
|
|
|
A.reset_allocation_state();
|
|
|
|
A.enable_recording_current();
|
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-21 22:34:42 -04:00
|
|
|
|
|
|
|
let _x = 24;
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-21 22:34:42 -04:00
|
|
|
|
|
|
|
let _x = Empty {};
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-21 22:34:42 -04:00
|
|
|
|
|
|
|
let _x = NonEmpty {
|
|
|
|
_x: 42,
|
|
|
|
_y: 84
|
|
|
|
};
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-21 22:34:42 -04:00
|
|
|
|
|
|
|
let _x = Box::new(42);
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(A.has_allocated_current());
|
2018-09-22 19:57:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
fn no_op() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_alloc_during_noop() {
|
2018-09-23 12:37:07 -04:00
|
|
|
A.reset_allocation_state();
|
|
|
|
A.enable_recording_current();
|
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-22 19:57:58 -04:00
|
|
|
|
|
|
|
no_op();
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-22 19:57:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
fn allocates() {
|
|
|
|
let _x = Box::new(42);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alloc_during_func_call() {
|
2018-09-23 12:37:07 -04:00
|
|
|
A.reset_allocation_state();
|
|
|
|
A.enable_recording_current();
|
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-22 19:57:58 -04:00
|
|
|
|
|
|
|
allocates();
|
2018-09-23 12:37:07 -04:00
|
|
|
assert!(A.has_allocated_current());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn allocates_unrecorded() {
|
|
|
|
A.reset_allocation_state();
|
|
|
|
assert!(!A.has_allocated_current());
|
|
|
|
|
|
|
|
allocates();
|
|
|
|
assert!(!A.has_allocated_current());
|
2018-09-21 22:34:42 -04:00
|
|
|
}
|