2018-11-05 21:58:33 -05:00
|
|
|
#![feature(asm)]
|
|
|
|
extern crate qadapt;
|
|
|
|
|
2018-11-10 01:30:39 -05:00
|
|
|
use qadapt::enter_protected;
|
|
|
|
use qadapt::exit_protected;
|
2018-11-10 21:59:39 -05:00
|
|
|
use qadapt::QADAPT;
|
2018-11-05 21:58:33 -05:00
|
|
|
|
|
|
|
#[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
|
2018-11-10 21:59:39 -05:00
|
|
|
unsafe { asm!("" : : "r"(&dummy)) }
|
2018-11-05 21:58:33 -05:00
|
|
|
dummy
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_copy() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-05 21:58:33 -05:00
|
|
|
black_box(0u8);
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-05 21:58:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn test_allocate() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-05 21:58:33 -05:00
|
|
|
let _x = Box::new(12);
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn unit_result(b: bool) -> Result<(), ()> {
|
|
|
|
if b {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unit_result() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
#[allow(unused)]
|
2018-11-10 21:59:39 -05:00
|
|
|
{
|
|
|
|
black_box(unit_result(true));
|
|
|
|
}
|
2018-11-06 20:51:44 -05:00
|
|
|
black_box(unit_result(true)).unwrap();
|
|
|
|
#[allow(unused)]
|
2018-11-10 21:59:39 -05:00
|
|
|
{
|
|
|
|
black_box(unit_result(false));
|
|
|
|
}
|
2018-11-06 20:51:44 -05:00
|
|
|
black_box(unit_result(false)).unwrap_err();
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn test_vec_push() {
|
|
|
|
let mut v = Vec::new();
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
v.push(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_vec_push_capacity() {
|
|
|
|
let mut v = Vec::with_capacity(1);
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
v.push(0);
|
|
|
|
v.pop();
|
|
|
|
v.push(0);
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_vec_with_zero() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
let _v: Vec<u8> = black_box(Vec::with_capacity(0));
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_vec_new() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
let _v: Vec<u8> = black_box(Vec::new());
|
2018-11-10 01:30:39 -05:00
|
|
|
exit_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn test_vec_with_one() {
|
2018-11-10 01:30:39 -05:00
|
|
|
enter_protected();
|
2018-11-06 20:51:44 -05:00
|
|
|
let _v: Vec<u8> = Vec::with_capacity(1);
|
2018-11-10 21:54:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn exit_too_often() {
|
|
|
|
enter_protected();
|
|
|
|
exit_protected();
|
|
|
|
exit_protected();
|
2018-11-10 21:59:39 -05:00
|
|
|
}
|