diff options
author | Dylan Reid <dgreid@chromium.org> | 2020-12-16 00:27:03 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-03-11 08:06:30 +0000 |
commit | 0323efc01ebab00f4bf8090687a6443f7a0edaa0 (patch) | |
tree | 7536e6caa6e28fd8ef0a3410ed779c89f0d5af06 /src/vhost_user/master.rs | |
parent | cc3810e49b06c1c1b2311b2be232d3368d075aaf (diff) | |
download | vmm_vhost-0323efc01ebab00f4bf8090687a6443f7a0edaa0.tar.gz |
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 <dgreid@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Diffstat (limited to 'src/vhost_user/master.rs')
-rw-r--r-- | src/vhost_user/master.rs | 35 |
1 files changed, 22 insertions, 13 deletions
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<P: AsRef<Path>>(path: P) -> (Master, Endpoint<MasterReq>) { @@ -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<MasterReq>) { - let path = temp_path(); + let dir = temp_dir(); + let mut path = dir.path().to_owned(); + path.push("sock"); let (master, peer) = create_pair(&path); { |