2016-07-17 08:34:26 +08:00
|
|
|
// This file is part of libfringe, a low-level green threading library.
|
|
|
|
// Copyright (c) whitequark <whitequark@whitequark.org>
|
2016-08-21 05:45:01 +08:00
|
|
|
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
|
|
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
|
|
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
|
|
// copied, modified, or distributed except according to those terms.
|
2016-07-17 08:34:26 +08:00
|
|
|
extern crate fringe;
|
|
|
|
|
2016-08-19 21:58:45 +08:00
|
|
|
use fringe::{Stack, SliceStack, OwnedStack, OsStack};
|
2016-07-17 08:34:26 +08:00
|
|
|
|
|
|
|
#[test]
|
2016-08-19 17:18:46 +08:00
|
|
|
fn slice_stack() {
|
|
|
|
let mut memory = [0; 1024];
|
|
|
|
let stack = SliceStack(&mut memory);
|
|
|
|
assert_eq!(stack.base() as isize - stack.limit() as isize, 1024);
|
|
|
|
}
|
|
|
|
|
2016-08-19 21:58:45 +08:00
|
|
|
#[test]
|
|
|
|
fn owned_stack() {
|
|
|
|
let stack = OwnedStack::new(1024);
|
|
|
|
assert_eq!(stack.base() as isize - stack.limit() as isize, 1024);
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:18:46 +08:00
|
|
|
#[test]
|
|
|
|
fn default_os_stack() {
|
2016-07-17 09:24:20 +08:00
|
|
|
let stack = OsStack::new(0).unwrap();
|
|
|
|
// Make sure the topmost page of the stack, at least, is accessible.
|
2016-08-12 07:18:36 +08:00
|
|
|
unsafe { *(stack.base().offset(-1)) = 0; }
|
2016-07-17 09:24:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-19 17:18:46 +08:00
|
|
|
fn one_page_os_stack() {
|
2016-07-17 08:34:26 +08:00
|
|
|
let stack = OsStack::new(4096).unwrap();
|
|
|
|
// Make sure the topmost page of the stack, at least, is accessible.
|
2016-08-12 07:18:36 +08:00
|
|
|
unsafe { *(stack.base().offset(-1)) = 0; }
|
2016-07-17 08:34:26 +08:00
|
|
|
}
|