From 08cce052c45a2c77317ff090d18521fccfbfc803 Mon Sep 17 00:00:00 2001 From: Jonathan Klimt Date: Tue, 17 Sep 2024 11:58:04 +0200 Subject: [PATCH 1/2] Activated log macros in tests --- src/arch/x86_64/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 30626bae..e8c356f0 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -320,6 +320,11 @@ mod tests { #[test] fn test_pagetable_initialization() { + let _ = env_logger::builder() + .filter(None, log::LevelFilter::Debug) + .is_test(true) + .try_init(); + let mut mem: Vec = vec![0; MIN_PHYSMEM_SIZE]; initialize_pagetables((&mut mem[0..MIN_PHYSMEM_SIZE]).try_into().unwrap()); @@ -369,6 +374,11 @@ mod tests { #[test] fn test_virt_to_phys() { + let _ = env_logger::builder() + .filter(None, log::LevelFilter::Trace) + .is_test(true) + .try_init(); + let mem = MmapMemory::new(0, MIN_PHYSMEM_SIZE * 2, GuestPhysAddr::new(0), true, true); initialize_pagetables(unsafe { mem.as_slice_mut() }.try_into().unwrap()); From 355a3f404af6fd9476ea08cb432870524c7f4647 Mon Sep 17 00:00:00 2001 From: "Panagiotis \"Ivory\" Vasilopoulos" Date: Fri, 20 Sep 2024 15:49:31 +0200 Subject: [PATCH 2/2] test: improve output information - Print to stdout as soon as the kernel successfully boots - Print to stdout in run_simple_vm to make it clear that the kernel has been compiled - Clarify the test-kernel being built, as the "name mismatch" between fs-test.rs and create_file.rs can be a bit confusing - Add newline between build_hermit_bin + run_simple_vm output and output coming from the kernel - Minor linguistic improvements These changes may seem redundant to the trained eye (for example, it is safe to assume that the output starting with "frequency: ..." is from the kernel, thus everything that follows is from the kernel), but can be very helpful to beginners. Based on local changes that I created for personal use, so as to better understand the debugging process. --- tests/common.rs | 7 +++++-- tests/gdb.rs | 1 + tests/test-kernels/src/bin/create_file.rs | 2 ++ tests/test-kernels/src/bin/gdb.rs | 2 ++ tests/test-kernels/src/bin/serial.rs | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/common.rs b/tests/common.rs index a8c4cf64..bdd9f58f 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -11,8 +11,9 @@ use uhyvelib::{params::Params, vm::UhyveVm}; /// Returns a path to the build binary. pub fn build_hermit_bin(kernel: impl AsRef) -> PathBuf { let kernel = kernel.as_ref(); - println!("Building Kernel {}", kernel.display()); let kernel_src_path = Path::new("tests/test-kernels"); + println!("Building test kernel: {}", kernel.display()); + let cmd = Command::new("cargo") .arg("build") .arg("-Zbuild-std=std,panic_abort") @@ -26,7 +27,8 @@ pub fn build_hermit_bin(kernel: impl AsRef) -> PathBuf { .current_dir(kernel_src_path) .status() .expect("failed to execute `cargo build`"); - assert!(cmd.success(), "Test binaries could not be build"); + + assert!(cmd.success(), "Test binaries could not be built."); [ kernel_src_path, Path::new("target/x86_64-unknown-hermit/debug"), @@ -39,6 +41,7 @@ pub fn build_hermit_bin(kernel: impl AsRef) -> PathBuf { /// Small wrapper around [`Uhyve::run`] with default parameters for a small and /// simple Uhyve vm pub fn run_simple_vm(kernel_path: PathBuf) { + println!("Launching kernel {}", kernel_path.display()); let params = Params { verbose: true, cpu_count: 2.try_into().unwrap(), diff --git a/tests/gdb.rs b/tests/gdb.rs index b3593f6d..a2dbd33f 100644 --- a/tests/gdb.rs +++ b/tests/gdb.rs @@ -47,6 +47,7 @@ symbol-file {bin_path} -o 0x400000 break gdb::main continue +next next next pipe print _x|cat >> {output_path} diff --git a/tests/test-kernels/src/bin/create_file.rs b/tests/test-kernels/src/bin/create_file.rs index eff52a1f..943d5b14 100644 --- a/tests/test-kernels/src/bin/create_file.rs +++ b/tests/test-kernels/src/bin/create_file.rs @@ -4,6 +4,8 @@ use std::{fs::File, io::prelude::*}; use hermit as _; fn main() { + println!("Hello from create_file!"); + let mut file = File::create("/root/foo.txt").unwrap(); file.write_all(b"Hello, world!").unwrap(); } diff --git a/tests/test-kernels/src/bin/gdb.rs b/tests/test-kernels/src/bin/gdb.rs index 526d0e01..251946e3 100644 --- a/tests/test-kernels/src/bin/gdb.rs +++ b/tests/test-kernels/src/bin/gdb.rs @@ -4,6 +4,8 @@ use hermit as _; static mut WATCH: u8 = 2; fn main() { + println!("Hello from gdb!"); + let _x = 5; opaque(_x); let _x = 3.5; diff --git a/tests/test-kernels/src/bin/serial.rs b/tests/test-kernels/src/bin/serial.rs index dd1af2af..c8fb8e03 100644 --- a/tests/test-kernels/src/bin/serial.rs +++ b/tests/test-kernels/src/bin/serial.rs @@ -27,7 +27,7 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option { } fn main() { - println!("Test"); + println!("Hello from serial!"); let mut serial_byte_port = Port::new(HypercallAddress::Uart as u16); for c in "ABCD\n".bytes() {