1
0
mirror of https://github.com/bspeice/qadapt synced 2025-07-01 22:06:49 -04:00

Revert "Don't use proc macro"

This reverts commit 000d0032a9.
This commit is contained in:
2018-11-14 23:38:21 -05:00
parent 000d0032a9
commit d9bc210ba0
10 changed files with 284 additions and 54 deletions

View File

@ -1,4 +1,4 @@
#[macro_use]
#![feature(asm)]
extern crate qadapt;
use qadapt::enter_protected;
@ -9,14 +9,17 @@ use qadapt::QADAPT;
#[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() {
let z = alloc_panic!({
let zero = 0;
zero
});
assert_eq!(z, 0);
enter_protected();
black_box(0u8);
exit_protected();
}
#[test]
@ -38,8 +41,16 @@ fn unit_result(b: bool) -> Result<(), ()> {
#[test]
fn test_unit_result() {
enter_protected();
unit_result(true).unwrap();
unit_result(false).unwrap_err();
#[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();
exit_protected();
}
@ -69,14 +80,14 @@ fn test_vec_push_capacity() {
#[test]
fn test_vec_with_zero() {
enter_protected();
let _v: Vec<u8> = Vec::with_capacity(0);
let _v: Vec<u8> = black_box(Vec::with_capacity(0));
exit_protected();
}
#[test]
fn test_vec_new() {
enter_protected();
let _v: Vec<u8> = Vec::new();
let _v: Vec<u8> = black_box(Vec::new());
exit_protected();
}

89
tests/macros.rs Normal file
View File

@ -0,0 +1,89 @@
extern crate qadapt;
use std::io;
use qadapt::allocate_panic;
use qadapt::QADAPT;
#[global_allocator]
static Q: QADAPT = QADAPT;
#[allocate_panic]
fn no_allocate() {
#[cfg(not(release))]
{
let _v = 0;
}
assert_eq!(::qadapt::protection_level(), 1);
let _v: Vec<()> = Vec::with_capacity(0);
}
#[test]
fn macro_no_allocate() {
no_allocate();
}
#[allocate_panic]
fn allocates() {
assert_eq!(::qadapt::protection_level(), 1);
// Without boxing, release profile can actually optimize out the allocation
let mut v = Box::new(Vec::new());
v.push(1);
}
#[test]
#[should_panic]
fn macro_allocates() {
allocates();
}
#[allocate_panic]
fn no_allocate_ret() -> bool {
return true;
}
#[test]
fn macro_return() {
assert!(no_allocate_ret());
}
#[allocate_panic]
fn no_allocate_implicit_ret() -> bool {
true
}
#[test]
fn macro_implicit_return() {
assert!(no_allocate_implicit_ret());
}
#[allocate_panic]
fn no_allocate_arg(b: bool) -> bool {
b
}
#[test]
fn macro_allocate_arg() {
no_allocate_arg(true);
no_allocate_arg(false);
}
#[allocate_panic]
fn no_allocate_args(_b: bool, _u: usize, i: i64) -> i64 {
i
}
#[test]
fn macro_allocate_args() {
no_allocate_args(true, 0, -1);
no_allocate_args(false, 4, -90);
}
#[allocate_panic]
fn return_result(r: Result<usize, io::Error>) -> Result<Result<usize, io::Error>, ()> {
Ok(r)
}
#[test]
fn macro_return_result() {
return_result(Ok(16)).unwrap().unwrap();
}

View File

@ -1,7 +0,0 @@
extern crate qadapt;
#[test]
#[should_panic]
fn panic_not_using_qadapt() {
::qadapt::enter_protected();
}