Skip to content

Make Android tests fail if no device is available #10977

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
Dec 19, 2013
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
19 changes: 8 additions & 11 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,13 @@ $(foreach target,$(CFG_TARGET), \
$(if $(findstring $(target),"arm-linux-androideabi"), \
$(if $(findstring adb,$(CFG_ADB)), \
$(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
$(info check: $(target) test enabled \
$(info check: android device attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
$(info check: $(target) test disabled \
$(info check: android device not attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
$(info check: android device attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
$(info check: android device not attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
), \
$(info check: $(target) test disabled \
$(info check: adb not found) \
$(eval $(call DEF_ADB_DEVICE_STATUS, false))) \
$(info check: adb not found) \
$(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
), \
) \
)
Expand Down Expand Up @@ -451,8 +448,8 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
@$$(call E, run: skipped $$< )
@touch $$@
@$$(call E, failing: no device for $$< )
false
endef

$(foreach host,$(CFG_HOST), \
Expand Down
200 changes: 90 additions & 110 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ use std::vec;
use extra::test::MetricMap;

pub fn run(config: config, testfile: ~str) {

match config.target {

~"arm-linux-androideabi" => {
if !config.adb_device_status {
fail!("android device not available");
}
}

_=> { }
}

let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
}
Expand Down Expand Up @@ -99,20 +111,8 @@ fn run_rfail_test(config: &config, props: &TestProps, testfile: &Path) {
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", &ProcRes);
}

match config.target {

~"arm-linux-androideabi" => {
if (config.adb_device_status) {
check_correct_failure_status(&ProcRes);
check_error_patterns(props, testfile, &ProcRes);
}
}

_=> {
check_correct_failure_status(&ProcRes);
check_error_patterns(props, testfile, &ProcRes);
}
}
check_correct_failure_status(&ProcRes);
check_error_patterns(props, testfile, &ProcRes);
}

fn check_correct_failure_status(ProcRes: &ProcRes) {
Expand Down Expand Up @@ -275,86 +275,86 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
let mut ProcArgs;
match config.target {
~"arm-linux-androideabi" => {
if (config.adb_device_status) {

cmds = cmds.replace("run","continue");

// write debugger script
let script_str = [~"set charset UTF-8",
format!("file {}",exe_file.as_str().unwrap().to_owned()),
~"target remote :5039",
cmds,
~"quit"].connect("\n");
debug!("script_str = {}", script_str);
dump_output_file(config, testfile, script_str, "debugger.script");


procsrv::run("", config.adb_path,
[~"push", exe_file.as_str().unwrap().to_owned(), config.adb_test_dir.clone()],
~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));

procsrv::run("", config.adb_path,
[~"forward", ~"tcp:5039", ~"tcp:5039"],
~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));

let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
config.adb_test_dir.clone(), config.adb_test_dir.clone(),
str::from_utf8(exe_file.filename().unwrap()));

let mut process = procsrv::run_background("", config.adb_path,
[~"shell",adb_arg.clone()],~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));
loop {
//waiting 1 second for gdbserver start
timer::sleep(1000);
let result = do task::try {
tcp::TcpStream::connect(
SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 5039 });
};
if result.is_err() {
continue;
}
break;
}

let args = split_maybe_args(&config.rustcflags);
let mut tool_path:~str = ~"";
for arg in args.iter() {
if arg.contains("--android-cross-path=") {
tool_path = arg.replace("--android-cross-path=","");
break;
}
}
cmds = cmds.replace("run","continue");

if tool_path.equals(&~"") {
fatal(~"cannot found android cross path");
}
// write debugger script
let script_str = [~"set charset UTF-8",
format!("file {}",exe_file.as_str().unwrap().to_owned()),
~"target remote :5039",
cmds,
~"quit"].connect("\n");
debug!("script_str = {}", script_str);
dump_output_file(config, testfile, script_str, "debugger.script");

let debugger_script = make_out_name(config, testfile, "debugger.script");
// FIXME (#9639): This needs to handle non-utf8 paths
let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx",
"-command=" + debugger_script.as_str().unwrap().to_owned()];

let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb");
let procsrv::Result{ out, err, status }=
procsrv::run("",
gdb_path,
debugger_opts, ~[(~"",~"")], None)
.expect(format!("failed to exec `{}`", gdb_path));
let cmdline = {
let cmdline = make_cmdline("", "arm-linux-androideabi-gdb", debugger_opts);
logv(config, format!("executing {}", cmdline));
cmdline

procsrv::run("", config.adb_path,
[~"push", exe_file.as_str().unwrap().to_owned(),
config.adb_test_dir.clone()],
~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));

procsrv::run("", config.adb_path,
[~"forward", ~"tcp:5039", ~"tcp:5039"],
~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));

let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
config.adb_test_dir.clone(), config.adb_test_dir.clone(),
str::from_utf8(exe_file.filename().unwrap()));

let mut process = procsrv::run_background("", config.adb_path,
[~"shell",adb_arg.clone()],
~[(~"",~"")], Some(~""))
.expect(format!("failed to exec `{}`", config.adb_path));
loop {
//waiting 1 second for gdbserver start
timer::sleep(1000);
let result = do task::try {
tcp::TcpStream::connect(
SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 5039 });
};
if result.is_err() {
continue;
}
break;
}

let args = split_maybe_args(&config.rustcflags);
let mut tool_path:~str = ~"";
for arg in args.iter() {
if arg.contains("--android-cross-path=") {
tool_path = arg.replace("--android-cross-path=","");
break;
}
}

ProcRes = ProcRes {status: status,
stdout: out,
stderr: err,
cmdline: cmdline};
process.force_destroy();
if tool_path.equals(&~"") {
fatal(~"cannot found android cross path");
}

let debugger_script = make_out_name(config, testfile, "debugger.script");
// FIXME (#9639): This needs to handle non-utf8 paths
let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx",
"-command=" + debugger_script.as_str().unwrap().to_owned()];

let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb");
let procsrv::Result{ out, err, status }=
procsrv::run("",
gdb_path,
debugger_opts, ~[(~"",~"")], None)
.expect(format!("failed to exec `{}`", gdb_path));
let cmdline = {
let cmdline = make_cmdline("", "arm-linux-androideabi-gdb", debugger_opts);
logv(config, format!("executing {}", cmdline));
cmdline
};

ProcRes = ProcRes {status: status,
stdout: out,
stderr: err,
cmdline: cmdline};
process.force_destroy();
}

