Rewrite the FPE test to not use Context directly
This commit is contained in:
parent
890e95b8a4
commit
375846bda5
26
tests/fpe.rs
26
tests/fpe.rs
|
@ -8,12 +8,9 @@
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
extern crate fringe;
|
extern crate fringe;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
use fringe::Context;
|
use fringe::{OsStack, Generator};
|
||||||
use test::black_box;
|
use test::black_box;
|
||||||
|
|
||||||
#[thread_local]
|
|
||||||
static mut ctx_slot: *mut Context<fringe::OsStack> = 0 as *mut Context<_>;
|
|
||||||
|
|
||||||
const FE_DIVBYZERO: i32 = 0x4;
|
const FE_DIVBYZERO: i32 = 0x4;
|
||||||
extern {
|
extern {
|
||||||
fn feenableexcept(except: i32) -> i32;
|
fn feenableexcept(except: i32) -> i32;
|
||||||
|
@ -22,20 +19,11 @@ extern {
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn fpe() {
|
fn fpe() {
|
||||||
unsafe extern "C" fn universe_destroyer(_arg: usize) -> ! {
|
let stack = OsStack::new(0).unwrap();
|
||||||
loop {
|
let mut gen = Generator::new(stack, move |yielder| {
|
||||||
println!("{:?}", 1.0/black_box(0.0));
|
yielder.generate(1.0 / black_box(0.0));
|
||||||
Context::swap(ctx_slot, ctx_slot, 0);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe { feenableexcept(FE_DIVBYZERO); }
|
||||||
let stack = fringe::OsStack::new(4 << 20).unwrap();
|
println!("{:?}", gen.next());
|
||||||
let mut ctx = Context::new(stack, universe_destroyer);
|
|
||||||
ctx_slot = &mut ctx;
|
|
||||||
|
|
||||||
Context::swap(ctx_slot, ctx_slot, 0);
|
|
||||||
feenableexcept(FE_DIVBYZERO);
|
|
||||||
Context::swap(ctx_slot, ctx_slot, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue