Skip to content

compiletest: Fix flaky Android gdb test runs #38883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 20 additions & 28 deletions src/tools/compiletest/src/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
33 changes: 19 additions & 14 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("",
Expand All @@ -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={}; \
Expand All @@ -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
Expand All @@ -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 = {
Expand Down