diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-09-06 14:36:26 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-09-06 14:36:26 +0200 |
| commit | 76ceeddb2b6fd4589cf8292d8dafa65a91ace019 (patch) | |
| tree | 11106836a5a37fc73a209a905786431ea0f10117 /src/test/run-pass/allocator | |
| parent | 20ca02569ae3e1dc29962e92739fbab632abf241 (diff) | |
| download | rust-76ceeddb2b6fd4589cf8292d8dafa65a91ace019.tar.gz rust-76ceeddb2b6fd4589cf8292d8dafa65a91ace019.zip | |
Migrated remaining `src/test/run-pass/` subdirectories to `src/test/ui/run-pass/`.
Diffstat (limited to 'src/test/run-pass/allocator')
| -rw-r--r-- | src/test/run-pass/allocator/auxiliary/custom-as-global.rs | 26 | ||||
| -rw-r--r-- | src/test/run-pass/allocator/auxiliary/custom.rs | 31 | ||||
| -rw-r--r-- | src/test/run-pass/allocator/auxiliary/helper.rs | 19 | ||||
| -rw-r--r-- | src/test/run-pass/allocator/custom.rs | 66 | ||||
| -rw-r--r-- | src/test/run-pass/allocator/xcrate-use.rs | 43 | ||||
| -rw-r--r-- | src/test/run-pass/allocator/xcrate-use2.rs | 56 |
6 files changed, 0 insertions, 241 deletions
diff --git a/src/test/run-pass/allocator/auxiliary/custom-as-global.rs b/src/test/run-pass/allocator/auxiliary/custom-as-global.rs deleted file mode 100644 index a3f05a01c5a..00000000000 --- a/src/test/run-pass/allocator/auxiliary/custom-as-global.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// no-prefer-dynamic - -#![crate_type = "rlib"] - -extern crate custom; - -use std::sync::atomic::{ATOMIC_USIZE_INIT, Ordering}; - -use custom::A; - -#[global_allocator] -static ALLOCATOR: A = A(ATOMIC_USIZE_INIT); - -pub fn get() -> usize { - ALLOCATOR.0.load(Ordering::SeqCst) -} diff --git a/src/test/run-pass/allocator/auxiliary/custom.rs b/src/test/run-pass/allocator/auxiliary/custom.rs deleted file mode 100644 index b17464e0419..00000000000 --- a/src/test/run-pass/allocator/auxiliary/custom.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// no-prefer-dynamic - -#![feature(allocator_api)] -#![crate_type = "rlib"] - -use std::alloc::{GlobalAlloc, System, Layout}; -use std::sync::atomic::{AtomicUsize, Ordering}; - -pub struct A(pub AtomicUsize); - -unsafe impl GlobalAlloc for A { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - self.0.fetch_add(1, Ordering::SeqCst); - System.alloc(layout) - } - - unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - self.0.fetch_add(1, Ordering::SeqCst); - System.dealloc(ptr, layout) - } -} diff --git a/src/test/run-pass/allocator/auxiliary/helper.rs b/src/test/run-pass/allocator/auxiliary/helper.rs deleted file mode 100644 index e75a432710d..00000000000 --- a/src/test/run-pass/allocator/auxiliary/helper.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// no-prefer-dynamic - -#![crate_type = "rlib"] - -use std::fmt; - -pub fn work_with(p: &fmt::Debug) { - drop(p); -} diff --git a/src/test/run-pass/allocator/custom.rs b/src/test/run-pass/allocator/custom.rs deleted file mode 100644 index 3a7f8fa8620..00000000000 --- a/src/test/run-pass/allocator/custom.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// aux-build:helper.rs -// no-prefer-dynamic - -#![feature(allocator_api)] - -extern crate helper; - -use std::alloc::{self, Global, Alloc, System, Layout}; -use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; - -static HITS: AtomicUsize = ATOMIC_USIZE_INIT; - -struct A; - -unsafe impl alloc::GlobalAlloc for A { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - HITS.fetch_add(1, Ordering::SeqCst); - System.alloc(layout) - } - - unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - HITS.fetch_add(1, Ordering::SeqCst); - System.dealloc(ptr, layout) - } -} - -#[global_allocator] -static GLOBAL: A = A; - -fn main() { - println!("hello!"); - - let n = HITS.load(Ordering::SeqCst); - assert!(n > 0); - unsafe { - let layout = Layout::from_size_align(4, 2).unwrap(); - - let ptr = Global.alloc(layout.clone()).unwrap(); - helper::work_with(&ptr); - assert_eq!(HITS.load(Ordering::SeqCst), n + 1); - Global.dealloc(ptr, layout.clone()); - assert_eq!(HITS.load(Ordering::SeqCst), n + 2); - - let s = String::with_capacity(10); - helper::work_with(&s); - assert_eq!(HITS.load(Ordering::SeqCst), n + 3); - drop(s); - assert_eq!(HITS.load(Ordering::SeqCst), n + 4); - - let ptr = System.alloc(layout.clone()).unwrap(); - assert_eq!(HITS.load(Ordering::SeqCst), n + 4); - helper::work_with(&ptr); - System.dealloc(ptr, layout); - assert_eq!(HITS.load(Ordering::SeqCst), n + 4); - } -} diff --git a/src/test/run-pass/allocator/xcrate-use.rs b/src/test/run-pass/allocator/xcrate-use.rs deleted file mode 100644 index 482e3b04aae..00000000000 --- a/src/test/run-pass/allocator/xcrate-use.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// aux-build:custom.rs -// aux-build:helper.rs -// no-prefer-dynamic - -#![feature(allocator_api)] - -extern crate custom; -extern crate helper; - -use std::alloc::{Global, Alloc, System, Layout}; -use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT}; - -#[global_allocator] -static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT); - -fn main() { - unsafe { - let n = GLOBAL.0.load(Ordering::SeqCst); - let layout = Layout::from_size_align(4, 2).unwrap(); - - let ptr = Global.alloc(layout.clone()).unwrap(); - helper::work_with(&ptr); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1); - Global.dealloc(ptr, layout.clone()); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2); - - let ptr = System.alloc(layout.clone()).unwrap(); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2); - helper::work_with(&ptr); - System.dealloc(ptr, layout); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2); - } -} diff --git a/src/test/run-pass/allocator/xcrate-use2.rs b/src/test/run-pass/allocator/xcrate-use2.rs deleted file mode 100644 index 7a45fd28bdb..00000000000 --- a/src/test/run-pass/allocator/xcrate-use2.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.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. - -// aux-build:custom.rs -// aux-build:custom-as-global.rs -// aux-build:helper.rs -// no-prefer-dynamic - -#![feature(allocator_api)] - -extern crate custom; -extern crate custom_as_global; -extern crate helper; - -use std::alloc::{alloc, dealloc, GlobalAlloc, System, Layout}; -use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT}; - -static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT); - -fn main() { - unsafe { - let n = custom_as_global::get(); - let layout = Layout::from_size_align(4, 2).unwrap(); - - // Global allocator routes to the `custom_as_global` global - let ptr = alloc(layout.clone()); - helper::work_with(&ptr); - assert_eq!(custom_as_global::get(), n + 1); - dealloc(ptr, layout.clone()); - assert_eq!(custom_as_global::get(), n + 2); - - // Usage of the system allocator avoids all globals - let ptr = System.alloc(layout.clone()); - helper::work_with(&ptr); - assert_eq!(custom_as_global::get(), n + 2); - System.dealloc(ptr, layout.clone()); - assert_eq!(custom_as_global::get(), n + 2); - - // Usage of our personal allocator doesn't affect other instances - let ptr = GLOBAL.alloc(layout.clone()); - helper::work_with(&ptr); - assert_eq!(custom_as_global::get(), n + 2); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 1); - GLOBAL.dealloc(ptr, layout); - assert_eq!(custom_as_global::get(), n + 2); - assert_eq!(GLOBAL.0.load(Ordering::SeqCst), 2); - } -} - |
