Skip to content

Commit 39efdf3

Browse files
author
Vytautas Astrauskas
committed
Move prctl test to the same file as other libc tests.
1 parent 60cd8aa commit 39efdf3

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

tests/run-pass/concurrency/libc_prctl_thread_name.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/run-pass/libc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ fn test_rwlock_libc_static_initializer() {
141141
}
142142
}
143143

144+
/// Test whether the `prctl` shim correctly sets the thread name.
145+
///
146+
/// Note: `prctl` exists only on Linux.
147+
fn test_prctl_thread_name() {
148+
use std::ffi::CString;
149+
unsafe {
150+
let thread_name = CString::new("hello").expect("CString::new failed");
151+
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);
152+
let mut buf = [0; 6];
153+
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);
154+
assert_eq!(thread_name.as_bytes_with_nul(), buf);
155+
}
156+
}
157+
144158
fn main() {
145159
#[cfg(target_os = "linux")]
146160
test_posix_fadvise();
@@ -152,4 +166,7 @@ fn main() {
152166

153167
#[cfg(target_os = "linux")]
154168
test_mutex_libc_static_initializer_recursive();
169+
170+
#[cfg(target_os = "linux")]
171+
test_prctl_thread_name();
155172
}

0 commit comments

Comments
 (0)