scripts, tests: Rustify the network setup commands for tests

Fixes: #2218

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2021-02-12 15:13:58 -08:00 committed by Rob Bradford
parent f58b6f8417
commit a838d0bde1
3 changed files with 118 additions and 47 deletions

View File

@ -203,11 +203,6 @@ if [ $RES -ne 0 ]; then
exit 1
fi
# Create tap interface without multiple queues support for vhost_user_net test.
sudo ip tuntap add name vunet-tap0 mode tap
# Create tap interface with multiple queues support for vhost_user_net test.
sudo ip tuntap add name vunet-tap1 mode tap multi_queue
BUILD_TARGET="aarch64-unknown-linux-${CH_LIBC}"
CFLAGS=""
TARGET_CC=""
@ -231,8 +226,4 @@ export RUST_BACKTRACE=1
time cargo test $features_test "tests::parallel::$test_filter"
RES=$?
# Tear vhost_user_net test network down
sudo ip link del vunet-tap0
sudo ip link del vunet-tap1
exit $RES

View File

@ -187,33 +187,6 @@ cp $FOCAL_OS_IMAGE $VFIO_DIR
cp $FW $VFIO_DIR
cp $VMLINUX_IMAGE $VFIO_DIR || exit 1
# VFIO test network setup.
# We reserve a different IP class for it: 172.18.0.0/24.
sudo ip link add name vfio-br0 type bridge
sudo ip link set vfio-br0 up
sudo ip addr add 172.18.0.1/24 dev vfio-br0
sudo ip tuntap add vfio-tap0 mode tap
sudo ip link set vfio-tap0 master vfio-br0
sudo ip link set vfio-tap0 up
sudo ip tuntap add vfio-tap1 mode tap
sudo ip link set vfio-tap1 master vfio-br0
sudo ip link set vfio-tap1 up
sudo ip tuntap add vfio-tap2 mode tap
sudo ip link set vfio-tap2 master vfio-br0
sudo ip link set vfio-tap2 up
sudo ip tuntap add vfio-tap3 mode tap
sudo ip link set vfio-tap3 master vfio-br0
sudo ip link set vfio-tap3 up
# Create tap interface without multiple queues support for vhost_user_net test.
sudo ip tuntap add name vunet-tap0 mode tap
# Create tap interface with multiple queues support for vhost_user_net test.
sudo ip tuntap add name vunet-tap1 mode tap multi_queue
BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}"
CFLAGS=""
TARGET_CC=""
@ -253,15 +226,4 @@ if [ $RES -eq 0 ]; then
RES=$?
fi
# Tear VFIO test network down
sudo ip link del vfio-br0
sudo ip link del vfio-tap0
sudo ip link del vfio-tap1
sudo ip link del vfio-tap2
sudo ip link del vfio-tap3
# Tear vhost_user_net test network down
sudo ip link del vunet-tap0
sudo ip link del vunet-tap1
exit $RES

View File

@ -2392,6 +2392,120 @@ mod tests {
)
}
// VFIO test network setup.
// We reserve a different IP class for it: 172.18.0.0/24.
fn setup_vfio_network_interfaces() {
// 'vfio-br0'
Command::new("bash")
.arg("-c")
.arg("sudo ip link add name vfio-br0 type bridge")
.output()
.expect("Failed to create 'vfio-br0'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-br0 up")
.output()
.expect("Failed to create 'vfio-br0'");
Command::new("bash")
.arg("-c")
.arg("sudo ip addr add 172.18.0.1/24 dev vfio-br0")
.output()
.expect("Failed to create 'vfio-br0'");
// 'vfio-tap0'
Command::new("bash")
.arg("-c")
.arg("sudo ip tuntap add vfio-tap0 mode tap")
.output()
.expect("Failed to create 'vfio-tap0'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap0 master vfio-br0")
.output()
.expect("Failed to create 'vfio-tap0'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap0 up")
.output()
.expect("Failed to create 'vfio-tap0'");
// 'vfio-tap1'
Command::new("bash")
.arg("-c")
.arg("sudo ip tuntap add vfio-tap1 mode tap")
.output()
.expect("Failed to create 'vfio-tap1'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap1 master vfio-br0")
.output()
.expect("Failed to create 'vfio-tap1'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap1 up")
.output()
.expect("Failed to create 'vfio-tap1'");
// 'vfio-tap2'
Command::new("bash")
.arg("-c")
.arg("sudo ip tuntap add vfio-tap2 mode tap")
.output()
.expect("Failed to create 'vfio-tap2'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap2 master vfio-br0")
.output()
.expect("Failed to create 'vfio-tap2'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap2 up")
.output()
.expect("Failed to create 'vfio-tap2'");
// 'vfio-tap3'
Command::new("bash")
.arg("-c")
.arg("sudo ip tuntap add vfio-tap3 mode tap")
.output()
.expect("Failed to create 'vfio-tap3'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap3 master vfio-br0")
.output()
.expect("Failed to create 'vfio-tap3'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link set vfio-tap3 up")
.output()
.expect("Failed to create 'vfio-tap3'");
}
// Tear VFIO test network down
fn cleanup_vfio_network_interfaces() {
Command::new("bash")
.arg("-c")
.arg("sudo ip link del vfio-br0")
.output()
.expect("Failed to delete 'vfio-br0'");
Command::new("bash")
.arg("-c")
.arg("sudo ip link del vfio-tap0")
.output()
.expect("Failed to delete ''");
Command::new("bash")
.arg("-c")
.arg("sudo ip link del vfio-tap1")
.output()
.expect("Failed to delete ''");
Command::new("bash")
.arg("-c")
.arg("sudo ip link del vfio-tap2")
.output()
.expect("Failed to delete ''");
Command::new("bash")
.arg("-c")
.arg("sudo ip link del vfio-tap3")
.output()
.expect("Failed to delete ''");
}
mod parallel {
use crate::tests::*;
@ -3845,6 +3959,8 @@ mod tests {
// The third device is added to validate that hotplug works correctly since
// it is being added to the L2 VM through hotplugging mechanism.
fn test_vfio() {
setup_vfio_network_interfaces();
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
let guest = Guest::new_from_ip_range(&mut focal, "172.18", 0);
@ -4075,6 +4191,8 @@ mod tests {
let _ = child.kill();
let output = child.wait_with_output().unwrap();
cleanup_vfio_network_interfaces();
handle_child_output(r, &output);
}