Skip to content

Commit c23ba29

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#136713 - matthiaskrgr:rollup-sy6py39, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#135179 (Make sure to use `Receiver` trait when extracting object method candidate) - rust-lang#136554 (Add `opt_alias_variances` and use it in outlives code) - rust-lang#136556 ([AIX] Update tests/ui/wait-forked-but-failed-child.rs to accomodate exiting and idle processes.) - rust-lang#136589 (Enable "jump to def" feature on rustc docs) - rust-lang#136615 (sys: net: Add UEFI stubs) - rust-lang#136635 (Remove outdated `base_port` calculation in std net test) - rust-lang#136682 (Move two windows process tests to tests/ui) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1ddaa63 + 46d1a62 commit c23ba29

File tree

4 files changed

+377
-178
lines changed

4 files changed

+377
-178
lines changed

Diff for: std/src/net/test.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToS
55
use crate::sync::atomic::{AtomicUsize, Ordering};
66

77
static PORT: AtomicUsize = AtomicUsize::new(0);
8+
const BASE_PORT: u16 = 19600;
89

910
pub fn next_test_ip4() -> SocketAddr {
10-
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
11+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
1112
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
1213
}
1314

1415
pub fn next_test_ip6() -> SocketAddr {
15-
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
16+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
1617
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
1718
}
1819

@@ -30,31 +31,3 @@ pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
3031
Err(e) => Err(e.to_string()),
3132
}
3233
}
33-
34-
// The bots run multiple builds at the same time, and these builds
35-
// all want to use ports. This function figures out which workspace
36-
// it is running in and assigns a port range based on it.
37-
fn base_port() -> u16 {
38-
let cwd = if cfg!(target_env = "sgx") {
39-
String::from("sgx")
40-
} else {
41-
env::current_dir().unwrap().into_os_string().into_string().unwrap()
42-
};
43-
let dirs = [
44-
"32-opt",
45-
"32-nopt",
46-
"musl-64-opt",
47-
"cross-opt",
48-
"64-opt",
49-
"64-nopt",
50-
"64-opt-vg",
51-
"64-debug-opt",
52-
"all-opt",
53-
"snap3",
54-
"dist",
55-
"sgx",
56-
];
57-
dirs.iter().enumerate().find(|&(_, dir)| cwd.contains(dir)).map(|p| p.0).unwrap_or(0) as u16
58-
* 1000
59-
+ 19600
60-
}

Diff for: std/src/process/tests.rs

-148
Original file line numberDiff line numberDiff line change
@@ -391,154 +391,6 @@ fn test_interior_nul_in_env_value_is_error() {
391391
}
392392
}
393393

