]> git.lizzy.rs Git - rust.git/blob - src/liballoc/alloc/tests.rs
Rollup merge of #68473 - nopsledder:rust_sanitizer_fuchsia, r=alexcrichton
[rust.git] / src / liballoc / alloc / tests.rs
1 use super::*;
2
3 extern crate test;
4 use crate::boxed::Box;
5 use test::Bencher;
6
7 #[test]
8 fn allocate_zeroed() {
9     unsafe {
10         let layout = Layout::from_size_align(1024, 1).unwrap();
11         let ptr =
12             Global.alloc_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));
13
14         let mut i = ptr.cast::<u8>().as_ptr();
15         let end = i.add(layout.size());
16         while i < end {
17             assert_eq!(*i, 0);
18             i = i.offset(1);
19         }
20         Global.dealloc(ptr, layout);
21     }
22 }
23
24 #[bench]
25 #[cfg_attr(miri, ignore)] // Miri does not support benchmarks
26 fn alloc_owned_small(b: &mut Bencher) {
27     b.iter(|| {
28         let _: Box<_> = box 10;
29     })
30 }