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

Enable per-thread tracking

This commit is contained in:
2018-09-23 12:37:07 -04:00
parent a2f21fb462
commit 7fde099c3a
5 changed files with 114 additions and 32 deletions

View File

@ -3,7 +3,6 @@ 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;
@ -24,23 +23,24 @@ struct NonEmpty {
#[test]
fn allocation_flag() {
A.clear_allocations();
assert!(!A.has_allocated());
A.reset_allocation_state();
A.enable_recording_current();
assert!(!A.has_allocated_current());
let _x = 24;
assert!(!A.has_allocated());
assert!(!A.has_allocated_current());
let _x = Empty {};
assert!(!A.has_allocated());
assert!(!A.has_allocated_current());
let _x = NonEmpty {
_x: 42,
_y: 84
};
assert!(!A.has_allocated());
assert!(!A.has_allocated_current());
let _x = Box::new(42);
assert!(A.has_allocated());
assert!(A.has_allocated_current());
}
#[inline(never)]
@ -48,11 +48,12 @@ fn no_op() {}
#[test]
fn no_alloc_during_noop() {
A.clear_allocations();
assert!(!A.has_allocated());
A.reset_allocation_state();
A.enable_recording_current();
assert!(!A.has_allocated_current());
no_op();
assert!(!A.has_allocated());
assert!(!A.has_allocated_current());
}
#[inline(never)]
@ -62,9 +63,19 @@ fn allocates() {
#[test]
fn alloc_during_func_call() {
A.clear_allocations();
assert!(!A.has_allocated());
A.reset_allocation_state();
A.enable_recording_current();
assert!(!A.has_allocated_current());
allocates();
assert!(A.has_allocated());
assert!(A.has_allocated_current());
}
#[test]
fn allocates_unrecorded() {
A.reset_allocation_state();
assert!(!A.has_allocated_current());
allocates();
assert!(!A.has_allocated_current());
}

View File

@ -1,20 +1,18 @@
extern crate qadapt;
use qadapt::QADAPT;
use std::sync::atomic::Ordering;
#[global_allocator]
static A: QADAPT = QADAPT::INIT;
#[test]
fn init() {
// Because the Allocator and its internals isn't the only "pre-main" allocation
// that happens, when starting up we expect to see that A has in fact allocated
assert!(A.has_allocated());
assert!(!A.has_allocated_current());
A.reset_allocation_state();
A.enable_recording_current();
A.clear_allocations();
assert!(!A.has_allocated());
assert!(!A.has_allocated_current());
let _x = Box::new(42);
assert!(A.has_allocated());
assert!(A.has_allocated_current());
}