Use `ffx test run` for testing v2 components
`ffx component run` doesn't seem suited to run test binaries, as it
doesn't seem to launch or destroy the tests correctly. On the other
hand, `ffx test run` works properly, and matches the behavior of `fx
test` (ref: https://cs.opensource.google/fuchsia/fuchsia/+/master:scripts/fxtest/lib/execution_handle.dart;l=142-153;drc=31e0aac9bad142eda921d422bbfce7595e14111a )
Test: fargo test --app-name wlancfg_lib_lib_test --sandbox-file-path \
meta/wlancfg_lib_lib_test.cml --manifest-path \
src/connectivity/wlan/wlancfg/Cargo.toml
Change-Id: I363f36fb7fe710243262e9bd22c7ebfad9a18cd9
Reviewed-on: https://fuchsia-review.googlesource.com/c/fargo/+/564010
Reviewed-by: Rob Tsuk <robtsuk@google.com>
diff --git a/src/command_line.rs b/src/command_line.rs
index 08f66e4..a33611e 100644
--- a/src/command_line.rs
+++ b/src/command_line.rs
@@ -196,6 +196,10 @@
#[structopt(long)]
run_with_ffx_component: bool,
+ /// Use ffx test run to run the binary.
+ #[structopt(long)]
+ run_with_ffx_test: bool,
+
/// Use Use sessionctl to run the binary.
#[structopt(short = "K", long)]
kill_all: bool,
@@ -249,6 +253,10 @@
#[structopt(long)]
run_with_ffx_component: bool,
+ /// Use ffx test run to run the binary.
+ #[structopt(long)]
+ run_with_ffx_test: bool,
+
/// Directory of app as it appears in the manifest file.
#[structopt(long, default_value = "bin")]
app_dir: String,
@@ -593,6 +601,7 @@
let run_mode = run_switches_to_mode(
run.run_with_ffx_component,
+ run.run_with_ffx_test,
run.run_with_tiles,
run.run_with_session_control,
);
@@ -616,6 +625,7 @@
let run_params: Vec<&str> = run_on_target.runner_args.iter().map(|s| &**s).collect();
let run_mode = run_switches_to_mode(
run_on_target.run_with_ffx_component,
+ run_on_target.run_with_ffx_test,
run_on_target.run_with_tiles,
run_on_target.run_with_session_control,
);
@@ -725,7 +735,7 @@
// file.
false
};
- let run_mode = run_switches_to_mode(is_v2_component, false, false);
+ let run_mode = run_switches_to_mode(false, is_v2_component, false, false);
return run_tests(
&run_cargo_options
diff --git a/src/lib.rs b/src/lib.rs
index b863746..6695f26 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,6 +62,7 @@
}
RunMode::Run => "run ".to_string(),
RunMode::FfxComponent => "component run ".to_string(),
+ RunMode::FfxTest => "test run ".to_string(),
};
command_string.push_str(&target_string);
@@ -85,7 +86,9 @@
}
match run_mode {
- RunMode::FfxComponent => ffx(verbose, &command_string).context("ssh failed")?,
+ RunMode::FfxComponent | RunMode::FfxTest => {
+ ffx(verbose, &command_string).context("ssh failed")?
+ }
_ => shell(verbose, target_options, &command_string).context("ssh failed")?,
}
Ok(())
@@ -236,6 +239,7 @@
pub enum RunMode {
Run,
FfxComponent,
+ FfxTest,
Tiles,
SessionControl,
}
@@ -245,13 +249,20 @@
RunMode::Run
}
}
-fn run_switches_to_mode(ffx: bool, tiles: bool, session_control: bool) -> RunMode {
+fn run_switches_to_mode(
+ ffx_component: bool,
+ ffx_test: bool,
+ tiles: bool,
+ session_control: bool,
+) -> RunMode {
if tiles {
RunMode::Tiles
} else if session_control {
RunMode::SessionControl
- } else if ffx {
+ } else if ffx_component {
RunMode::FfxComponent
+ } else if ffx_test {
+ RunMode::FfxTest
} else {
RunMode::Run
}
@@ -458,6 +469,7 @@
let app_name_arg = format!("--{}", APP_NAME);
let run_arg = format!("--{}", RUN_WITH_RUN);
let run_with_ffx_component_arg = format!("--{}", RUN_WITH_FFX_COMP);
+ let run_with_ffx_test_arg = format!("--{}", RUN_WITH_FFX_TEST);
let nocapture_arg = format!("--{}", NOCAPTURE);
let fargo_path = if let Some(runner) = runner {
@@ -503,6 +515,7 @@
RunMode::SessionControl => runner_args.push(&session_control_arg),
RunMode::Run => runner_args.push(&run_arg),
RunMode::FfxComponent => runner_args.push(&run_with_ffx_component_arg),
+ RunMode::FfxTest => runner_args.push(&run_with_ffx_test_arg),
}
if let Some(args_for_target) = additional_target_args {
@@ -719,6 +732,7 @@
const RUN_WITH_TILES: &str = "run-with-tiles";
const RUN_WITH_RUN: &str = "run-with-run";
const RUN_WITH_FFX_COMP: &str = "run-with-ffx-component";
+const RUN_WITH_FFX_TEST: &str = "run-with-ffx-test";
const RUN_WITH_SESSION_CONTROL: &str = "run-with-session-control";
const DEFAULT_MOD_NAME: &str = "fargo";
const APP_DIR: &str = "app-dir";