_=> {
Expand Down Expand Up @@ -662,11 +662,7 @@ fn exec_compiled_test(config: &config, props: &TestProps,
match config.target {

~"arm-linux-androideabi" => {
if (config.adb_device_status) {
_arm_exec_compiled_test(config, props, testfile, env)
} else {
_dummy_exec_compiled_test(config, props, testfile)
}
_arm_exec_compiled_test(config, props, testfile, env)
}

_=> {
Expand Down Expand Up @@ -710,9 +706,7 @@ fn compose_and_run_compiler(
match config.target {

~"arm-linux-androideabi" => {
if (config.adb_device_status) {
_arm_push_aux_shared_library(config, testfile);
}
_arm_push_aux_shared_library(config, testfile);
}

_=> { }
Expand Down Expand Up @@ -992,20 +986,6 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
}
}

fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
testfile: &Path) -> ProcRes {

let args = make_run_args(config, props, testfile);
let cmdline = make_cmdline("", args.prog, args.args);

match config.mode {
mode_run_fail => ProcRes {status: process::ExitStatus(101), stdout: ~"",
stderr: ~"", cmdline: cmdline},
_ => ProcRes {status: process::ExitStatus(0), stdout: ~"",
stderr: ~"", cmdline: cmdline}
}
}

fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
let tdir = aux_output_dir_name(config, testfile);

Expand Down