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 <amulmek1@in.ibm.com>
This commit is contained in:
Amulyam24
2024-01-18 19:16:44 +05:30
committed by Hyounggyu Choi
parent 610f878894
commit f6fea5f2ca
5 changed files with 40 additions and 3 deletions

View File

@@ -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<String>,
devices: Vec<Vec<LinuxDeviceCgroup>>,

View File

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

View File

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

View File

@@ -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<u64, Errno> {
let stat = statfs::statfs(path)?;
let block_size = stat.block_size() as u64;
Ok(block_size)
}
#[tokio::test]

View File

@@ -655,6 +655,8 @@ fn onlined_cpus() -> Result<i32> {
}
#[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!();