2018-11-10 20:54:35 -05:00
|
|
|
extern crate qadapt;
|
|
|
|
|
|
|
|
use qadapt::allocate_panic;
|
2018-11-11 22:34:05 -05:00
|
|
|
use qadapt::QADAPT;
|
2018-11-10 20:54:35 -05:00
|
|
|
|
2018-11-11 22:22:24 -05:00
|
|
|
#[global_allocator]
|
|
|
|
static Q: QADAPT = QADAPT;
|
|
|
|
|
2018-11-10 20:54:35 -05:00
|
|
|
#[allocate_panic]
|
|
|
|
fn allocates() {
|
2018-11-11 22:22:24 -05:00
|
|
|
assert_eq!(::qadapt::protection_level(), 1);
|
2018-11-11 22:34:05 -05:00
|
|
|
// Without boxing, release profile can actually optimize out the allocation
|
|
|
|
let mut v = Box::new(Vec::new());
|
2018-11-11 22:22:24 -05:00
|
|
|
v.push(1);
|
2018-11-10 20:54:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allocate_panic]
|
|
|
|
fn no_allocate() {
|
2018-11-11 22:22:24 -05:00
|
|
|
assert_eq!(::qadapt::protection_level(), 1);
|
2018-11-10 20:54:35 -05:00
|
|
|
let _v: Vec<()> = Vec::with_capacity(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_allocate() {
|
|
|
|
no_allocate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn test_allocates() {
|
|
|
|
allocates();
|
|
|
|
}
|