From 32b855df3a5f5d4b09f635e333871043347014f4 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 20 Jun 2022 14:05:17 +0000 Subject: [PATCH] tests: switch from lazy_static to once_cell Once_cell does not require using macro and is slated to become part of Rust std at some point. Signed-off-by: Wei Liu --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- test_infra/Cargo.toml | 2 +- test_infra/src/lib.rs | 8 ++------ tests/integration.rs | 9 ++------- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5363b23aa..38828ce0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,10 +165,10 @@ dependencies = [ "epoll", "event_monitor", "hypervisor", - "lazy_static", "libc", "log", "net_util", + "once_cell", "option_parser", "seccompiler", "serde_json", @@ -1038,8 +1038,8 @@ version = "0.1.0" dependencies = [ "dirs", "epoll", - "lazy_static", "libc", + "once_cell", "ssh2", "vmm-sys-util", "wait-timeout", diff --git a/Cargo.toml b/Cargo.toml index f49ed2490..eddd20fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,8 +44,8 @@ versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_deri [dev-dependencies] dirs = "4.0.0" -lazy_static= "1.4.0" net_util = { path = "net_util" } +once_cell = "1.12.0" serde_json = "1.0.81" test_infra = { path = "test_infra" } wait-timeout = "0.2.0" diff --git a/test_infra/Cargo.toml b/test_infra/Cargo.toml index 7b1bdef28..3b6729559 100644 --- a/test_infra/Cargo.toml +++ b/test_infra/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] dirs = "4.0.0" epoll = "4.3.1" -lazy_static = "1.4.0" libc = "0.2.126" +once_cell = "1.12.0" ssh2 = { version = "0.9.1", features = ["vendored-openssl"]} vmm-sys-util = "0.9.0" wait-timeout = "0.2.0" diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index 272d83cbf..eb30af366 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -3,9 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#[macro_use] -extern crate lazy_static; - +use once_cell::sync::Lazy; use ssh2::Session; use std::env; use std::ffi::OsStr; @@ -722,9 +720,7 @@ pub fn exec_host_command_output(command: &str) -> Output { pub const PIPE_SIZE: i32 = 32 << 20; -lazy_static! { - static ref NEXT_VM_ID: Mutex = Mutex::new(1); -} +static NEXT_VM_ID: Lazy> = Lazy::new(|| Mutex::new(1)); pub struct Guest { pub tmp_dir: TempDir, diff --git a/tests/integration.rs b/tests/integration.rs index cf02137da..411884a1f 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -8,10 +8,6 @@ // related warnings for our quality workflow to pass. #![allow(dead_code)] -#[cfg(target_arch = "x86_64")] -#[macro_use] -extern crate lazy_static; - extern crate test_infra; use net_util::MacAddr; @@ -6565,10 +6561,9 @@ mod sequential { #[cfg(target_arch = "x86_64")] mod windows { use crate::*; + use once_cell::sync::Lazy; - lazy_static! { - static ref NEXT_DISK_ID: Mutex = Mutex::new(1); - } + static NEXT_DISK_ID: Lazy> = Lazy::new(|| Mutex::new(1)); struct WindowsGuest { guest: Guest,