crosvm/base/tests/unix/syslog.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

66 lines
1.6 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.
use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::sync::Once;
use base::syslog::*;
static EARLY_INIT_ONCE: Once = Once::new();
pub fn setup() {
EARLY_INIT_ONCE.call_once(|| {
early_init();
});
}
#[test]
fn fds() {
setup();
let mut fds = Vec::new();
push_descriptors(&mut fds);
assert!(!fds.is_empty());
for fd in fds {
assert!(fd >= 0);
}
}
#[test]
fn syslog_file() {
setup();
let mut file = tempfile::tempfile().expect("failed to create tempfile");
let syslog_file = file.try_clone().expect("error cloning shared memory file");
let state = State::new(LogConfig {
pipe: Some(Box::new(syslog_file)),
..Default::default()
})
.unwrap();
const TEST_STR: &str = "hello shared memory file";
state.log(
&log::RecordBuilder::new()
.level(Level::Error)
.args(format_args!("{}", TEST_STR))
.build(),
);
file.seek(SeekFrom::Start(0))
.expect("error seeking shared memory file");
let mut buf = String::new();
file.read_to_string(&mut buf)
.expect("error reading shared memory file");
assert!(buf.contains(TEST_STR));
}
#[test]
fn macros() {
setup();
log::error!("this is an error {}", 3);
log::warn!("this is a warning {}", "uh oh");
log::info!("this is info {}", true);
log::debug!("this is debug info {:?}", Some("helpful stuff"));
}