From 23338de4c4f8d87343bab9a6aa8e1999bb774114 Mon Sep 17 00:00:00 2001 From: Qiu Wenbo Date: Mon, 2 Mar 2020 05:32:37 +0000 Subject: [PATCH] tests: add simple test case for ARM64 Image loader The test_image.bin is a cut of the first 4096 bytes of a pre-compiled linux kernel ARM64 Image. Signed-off-by: Qiu Wenbo --- src/loader/mod.rs | 25 +++++++++++++++++++++++-- src/loader/test_image.bin | Bin 0 -> 4000 bytes 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/loader/test_image.bin 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 0000000000000000000000000000000000000000..936281e823c5ea22ca152b5c871ee8ff4f6bf958 GIT binary patch literal 4000 zcmeZ`Vwm{f-b;jmfr9}8yct0>7nFyKat!iKaR5pNxH2%LtYSh@wt#_+iJOT@gkgaZ zBSU}$Snh|vCL@CYk}?n*RU1?iXg^dPAveHGV}mhBp!G^pD@s7>L2d-u2cwb9P+(w4 z&`U`yNd$?3{ILP3_7hMsh(-bq3=9Y46_~G%;?Xb|O#`E8U^ESkrh(BkFq#HN)4*sN S7)=ACX<#%BjHUr{(*OYQwEZ~% literal 0 HcmV?d00001