Skip to content

Commit

Permalink
Merge pull request #759 from n0toose/test-output
Browse files Browse the repository at this point in the history
tests: improve output information
  • Loading branch information
jounathaen authored Nov 19, 2024
2 parents c0a8bac + 3813588 commit 7843de8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = vec![0; MIN_PHYSMEM_SIZE];
initialize_pagetables((&mut mem[0..MIN_PHYSMEM_SIZE]).try_into().unwrap());

Expand Down Expand Up @@ -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());

Expand Down
7 changes: 5 additions & 2 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> 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")
Expand All @@ -26,7 +27,8 @@ pub fn build_hermit_bin(kernel: impl AsRef<Path>) -> 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"),
Expand All @@ -39,6 +41,7 @@ pub fn build_hermit_bin(kernel: impl AsRef<Path>) -> 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(),
Expand Down
1 change: 1 addition & 0 deletions tests/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ symbol-file {bin_path} -o 0x400000
break gdb::main
continue
next
next
next
pipe print _x|cat >> {output_path}
Expand Down
2 changes: 2 additions & 0 deletions tests/test-kernels/src/bin/create_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions tests/test-kernels/src/bin/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/test-kernels/src/bin/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn virtual_to_physical(virtual_address: VirtAddr) -> Option<GuestPhysAddr> {
}

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() {
Expand Down

0 comments on commit 7843de8

Please sign in to comment.