From cc7a96e9d3b59f4b856ea35c6db355c211cc56dd Mon Sep 17 00:00:00 2001 From: Cathy Zhang Date: Wed, 28 Aug 2019 17:56:33 +0800 Subject: [PATCH] main: Add integration test Use qemu/tests/vhost-user-bridge as the backend for integration test for vhost-user-net. Signed-off-by: Cathy Zhang --- scripts/run_integration_tests.sh | 6 ++- src/main.rs | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/scripts/run_integration_tests.sh b/scripts/run_integration_tests.sh index 1d9daeeb2..c916c91a7 100755 --- a/scripts/run_integration_tests.sh +++ b/scripts/run_integration_tests.sh @@ -79,14 +79,16 @@ if [ ! -f "$VMLINUX_IMAGE" ]; then fi VIRTIOFSD="$WORKLOADS_DIR/virtiofsd" +VUBRIDGE="$WORKLOADS_DIR/vubridge" QEMU_DIR="qemu_build" -if [ ! -f "$VIRTIOFSD" ]; then +if [ ! -f "$VIRTIOFSD" || ! -f "$VUBRIDGE" ]; then pushd $WORKLOADS_DIR git clone --depth 1 "https://github.com/sboeuf/qemu.git" -b "virtio-fs" $QEMU_DIR pushd $QEMU_DIR ./configure --prefix=$PWD --target-list=x86_64-softmmu - make virtiofsd -j `nproc` + make virtiofsd tests/vhost-user-bridge -j `nproc` cp virtiofsd $VIRTIOFSD + cp tests/vhost-user-bridge $VUBRIDGE popd rm -rf $QEMU_DIR sudo setcap cap_dac_override,cap_sys_admin+epi "virtiofsd" diff --git a/src/main.rs b/src/main.rs index 772671c4f..d5fd69f80 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1097,6 +1097,72 @@ mod tests { }); } + #[test] + fn test_vhost_user_net() { + test_block!(tb, "", { + let mut clear = ClearDiskConfig::new(); + let guest = Guest::new(&mut clear); + + let mut workload_path = dirs::home_dir().unwrap(); + workload_path.push("workloads"); + + let mut vubridge_path = workload_path.clone(); + vubridge_path.push("vubridge"); + let vubridge_path = String::from(vubridge_path.to_str().unwrap()); + + // Start the daemon + let mut daemon_child = Command::new(vubridge_path.as_str()).spawn().unwrap(); + + let mut cloud_child = Command::new("target/debug/cloud-hypervisor") + .args(&["--cpus", "4"]) + .args(&["--memory", "size=512M,file=/dev/shm"]) + .args(&["--kernel", guest.fw_path.as_str()]) + .args(&[ + "--disk", + guest + .disk_config + .disk(DiskType::OperatingSystem) + .unwrap() + .as_str(), + guest + .disk_config + .disk(DiskType::CloudInit) + .unwrap() + .as_str(), + ]) + .args(&[ + "--vhost-user-net", + "mac=52:54:00:02:d9:01,sock=/tmp/vubr.sock", + ]) + .args(&["--net", guest.default_net_string().as_str()]) + .spawn() + .unwrap(); + + // 2 network interfaces + default localhost ==> 3 interfaces + aver_eq!( + tb, + guest + .ssh_command("ip -o link | wc -l") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(), + 3 + ); + + thread::sleep(std::time::Duration::new(5, 0)); + let _ = daemon_child.kill(); + let _ = daemon_child.wait(); + + guest.ssh_command("sudo reboot")?; + thread::sleep(std::time::Duration::new(5, 0)); + let _ = cloud_child.kill(); + let _ = cloud_child.wait(); + + Ok(()) + }); + } + #[test] fn test_split_irqchip() { test_block!(tb, "", {