Skip to content

Commit faf595e

Browse files
Alexandra Iordachesandreim
authored andcommitted
tests: removed test_main
Running the whole Firecracker main function in a unit test kind of defeats the purpose of unit tests. It's extensively tested in the integration tests, and causes unit test pain because of the seccomp filters it installs (and maintains across the whole suite). Signed-off-by: Alexandra Iordache <[email protected]>
1 parent c57f589 commit faf595e

File tree

2 files changed

+1
-112
lines changed

2 files changed

+1
-112
lines changed

src/main.rs

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -374,114 +374,3 @@ fn vmm_control_event(
374374
};
375375
Ok(())
376376
}
377-
378-
#[cfg(test)]
379-
mod tests {
380-
extern crate tempfile;
381-
382-
use self::tempfile::NamedTempFile;
383-
use super::*;
384-
385-
use logger::AppInfo;
386-
use std::fs::File;
387-
use std::io::BufRead;
388-
use std::io::BufReader;
389-
use std::path::Path;
390-
use std::time::Duration;
391-
use std::{fs, thread};
392-
393-
/// Look through the log for lines that match expectations.
394-
/// expectations is a list of tuples of words we're looking for.
395-
/// A tuple matches a line if all the words in the tuple can be found on that line.
396-
/// For this test to pass, every tuple must match at least one line.
397-
fn validate_backtrace(
398-
log_path: &str,
399-
expectations: &[(&'static str, &'static str, &'static str)],
400-
) -> bool {
401-
let f = File::open(log_path).unwrap();
402-
let reader = BufReader::new(f);
403-
let mut expectation_iter = expectations.iter();
404-
let mut expected_words = expectation_iter.next().unwrap();
405-
406-
for ln_res in reader.lines() {
407-
let line = ln_res.unwrap();
408-
if !(line.contains(expected_words.0)
409-
&& line.contains(expected_words.1)
410-
&& line.contains(expected_words.2))
411-
{
412-
continue;
413-
}
414-
if let Some(w) = expectation_iter.next() {
415-
expected_words = w;
416-
continue;
417-
}
418-
return true;
419-
}
420-
false
421-
}
422-
423-
#[test]
424-
fn test_main() {
425-
const FIRECRACKER_INIT_TIMEOUT_MILLIS: u64 = 150;
426-
427-
// If the default api socket path exist, remove it so we can continue running the test.
428-
if Path::new(DEFAULT_API_SOCK_PATH).exists() {
429-
fs::remove_file(DEFAULT_API_SOCK_PATH).expect("failure in removing socket file");
430-
}
431-
432-
let log_file_temp =
433-
NamedTempFile::new().expect("Failed to create temporary output logging file.");
434-
let metrics_file_temp =
435-
NamedTempFile::new().expect("Failed to create temporary metrics logging file.");
436-
let log_file = String::from(log_file_temp.path().to_path_buf().to_str().unwrap());
437-
438-
// Start Firecracker in a separate thread
439-
thread::spawn(|| {
440-
main();
441-
});
442-
443-
// Wait around for a bit, so Firecracker has time to initialize and create the
444-
// API socket.
445-
thread::sleep(Duration::from_millis(FIRECRACKER_INIT_TIMEOUT_MILLIS));
446-
447-
// If Firecracker hasn't finished initializing yet, something is really wrong!
448-
assert!(Path::new(DEFAULT_API_SOCK_PATH).exists());
449-
450-
// Initialize the logger
451-
LOGGER
452-
.init(
453-
&AppInfo::new("Firecracker", "1.0"),
454-
Box::new(log_file_temp),
455-
Box::new(metrics_file_temp),
456-
)
457-
.expect("Could not initialize logger.");
458-
459-
// Cause some controlled panic and see if a backtrace shows up in the log,
460-
// as it's supposed to.
461-
let _ = panic::catch_unwind(|| {
462-
panic!("Oh, noes!");
463-
});
464-
465-
// Before checking the backtrace let's remove the API socket to make sure we don't
466-
// leave it on the host in case the assert fails.
467-
fs::remove_file(DEFAULT_API_SOCK_PATH).expect("failure in removing socket file");
468-
469-
// Look for the expected backtrace inside the log
470-
let backtrace_check_result = validate_backtrace(
471-
log_file.as_str(),
472-
&[
473-
// Lines containing these words should have appeared in the log, in this order
474-
("ERROR", "main.rs", "Firecracker panicked at"),
475-
("ERROR", "main.rs", "stack backtrace:"),
476-
("0:", "0x", "firecracker::main::"),
477-
],
478-
);
479-
480-
// Since here we have bound `stderr` to a file as a result of initializing the logger,
481-
// we need to output debugging info on test failure to `stdout` instead.
482-
if !backtrace_check_result {
483-
println!("Could not validate backtrace!\n {:?}", Backtrace::new());
484-
panic!();
485-
}
486-
}
487-
}

tests/integration_tests/build/test_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import host_tools.cargo_build as host # pylint: disable=import-error
2121

22-
COVERAGE_TARGET_PCT = 85.8
22+
COVERAGE_TARGET_PCT = 85.0
2323
COVERAGE_MAX_DELTA = 0.01
2424

2525
CARGO_KCOV_REL_PATH = os.path.join(host.CARGO_BUILD_REL_PATH, 'kcov')

0 commit comments

Comments
 (0)