From 8590f51f851897f021b7959bb2d4c9bd5cb9da4f Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 16 Apr 2025 10:57:16 +0200 Subject: [PATCH] uptime: adapt test to API changes in bincode --- Cargo.toml | 2 +- tests/by-util/test_uptime.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a75a719ef..b0889dabd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -537,7 +537,7 @@ xattr = { workspace = true } # to deserialize a utmpx struct into a binary file [target.'cfg(all(target_family= "unix",not(target_os = "macos")))'.dev-dependencies] serde = { version = "1.0.202", features = ["derive"] } -bincode = { version = "2.0.1" } +bincode = { version = "2.0.1", features = ["serde"] } serde-big-array = "0.5.1" diff --git a/tests/by-util/test_uptime.rs b/tests/by-util/test_uptime.rs index b2618a8a9..7573d434f 100644 --- a/tests/by-util/test_uptime.rs +++ b/tests/by-util/test_uptime.rs @@ -13,7 +13,7 @@ use uutests::util::TestScenario; use uutests::util_name; #[cfg(not(any(target_os = "macos", target_os = "openbsd")))] -use bincode::serialize; +use bincode::{config, serde::encode_to_vec}; use regex::Regex; #[cfg(not(any(target_os = "macos", target_os = "openbsd")))] use serde::Serialize; @@ -134,12 +134,14 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { } arr } + // Creates a file utmp records of three different types including a valid BOOT_TIME entry fn utmp(path: &PathBuf) { // Definitions of our utmpx structs const BOOT_TIME: i32 = 2; const RUN_LVL: i32 = 1; const USER_PROCESS: i32 = 7; + #[derive(Serialize)] #[repr(C)] pub struct TimeVal { @@ -153,6 +155,7 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { e_termination: i16, e_exit: i16, } + #[derive(Serialize)] #[repr(C, align(4))] pub struct Utmp { @@ -230,9 +233,10 @@ fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() { glibc_reserved: [0; 20], }; - let mut buf = serialize(&utmp).unwrap(); - buf.append(&mut serialize(&utmp1).unwrap()); - buf.append(&mut serialize(&utmp2).unwrap()); + let config = config::legacy(); + let mut buf = encode_to_vec(utmp, config).unwrap(); + buf.append(&mut encode_to_vec(utmp1, config).unwrap()); + buf.append(&mut encode_to_vec(utmp2, config).unwrap()); let mut f = File::create(path).unwrap(); f.write_all(&buf).unwrap(); }