diff --git a/Cargo.toml b/Cargo.toml index b928a18..d97f94b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ regex = { version = "1" } reqwest = { version = "0.11", features = ["blocking"], optional = true } ping = { version = "0.5", optional = true } -sysinfo = { version = "0.29", optional = true } +sysinfo = { version = "0.30", optional = true } byte-unit = { version = "5.0", optional = true } num_cpus = { version = "1.13", optional = true } which = { version = "5.0", optional = true } diff --git a/README.md b/README.md index 815f1eb..1f0f67a 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,7 @@ the test runner will treat it as the test in Rust and also provide the same summ The `runtime` feature should be enabled and include as normal dependency, and also include the `libtest-with` with corresponding features in `Cargo.toml`. ```toml test-with = { version = "0.10", features = ["runtime"] } -libtest-with = { version = "0.6.1-5", features = ["net", "resource", "user", "executable"] } +libtest-with = { version = "0.6.1-6", features = ["net", "resource", "user", "executable"] } ``` Create an example with the following runtime macros (`test_with::runner!`, `#[test_with::module]`, `#[test_with::runtime_env()]`). diff --git a/examples/runner/Cargo.toml b/examples/runner/Cargo.toml index 1c73c36..80cd500 100644 --- a/examples/runner/Cargo.toml +++ b/examples/runner/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] test-with = { path = "../../", features = ["runtime"] } -libtest-with = { version = "0.6.1-5", features = ["net", "resource", "user", "executable"]} +libtest-with = { version = "0.6.1-6", features = ["net", "resource", "user", "executable"]} diff --git a/src/lib.rs b/src/lib.rs index 6df8bfa..b221265 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,7 +35,7 @@ //! ```toml //! [dependencies] //! test-with = { version = "*", default-features = false, features = ["runtime"] } -//! libtest-with = { version = "0.6.1-5", features = ["net", "resource", "user", "executable"] } +//! libtest-with = { version = "0.6.1-6", features = ["net", "resource", "user", "executable"] } //! ``` //! //! ```rust @@ -65,8 +65,6 @@ use syn::{parse_macro_input, ItemFn, ItemMod}; #[cfg(feature = "runtime")] use syn::{Item, ItemStruct, ItemType}; -#[cfg(feature = "resource")] -use sysinfo::SystemExt; #[cfg(feature = "executable")] use which::which; @@ -1451,8 +1449,9 @@ pub fn mem(attr: TokenStream, stream: TokenStream) -> TokenStream { #[cfg(feature = "resource")] fn check_mem_condition(mem_size_str: String) -> (bool, String) { - let mut sys = sysinfo::System::new_all(); - sys.refresh_all(); + let sys = sysinfo::System::new_with_specifics( + sysinfo::RefreshKind::new().with_memory(sysinfo::MemoryRefreshKind::new().with_swap()), + ); let mem_size = match byte_unit::Byte::parse_str(format!("{} B", sys.total_memory()), false) { Ok(b) => b, Err(_) => abort_call_site!("memory size description is not correct"), @@ -1508,9 +1507,9 @@ pub fn runtime_mem(attr: TokenStream, stream: TokenStream) -> TokenStream { quote::quote! { fn #check_ident() -> Result<(), libtest_with::Failed> { - use libtest_with::sysinfo::SystemExt; - let mut sys = libtest_with::sysinfo::System::new_all(); - sys.refresh_all(); + let sys = libtest_with::sysinfo::System::new_with_specifics( + libtest_with::sysinfo::RefreshKind::new().with_memory(libtest_with::sysinfo::MemoryRefreshKind::new().with_ram()), + ); let mem_size = match libtest_with::byte_unit::Byte::parse_str(format!("{} B", sys.total_memory()), false) { Ok(b) => b, Err(_) => panic!("system memory size can not get"), @@ -1573,9 +1572,9 @@ pub fn runtime_free_mem(attr: TokenStream, stream: TokenStream) -> TokenStream { quote::quote! { fn #check_ident() -> Result<(), libtest_with::Failed> { - use libtest_with::sysinfo::SystemExt; - let mut sys = libtest_with::sysinfo::System::new_all(); - sys.refresh_all(); + let sys = libtest_with::sysinfo::System::new_with_specifics( + libtest_with::sysinfo::RefreshKind::new().with_memory(libtest_with::sysinfo::MemoryRefreshKind::new().with_ram()), + ); let mem_size = match libtest_with::byte_unit::Byte::parse_str(format!("{} B", sys.free_memory()), false) { Ok(b) => b, Err(_) => panic!("system memory size can not get"), @@ -1638,9 +1637,9 @@ pub fn runtime_available_mem(attr: TokenStream, stream: TokenStream) -> TokenStr quote::quote! { fn #check_ident() -> Result<(), libtest_with::Failed> { - use libtest_with::sysinfo::SystemExt; - let mut sys = libtest_with::sysinfo::System::new_all(); - sys.refresh_all(); + let sys = libtest_with::sysinfo::System::new_with_specifics( + libtest_with::sysinfo::RefreshKind::new().with_memory(libtest_with::sysinfo::MemoryRefreshKind::new().with_ram()), + ); let mem_size = match libtest_with::byte_unit::Byte::parse_str(format!("{} B", sys.available_memory()), false) { Ok(b) => b, Err(_) => panic!("system memory size can not get"), @@ -1697,8 +1696,9 @@ pub fn swap(attr: TokenStream, stream: TokenStream) -> TokenStream { #[cfg(feature = "resource")] fn check_swap_condition(swap_size_str: String) -> (bool, String) { - let mut sys = sysinfo::System::new_all(); - sys.refresh_all(); + let sys = sysinfo::System::new_with_specifics( + sysinfo::RefreshKind::new().with_memory(sysinfo::MemoryRefreshKind::new().with_swap()), + ); let swap_size = match byte_unit::Byte::parse_str(format!("{} B", sys.total_swap()), false) { Ok(b) => b, Err(_) => abort_call_site!("Swap size description is not correct"), @@ -1754,9 +1754,9 @@ pub fn runtime_swap(attr: TokenStream, stream: TokenStream) -> TokenStream { quote::quote! { fn #check_ident() -> Result<(), libtest_with::Failed> { - use libtest_with::sysinfo::SystemExt; - let mut sys = libtest_with::sysinfo::System::new_all(); - sys.refresh_all(); + let sys = libtest_with::sysinfo::System::new_with_specifics( + libtest_with::sysinfo::RefreshKind::new().with_memory(libtest_with::sysinfo::MemoryRefreshKind::new().with_swap()), + ); let swap_size = match libtest_with::byte_unit::Byte::parse_str(format!("{} B", sys.total_swap()), false) { Ok(b) => b, Err(_) => panic!("system swap size can not get"), @@ -1819,9 +1819,9 @@ pub fn runtime_free_swap(attr: TokenStream, stream: TokenStream) -> TokenStream quote::quote! { fn #check_ident() -> Result<(), libtest_with::Failed> { - use libtest_with::sysinfo::SystemExt; - let mut sys = libtest_with::sysinfo::System::new_all(); - sys.refresh_all(); + let sys = libtest_with::sysinfo::System::new_with_specifics( + libtest_with::sysinfo::RefreshKind::new().with_memory(libtest_with::sysinfo::MemoryRefreshKind::new().with_swap()), + ); let swap_size = match libtest_with::byte_unit::Byte::parse_str(format!("{} B", sys.free_swap()), false) { Ok(b) => b, Err(_) => panic!("system swap size can not get"),