crosvm/base/tests/unix/main.rs
Dennis Kempin b896b869e4 base: Extract integration tests
The extracted tests rely on access to system devices
or global state that prevent them from being run in parallel
or in restricted environments.

As an integration test they will be executed separately and
single threaded.

Updates the test runner to ensure integration tests are actually
run single threaded as intended.

BUG=b:244623061
TEST=./tools/run_tests base:\* --repeat 100 -p x86_64/mingw64/aarch64

Change-Id: I4267b9f79055208aca86796d902da251816bcada
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3971025
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-10-24 22:49:29 +00:00

49 lines
1 KiB
Rust

// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![cfg(unix)]
use std::path::Path;
use base::safe_descriptor_from_path;
use base::Error;
use libc::EBADF;
use libc::EINVAL;
/// Runs all unix specific integration tests in a single binary.
mod net;
mod scoped_signal_handler;
mod syslog;
mod tube;
#[test]
fn safe_descriptor_from_path_valid() {
assert!(safe_descriptor_from_path(Path::new("/proc/self/fd/2"))
.unwrap()
.is_some());
}
#[test]
fn safe_descriptor_from_path_invalid_integer() {
assert_eq!(
safe_descriptor_from_path(Path::new("/proc/self/fd/blah")),
Err(Error::new(EINVAL))
);
}
#[test]
fn safe_descriptor_from_path_invalid_fd() {
assert_eq!(
safe_descriptor_from_path(Path::new("/proc/self/fd/42")),
Err(Error::new(EBADF))
);
}
#[test]
fn safe_descriptor_from_path_none() {
assert_eq!(
safe_descriptor_from_path(Path::new("/something/else")).unwrap(),
None
);
}