]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/stdio-is-blocking.rs
2 // ignore-emscripten no processes
3 // ignore-sgx no processes
6 use std
::io
::prelude
::*;
7 use std
::process
::Command
;
10 const THREADS
: usize = 20;
11 const WRITES
: usize = 100;
12 const WRITE_SIZE
: usize = 1024 * 32;
15 let args
= env
::args().collect
::<Vec
<_
>>();
24 let me
= env
::current_exe().unwrap();
25 let mut cmd
= Command
::new(me
);
26 cmd
.arg("run-the-test");
27 let output
= cmd
.output().unwrap();
28 assert
!(output
.status
.success());
29 assert_eq
!(output
.stderr
.len(), 0);
30 assert_eq
!(output
.stdout
.len(), WRITES
* THREADS
* WRITE_SIZE
);
31 for byte
in output
.stdout
.iter() {
32 assert_eq
!(*byte
, b'a'
);
37 let threads
= (0..THREADS
).map(|_
| {
39 let buf
= [b'a'
; WRITE_SIZE
];
44 }).collect
::<Vec
<_
>>();
46 for thread
in threads
{
47 thread
.join().unwrap();
52 fn write_all(buf
: &[u8]) {
55 use std
::os
::unix
::prelude
::*;
57 let mut file
= unsafe { File::from_raw_fd(1) }
;
58 let res
= file
.write_all(buf
);
64 fn write_all(buf
: &[u8]) {
67 use std
::os
::windows
::raw
::*;
68 use std
::os
::windows
::prelude
::*;
70 const STD_OUTPUT_HANDLE
: u32 = (-11i32) as u32;
73 fn GetStdHandle(handle
: u32) -> HANDLE
;
76 let mut file
= unsafe {
77 let handle
= GetStdHandle(STD_OUTPUT_HANDLE
);
78 assert
!(!handle
.is_null());
79 File
::from_raw_handle(handle
)
81 let res
= file
.write_all(buf
);