1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

uptime: adapt test to API changes in bincode

This commit is contained in:
Daniel Hofstetter 2025-04-16 10:57:16 +02:00
parent e263ff3167
commit 8590f51f85
2 changed files with 9 additions and 5 deletions

View file

@ -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"

View file

@ -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();
}