From 3d0d6ee271a34d2329235b9a04cf4a421d9026cd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 2 Aug 2019 01:40:56 +0300 Subject: liballoc: Unconfigure tests during normal build Remove additional libcore-like restrictions from liballoc, turns out the testing works ok if the tests are a part of liballoc itself. --- src/liballoc/alloc/tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/liballoc/alloc/tests.rs (limited to 'src/liballoc/alloc') diff --git a/src/liballoc/alloc/tests.rs b/src/liballoc/alloc/tests.rs new file mode 100644 index 00000000000..c69f4e49ee1 --- /dev/null +++ b/src/liballoc/alloc/tests.rs @@ -0,0 +1,30 @@ +use super::*; + +extern crate test; +use test::Bencher; +use crate::boxed::Box; + +#[test] +fn allocate_zeroed() { + unsafe { + let layout = Layout::from_size_align(1024, 1).unwrap(); + let ptr = Global.alloc_zeroed(layout.clone()) + .unwrap_or_else(|_| handle_alloc_error(layout)); + + let mut i = ptr.cast::().as_ptr(); + let end = i.add(layout.size()); + while i < end { + assert_eq!(*i, 0); + i = i.offset(1); + } + Global.dealloc(ptr, layout); + } +} + +#[bench] +#[cfg(not(miri))] // Miri does not support benchmarks +fn alloc_owned_small(b: &mut Bencher) { + b.iter(|| { + let _: Box<_> = box 10; + }) +} -- cgit 1.4.1-3-g733a5