base: Move clone_equality test to integration test

In non-privileged containers, comparing a file descriptor may not
work. So the test will not work in every runtime environment.

BUG=b:244623061
TEST=dev_container --podman --unprivileged tools/run_tests base:base

Change-Id: Ifa67e11db9694c36b47cd5ae88de9247284e1cdf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3999711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2022-11-02 20:37:25 +00:00 committed by crosvm LUCI
parent 11322f007d
commit 86034fd5fb
2 changed files with 27 additions and 25 deletions

View file

@ -214,28 +214,3 @@ IntoRawDescriptor!(UnixDatagram);
AsRawDescriptor!(Stdin);
AsRawDescriptor!(Stdout);
AsRawDescriptor!(Stderr);
#[test]
#[allow(clippy::eq_op)]
fn clone_equality() {
let ret = unsafe { libc::eventfd(0, 0) };
if ret < 0 {
panic!("failed to create eventfd");
}
let descriptor = unsafe { SafeDescriptor::from_raw_descriptor(ret) };
assert_eq!(descriptor, descriptor);
assert_eq!(
descriptor,
descriptor.try_clone().expect("failed to clone eventfd")
);
let ret = unsafe { libc::eventfd(0, 0) };
if ret < 0 {
panic!("failed to create eventfd");
}
let another = unsafe { SafeDescriptor::from_raw_descriptor(ret) };
assert_ne!(descriptor, another);
}

View file

@ -8,6 +8,8 @@ use std::path::Path;
use base::safe_descriptor_from_path;
use base::Error;
use base::FromRawDescriptor;
use base::SafeDescriptor;
use libc::EBADF;
use libc::EINVAL;
@ -47,3 +49,28 @@ fn safe_descriptor_from_path_none() {
None
);
}
#[test]
#[allow(clippy::eq_op)]
fn clone_equality() {
let ret = unsafe { libc::eventfd(0, 0) };
if ret < 0 {
panic!("failed to create eventfd");
}
let descriptor = unsafe { SafeDescriptor::from_raw_descriptor(ret) };
assert_eq!(descriptor, descriptor);
assert_eq!(
descriptor,
descriptor.try_clone().expect("failed to clone eventfd")
);
let ret = unsafe { libc::eventfd(0, 0) };
if ret < 0 {
panic!("failed to create eventfd");
}
let another = unsafe { SafeDescriptor::from_raw_descriptor(ret) };
assert_ne!(descriptor, another);
}