From 0323efc01ebab00f4bf8090687a6443f7a0edaa0 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Wed, 16 Dec 2020 00:27:03 -0800 Subject: use sys_util and tempfile from crosvm Adjust dependencies to use the crosvm-local crates. The tempfile interface is subtly different use the crosvm implementation to avoid a dependency on `rand`. Using a temporary directory avoids any chance of name collision with using rand to generate a string for a socket name. Some of the ScmSocket interfaces have changed and needed updating on both ends. BUG=b:181227406 TEST=cargo test Change-Id: Idee69f0c561642954ac1fa05c2951949e3b74fb5 Cq-Depend: chromium:2740533 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/rust-vmm/vhost/+/2717529 Tested-by: Dylan Reid Commit-Queue: Keiichi Watanabe Reviewed-by: Keiichi Watanabe Reviewed-by: Chirantan Ekbote --- src/vhost_user/master.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/vhost_user/master.rs') diff --git a/src/vhost_user/master.rs b/src/vhost_user/master.rs index f9da535..f098982 100644 --- a/src/vhost_user/master.rs +++ b/src/vhost_user/master.rs @@ -9,7 +9,7 @@ use std::os::unix::net::UnixStream; use std::path::Path; use std::sync::{Arc, Mutex, MutexGuard}; -use vmm_sys_util::eventfd::EventFd; +use sys_util::EventFd; use super::connection::Endpoint; use super::message::*; @@ -645,15 +645,12 @@ impl MasterInternal { mod tests { use super::super::connection::Listener; use super::*; - use vmm_sys_util::rand::rand_alphanumerics; + use tempfile::{Builder, TempDir}; use std::path::PathBuf; - fn temp_path() -> PathBuf { - PathBuf::from(format!( - "/tmp/vhost_test_{}", - rand_alphanumerics(8).to_str().unwrap() - )) + fn temp_dir() -> TempDir { + Builder::new().prefix("/tmp/vhost_test").tempdir().unwrap() } fn create_pair>(path: P) -> (Master, Endpoint) { @@ -666,7 +663,9 @@ mod tests { #[test] fn create_master() { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let listener = Listener::new(&path, true).unwrap(); listener.set_nonblocking(true).unwrap(); @@ -693,7 +692,9 @@ mod tests { #[test] fn test_create_failure() { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let _ = Listener::new(&path, true).unwrap(); let _ = Listener::new(&path, false).is_err(); assert!(Master::connect(&path, 1).is_err()); @@ -708,7 +709,9 @@ mod tests { #[test] fn test_features() { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let (master, mut peer) = create_pair(&path); master.set_owner().unwrap(); @@ -743,7 +746,9 @@ mod tests { #[test] fn test_protocol_features() { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let (mut master, mut peer) = create_pair(&path); master.set_owner().unwrap(); @@ -794,7 +799,9 @@ mod tests { #[test] fn test_master_set_config_negative() { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let (mut master, _peer) = create_pair(&path); let buf = vec![0x0; MAX_MSG_SIZE + 1]; @@ -835,7 +842,9 @@ mod tests { } fn create_pair2() -> (Master, Endpoint) { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let (master, peer) = create_pair(&path); { -- cgit v1.2.3