From 39efdf31cf4f69ac0e33f79efe83243c6cdb4d35 Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Sun, 26 Apr 2020 14:56:31 -0700 Subject: [PATCH] Move prctl test to the same file as other libc tests. --- .../concurrency/libc_prctl_thread_name.rs | 18 ------------------ tests/run-pass/libc.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 tests/run-pass/concurrency/libc_prctl_thread_name.rs diff --git a/tests/run-pass/concurrency/libc_prctl_thread_name.rs b/tests/run-pass/concurrency/libc_prctl_thread_name.rs deleted file mode 100644 index b8ba27b3a89..00000000000 --- a/tests/run-pass/concurrency/libc_prctl_thread_name.rs +++ /dev/null @@ -1,18 +0,0 @@ -// ignore-windows: No libc on Windows -// ignore-macos: No prctl on MacOS - -#![feature(rustc_private)] - -extern crate libc; - -use std::ffi::CString; - -fn main() { - unsafe { - let thread_name = CString::new("hello").expect("CString::new failed"); - assert_eq!(libc::prctl(libc::PR_SET_NAME, thread_name.as_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0); - let mut buf = [0; 6]; - assert_eq!(libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0); - assert_eq!(thread_name.as_bytes_with_nul(), buf); - } -} diff --git a/tests/run-pass/libc.rs b/tests/run-pass/libc.rs index 14d12de0d18..5873d429695 100644 --- a/tests/run-pass/libc.rs +++ b/tests/run-pass/libc.rs @@ -141,6 +141,20 @@ fn test_rwlock_libc_static_initializer() { } } +/// Test whether the `prctl` shim correctly sets the thread name. +/// +/// Note: `prctl` exists only on Linux. +fn test_prctl_thread_name() { + use std::ffi::CString; + unsafe { + let thread_name = CString::new("hello").expect("CString::new failed"); + assert_eq!(libc::prctl(libc::PR_SET_NAME, thread_name.as_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0); + let mut buf = [0; 6]; + assert_eq!(libc::prctl(libc::PR_GET_NAME, buf.as_mut_ptr() as libc::c_long, 0 as libc::c_long, 0 as libc::c_long, 0 as libc::c_long), 0); + assert_eq!(thread_name.as_bytes_with_nul(), buf); + } +} + fn main() { #[cfg(target_os = "linux")] test_posix_fadvise(); @@ -152,4 +166,7 @@ fn main() { #[cfg(target_os = "linux")] test_mutex_libc_static_initializer_recursive(); + + #[cfg(target_os = "linux")] + test_prctl_thread_name(); } -- 2.44.0