1
0
mirror of https://github.com/bspeice/qadapt synced 2025-07-01 05:46:16 -04:00

Multi-threaded allocation checker!

Holy crap that was much harder than expected
This commit is contained in:
2018-11-10 01:30:39 -05:00
parent 18d1c3e6d1
commit 753b3a4e8b
3 changed files with 87 additions and 65 deletions

View File

@ -2,7 +2,8 @@
extern crate qadapt;
use qadapt::QADAPT;
use qadapt::set_panic;
use qadapt::enter_protected;
use qadapt::exit_protected;
#[global_allocator]
static Q: QADAPT = QADAPT;
@ -15,17 +16,17 @@ pub fn black_box<T>(dummy: T) -> T {
#[test]
fn test_copy() {
set_panic(true);
enter_protected();
black_box(0u8);
set_panic(false);
exit_protected();
}
#[test]
#[should_panic]
fn test_allocate() {
set_panic(true);
enter_protected();
let _x = Box::new(12);
set_panic(false);
exit_protected();
}
fn unit_result(b: bool) -> Result<(), ()> {
@ -38,51 +39,51 @@ fn unit_result(b: bool) -> Result<(), ()> {
#[test]
fn test_unit_result() {
set_panic(true);
enter_protected();
#[allow(unused)]
{ black_box(unit_result(true)); }
black_box(unit_result(true)).unwrap();
#[allow(unused)]
{ black_box(unit_result(false)); }
black_box(unit_result(false)).unwrap_err();
set_panic(false);
exit_protected();
}
#[test]
#[should_panic]
fn test_vec_push() {
let mut v = Vec::new();
set_panic(true);
enter_protected();
v.push(0);
}
#[test]
fn test_vec_push_capacity() {
let mut v = Vec::with_capacity(1);
set_panic(true);
enter_protected();
v.push(0);
v.pop();
v.push(0);
set_panic(false);
exit_protected();
}
#[test]
fn test_vec_with_zero() {
set_panic(true);
enter_protected();
let _v: Vec<u8> = black_box(Vec::with_capacity(0));
set_panic(false);
exit_protected();
}
#[test]
fn test_vec_new() {
set_panic(true);
enter_protected();
let _v: Vec<u8> = black_box(Vec::new());
set_panic(false);
exit_protected();
}
#[test]
#[should_panic]
fn test_vec_with_one() {
set_panic(true);
enter_protected();
let _v: Vec<u8> = Vec::with_capacity(1);
}