Skip to content

Commit

Permalink
pthread-threadname: ensure we can see the name set via the Rust API
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 18, 2024
1 parent 8bb356c commit 5db0e40
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ fn main() {
}
}

// Set name via Rust API, get it via pthreads.
let long_name2 = long_name.clone();
thread::Builder::new()
.name(long_name.clone())
.spawn(move || {
let mut buf = vec![0u8; long_name2.len() + 1];
assert_eq!(get_thread_name(&mut buf), 0);
let cstr = CStr::from_bytes_until_nul(&buf).unwrap();
let truncated_name = &long_name2[..long_name2.len().min(MAX_THREAD_NAME_LEN - 1)];
assert_eq!(cstr.to_bytes(), truncated_name.as_bytes());
})
.unwrap()
.join()
.unwrap();

// Set name via pthread and get it again (short name).
thread::Builder::new()
.spawn(move || {
// Set short thread name.
Expand Down Expand Up @@ -130,6 +146,7 @@ fn main() {
.join()
.unwrap();

// Set name via pthread and get it again (long name).
thread::Builder::new()
.spawn(move || {
// Set full thread name.
Expand Down

0 comments on commit 5db0e40

Please sign in to comment.