about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/compiletest/src/procsrv.rs48
-rw-r--r--src/tools/compiletest/src/runtest.rs33
2 files changed, 39 insertions, 42 deletions
diff --git a/src/tools/compiletest/src/procsrv.rs b/src/tools/compiletest/src/procsrv.rs
index ed690c08a1e..7e4f40af9ce 100644
--- a/src/tools/compiletest/src/procsrv.rs
+++ b/src/tools/compiletest/src/procsrv.rs
@@ -11,6 +11,7 @@
 use std::env;
 use std::ffi::OsString;
 use std::io::prelude::*;
+use std::io;
 use std::path::PathBuf;
 use std::process::{Child, Command, ExitStatus, Output, Stdio};
 
@@ -52,7 +53,7 @@ pub fn run(lib_path: &str,
            args: &[String],
            env: Vec<(String, String)>,
            input: Option<String>)
-           -> Option<Result> {
+           -> io::Result<Result> {
 
     let mut cmd = Command::new(prog);
     cmd.args(args)
@@ -64,21 +65,17 @@ pub fn run(lib_path: &str,
         cmd.env(&key, &val);
     }
 
-    match cmd.spawn() {
-        Ok(mut process) => {
-            if let Some(input) = input {
-                process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
-            }
-            let Output { status, stdout, stderr } = process.wait_with_output().unwrap();
-
-            Some(Result {
-                status: status,
-                out: String::from_utf8(stdout).unwrap(),
-                err: String::from_utf8(stderr).unwrap(),
-            })
-        }
-        Err(..) => None,
+    let mut process = cmd.spawn()?;
+    if let Some(input) = input {
+        process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
     }
+    let Output { status, stdout, stderr } = process.wait_with_output().unwrap();
+
+    Ok(Result {
+        status: status,
+        out: String::from_utf8(stdout).unwrap(),
+        err: String::from_utf8(stderr).unwrap(),
+    })
 }
 
 pub fn run_background(lib_path: &str,
@@ -87,26 +84,21 @@ pub fn run_background(lib_path: &str,
                       args: &[String],
                       env: Vec<(String, String)>,
                       input: Option<String>)
-                      -> Option<Child> {
+                      -> io::Result<Child> {
 
     let mut cmd = Command::new(prog);
     cmd.args(args)
-        .stdin(Stdio::piped())
-        .stdout(Stdio::piped())
-        .stderr(Stdio::piped());
+       .stdin(Stdio::piped())
+       .stdout(Stdio::piped());
     add_target_env(&mut cmd, lib_path, aux_path);
     for (key, val) in env {
         cmd.env(&key, &val);
     }
 
-    match cmd.spawn() {
-        Ok(mut process) => {
-            if let Some(input) = input {
-                process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
-            }
-
-            Some(process)
-        }
-        Err(..) => None,
+    let mut process = cmd.spawn()?;
+    if let Some(input) = input {
+        process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
     }
+
+    Ok(process)
 }
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 05f9beca3d1..05d6e21e9aa 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -21,13 +21,12 @@ use test::TestPaths;
 use uidiff;
 use util::logv;
 
-use std::env;
 use std::collections::HashSet;
+use std::env;
 use std::fmt;
 use std::fs::{self, File};
-use std::io::{self, BufReader};
 use std::io::prelude::*;
-use std::net::TcpStream;
+use std::io::{self, BufReader};
 use std::path::{Path, PathBuf};
 use std::process::{Command, Output, ExitStatus};
 use std::str;
@@ -506,8 +505,8 @@ actual:\n\
                                  exe_file.to_str().unwrap().to_owned(),
                                  self.config.adb_test_dir.clone()
                              ],
-                             vec![("".to_owned(), "".to_owned())],
-                             Some("".to_owned()))
+                             Vec::new(),
+                             None)
                     .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
 
                 procsrv::run("",
@@ -518,8 +517,8 @@ actual:\n\
                                  "tcp:5039".to_owned(),
                                  "tcp:5039".to_owned()
                              ],
-                             vec![("".to_owned(), "".to_owned())],
-                             Some("".to_owned()))
+                             Vec::new(),
+                             None)
                     .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
 
                 let adb_arg = format!("export LD_LIBRARY_PATH={}; \
@@ -539,17 +538,23 @@ actual:\n\
                                                               "shell".to_owned(),
                                                               adb_arg.clone()
                                                           ],
-                                                          vec![("".to_owned(),
-                                                                "".to_owned())],
-                                                          Some("".to_owned()))
+                                                          Vec::new(),
+                                                          None)
                     .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
+
+                // Wait for the gdbserver to print out "Listening on port ..."
+                // at which point we know that it's started and then we can
+                // execute the debugger below.
+                let mut stdout = BufReader::new(process.stdout.take().unwrap());
+                let mut line = String::new();
                 loop {
-                    //waiting 1 second for gdbserver start
-                    ::std::thread::sleep(::std::time::Duration::new(1,0));
-                    if TcpStream::connect("127.0.0.1:5039").is_ok() {
+                    line.truncate(0);
+                    stdout.read_line(&mut line).unwrap();
+                    if line.starts_with("Listening on port 5039") {
                         break
                     }
                 }
+                drop(stdout);
 
                 let debugger_script = self.make_out_name("debugger.script");
                 // FIXME (#9639): This needs to handle non-utf8 paths
@@ -569,7 +574,7 @@ actual:\n\
                                  &gdb_path,
                                  None,
                                  &debugger_opts,
-                                 vec![("".to_owned(), "".to_owned())],
+                                 Vec::new(),
                                  None)
                     .expect(&format!("failed to exec `{:?}`", gdb_path));
                 let cmdline = {