From f87295a8ce0709198d6473ed1952dcfd894c8030 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 6 Apr 2022 21:19:03 +0000 Subject: [PATCH] crosvm: skip creating tap device in plugins tests if not enough capabilities BUG=none TEST=presubmit Change-Id: Icf3948941103b535ec138e68a05298c18d469485 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3574989 Auto-Submit: Anton Romanov Tested-by: kokoro Reviewed-by: Dmitry Torokhov Commit-Queue: Dmitry Torokhov --- Cargo.toml | 1 + tests/plugins.rs | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 955ddcbf7c..442a5258cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -198,6 +198,7 @@ aarch64 = { path = "aarch64" } [dev-dependencies] base = "*" +lazy_static = "*" [patch.crates-io] assertions = { path = "common/assertions" } diff --git a/tests/plugins.rs b/tests/plugins.rs index 1cbb2fd6c5..cb7afad517 100644 --- a/tests/plugins.rs +++ b/tests/plugins.rs @@ -17,6 +17,13 @@ use std::time::Duration; use base::{ioctl, AsRawDescriptor}; use tempfile::tempfile; +lazy_static::lazy_static! { + static ref TAP_AVAILABLE: bool = { + use net_util::TapT; + net_util::Tap::new(true, false).is_ok() + }; +} + struct RemovePath(PathBuf); impl Drop for RemovePath { fn drop(&mut self) { @@ -89,12 +96,6 @@ fn run_plugin(bin_path: &Path, with_sandbox: bool) { "run", "-c", "1", - "--host_ip", - "100.115.92.5", - "--netmask", - "255.255.255.252", - "--mac", - "de:21:e8:47:6b:6a", "--seccomp-policy-dir", "tests", "--plugin", @@ -104,6 +105,17 @@ fn run_plugin(bin_path: &Path, with_sandbox: bool) { .canonicalize() .expect("failed to canonicalize plugin path"), ); + + if *TAP_AVAILABLE { + cmd.args(&[ + "--host_ip", + "100.115.92.5", + "--netmask", + "255.255.255.252", + "--mac", + "de:21:e8:47:6b:6a", + ]); + } if !with_sandbox { cmd.arg("--disable-sandbox"); } @@ -286,7 +298,9 @@ fn test_vcpu_pause() { #[test] fn test_net_config() { - test_plugin(include_str!("plugin_net_config.c")); + if *TAP_AVAILABLE { + test_plugin(include_str!("plugin_net_config.c")); + } } #[test]