From f6fea5f2ca5ac6b88ba2ad07aef1a617aef85f24 Mon Sep 17 00:00:00 2001 From: Amulyam24 Date: Thu, 18 Jan 2024 19:16:44 +0530 Subject: [PATCH] agent: fix failing unit tests on ppc64le - test_volume_capacity_stats: verify the file block size against the fetched size via statfs() - test_reseed_rng: Correct the request codes for RNDADDTOENTCNT and RNDRESEEDCRNG when platform is ppc64le - test list_routes: Add the route only if destination is not empty - test_new_fs_manager: skip the test if cgroups v2 is used by default - skip test cases rpc::tests::test_do_write_stream, sandbox::tests::test_find_process, sandbox::t ests::test_find_container_process and sandbox::tests::add_and_get_container on ppc64le as they are fl aky Signed-off-by: Amulyam24 --- src/agent/rustjail/src/cgroups/fs/mod.rs | 14 ++++++++++++++ src/agent/src/netlink.rs | 4 +++- src/agent/src/random.rs | 6 ++++++ src/agent/src/rpc.rs | 14 ++++++++++++-- src/agent/src/sandbox.rs | 5 +++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index e00650494c..dce621e186 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -1400,6 +1400,20 @@ mod tests { fn test_new_fs_manager() { skip_if_not_root!(); + let output = Command::new("stat") + .arg("-f") + .arg("-c") + .arg("%T") + .arg("/sys/fs/cgroup/") + .output() + .unwrap(); + let output_str = String::from_utf8(output.stdout).unwrap(); + let cgroup_version = output_str.strip_suffix("\n").unwrap(); + if cgroup_version.eq("cgroup2fs") { + println!("INFO: Skipping the test as cgroups v2 is used by default"); + return; + } + struct TestCase { cpath: Vec, devices: Vec>, diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index 280b0d95a6..b41cf9b096 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -320,7 +320,9 @@ impl Handle { route.device = self.find_link(LinkFilter::Index(index)).await?.name(); } - result.push(route); + if !route.dest.is_empty() { + result.push(route); + } } Ok(result) diff --git a/src/agent/src/random.rs b/src/agent/src/random.rs index f97f0f0334..6e1e87c3d4 100644 --- a/src/agent/src/random.rs +++ b/src/agent/src/random.rs @@ -12,7 +12,13 @@ use std::os::unix::io::{AsRawFd, FromRawFd}; use tracing::instrument; pub const RNGDEV: &str = "/dev/random"; +#[cfg(target_arch = "powerpc64")] +pub const RNDADDTOENTCNT: libc::c_uint = 0x80045201; +#[cfg(target_arch = "powerpc64")] +pub const RNDRESEEDCRNG: libc::c_int = 0x20005207; +#[cfg(not(target_arch = "powerpc64"))] pub const RNDADDTOENTCNT: libc::c_int = 0x40045201; +#[cfg(not(target_arch = "powerpc64"))] pub const RNDRESEEDCRNG: libc::c_int = 0x5207; // Handle the differing ioctl(2) request types for different targets diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 57690cdfb4..2ce66ecbc6 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -1963,6 +1963,7 @@ fn load_kernel_module(module: &protocols::agent::KernelModule) -> Result<()> { } #[cfg(test)] +#[allow(dead_code)] mod tests { use std::time::{SystemTime, UNIX_EPOCH}; @@ -2154,6 +2155,7 @@ mod tests { } #[tokio::test] + #[cfg(not(target_arch = "powerpc64"))] async fn test_do_write_stream() { skip_if_not_root!(); @@ -2694,8 +2696,16 @@ OtherField:other fs::write(mount_dir.path().join("file.dat"), "foobar").unwrap(); stats = get_volume_capacity_stats(mount_dir.path().to_str().unwrap()).unwrap(); - assert_eq!(stats.used, 4 * 1024); - assert_eq!(stats.available, available - 4 * 1024); + let size = get_block_size(mount_dir.path().to_str().unwrap()).unwrap(); + + assert_eq!(stats.used, size); + assert_eq!(stats.available, available - size); + } + + fn get_block_size(path: &str) -> Result { + let stat = statfs::statfs(path)?; + let block_size = stat.block_size() as u64; + Ok(block_size) } #[tokio::test] diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index 8137939c8e..30f168f2c8 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -655,6 +655,8 @@ fn onlined_cpus() -> Result { } #[cfg(test)] +#[allow(dead_code)] +#[allow(unused_imports)] mod tests { use super::*; use crate::mount::baremount; @@ -924,6 +926,7 @@ mod tests { #[tokio::test] #[serial] + #[cfg(not(target_arch = "powerpc64"))] async fn add_and_get_container() { skip_if_not_root!(); @@ -989,6 +992,7 @@ mod tests { } #[tokio::test] + #[cfg(not(target_arch = "powerpc64"))] async fn test_find_container_process() { skip_if_not_root!(); @@ -1036,6 +1040,7 @@ mod tests { } #[tokio::test] + #[cfg(not(target_arch = "powerpc64"))] async fn test_find_process() { skip_if_not_root!();