diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml index cc9d95d10d..805274149d 100644 --- a/integration_tests/Cargo.toml +++ b/integration_tests/Cargo.toml @@ -5,8 +5,12 @@ authors = ["The Chromium OS Authors"] edition = "2021" [dev-dependencies] -tempfile = "3" +anyhow = "*" arch = { path = "../arch" } base = "*" +cfg-if = "*" libc = "0.2.65" -anyhow = "*" +tempfile = "3" + +[features] +direct = [] diff --git a/integration_tests/run b/integration_tests/run index 1d2cd15ce9..5bb55c13c2 100755 --- a/integration_tests/run +++ b/integration_tests/run @@ -7,5 +7,5 @@ # There is an RFC for cargo to allow for this kind of dependency: # https://github.com/rust-lang/cargo/issues/9096 cd $(dirname $0) -(cd .. && cargo build $@) +(cd .. && cargo build $@ && cargo build --features=direct --bin crosvm-direct) cargo test $@ diff --git a/integration_tests/tests/fixture.rs b/integration_tests/tests/fixture.rs index 0ab1dd5cd7..bf6b73059d 100644 --- a/integration_tests/tests/fixture.rs +++ b/integration_tests/tests/fixture.rs @@ -80,18 +80,29 @@ fn rootfs_path() -> PathBuf { /// The crosvm binary is expected to be alongside to the integration tests /// binary. Alternatively in the parent directory (cargo will put the -/// test binary in target/debug/deps/ but the crosvm binary in target/debug). +/// test binary in target/debug/deps/ but the crosvm binary in target/debug) fn find_crosvm_binary() -> PathBuf { + cfg_if::cfg_if! { + if #[cfg(features="direct")] { + let binary_name = "crosvm-direct"; + } else { + let binary_name = "crosvm"; + } + } + let exe_dir = env::current_exe().unwrap().parent().unwrap().to_path_buf(); - let first = exe_dir.join("crosvm"); + let first = exe_dir.join(binary_name); if first.exists() { return first; } - let second = exe_dir.parent().unwrap().join("crosvm"); + let second = exe_dir.parent().unwrap().join(binary_name); if second.exists() { return second; } - panic!("Cannot find ./crosvm or ../crosvm alongside test binary."); + panic!( + "Cannot find {} in ./ or ../ alongside test binary.", + binary_name + ); } /// Safe wrapper for libc::mkfifo diff --git a/tools/impl/test_runner.py b/tools/impl/test_runner.py index c694e13a95..3c5cd52bfe 100644 --- a/tools/impl/test_runner.py +++ b/tools/impl/test_runner.py @@ -226,15 +226,18 @@ def build_common_crate(build_env: dict[str, str], build_arch: Arch, crate: Crate return list(cargo_build_executables([], build_arch, env=build_env, cwd=crate.path)) -def build_all_binaries(target: TestTarget, build_arch: Arch): +def build_all_binaries(target: TestTarget, build_arch: Arch, crosvm_direct: bool): """Discover all crates and build them.""" build_env = os.environ.copy() build_env.update(test_target.get_cargo_env(target, build_arch)) print("Building crosvm workspace") + features = BUILD_FEATURES[build_arch] + if crosvm_direct: + features += ",direct" yield from cargo_build_executables( [ - "--features=" + BUILD_FEATURES[build_arch], + "--features=" + features, "--verbose", "--workspace", *[f"--exclude={crate}" for crate in get_workspace_excludes(build_arch)], @@ -379,6 +382,10 @@ def main(): "--build-only", action="store_true", ) + parser.add_argument( + "--crosvm-direct", + action="store_true", + ) parser.add_argument( "--repeat", type=int, @@ -406,7 +413,7 @@ def main(): testvm.build_if_needed(target.vm) testvm.up(target.vm) - executables = list(build_all_binaries(target, build_arch)) + executables = list(build_all_binaries(target, build_arch, args.crosvm_direct)) if args.build_only: print("Not running tests as requested.")