mirror of
https://github.com/bspeice/qadapt
synced 2025-06-30 21:36:41 -04:00
Much simpler take, and actually works this time.
This commit is contained in:
@ -1,81 +0,0 @@
|
||||
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() {
|
||||
A.reset_allocation_state();
|
||||
A.enable_recording_current();
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
let _x = 24;
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
let _x = Empty {};
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
let _x = NonEmpty {
|
||||
_x: 42,
|
||||
_y: 84
|
||||
};
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
let _x = Box::new(42);
|
||||
assert!(A.has_allocated_current());
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn no_op() {}
|
||||
|
||||
#[test]
|
||||
fn no_alloc_during_noop() {
|
||||
A.reset_allocation_state();
|
||||
A.enable_recording_current();
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
no_op();
|
||||
assert!(!A.has_allocated_current());
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn allocates() {
|
||||
let _x = Box::new(42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alloc_during_func_call() {
|
||||
A.reset_allocation_state();
|
||||
A.enable_recording_current();
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
allocates();
|
||||
assert!(A.has_allocated_current());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allocates_unrecorded() {
|
||||
A.reset_allocation_state();
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
allocates();
|
||||
assert!(!A.has_allocated_current());
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
extern crate qadapt;
|
||||
|
||||
use qadapt::QADAPT;
|
||||
|
||||
#[global_allocator]
|
||||
static A: QADAPT = QADAPT::INIT;
|
||||
|
||||
#[test]
|
||||
fn init() {
|
||||
assert!(!A.has_allocated_current());
|
||||
A.reset_allocation_state();
|
||||
A.enable_recording_current();
|
||||
|
||||
assert!(!A.has_allocated_current());
|
||||
|
||||
let _x = Box::new(42);
|
||||
assert!(A.has_allocated_current());
|
||||
}
|
30
tests/simple.rs
Normal file
30
tests/simple.rs
Normal file
@ -0,0 +1,30 @@
|
||||
#![feature(asm)]
|
||||
|
||||
extern crate qadapt;
|
||||
|
||||
use qadapt::QADAPT;
|
||||
use qadapt::set_panic;
|
||||
|
||||
#[global_allocator]
|
||||
static Q: QADAPT = QADAPT;
|
||||
|
||||
pub fn black_box<T>(dummy: T) -> T {
|
||||
// Taken from test lib, need to mark the arg as non-introspectable
|
||||
unsafe {asm!("" : : "r"(&dummy))}
|
||||
dummy
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_copy() {
|
||||
set_panic(true);
|
||||
black_box(0u8);
|
||||
set_panic(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_allocate() {
|
||||
set_panic(true);
|
||||
let _x = Box::new(12);
|
||||
set_panic(false);
|
||||
}
|
Reference in New Issue
Block a user