about summary refs log tree commit diff
path: root/src/liballoc/alloc
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-02 01:40:56 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-02 01:59:01 +0300
commit3d0d6ee271a34d2329235b9a04cf4a421d9026cd (patch)
treebdd574c1b42fe28031d69a18d7f7694ce8742021 /src/liballoc/alloc
parent310b9fc76002066feb89dcfbf8e88b34fe5f4ad3 (diff)
downloadrust-3d0d6ee271a34d2329235b9a04cf4a421d9026cd.tar.gz
rust-3d0d6ee271a34d2329235b9a04cf4a421d9026cd.zip
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.
Diffstat (limited to 'src/liballoc/alloc')
-rw-r--r--src/liballoc/alloc/tests.rs30
1 files changed, 30 insertions, 0 deletions
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::<u8>().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;
+    })
+}