1
0
mirror of https://github.com/bspeice/qadapt synced 2025-06-30 21:36:41 -04:00

Add an initial pass on an allocation tracing tool

This commit is contained in:
2018-09-21 22:34:42 -04:00
commit a489f71ae2
5 changed files with 109 additions and 0 deletions

44
tests/basic.rs Normal file
View File

@ -0,0 +1,44 @@
extern crate qadapt;
use qadapt::QADAPT;
use std::alloc::alloc;
use std::alloc::Layout;
use std::sync::atomic::Ordering;
#[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() {
A.clear_allocations();
assert!(!A.has_allocated.load(Ordering::SeqCst));
let _x = 24;
assert!(!A.has_allocated.load(Ordering::SeqCst));
let _x = Empty {};
assert!(!A.has_allocated.load(Ordering::SeqCst));
let _x = NonEmpty {
_x: 42,
_y: 84
};
assert!(!A.has_allocated.load(Ordering::SeqCst));
let _x = Box::new(42);
assert!(A.has_allocated.load(Ordering::SeqCst));
}