394-
/// Tests that process creation flags work by debugging a process.
395-
/// Other creation flags make it hard or impossible to detect
396-
/// behavioral changes in the process.
397-
#[test]
398-
#[cfg(windows)]
399-
fn test_creation_flags() {
400-
use crate::os::windows::process::CommandExt;
401-
use crate::sys::c::{BOOL, INFINITE};
402-
#[repr(C)]
403-
struct DEBUG_EVENT {
404-
pub event_code: u32,
405-
pub process_id: u32,
406-
pub thread_id: u32,
407-
// This is a union in the real struct, but we don't
408-
// need this data for the purposes of this test.
409-
pub _junk: [u8; 164],
410-
}
411-
412-
extern "system" {
413-
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: u32) -> BOOL;
414-
fn ContinueDebugEvent(dwProcessId: u32, dwThreadId: u32, dwContinueStatus: u32) -> BOOL;
415-
}
416-
417-
const DEBUG_PROCESS: u32 = 1;
418-
const EXIT_PROCESS_DEBUG_EVENT: u32 = 5;
419-
const DBG_EXCEPTION_NOT_HANDLED: u32 = 0x80010001;
420-
421-
let mut child = Command::new("cmd")
422-
.creation_flags(DEBUG_PROCESS)
423-
.stdin(Stdio::piped())
424-
.stdout(Stdio::null())
425-
.stderr(Stdio::null())
426-
.spawn()
427-
.unwrap();
428-
child.stdin.take().unwrap().write_all(b"exit\r\n").unwrap();
429-
let mut events = 0;
430-
let mut event = DEBUG_EVENT { event_code: 0, process_id: 0, thread_id: 0, _junk: [0; 164] };
431-
loop {
432-
if unsafe { WaitForDebugEvent(&mut event as *mut DEBUG_EVENT, INFINITE) } == 0 {
433-
panic!("WaitForDebugEvent failed!");
434-
}
435-
events += 1;
436-
437-
if event.event_code == EXIT_PROCESS_DEBUG_EVENT {
438-
break;
439-
}
440-
441-
if unsafe {
442-
ContinueDebugEvent(event.process_id, event.thread_id, DBG_EXCEPTION_NOT_HANDLED)
443-
} == 0
444-
{
445-
panic!("ContinueDebugEvent failed!");
446-
}
447-
}
448-
assert!(events > 0);
449-
}
450-
451-
/// Tests proc thread attributes by spawning a process with a custom parent process,
452-
/// then comparing the parent process ID with the expected parent process ID.
453-
#[test]
454-
#[cfg(windows)]
455-
fn test_proc_thread_attributes() {
456-
use crate::mem;
457-
use crate::os::windows::io::AsRawHandle;
458-
use crate::os::windows::process::{CommandExt, ProcThreadAttributeList};
459-
use crate::sys::c::{BOOL, CloseHandle, HANDLE};
460-
use crate::sys::cvt;
461-
462-
#[repr(C)]
463-
#[allow(non_snake_case)]
464-
struct PROCESSENTRY32W {
465-
dwSize: u32,
466-
cntUsage: u32,
467-
th32ProcessID: u32,
468-
th32DefaultHeapID: usize,
469-
th32ModuleID: u32,
470-
cntThreads: u32,
471-
th32ParentProcessID: u32,
472-
pcPriClassBase: i32,
473-
dwFlags: u32,
474-
szExeFile: [u16; 260],
475-
}
476-
477-
extern "system" {
478-
fn CreateToolhelp32Snapshot(dwflags: u32, th32processid: u32) -> HANDLE;
479-
fn Process32First(hsnapshot: HANDLE, lppe: *mut PROCESSENTRY32W) -> BOOL;
480-
fn Process32Next(hsnapshot: HANDLE, lppe: *mut PROCESSENTRY32W) -> BOOL;
481-
}
482-
483-
const PROC_THREAD_ATTRIBUTE_PARENT_PROCESS: usize = 0x00020000;
484-
const TH32CS_SNAPPROCESS: u32 = 0x00000002;
485-
486-
struct ProcessDropGuard(crate::process::Child);
487-
488-
impl Drop for ProcessDropGuard {
489-
fn drop(&mut self) {
490-
let _ = self.0.kill();
491-
}
492-
}
493-
494-
let mut parent = Command::new("cmd");
495-
parent.stdout(Stdio::null()).stderr(Stdio::null());
496-
497-
let parent = ProcessDropGuard(parent.spawn().unwrap());
498-
499-
let mut child_cmd = Command::new("cmd");
500-
child_cmd.stdout(Stdio::null()).stderr(Stdio::null());
501-
502-
let parent_process_handle = parent.0.as_raw_handle();
503-
504-
let mut attribute_list = ProcThreadAttributeList::build()
505-
.attribute(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &parent_process_handle)
506-
.finish()
507-
.unwrap();
508-
509-
let child = ProcessDropGuard(child_cmd.spawn_with_attributes(&mut attribute_list).unwrap());
510-
511-
let h_snapshot = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) };
512-
513-
let mut process_entry = PROCESSENTRY32W {
514-
dwSize: mem::size_of::<PROCESSENTRY32W>() as u32,
515-
cntUsage: 0,
516-
th32ProcessID: 0,
517-
th32DefaultHeapID: 0,
518-
th32ModuleID: 0,
519-
cntThreads: 0,
520-
th32ParentProcessID: 0,
521-
pcPriClassBase: 0,
522-
dwFlags: 0,
523-
szExeFile: [0; 260],
524-
};
525-
526-
unsafe { cvt(Process32First(h_snapshot, &mut process_entry as *mut _)) }.unwrap();
527-
528-
loop {
529-
if child.0.id() == process_entry.th32ProcessID {
530-
break;
531-
}
532-
unsafe { cvt(Process32Next(h_snapshot, &mut process_entry as *mut _)) }.unwrap();
533-
}
534-
535-
unsafe { cvt(CloseHandle(h_snapshot)) }.unwrap();
536-
537-
assert_eq!(parent.0.id(), process_entry.th32ParentProcessID);
538-
539-
drop(child)
540-
}
541-
542394
#[test]
543395
fn test_command_implements_send_sync() {
544396
fn take_send_sync_type<T: Send + Sync>(_: T) {}

0 commit comments

Comments
 (0)