Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/uu/pgrep/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,26 @@ unknown /dev/tty 4 1-63 console"#;
#[test]
#[cfg(target_os = "linux")]
fn test_thread_ids() {
let main_tid = rustix::thread::gettid().as_raw_nonzero().get() as u64;
let main_tid = rustix::thread::gettid().as_raw_nonzero().get() as usize;
std::thread::spawn(move || {
let mut pid_entry = ProcessInformation::current_process_info().unwrap();
let thread_ids = pid_entry.thread_ids();

assert!(thread_ids.contains(&(main_tid as usize)));

let new_thread_tid = rustix::thread::gettid().as_raw_nonzero().get() as u64;
assert!(thread_ids.contains(&(new_thread_tid as usize)));
let new_thread_tid = rustix::thread::gettid().as_raw_nonzero().get() as usize;
// This thread is already running, but readdir on /proc/<pid>/task
// can skip entries while other test threads exit concurrently, so a
// single snapshot may miss a tid (https://github.com/uutils/procps/issues/471).
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
loop {
let mut pid_entry = ProcessInformation::current_process_info().unwrap();
let thread_ids = pid_entry.thread_ids();
if thread_ids.contains(&main_tid) && thread_ids.contains(&new_thread_tid) {
return;
}
if std::time::Instant::now() >= deadline {
panic!(
"thread_ids missing main {main_tid} or new {new_thread_tid}: {thread_ids:?}"
);
}
std::thread::sleep(std::time::Duration::from_millis(5));
}
})
.join()
.unwrap();
Expand Down
Loading