diff --git a/src/loader/mod.rs b/src/loader/mod.rs index 48612a4c..57e33603 100644 --- a/src/loader/mod.rs +++ b/src/loader/mod.rs @@ -513,8 +513,7 @@ impl KernelLoader for Image { #[cfg(test)] mod test { use super::*; - #[cfg(any(feature = "elf", feature = "bzimage"))] - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + #[cfg(any(feature = "elf", feature = "bzimage", feature = "image"))] use std::io::Cursor; use vm_memory::{Address, GuestAddress, GuestMemoryMmap}; @@ -541,6 +540,15 @@ mod test { v } + // first 4096 bytes of a precompiled ARM64 kernel Image. + #[cfg(feature = "image")] + #[cfg(target_arch = "aarch64")] + fn make_image_bin() -> Vec { + let mut v = Vec::new(); + v.extend_from_slice(include_bytes!("test_image.bin")); + v + } + #[allow(safe_packed_borrows)] #[allow(non_snake_case)] #[test] @@ -663,6 +671,19 @@ mod test { ); } + #[test] + #[cfg(feature = "image")] + #[cfg(target_arch = "aarch64")] + fn load_image() { + let gm = create_guest_mem(); + let image = make_image_bin(); + let kernel_addr = GuestAddress(0x200000); + + let loader_result = + Image::load(&gm, Some(kernel_addr), &mut Cursor::new(&image), None).unwrap(); + assert_eq!(loader_result.kernel_load.raw_value(), 0x280000); + } + #[test] fn cmdline_overflow() { let gm = create_guest_mem(); diff --git a/src/loader/test_image.bin b/src/loader/test_image.bin new file mode 100644 index 00000000..936281e8 Binary files /dev/null and b/src/loader/test_image.bin differ