From be21d758141b1d189a500bdc607b6714af7d2e82 Mon Sep 17 00:00:00 2001 From: edef Date: Mon, 20 Jul 2015 23:36:45 -0400 Subject: [PATCH] add (ignored) test for floating point exception state Thanks, @talchas! Fix #13 --- tests/fpe.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/fpe.rs diff --git a/tests/fpe.rs b/tests/fpe.rs new file mode 100644 index 0000000..90e5868 --- /dev/null +++ b/tests/fpe.rs @@ -0,0 +1,42 @@ +// This file is part of libfringe, a low-level green threading library. +// Copyright (c) 2015, Ben Segall +// Copyright (c) 2015, edef +// See the LICENSE file included in this distribution. +#![cfg(target_os = "linux")] +#![feature(test)] +#![feature(thread_local)] +#![feature(asm)] +extern crate fringe; +extern crate test; +use fringe::Context; +use test::black_box; + +#[thread_local] +static mut ctx_slot: *mut Context<'static, fringe::OsStack> = 0 as *mut Context<_>; + +const FE_DIVBYZERO: i32 = 0x4; +extern { + fn feenableexcept(except: i32) -> i32; +} + +#[test] +#[ignore] +fn fpe() { + unsafe { + let stack = fringe::OsStack::new(4 << 20).unwrap(); + + let mut ctx = Context::new(stack, move || { + println!("it's alive!"); + loop { + println!("{:?}", 1.0/black_box(0.0)); + Context::swap(ctx_slot, ctx_slot); + } + }); + + ctx_slot = &mut ctx; + + Context::swap(ctx_slot, ctx_slot); + feenableexcept(FE_DIVBYZERO); + Context::swap(ctx_slot, ctx_slot); + } +}