tests: Add virtio-fs testing

This commit introduces the testing of the --fs option based on the
virtio-fs implementation. This does not simply add a test, but also
updates the integration script by generating a new kernel embedding
the virtio-fs patches and by downloading the virtiofsd daemon.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-06-14 17:41:13 -07:00 committed by Samuel Ortiz
parent 53085c7ccc
commit 0fcca3ed74
3 changed files with 2709 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ if [ ! -f "$OS_IMAGE" ]; then
popd
fi
# Build generic kernel
VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
BZIMAGE_IMAGE="$WORKLOADS_DIR/bzImage"
@ -44,6 +44,39 @@ if [ ! -f "$VMLINUX_IMAGE" ]; then
popd
fi
# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
VMLINUX_CUSTOM_IMAGE="$WORKLOADS_DIR/vmlinux-custom"
LINUX_CUSTOM_DIR="linux-custom"
if [ ! -f "$VMLINUX_CUSTOM_IMAGE" ]; then
SRCDIR=$PWD
pushd $WORKLOADS_DIR
git clone --depth 1 "https://github.com/sboeuf/linux.git" -b "virtio-pmem_and_virtio-fs" $LINUX_CUSTOM_DIR
pushd $LINUX_CUSTOM_DIR
cp $SRCDIR/resources/linux-virtio-pmem-and-virtio-fs-config .config
make bzImage -j `nproc`
cp vmlinux $VMLINUX_CUSTOM_IMAGE
popd
rm -r $LINUX_CUSTOM_DIR
popd
fi
VIRTIOFSD_URL="$(curl --silent https://api.github.com/repos/intel/nemu/releases/latest | grep "browser_download_url" | grep "virtiofsd-x86_64" | grep -o 'https://.*[^ "]')"
VIRTIOFSD="$WORKLOADS_DIR/virtiofsd"
if [ ! -f "$VIRTIOFSD" ]; then
pushd $WORKLOADS_DIR
wget --quiet $VIRTIOFSD_URL -O "virtiofsd"
chmod +x "virtiofsd"
sudo setcap cap_sys_admin+epi "virtiofsd"
popd
fi
SHARED_DIR="$WORKLOADS_DIR/shared_dir"
if [ ! -d "$SHARED_DIR" ]; then
mkdir -p $SHARED_DIR
echo "foo" > "$SHARED_DIR/file1"
echo "bar" > "$SHARED_DIR/file3"
fi
rm /tmp/cloudinit.img
mkdosfs -n config-2 -C /tmp/cloudinit.img 8192
@ -53,4 +86,4 @@ cargo build
sudo setcap cap_net_admin+ep target/debug/cloud-hypervisor
# Tests must be executed serially for now as they have a hardcoded IP address
cargo test --features "integration_tests" -- --test-threads=1
cargo test --features "integration_tests" -- --test-threads=1

View File

@ -211,6 +211,34 @@ mod tests {
(disks, String::from(fw_path.to_str().unwrap()))
}
fn prepare_virtiofsd() -> (std::process::Child, String) {
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let mut virtiofsd_path = workload_path.clone();
virtiofsd_path.push("virtiofsd");
let virtiofsd_path = String::from(virtiofsd_path.to_str().unwrap());
let mut shared_dir_path = workload_path.clone();
shared_dir_path.push("shared_dir");
let shared_dir_path = String::from(shared_dir_path.to_str().unwrap());
let virtiofsd_socket_path = String::from("/tmp/virtiofs.sock");
// Start the daemon
let child = Command::new(virtiofsd_path.as_str())
.args(&[
"-o",
format!("vhost_user_socket={}", virtiofsd_socket_path).as_str(),
])
.args(&["-o", format!("source={}", shared_dir_path).as_str()])
.args(&["-o", "cache=none"])
.spawn()
.unwrap();
(child, virtiofsd_socket_path)
}
fn get_cpu_count() -> u32 {
ssh_command("grep -c processor /proc/cpuinfo")
.trim()
@ -439,7 +467,7 @@ mod tests {
let (disks, fw_path) = prepare_files();
let mut child = Command::new("target/debug/cloud-hypervisor")
.args(&["--cpus", "1"])
.args(&["--memory", "512"])
.args(&["--memory", "size=512"])
.args(&["--kernel", fw_path.as_str()])
.args(&["--disk", disks[0], disks[1]])
.args(&["--net", "tap=,mac=,ip=192.168.2.1,mask=255.255.255.0"])
@ -472,4 +500,60 @@ mod tests {
Ok(())
});
}
#[test]
fn test_virtio_fs() {
test_block!(tb, "", {
let (disks, _) = prepare_files();
let (mut daemon_child, virtiofsd_socket_path) = prepare_virtiofsd();
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let mut kernel_path = workload_path.clone();
kernel_path.push("vmlinux-custom");
let mut child = Command::new("target/debug/cloud-hypervisor")
.args(&["--cpus", "1"])
.args(&["--memory", "size=512,file=/dev/shm"])
.args(&["--kernel", kernel_path.to_str().unwrap()])
.args(&["--disk", disks[0], disks[1]])
.args(&["--net", "tap=,mac=,ip=192.168.2.1,mask=255.255.255.0"])
.args(&[
"--fs",
format!(
"tag=virtiofs,sock={},num_queues=1,queue_size=1024",
virtiofsd_socket_path
)
.as_str(),
])
.args(&["--cmdline", "root=PARTUUID=3cb0e0a5-925d-405e-bc55-edf0cec8f10a console=tty0 console=ttyS0,115200n8 console=hvc0 quiet init=/usr/lib/systemd/systemd-bootchart initcall_debug tsc=reliable no_timer_check noreplace-smp cryptomgr.notests rootfstype=ext4,btrfs,xfs kvm-intel.nested=1 rw"])
.spawn()
.unwrap();
thread::sleep(std::time::Duration::new(10, 0));
// Mount shared directory through virtio_fs filesystem
aver_eq!(
tb,
ssh_command("mkdir -p mount_dir && sudo mount -t virtio_fs /dev/null mount_dir/ -o tag=virtiofs,rootmode=040000,user_id=1001,group_id=1001 && echo ok")
.trim(),
"ok"
);
// Check file1 exists and its content is "foo"
aver_eq!(tb, ssh_command("cat mount_dir/file1").trim(), "foo");
// Check file2 does not exist
aver_ne!(
tb,
ssh_command("ls mount_dir/file2").trim(),
"mount_dir/file2"
);
// Check file3 exists and its content is "bar"
aver_eq!(tb, ssh_command("cat mount_dir/file3").trim(), "bar");
ssh_command("sudo reboot");
let _ = child.wait();
let _ = daemon_child.wait();
Ok(())
});
}
}