3 // [thir]compile-flags: -Zthir-unsafeck
5 #![allow(stable_features)]
6 // ignore-windows - this is a unix-specific test
7 // ignore-emscripten no processes
8 // ignore-sgx no processes
9 #![feature(process_exec, rustc_private)]
13 use std::os::unix::process::CommandExt;
14 use std::process::Command;
15 use std::sync::atomic::{AtomicUsize, Ordering};
18 #[cfg(not(target_os = "linux"))]
24 /// We need to directly use the getpid syscall instead of using `process::id()`
25 /// because the libc wrapper might return incorrect values after a process was
27 #[cfg(target_os = "linux")]
31 libc::syscall(libc::SYS_getpid) as _
36 if let Some(arg) = env::args().nth(1) {
38 "test1" => println!("hello2"),
39 "test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"),
40 "test3" => assert_eq!(env::current_dir().unwrap().to_str().unwrap(), "/"),
42 _ => panic!("unknown argument: {}", arg),
47 let me = env::current_exe().unwrap();
59 assert!(output.status.success());
60 assert!(output.stderr.is_empty());
61 assert_eq!(output.stdout, b"hello\nhello2\n");
67 env::set_current_dir("/").unwrap();
73 assert!(output.status.success());
74 assert!(output.stderr.is_empty());
75 assert!(output.stdout.is_empty());
80 .pre_exec(|| Err(Error::from_raw_os_error(102)))
84 assert_eq!(output.raw_os_error(), Some(102));
92 assert!(pid != child);
98 assert!(output.status.success());
99 assert!(output.stderr.is_empty());
100 assert!(output.stdout.is_empty());
102 let mem = Arc::new(AtomicUsize::new(0));
103 let mem2 = mem.clone();
104 let output = unsafe {
108 assert_eq!(mem2.fetch_add(1, Ordering::SeqCst), 0);
114 assert!(output.status.success());
115 assert!(output.stderr.is_empty());
116 assert!(output.stdout.is_empty());
117 assert_eq!(mem.load(Ordering::SeqCst), 0);