Skip to content

Commit

Permalink
Fix some windows rpass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Apr 6, 2014
1 parent 0d9fd8e commit 08f36a2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 29 deletions.
81 changes: 55 additions & 26 deletions src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub struct Process {

/// None until finish() is called.
exit_code: Option<p::ProcessExit>,

/// Manually delivered signal
exit_signal: Option<int>,
}

impl Process {
Expand Down Expand Up @@ -107,7 +110,12 @@ impl Process {

match res {
Ok(res) => {
Ok((Process { pid: res.pid, handle: res.handle, exit_code: None },
Ok((Process {
pid: res.pid,
handle: res.handle,
exit_code: None,
exit_signal: None,
},
ret_io))
}
Err(e) => Err(e)
Expand All @@ -127,6 +135,14 @@ impl rtio::RtioProcess for Process {
Some(code) => code,
None => {
let code = waitpid(self.pid);
// On windows, waitpid will never return a signal. If a signal
// was successfully delivered to the process, however, we can
// consider it as having died via a signal.
let code = match self.exit_signal {
None => code,
Some(signal) if cfg!(windows) => p::ExitSignal(signal),
Some(..) => code,
};
self.exit_code = Some(code);
code
}
Expand Down Expand Up @@ -157,7 +173,14 @@ impl rtio::RtioProcess for Process {
}),
None => {}
}
return unsafe { killpid(self.pid, signum) };

// A successfully delivered signal that isn't 0 (just a poll for being
// alive) is recorded for windows (see wait())
match unsafe { killpid(self.pid, signum) } {
Ok(()) if signum == 0 => Ok(()),
Ok(()) => { self.exit_signal = Some(signum); Ok(()) }
Err(e) => Err(e),
}
}
}

Expand Down Expand Up @@ -256,31 +279,37 @@ fn spawn_process_os(config: p::ProcessConfig,

let cur_proc = GetCurrentProcess();

let orig_std_in = get_osfhandle(in_fd) as HANDLE;
if orig_std_in == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_in, cur_proc, &mut si.hStdInput,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
if in_fd != -1 {
let orig_std_in = get_osfhandle(in_fd) as HANDLE;
if orig_std_in == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_in, cur_proc, &mut si.hStdInput,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
}
}

let orig_std_out = get_osfhandle(out_fd) as HANDLE;
if orig_std_out == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_out, cur_proc, &mut si.hStdOutput,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
if out_fd != -1 {
let orig_std_out = get_osfhandle(out_fd) as HANDLE;
if orig_std_out == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_out, cur_proc, &mut si.hStdOutput,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
}
}

let orig_std_err = get_osfhandle(err_fd) as HANDLE;
if orig_std_err == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_err, cur_proc, &mut si.hStdError,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
if err_fd != -1 {
let orig_std_err = get_osfhandle(err_fd) as HANDLE;
if orig_std_err == INVALID_HANDLE_VALUE as HANDLE {
fail!("failure in get_osfhandle: {}", os::last_os_error());
}
if DuplicateHandle(cur_proc, orig_std_err, cur_proc, &mut si.hStdError,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
fail!("failure in DuplicateHandle: {}", os::last_os_error());
}
}

let cmd = make_command_line(config.program, config.args);
Expand All @@ -307,9 +336,9 @@ fn spawn_process_os(config: p::ProcessConfig,
})
});

assert!(CloseHandle(si.hStdInput) != 0);
assert!(CloseHandle(si.hStdOutput) != 0);
assert!(CloseHandle(si.hStdError) != 0);
if in_fd != -1 { assert!(CloseHandle(si.hStdInput) != 0); }
if out_fd != -1 { assert!(CloseHandle(si.hStdOutput) != 0); }
if err_fd != -1 { assert!(CloseHandle(si.hStdError) != 0); }

match create_err {
Some(err) => return Err(err),
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[no_std];
#![no_std]

#[lang="fail_"]
fn fail(_: *i8, _: *i8, _: uint) -> ! { loop {} }
Expand Down
3 changes: 2 additions & 1 deletion src/test/run-pass/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

// aux-build:lang-item-public.rs
// ignore-android
// ignore-win32 #13361

#[no_std];
#![no_std]

extern crate lang_lib = "lang-item-public";

Expand Down
12 changes: 11 additions & 1 deletion src/test/run-pass/tcp-stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@
#[phase(syntax, link)]
extern crate log;
extern crate libc;
extern crate green;
extern crate rustuv;

use std::io::net::ip::{Ipv4Addr, SocketAddr};
use std::io::net::tcp::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};
use std::task;

#[start]
fn start(argc: int, argv: **u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}

fn main() {
// This test has a chance to time out, try to not let it time out
Expand Down Expand Up @@ -53,7 +61,9 @@ fn main() {
let (tx, rx) = channel();
for _ in range(0, 1000) {
let tx = tx.clone();
spawn(proc() {
let mut builder = task::task();
builder.opts.stack_size = Some(32 * 1024);
builder.spawn(proc() {
match TcpStream::connect(addr) {
Ok(stream) => {
let mut stream = stream;
Expand Down

8 comments on commit 08f36a2

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@08f36a2

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/remove-check-fast = 08f36a2 into auto

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/remove-check-fast = 08f36a2 merged ok, testing candidate = 7a8e80b1

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@08f36a2

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/remove-check-fast = 08f36a2 into auto

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/remove-check-fast = 08f36a2 merged ok, testing candidate = 0fb95b1

@bors
Copy link
Contributor

@bors bors commented on 08f36a2 Apr 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.